本文整理汇总了Python中caffe2.python.core.config方法的典型用法代码示例。如果您正苦于以下问题:Python core.config方法的具体用法?Python core.config怎么用?Python core.config使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类caffe2.python.core
的用法示例。
在下文中一共展示了core.config方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: configure_bbox_reg_weights
# 需要导入模块: from caffe2.python import core [as 别名]
# 或者: from caffe2.python.core import config [as 别名]
def configure_bbox_reg_weights(model, saved_cfg):
"""Compatibility for old models trained with bounding box regression
mean/std normalization (instead of fixed weights).
"""
if 'MODEL' not in saved_cfg or 'BBOX_REG_WEIGHTS' not in saved_cfg.MODEL:
logger.warning('Model from weights file was trained before config key '
'MODEL.BBOX_REG_WEIGHTS was added. Forcing '
'MODEL.BBOX_REG_WEIGHTS = (1., 1., 1., 1.) to ensure '
'correct **inference** behavior.')
# Generally we don't allow modifying the config, but this is a one-off
# hack to support some very old models
is_immutable = cfg.is_immutable()
cfg.immutable(False)
cfg.MODEL.BBOX_REG_WEIGHTS = (1., 1., 1., 1.)
cfg.immutable(is_immutable)
logger.info('New config:')
logger.info(pprint.pformat(cfg))
assert not model.train, (
'This model was trained with an older version of the code that '
'used bounding box regression mean/std normalization. It can no '
'longer be used for training. To upgrade it to a trainable model '
'please use fb/compat/convert_bbox_reg_normalized_model.py.'
)
示例2: parse_args
# 需要导入模块: from caffe2.python import core [as 别名]
# 或者: from caffe2.python.core import config [as 别名]
def parse_args():
parser = argparse.ArgumentParser(
description='Train a network with Detectron'
)
parser.add_argument(
'--cfg',
dest='cfg_file',
help='Config file for training (and optionally testing)',
default=None,
type=str
)
parser.add_argument(
'opts',
help='See lib/core/config.py for all options',
default=None,
nargs=argparse.REMAINDER
)
if len(sys.argv) == 1:
parser.print_help()
sys.exit(1)
return parser.parse_args()
示例3: configure_bbox_reg_weights
# 需要导入模块: from caffe2.python import core [as 别名]
# 或者: from caffe2.python.core import config [as 别名]
def configure_bbox_reg_weights(model, saved_cfg):
"""Compatibility for old models trained with bounding box regression
mean/std normalization (instead of fixed weights).
"""
if 'MODEL' not in saved_cfg or 'BBOX_REG_WEIGHTS' not in saved_cfg.MODEL:
logger.warning('Model from weights file was trained before config key '
'MODEL.BBOX_REG_WEIGHTS was added. Forcing '
'MODEL.BBOX_REG_WEIGHTS = (1., 1., 1., 1.) to ensure '
'correct **inference** behavior.')
cfg.MODEL.BBOX_REG_WEIGHTS = (1., 1., 1., 1.)
logger.info('New config:')
logger.info(pprint.pformat(cfg))
assert not model.train, (
'This model was trained with an older version of the code that '
'used bounding box regression mean/std normalization. It can no '
'longer be used for training. To upgrade it to a trainable model '
'please use fb/compat/convert_bbox_reg_normalized_model.py.'
)
示例4: parse_args
# 需要导入模块: from caffe2.python import core [as 别名]
# 或者: from caffe2.python.core import config [as 别名]
def parse_args():
parser = argparse.ArgumentParser(description='Run DetectandTrack on a single video and visualize the results')
parser.add_argument(
'--cfg', '-c', dest='cfg_file', required=True,
help='Config file to run')
parser.add_argument(
'--video', '-v', dest='video_path',
help='Path to Video',
required=True)
parser.add_argument(
'--output', '-o', dest='out_path',
help='Path to Output')
parser.add_argument(
'opts', help='See lib/core/config.py for all options', default=None,
nargs=argparse.REMAINDER)
if len(sys.argv) == 1:
parser.print_help()
sys.exit(1)
return parser.parse_args()
示例5: configure_bbox_reg_weights
# 需要导入模块: from caffe2.python import core [as 别名]
# 或者: from caffe2.python.core import config [as 别名]
def configure_bbox_reg_weights(model, saved_cfg):
if 'MODEL' not in saved_cfg or 'BBOX_REG_WEIGHTS' not in saved_cfg.MODEL:
logger.warning('Model from weights file was trained before config key '
'MODEL.BBOX_REG_WEIGHTS was added. Forcing '
'MODEL.BBOX_REG_WEIGHTS = (1., 1., 1., 1.) to ensure '
'correct **inference** behavior.')
cfg.MODEL.BBOX_REG_WEIGHTS = (1., 1., 1., 1.)
logger.info('New config:')
logger.info(pprint.pformat(cfg))
assert not model.train, 'This mode should only be used for inference'
示例6: parse_args
# 需要导入模块: from caffe2.python import core [as 别名]
# 或者: from caffe2.python.core import config [as 别名]
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument(
'--loaders', dest='num_loaders',
help='Number of data loading threads',
default=4, type=int)
parser.add_argument(
'--dequeuers', dest='num_dequeuers',
help='Number of dequeuers',
default=1, type=int)
parser.add_argument(
'--minibatch-queue-size', dest='minibatch_queue_size',
help='Size of minibatch queue',
default=64, type=int)
parser.add_argument(
'--blobs-queue-capacity', dest='blobs_queue_capacity',
default=8, type=int)
parser.add_argument(
'--num-batches', dest='num_batches',
help='Number of minibatches to run',
default=200, type=int)
parser.add_argument(
'--sleep', dest='sleep_time',
help='Seconds sleep to emulate a network running',
default=0.1, type=float)
parser.add_argument(
'--cfg', dest='cfg_file', help='optional config file', default=None,
type=str)
parser.add_argument(
'--x-factor', dest='x_factor', help='simulates x-factor more GPUs',
default=1, type=int)
parser.add_argument(
'--profiler', dest='profiler', help='profile minibatch load time',
action='store_true')
parser.add_argument(
'opts', help='See lib/core/config.py for all options', default=None,
nargs=argparse.REMAINDER)
if len(sys.argv) == 1:
parser.print_help()
sys.exit(1)
args = parser.parse_args()
return args
示例7: parse_args
# 需要导入模块: from caffe2.python import core [as 别名]
# 或者: from caffe2.python.core import config [as 别名]
def parse_args():
parser = argparse.ArgumentParser(
description='Convert a trained network to pb format'
)
parser.add_argument(
'--cfg', dest='cfg_file', help='optional config file', default=None,
type=str)
parser.add_argument(
'--net_name', dest='net_name', help='optional name for the net',
default="detectron", type=str)
parser.add_argument(
'--out_dir', dest='out_dir', help='output dir', default=None,
type=str)
parser.add_argument(
'--test_img', dest='test_img',
help='optional test image, used to verify the model conversion',
default=None,
type=str)
parser.add_argument(
'--fuse_af', dest='fuse_af', help='1 to fuse_af',
default=1,
type=int)
parser.add_argument(
'--device', dest='device',
help='Device to run the model on',
choices=['cpu', 'gpu'],
default='cpu',
type=str)
parser.add_argument(
'--net_execution_type', dest='net_execution_type',
help='caffe2 net execution type',
choices=['simple', 'dag'],
default='simple',
type=str)
parser.add_argument(
'--use_nnpack', dest='use_nnpack',
help='Use nnpack for conv',
default=1,
type=int)
parser.add_argument(
'opts', help='See lib/core/config.py for all options', default=None,
nargs=argparse.REMAINDER)
if len(sys.argv) == 1:
parser.print_help()
sys.exit(1)
ret = parser.parse_args()
ret.out_dir = os.path.abspath(ret.out_dir)
if ret.device == 'gpu' and ret.use_nnpack:
logger.warn('Should not use mobile engine for gpu model.')
ret.use_nnpack = 0
return ret
示例8: main
# 需要导入模块: from caffe2.python import core [as 别名]
# 或者: from caffe2.python.core import config [as 别名]
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)
示例9: parse_args
# 需要导入模块: from caffe2.python import core [as 别名]
# 或者: from caffe2.python.core import config [as 别名]
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument(
'--loaders', dest='num_loaders',
help='Number of data loading threads',
default=4, type=int)
parser.add_argument(
'--dequeuers', dest='num_dequeuers',
help='Number of dequeuers',
default=1, type=int)
parser.add_argument(
'--minibatch-queue-size', dest='minibatch_queue_size',
help='Size of minibatch queue',
default=64, type=int)
parser.add_argument(
'--blobs-queue-capacity', dest='blobs_queue_capacity',
default=8, type=int)
parser.add_argument(
'--num-batches', dest='num_batches',
help='Number of minibatches to run',
default=500, type=int)
parser.add_argument(
'--sleep', dest='sleep_time',
help='Seconds sleep to emulate a network running',
default=0.1, type=float)
parser.add_argument(
'--cfg', dest='cfg_file', help='optional config file', default=None,
type=str)
parser.add_argument(
'--x-factor', dest='x_factor', help='simulates x-factor more GPUs',
default=1, type=int)
parser.add_argument(
'--profiler', dest='profiler', help='profile minibatch load time',
action='store_true')
parser.add_argument(
'opts', help='See lib/core/config.py for all options', default=None,
nargs=argparse.REMAINDER)
if len(sys.argv) == 1:
parser.print_help()
sys.exit(1)
args = parser.parse_args()
return args