def check_sanity(self): for i in tqdm(self.image_ids): assert self.image_files[i][:-4] == self.label_files[i][:-4],\ 'image - label filename mismatch: {} - {}'.format(self.image_files[i], self.label_files[i]) img = load_image_rgb( os.path.join(self.image_dir, self.image_files[i])) msk = load_image_rgb( os.path.join(self.label_dir, self.label_files[i])) assert img.shape == msk.shape,\ 'img.shape: {}, msk.shape: {}'.format(img.shape, msk.shape)
def display(self): should_update = super(GuiInferenceViewer, self).display() if should_update: image_file = self.image_files[self.image_id] print('Processing {}...'.format(os.path.basename(image_file))) img = load_image_rgb(image_file) t = time.time() det = self.model.predict(img.astype(np.float32), self.threshold) time_taken = time.time() - t print("\ttime taken: {}".format(time_taken)) if self.model.config.MODEL == 'maskrcnn': display_instances(image=img, boxes=det['rois'], masks=det['masks'], class_ids=det['class_ids'], scores=det['scores'], title=image_file, class_names=self.class_names, ax=self.ax) else: display_segmentation(image=img, masks=det, class_names=self.class_names, ax=self.ax) title = "ID: {}\nImage file name: {}".format( self.image_id, os.path.basename(image_file)) self.fig.suptitle(title, fontsize=20) self.fig.canvas.draw_idle()
def display(self): should_update = super(GuiImageViewer, self).display() if should_update: image_file = self.image_files[self.image_id] print('Processing {}...'.format(os.path.basename(image_file))) img = load_image_rgb(image_file) self.ax.imshow(img.astype(np.uint8)) title = "ID: {}\nImage file name: {}".format( self.image_id, os.path.basename(image_file)) self.fig.suptitle(title, fontsize=20) self.fig.canvas.draw_idle()
def load_mask(self, image_id): rgb_mask = load_image_rgb( os.path.join(self.label_dir, self.label_files[image_id])) mask = np.zeros( (rgb_mask.shape[0], rgb_mask.shape[1], self.num_classes - 1)) for cls in range(self.num_classes - 1): colors = self.trainId2colors[cls] cls_mask = np.zeros((rgb_mask.shape[0], rgb_mask.shape[1])) for color in colors: cls_mask = np.logical_or(cls_mask, (rgb_mask == color).all(axis=2)) mask[:, :, cls] = cls_mask return mask
model.load_weights(args.weights) image_files = sorted([ os.path.join(args.image_dir, x) for x in os.listdir(args.image_dir) if x.lower().endswith('.jpg') or x.lower().endswith('.png') or x.lower().endswith('.bmp') ]) dst_dir = os.path.join(args.image_dir, 'results') if not os.path.exists(dst_dir): os.mkdir(dst_dir) for image_file in image_files: filename = os.path.basename(image_file) print('Processing {}...'.format(filename)) img = load_image_rgb(image_file) t = time.time() det = model.predict(img.astype(np.float32), args.threshold) time_taken = time.time() - t print("\ttime taken: {}".format(time_taken)) if model.config.MODEL == 'maskrcnn': res = draw_instances(image=img, boxes=det['rois'], masks=det['masks'], class_ids=det['class_ids'], scores=det['scores'], title=image_file, class_names=label) else: res = draw_segmentation(image=img, masks=det, class_names=label)
def load_image(self, image_id): return load_image_rgb( os.path.join(self.image_dir, self.image_files[image_id]))
def load_image(self, image_id): return load_image_rgb(self.annotations[image_id]['path'])
def load_image(self, image_id): image = load_image_rgb(self.image_info[image_id]['path']) return image