示例#1
0
    def visualization(self, image_index, save_dir):
        '''
        visualize the images loaded into the dataset
        '''
        image_path = self.image_info[image_index]['path']
        _, filename, _ = fileparts(image_path)
        image = self.load_image(image_index)

        masks, class_ids = self.load_mask(image_index)
        bbox = bboxes_from_mask(masks)  # TLBR format, N x 4
        fig, _ = visualize_image_with_bbox_mask(image,
                                                boxes=bbox,
                                                masks=masks,
                                                class_ids=class_ids,
                                                class_names=['BG'] +
                                                cityscape_class_names)
        save_path_tmp = os.path.join(save_dir, filename + '.jpg')
        save_vis_close_helper(fig=fig,
                              transparent=False,
                              save_path=save_path_tmp)
示例#2
0
                                              pin_memory=True)

count = 1
vis_dir = os.path.join(dataset_dir, gttype, 'vis_%s' % split)
mkdir_if_missing(vis_dir)
for images, image_metas, rpn_match, rpn_bbox, gt_class_ids, gt_boxes, gt_masks, image_index, filename in train_generator:
    print('Cityscapes Dataset Visualization Processing: %d' % count)
    # dataset_cityscape.visualization(image_index.item(), save_dir=vis_dir)

    image_path = dataset_cityscape.image_info[image_index.item()]['path']
    _, filename, _ = fileparts(image_path)

    images = images.numpy()[0].transpose(1, 2, 0)
    images = unmold_image(images, config)
    gt_masks, gt_boxes, gt_class_ids = gt_masks.numpy()[0], gt_boxes.numpy(
    )[0].astype('int64'), gt_class_ids.numpy()[0]
    gt_masks = gt_masks.transpose(1, 2, 0)
    gt_masks = expand_mask(gt_boxes, gt_masks, images.shape)
    gt_boxes[:, [0, 1]] = gt_boxes[:, [1, 0]]
    gt_boxes[:, [2, 3]] = gt_boxes[:, [3, 2]]

    fig, _ = visualize_image_with_bbox_mask(images,
                                            boxes=gt_boxes,
                                            masks=gt_masks,
                                            class_ids=gt_class_ids,
                                            class_names=['BG'] +
                                            cityscape_class_names)
    save_path_tmp = os.path.join(vis_dir, filename + '.jpg')
    save_vis_close_helper(fig=fig, transparent=False, save_path=save_path_tmp)

    count += 1