dataset = CityscapeDataset() dataset.load_cityscape(args.data_dir, "val", args.num_frames, args.fix) dataset.prepare() print("Image Count: {}".format(len(dataset.image_ids))) resnet = ResNet(config=config) flownet = FlowNet(config=config) maskrcnn = MaskRCNN(config=config) warp = Warp(config=config) decision = Decision(config=config) model_path = args.restore_from resnet.load_weights(model_path, by_name=True) flownet.load_weights(model_path, by_name=True) maskrcnn.load_weights(model_path, by_name=True) decision.load_weights(args.decision_from, by_name=True) AP50s = [] APs = [] seg_step = 0 flow_step = 0 score = 0 if args.method == 2: target = -args.target else: target = args.target if args.is_save and not os.path.exists(args.save_dir): os.makedirs(args.save_dir) for image_id in range(len(dataset.image_ids)): # Load image and ground truth data image, image_meta, gt_class_id, gt_bbox, gt_mask =\
def main(): args = get_arguments() print(args) config = CityscapeConfig() config.FLOW = args.flowmodel config.BACKBONE = args.resnetmodel config.IMAGE_SHAPE = [1024, 1024, 6] config.POST_NMS_ROIS_INFERENCE = 500 #config.display() resnet = ResNet(config=config) flownet = FlowNet(config=config) maskrcnn = MaskRCNN(config=config) warp = Warp(config=config) decision = Decision(config=config) model_path = args.restore_from resnet.load_weights(model_path, by_name=True) flownet.load_weights(model_path, by_name=True) maskrcnn.load_weights(model_path, by_name=True) decision.load_weights(args.decision_from, by_name=True) seg_step = 0 flow_step = 0 target = args.target list_file = open(args.data_list, 'r') if args.is_save and not os.path.exists(args.save_dir): os.makedirs(args.save_dir) for step in range(args.num_steps): f1 = list_file.readline().split('\n')[0] f1 = os.path.join(args.data_dir, f1) current = np.expand_dims(skimage.io.imread(f1), 0) current, image_metas, window = mold_inputs(config, current) image = current[0] + config.MEAN_PIXEL if step == 0: seg_step += 1 key_P2, key_P3, key_P4, key_P5, key_P6 = resnet.keras_model.predict( current) key = current P2, P3, P4, P5, P6 = key_P2, key_P3, key_P4, key_P5, key_P6 else: images = np.concatenate([current, key], 3) flow, flow_feature = flownet.keras_model.predict(images) score = decision.keras_model.predict(flow_feature)[0][0] print("step: {:4d} predict score: {:.3f} target: {:.2f}".format( step, score, target)) if score < target: if args.dynamic and target < 50: target -= 0.5 seg_step += 1 key_P2, key_P3, key_P4, key_P5, key_P6 = resnet.keras_model.predict( current) key = current P2, P3, P4, P5, P6 = key_P2, key_P3, key_P4, key_P5, key_P6 else: if args.dynamic and target < 95: target += 0.25 flow_step += 1 P2, P3, P4, P5, P6 = warp.predict( [key_P2, key_P3, key_P4, key_P5, key_P6, flow]) inputs = [image_metas, P2, P3, P4, P5, P6] result = maskrcnn.detect_molded(inputs) # Save if args.is_save: save_name = args.save_dir + 'mask' + str(step) + '.png' colors = np.array(label_colors) / 255.0 pred_img = visualize.display_instances(image, result['rois'], result['masks'], result['class_ids'], class_names, result['scores'], colors=colors, save_name=save_name) print("segmentation steps:", seg_step, "flow steps:", flow_step)