Views
No views yet
| Model | Download | Download (with sample test data) | ONNX version | Opset version | Accuracy |
|---|---|---|---|---|---|
| Mask R-CNN R-50-FPN | 177.9 MB | 168.8 MB | 1.5 | 10 | mAP of 0.36 & 0.33 |
| Mask R-CNN R-50-FPN-fp32 | 169.7 MB | 157.3 MB | 1.9 | 12 | mAP of 0.3372 |
| Mask R-CNN R-50-FPN-int8 | 44 MB | 38 MB | 1.9 | 12 | mAP of 0.3314 |
| Mask R-CNN R-50-FPN-qdq | 44 MB | 30 MB | 1.9 | 12 | mAP of 0.3328 |
Compared with the Mask R-CNN R-50-FPN-fp32, Mask R-CNN R-50-FPN-int8's mAP decline is 0.0058 and performance improvement is 1.99x.Note the performance depends on the test hardware.Performance data here is collected with Intel® Xeon® Platinum 8280 Processor, 1s 4c per instance, CentOS Linux 8.3, data batch size is 1.
(3x'height'x'width')1import numpy as np
2from PIL import Image
3
4def preprocess(image):
5# Resize
6ratio = 800.0 / min(image.size[0], image.size[1])
7image = image.resize((int(ratio * image.size[0]), int(ratio * image.size[1])), Image.BILINEAR)
8
9# Convert to BGR
10image = np.array(image)[:, :, [2, 1, 0]].astype('float32')
11
12# HWC -> CHW
13image = np.transpose(image, [2, 0, 1])
14
15# Normalize
16mean_vec = np.array([102.9801, 115.9465, 122.7717])
17for i in range(image.shape[0]):
18image[i, :, :] = image[i, :, :] - mean_vec[i]
19
20# Pad to be divisible of 32
21import math
22padded_h = int(math.ceil(image.shape[1] / 32) * 32)
23padded_w = int(math.ceil(image.shape[2] / 32) * 32)
24
25padded_image = np.zeros((3, padded_h, padded_w), dtype=np.float32)
26padded_image[:, :image.shape[1], :image.shape[2]] = image
27image = padded_image
28
29return image
30
31img = Image.open('dependencies/demo.jpg')
32img_data = preprocess(img)('nbox'x4), in (xmin, ymin, xmax, ymax).('nbox').('nbox').('nbox', 1, 28, 28).1import matplotlib.pyplot as plt
2import matplotlib.patches as patches
3
4import pycocotools.mask as mask_util
5import cv2
6
7classes = [line.rstrip('\n') for line in open('coco_classes.txt')]
8
9def display_objdetect_image(image, boxes, labels, scores, masks, score_threshold=0.7):
10# Resize boxes
11ratio = 800.0 / min(image.size[0], image.size[1])
12boxes /= ratio
13
14_, ax = plt.subplots(1, figsize=(12,9))
15
16image = np.array(image)
17
18for mask, box, label, score in zip(masks, boxes, labels, scores):
19# Showing boxes with score > 0.7
20if score <= score_threshold:
21continue
22
23# Finding contour based on mask
24mask = mask[0, :, :, None]
25int_box = [int(i) for i in box]
26mask = cv2.resize(mask, (int_box[2]-int_box[0]+1, int_box[3]-int_box[1]+1))
27mask = mask > 0.5
28im_mask = np.zeros((image.shape[0], image.shape[1]), dtype=np.uint8)
29x_0 = max(int_box[0], 0)
30x_1 = min(int_box[2] + 1, image.shape[1])
31y_0 = max(int_box[1], 0)
32y_1 = min(int_box[3] + 1, image.shape[0])
33mask_y_0 = max(y_0 - box[1], 0)
34mask_y_1 = mask_y_0 + y_1 - y_0
35mask_x_0 = max(x_0 - box[0], 0)
36mask_x_1 = mask_x_0 + x_1 - x_0
37im_mask[y_0:y_1, x_0:x_1] = mask[
38mask_y_0 : mask_y_1, mask_x_0 : mask_x_1
39]
40im_mask = im_mask[:, :, None]
41
42# OpenCV version 4.x
43contours, hierarchy = cv2.findContours(
44im_mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE
45)
46
47image = cv2.drawContours(image, contours, -1, 25, 3)
48
49rect = patches.Rectangle((box[0], box[1]), box[2] - box[0], box[3] - box[1], linewidth=1, edgecolor='b', facecolor='none')
50ax.annotate(classes[label] + ':' + str(np.round(score, 2)), (box[0], box[1]), color='w', fontsize=12)
51ax.add_patch(rect)
52
53ax.imshow(image)
54plt.show()
55
56display_objdetect_image(img, boxes, labels, scores, masks)coco_2014_minival dataset from COCO, which is exactly equivalent to the coco_2017_val dataset.wget https://github.com/onnx/models/raw/main/vision/object_detection_segmentation/mask-rcnn/model/MaskRCNN-12.onnx1bash run_tuning.sh --input_model=path/to/model \ # model path as *.onnx
2--config=mask_rcnn.yaml \
3--data_path=path/to/COCO2017 \
4--output_model=path/to/save