Skip to content

4c Instance segmentation

Hou Yujun edited this page Nov 12, 2024 · 3 revisions

Inference

The script inference.py utilises a Mask2Former model pretrained on the Mapillary Vistas Dataset to perform instance segmentation for each input image, producing both pixel counts from semantic segmentation and instance counts from instance detection, for 65 object categories.

Set up environment with requirements-cv-linux.txt.

Input

The input CSV should:

  • have each row representing an image to process, and
  • contain minimally two columns, named uuid and path, to specify image UUID and the local image file path, respectively

Output

Two CSVs:

  • segmentation.csv for pixel counts from semantic segmentation
  • instances.csv for for instance counts from instance detection

To reproduce output in sample_output

Simply modify out_Folder (path to the folder to store output CSVs) in inference.py, then run

python3 inference.py

To run inference for other images

Modify inference.py:

  1. Modify out_Folder to the directory you wish to store the output CSVs
  2. Modify in_Path to the path of your input CSV

Run:

python3 inference.py

Acknowledgements

This part of our work is based on models from facebook/mask2former-swin-large-mapillary-vistas-panoptic by Cheng et al. (2022).