def __init__(self, name, project): fname = "{}-{}.h5".format(name, project) self.fname = os.path.join(DIR, fname) # Uses default im_list config = utils.get_config(project) self.im_list = utils.open_im_list(config["im_list"]) self.n = len(self.im_list) self.save_freq = 10 # Metrics # im x NUMCLASS self.load() assert self.precision.shape[0] == self.n assert self.recall.shape[0] == self.n assert self.iou.shape[0] == self.n
gt_s = image_utils.scale_maxside(gt, maxside=maxside) box = image_utils.random_crop(img_s) data = image_utils.crop_array(img_s, box) label = image_utils.crop_array(gt_s, box) # Batch size of 1 data = data[np.newaxis, ...] label = label[np.newaxis, ...] yield (data, label) if __name__ == "__main__": project = "local" config = utils.get_config(project) im_list = utils.open_im_list(config["im_list"]) datasource = DataSource(config) generator = DataGenerator(im_list, datasource, maxside=512) data, label = generator.next() print data.shape print label.shape data = data[0] label = label[0] unlabeled = np.max(label, axis=2) == 0 gt = np.argmax(label, axis=2) + 1 gt[unlabeled] = 0 gt = utils.add_color(gt)
config = utils.get_config(args.project) if args.prediction is not None: config["pspnet_prediction"] = args.prediction datasource = DataSource(config) evaluator = Evaluator(args.name, args.project, datasource) # Evaluation results vis = ProjectVisualizer(args.project, datasource, MAX=args.number, evaluator=evaluator) # Image List im_list = None if args.im_list: # Open specific image list im_list = utils.open_im_list(args.im_list) elif args.category: im_list = evaluator.get_im_list_by_category(args.category) else: # Open default image list im_list = utils.open_im_list(config["im_list"]) if args.randomize: # Shuffle image list random.seed(3) random.shuffle(im_list) im_list = im_list[args.start:] vis.visualize_images(im_list, category=args.category)
img_color = np.zeros((h,w,3)) for i in xrange(1,151): img_color[img == i] = utils.to_color(i) path = self.save(img_color) return img_color, path def save(self, img): fname = "{}.jpg".format(uuid.uuid4().hex) path = os.path.join(IMAGES_DIR, fname) misc.imsave(path, img) return path if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument('-p', '--project', required=True, help="Project name") parser.add_argument('-i', '--image', help="Image name") args = parser.parse_args() im = args.image if not args.image: im_list = utils.open_im_list(args.project) im = im_list[0] print args.project, im config = utils.get_config(args.project) datasource = DataSource(config) vis = ImageVisualizer(args.project, datasource) paths = vis.visualize(im) print paths