def main(): workspace.GlobalInit(['caffe2', '--caffe2_log_level=0']) args = parse_args() logger.info('Called with args:') logger.info(args) if args.cfg_file is not None: merge_cfg_from_file(args.cfg_file) if args.opts is not None: merge_cfg_from_list(args.opts) cfg.NUM_GPUS = 1 assert_and_infer_cfg() logger.info('Conerting model with config:') logger.info(pprint.pformat(cfg)) assert not cfg.MODEL.KEYPOINTS_ON, "Keypoint model not supported." assert not cfg.MODEL.MASK_ON, "Mask model not supported." assert not cfg.FPN.FPN_ON, "FPN not supported." assert not cfg.RETINANET.RETINANET_ON, "RetinaNet model not supported." # load model from cfg model, blobs = load_model(args) net = core.Net('') net.Proto().op.extend(copy.deepcopy(model.net.Proto().op)) net.Proto().external_input.extend( copy.deepcopy(model.net.Proto().external_input)) net.Proto().external_output.extend( copy.deepcopy(model.net.Proto().external_output)) net.Proto().type = args.net_execution_type net.Proto().num_workers = 1 if args.net_execution_type == 'simple' else 4 # Reset the device_option, change to unscope name and replace python operators convert_net(args, net.Proto(), blobs) # add operators for bbox add_bbox_ops(args, net, blobs) if args.fuse_af: print('Fusing affine channel...') net, blobs = mutils.fuse_net_affine( net, blobs) if args.use_nnpack: mutils.update_mobile_engines(net.Proto()) # generate init net empty_blobs = ['data', 'im_info'] init_net = gen_init_net(net, blobs, empty_blobs) if args.device == 'gpu': [net, init_net] = convert_model_gpu(args, net, init_net) net.Proto().name = args.net_name init_net.Proto().name = args.net_name + "_init" if args.test_img is not None: verify_model(args, [net, init_net], args.test_img) _save_models(net, init_net, args)
def main(): workspace.GlobalInit(['caffe2', '--caffe2_log_level=0']) args = parse_args() logger.info('Called with args:') logger.info(args) if args.cfg_file is not None: merge_cfg_from_file(args.cfg_file) if args.opts is not None: merge_cfg_from_list(args.opts) cfg.NUM_GPUS = 1 assert_and_infer_cfg() logger.info('Conerting model with config:') logger.info(pprint.pformat(cfg)) assert not cfg.MODEL.KEYPOINTS_ON, "Keypoint model not supported." assert not cfg.MODEL.MASK_ON, "Mask model not supported." assert not cfg.FPN.FPN_ON, "FPN not supported." assert not cfg.RETINANET.RETINANET_ON, "RetinaNet model not supported." # load model from cfg model, blobs = load_model(args) net = core.Net('') net.Proto().op.extend(copy.deepcopy(model.net.Proto().op)) net.Proto().external_input.extend( copy.deepcopy(model.net.Proto().external_input)) net.Proto().external_output.extend( copy.deepcopy(model.net.Proto().external_output)) net.Proto().type = args.net_execution_type net.Proto().num_workers = 1 if args.net_execution_type == 'simple' else 4 # Reset the device_option, change to unscope name and replace python operators convert_net(args, net.Proto(), blobs) # add operators for bbox add_bbox_ops(args, net, blobs) if args.fuse_af: print('Fusing affine channel...') net, blobs = mutils.fuse_net_affine( net, blobs) if args.use_nnpack: mutils.update_mobile_engines(net.Proto()) # generate init net empty_blobs = ['data', 'im_info'] init_net = gen_init_net(net, blobs, empty_blobs) if args.device == 'gpu': [net, init_net] = convert_model_gpu(args, net, init_net) net.Proto().name = args.net_name init_net.Proto().name = args.net_name + "_init" if args.test_img is not None: verify_model(args, [net, init_net], args.test_img) _save_models(net, init_net, args)
def convert_main_net(args, main_net, blobs): net = core.Net('') net.Proto().op.extend(copy.deepcopy(main_net.op)) net.Proto().external_input.extend(copy.deepcopy(main_net.external_input)) net.Proto().external_output.extend(copy.deepcopy(main_net.external_output)) net.Proto().type = args.net_execution_type net.Proto().num_workers = 1 if args.net_execution_type == 'simple' else 4 convert_tools.convert_net(args, net.Proto(), blobs) convert_tools.add_bbox_ops(args, net, blobs) if args.fuse_af: print('Fusing affine channel...') net, blobs = mutils.fuse_net_affine(net, blobs) if args.use_nnpack: mutils.update_mobile_engines(net.Proto()) empty_blobs = ['data', 'im_info'] init_net = convert_tools.gen_init_net(net, blobs, empty_blobs) if args.device == 'gpu': [net, init_net] = convert_tools.convert_model_gpu(args, net, init_net) net.Proto().name = args.net_name init_net.Proto().name = args.net_name + '_init' save_model(net.Proto(), init_net.Proto(), args.out_dir)
def convert_main_net(args, main_net, blobs): net = core.Net('') net.Proto().op.extend(copy.deepcopy(main_net.op)) net.Proto().external_input.extend(copy.deepcopy(main_net.external_input)) net.Proto().external_output.extend(copy.deepcopy(main_net.external_output)) net.Proto().type = args.net_execution_type net.Proto().num_workers = 1 if args.net_execution_type == 'simple' else 4 convert_tools.convert_net(args, net.Proto(), blobs) convert_tools.add_bbox_ops(args, net, blobs) if args.fuse_af: print ('Fusing affine channel...') net, blobs = mutils.fuse_net_affine(net, blobs) if args.use_nnpack: mutils.update_mobile_engines(net.Proto()) empty_blobs = ['data', 'im_info'] init_net = convert_tools.gen_init_net(net, blobs, empty_blobs) if args.device == 'gpu': [net, init_net] = convert_tools.convert_model_gpu(args, net, init_net) net.Proto().name = args.net_name init_net.Proto().name = args.net_name + '_init' save_model(net.Proto(), init_net.Proto(), args.out_dir)
def main(): workspace.GlobalInit(["caffe2", "--caffe2_log_level=0"]) args = parse_args() logger.info("Called with args:") logger.info(args) if args.cfg_file is not None: merge_cfg_from_file(args.cfg_file) if args.opts is not None: merge_cfg_from_list(args.opts) cfg.NUM_GPUS = 1 assert_and_infer_cfg() logger.info("Converting model with config:") logger.info(pprint.pformat(cfg)) # script will stop when it can't find an operator rather # than stopping based on these flags # # assert not cfg.MODEL.KEYPOINTS_ON, "Keypoint model not supported." # assert not cfg.MODEL.MASK_ON, "Mask model not supported." # assert not cfg.FPN.FPN_ON, "FPN not supported." # assert not cfg.RETINANET.RETINANET_ON, "RetinaNet model not supported." # load model from cfg model, blobs = load_model(args) net = core.Net("") net.Proto().op.extend(copy.deepcopy(model.net.Proto().op)) net.Proto().external_input.extend( copy.deepcopy(model.net.Proto().external_input)) net.Proto().external_output.extend( copy.deepcopy(model.net.Proto().external_output)) net.Proto().type = args.net_execution_type net.Proto().num_workers = 1 if args.net_execution_type == "simple" else 4 # Reset the device_option, change to unscope name and replace python operators convert_net(args, net.Proto(), blobs) # add operators for bbox add_bbox_ops(args, net, blobs) if args.fuse_af: print("Fusing affine channel...") net, blobs = mutils.fuse_net_affine(net, blobs) if args.use_nnpack: mutils.update_mobile_engines(net.Proto()) # generate init net empty_blobs = ["data", "im_info"] init_net = gen_init_net(net, blobs, empty_blobs) if args.device == "gpu": [net, init_net] = convert_model_gpu(args, net, init_net) net.Proto().name = args.net_name init_net.Proto().name = args.net_name + "_init" if args.test_img is not None: verify_model(args, [net, init_net], args.test_img) if args.logdb == 1: output_file = os.path.join(args.out_dir, "model.logfiledb") _export_to_logfiledb(args, net, init_net, empty_blobs, output_file) else: _save_models(net, init_net, args)