This project performs instance segmentation on images using a pre-trained Mask R-CNN model.
The main steps are:
- Clone the Mask R-CNN repository
- Setup the Mask R-CNN model and load pre-trained weights
- Load and pre-process an input image
- Make predictions using the model
- Post-process and visualize results
- Install dependencies:
pip install -r requirements.txt
- Clone Mask R-CNN repo:
clone_repo("https://github.com/matterport/Mask_RCNN")
- Setup model and load weights:
config = MaskRCNNConfig() model = setup_model(config) load_weights(model, weights_path)
- Load input image:
img = load_and_display(image_path)
- Make predictions:
results = model.detect([img])
- Visualize predictions:
display_predictions(img, results[0], class_names)
The results
dictionary contains the following keys:
rois
: Bounding box coordinatesmasks
: Segmentation masksclass_ids
: Class IDs for each detectionscores
: Confidence scores
Post-processing functions include:
- Drawing bounding boxes on the image
- Calculating mask pixel sums
- Segmenting the image based on the highest scoring mask