1 from __future__
import print_function
8 import chainer_mask_rcnn
as cmr
10 print(
'chainer_mask_rcnn cannot be imported.')
20 class_names_path = osp.join(root_dir,
'class_names.txt')
21 with open(class_names_path,
'r') as f: 22 class_names = f.readlines() 27 images_dir = osp.join(root_dir,
'JPEGImages')
28 labels_dir = osp.join(root_dir,
'SegmentationClass')
29 for image_
in sorted(os.listdir(images_dir)):
30 image_path = osp.join(images_dir, image_)
31 basename = image_.rstrip(
'.jpg')
32 label_path = osp.join(labels_dir, basename +
'.npy')
33 self._images.append(image_path)
34 self._labels.append(label_path)
43 image = cv2.imread(image_path)
44 assert image.dtype == np.uint8
45 assert image.ndim == 3
47 label = np.load(label_path)
48 assert label.dtype == np.int32
49 assert label.ndim == 2
59 class_names_path = osp.join(root_dir,
'class_names.txt')
60 with open(class_names_path,
'r') as f: 61 class_names = f.readlines() 68 images_dir = osp.join(root_dir,
'JPEGImages')
69 class_labels_dir = osp.join(root_dir,
'SegmentationClass')
70 instance_labels_dir = osp.join(root_dir,
'SegmentationObject')
71 for image_
in sorted(os.listdir(images_dir)):
72 image_path = osp.join(images_dir, image_)
73 basename = image_.rstrip(
'.jpg')
74 class_label_path = osp.join(
75 class_labels_dir, basename +
'.npy')
76 instance_label_path = osp.join(
77 instance_labels_dir, basename +
'.npy')
78 self._images.append(image_path)
79 self._class_labels.append(class_label_path)
80 self._instance_labels.append(instance_label_path)
90 image = cv2.imread(image_path)
91 assert image.dtype == np.uint8
92 assert image.ndim == 3
94 class_label = np.load(class_label_path)
95 assert class_label.dtype == np.int32
96 assert class_label.ndim == 2
98 instance_label = np.load(instance_label_path)
100 instance_label[instance_label == 0] = -1
101 assert instance_label.dtype == np.int32
102 assert instance_label.ndim == 2
104 assert image.shape[:2] == class_label.shape == instance_label.shape
106 labels, bboxes, masks = cmr.utils.label2instance_boxes(
107 label_instance=instance_label, label_class=class_label,
110 masks = masks.astype(np.int32, copy=
False)
111 labels = labels.astype(np.int32, copy=
False)
113 bboxes = bboxes.astype(np.float32, copy=
False)
115 return image, bboxes, labels, masks
def __init__(self, root_dir)
def __init__(self, root_dir)