No account yet ?
Tested in Anaconda and Python 3.7
import mrcnn import mrcnn.config import mrcnn.model import mrcnn.visualize import cv2 import os CLASS_NAMES = ['BG', 'person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 'truck', 'boat', 'traffic light', 'fire hydrant', 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', 'baseball glove', 'skateboard', 'surfboard', 'tennis racket', 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot', 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', 'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', 'mouse', 'remote', 'keyboard', 'cell phone', 'microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase', 'scissors', 'teddy bear', 'hair drier', 'toothbrush'] class SimpleConfig(mrcnn.config.Config): NAME = "coco_inference" GPU_COUNT = 1 IMAGES_PER_GPU = 1 NUM_CLASSES = len(CLASS_NAMES) model = mrcnn.model.MaskRCNN(mode="inference", config=SimpleConfig(), model_dir=os.getcwd()) model.load_weights(filepath="mask_rcnn_coco.h5", by_name=True) image = cv2.imread("pexels-thirdman-9313620.jpg") image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) r = model.detect([image], verbose=0) r = r[0] mrcnn.visualize.display_instances(image=image, boxes=r['rois'], masks=r['masks'], class_ids=r['class_ids'], class_names=CLASS_NAMES, scores=r['scores'])
Source : https://blog.paperspace.com/mask-r-cnn-tensorflow-2-0-keras/
mask_rcnn_coco.h5 : https://github.com/matterport/Mask_RCNN/releases/download/v2.0/mask_rcnn_coco.h5
Mask R-CNN
Copyright (c) 2017 Matterport, Inc.
Welcome, my name is Eric Soupet and I am the administrator of the site elodees.com. elodees.com is a state of the art of Artificial Intelligence and aims to be collaborative, you can now offer content such as articles, events, tutorials, ... so don't hesitate !
Platform images credit : Pixabay - Pixabay License | Pexels - Pexels License