def __init__(self, gpu_id=None): self.gpu_id = gpu_id self.model = "fm-res39" self.model_path = fast_mask_root + "/models/" + self.model + ".test.prototxt" self.weight_path = fast_mask_root + "/params/" + self.model + "_final.caffemodel" self.threshold = 0.85 self.COLORS = COLORS self.br = cv_bridge.CvBridge() self.net = None self.save_and_display = rospy.get_param("~save_and_display", True) # load config if os.path.exists(fast_mask_root + "/configs/%szoom.json" % self.model): load_config(fast_mask_root + "/configs/%szoom.json" % self.model) else: print "Specified config does not exists, use the default config..." s = rospy.Service("fast_mask_segmentation_server", FastMaskSegmentation, self.handle_fast_mask_segmentation) rospy.spin()
parser.add_argument('--restore', dest='restore', type=str) parser.add_argument('--debug', dest='debug', type=bool, default=False) parser.add_argument('--init_weights', dest='init_weights', type=str, default='ResNet-50-model.caffemodel') parser.add_argument('--step', dest='step', type=int, default=int(1e5)) args = parser.parse_args() return args if __name__ == '__main__': args = parse_args() config.model = args.model config.solver_prototxt = args.model + '.solver.prototxt' if os.path.exists("configs/%s.json" % config.model): load_config("configs/%s.json" % config.model) else: print "The config file does not exist, use the default config..." caffe.set_mode_gpu() caffe.set_device(int(args.gpu_id)) setproctitle.setproctitle('spider ' + args.model) print 'models/%s' % config.solver_prototxt solver = caffe.SGDSolver('models/%s' % config.solver_prototxt) setproctitle.setproctitle(args.model) # restore if getattr(args, 'restore', None) is not None: solver.restore("params/%s" % args.restore) # finetune else:
return args if __name__ == '__main__': args = parse_args() # caffe setup caffe.set_mode_gpu() caffe.set_device(int(args.gpu_id)) net = caffe.Net('models/' + args.model + '.test.prototxt', 'params/' + args.init_weights, caffe.TEST) # load config if os.path.exists("configs/%s.json" % args.model): load_config("configs/%s.json" % args.model) else: print("Specified config does not exists, use the default config...") image = load_image(args.input_image) oh, ow = image.shape[:2] im_scale = config.TEST_SCALE * 1.0 / max(oh, ow) input_blob = image - config.RGB_MEAN input_blob = input_blob.transpose((2, 0, 1)) ih, iw = int(oh * im_scale), int(ow * im_scale) ih, iw = ih - ih % 4, iw - iw % 4 input_blob = resize_blob(input_blob, dest_shape=(ih, iw)) input_blob = input_blob[np.newaxis, ...] ret_masks, ret_scores = gen_masks(net, input_blob,
# caffe setup caffe.set_mode_gpu() gpu_id = 0 caffe.set_device(gpu_id) model = "fm-res39" init_weights = "fm-res39_final.caffemodel" input_image = fast_mask_root + "/images/frame0000.jpg" threshold = 0.85 net = caffe.Net(fast_mask_root + 'models/' + model + '.test.prototxt', fast_mask_root + 'params/' + init_weights, caffe.TEST) # load config if os.path.exists("configs/%s.json" % model): load_config("configs/%szoom.json" % model) else: print "Specified config does not exists, use the default config..." image = cv2.imread(input_image) image = image.astype(np.float64) oh, ow = image.shape[:2] im_scale = config.TEST_SCALE * 1.0 / max(oh, ow) input_blob = image - config.RGB_MEAN input_blob = input_blob.transpose((2, 0, 1)) ih, iw = int(oh * im_scale), int(ow * im_scale) ih, iw = ih - ih % 4, iw - iw % 4 input_blob = resize_blob(input_blob, dest_shape=(ih, iw)) input_blob = input_blob[np.newaxis, ...] ret_masks, ret_scores = gen_masks(net,
args = parser.parse_args() return args if __name__ == '__main__': args = parse_args() caffe.set_mode_gpu() caffe.set_device(int(args.gpu_id)) setproctitle.setproctitle(args.model_prototxt) net = caffe.Net('models/' + args.model_prototxt + ".test.prototxt", 'params/' + args.init_weights, caffe.TEST) if os.path.exists("configs/%s.json" % args.model_prototxt): load_config("configs/%s.json" % args.model_prototxt) else: print "Specified config does not exists, use the default config..." config.ANNOTATION_TYPE = "val2014" config.IMAGE_SET = "val2014" from spiders.coco_ssm_spider import COCOSSMDemoSpider spider = COCOSSMDemoSpider() ds = spider.dataset i = 0 while i < args.start_from: spider.next_idx() i += 1 timer = Timer()