本文整理汇总了Python中caffe2.python.workspace.CreateNet方法的典型用法代码示例。如果您正苦于以下问题:Python workspace.CreateNet方法的具体用法?Python workspace.CreateNet怎么用?Python workspace.CreateNet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类caffe2.python.workspace
的用法示例。
在下文中一共展示了workspace.CreateNet方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_model_pb
# 需要导入模块: from caffe2.python import workspace [as 别名]
# 或者: from caffe2.python.workspace import CreateNet [as 别名]
def load_model_pb(net_file, init_file=None, is_run_init=True, is_create_net=True):
net = core.Net("net")
if net_file is not None:
net.Proto().ParseFromString(open(net_file, "rb").read())
if init_file is None:
fn, ext = os.path.splitext(net_file)
init_file = fn + "_init" + ext
init_net = caffe2_pb2.NetDef()
init_net.ParseFromString(open(init_file, "rb").read())
if is_run_init:
workspace.RunNetOnce(init_net)
create_blobs_if_not_existed(net.external_inputs)
if net.Proto().name == "":
net.Proto().name = "net"
if is_create_net:
workspace.CreateNet(net)
return (net, init_net)
示例2: setup_model_for_training
# 需要导入模块: from caffe2.python import workspace [as 别名]
# 或者: from caffe2.python.workspace import CreateNet [as 别名]
def setup_model_for_training(model, weights_file, output_dir):
"""Loaded saved weights and create the network in the C2 workspace."""
logger = logging.getLogger(__name__)
add_model_training_inputs(model)
if weights_file:
# Override random weight initialization with weights from a saved model
nu.initialize_gpu_from_weights_file(model, weights_file, gpu_id=0)
# Even if we're randomly initializing we still need to synchronize
# parameters across GPUs
nu.broadcast_parameters(model)
workspace.CreateNet(model.net)
logger.info('Outputs saved to: {:s}'.format(os.path.abspath(output_dir)))
dump_proto_files(model, output_dir)
# Start loading mini-batches and enqueuing blobs
model.roi_data_loader.register_sigint_handler()
model.roi_data_loader.start(prefill=True)
return output_dir
示例3: _run_speed_test
# 需要导入模块: from caffe2.python import workspace [as 别名]
# 或者: from caffe2.python.workspace import CreateNet [as 别名]
def _run_speed_test(self, iters=5, N=1024):
"""This function provides an example of how to benchmark custom
operators using the Caffe2 'prof_dag' network execution type. Please
note that for 'prof_dag' to work, Caffe2 must be compiled with profiling
support using the `-DUSE_PROF=ON` option passed to `cmake` when building
Caffe2.
"""
net = core.Net('test')
net.Proto().type = 'prof_dag'
net.Proto().num_workers = 2
Y = net.BatchPermutation(['X', 'I'], 'Y')
Y_flat = net.FlattenToVec([Y], 'Y_flat')
loss = net.AveragedLoss([Y_flat], 'loss')
net.AddGradientOperators([loss])
workspace.CreateNet(net)
X = np.random.randn(N, 256, 14, 14)
for _i in range(iters):
I = np.random.permutation(N)
workspace.FeedBlob('X', X.astype(np.float32))
workspace.FeedBlob('I', I.astype(np.int32))
workspace.RunNet(net.Proto().name)
np.testing.assert_allclose(
workspace.FetchBlob('Y'), X[I], rtol=1e-5, atol=1e-08
)
示例4: initialize_model_from_cfg
# 需要导入模块: from caffe2.python import workspace [as 别名]
# 或者: from caffe2.python.workspace import CreateNet [as 别名]
def initialize_model_from_cfg(weights_file, gpu_id=0):
"""Initialize a model from the global cfg. Loads test-time weights and
creates the networks in the Caffe2 workspace.
"""
model = model_builder.create(cfg.MODEL.TYPE, train=False, gpu_id=gpu_id)
net_utils.initialize_gpu_from_weights_file(
model, weights_file, gpu_id=gpu_id,
)
model_builder.add_inference_inputs(model)
workspace.CreateNet(model.net)
workspace.CreateNet(model.conv_body_net)
if cfg.MODEL.MASK_ON:
workspace.CreateNet(model.mask_net)
if cfg.MODEL.KEYPOINTS_ON:
workspace.CreateNet(model.keypoint_net)
return model
示例5: create_model
# 需要导入模块: from caffe2.python import workspace [as 别名]
# 或者: from caffe2.python.workspace import CreateNet [as 别名]
def create_model(self, X, S_lengths, S_indices, T):
#setup tril indices for the interactions
offset = 1 if self.arch_interaction_itself else 0
num_fea = len(self.emb_l) + 1
tril_indices = np.array([j + i * num_fea
for i in range(num_fea) for j in range(i + offset)])
self.FeedBlobWrapper(self.tint + "_tril_indices", tril_indices)
# create compute graph
if T is not None:
# WARNING: RunNetOnce call is needed only if we use brew and ConstantFill.
# We could use direct calls to self.model functions above to avoid it
workspace.RunNetOnce(self.model.param_init_net)
workspace.CreateNet(self.model.net)
if self.test_net is not None:
workspace.CreateNet(self.test_net)
示例6: initialize_model_from_cfg
# 需要导入模块: from caffe2.python import workspace [as 别名]
# 或者: from caffe2.python.workspace import CreateNet [as 别名]
def initialize_model_from_cfg():
"""Initialize a model from the global cfg. Loads test-time weights and
creates the networks in the Caffe2 workspace.
"""
model = model_builder.create(cfg.MODEL.TYPE, train=False)
net_utils.initialize_from_weights_file(
model, cfg.TEST.WEIGHTS, broadcast=False
)
model_builder.add_inference_inputs(model)
workspace.CreateNet(model.net)
workspace.CreateNet(model.conv_body_net)
if cfg.MODEL.MASK_ON:
workspace.CreateNet(model.mask_net)
if cfg.MODEL.KEYPOINTS_ON:
workspace.CreateNet(model.keypoint_net)
return model
示例7: setup_model_for_training
# 需要导入模块: from caffe2.python import workspace [as 别名]
# 或者: from caffe2.python.workspace import CreateNet [as 别名]
def setup_model_for_training(model, output_dir):
"""Loaded saved weights and create the network in the C2 workspace."""
logger = logging.getLogger(__name__)
add_model_training_inputs(model)
if cfg.TRAIN.WEIGHTS:
# Override random weight initialization with weights from a saved model
nu.initialize_gpu_0_from_weights_file(model, cfg.TRAIN.WEIGHTS)
# Even if we're randomly initializing we still need to synchronize
# parameters across GPUs
nu.broadcast_parameters(model)
workspace.CreateNet(model.net)
logger.info('Outputs saved to: {:s}'.format(os.path.abspath(output_dir)))
dump_proto_files(model, output_dir)
# Start loading mini-batches and enqueuing blobs
model.roi_data_loader.register_sigint_handler()
model.roi_data_loader.start(prefill=True)
return output_dir
示例8: setup_model_for_training
# 需要导入模块: from caffe2.python import workspace [as 别名]
# 或者: from caffe2.python.workspace import CreateNet [as 别名]
def setup_model_for_training(model, weights_file, output_dir):
"""Loaded saved weights and create the network in the C2 workspace."""
logger = logging.getLogger(__name__)
if cfg.TRAIN.DOMAIN_ADAPTATION:
add_model_da_training_inputs(model)
else:
add_model_training_inputs(model)
if weights_file:
# Override random weight initialization with weights from a saved model
nu.initialize_gpu_from_weights_file(model, weights_file, gpu_id=0)
# Even if we're randomly initializing we still need to synchronize
# parameters across GPUs
nu.broadcast_parameters(model)
workspace.CreateNet(model.net)
logger.info('Outputs saved to: {:s}'.format(os.path.abspath(output_dir)))
dump_proto_files(model, output_dir)
# Start loading mini-batches and enqueuing blobs
model.roi_data_loader.register_sigint_handler()
model.roi_data_loader.start(prefill=True)
return output_dir
示例9: setup_model_for_training
# 需要导入模块: from caffe2.python import workspace [as 别名]
# 或者: from caffe2.python.workspace import CreateNet [as 别名]
def setup_model_for_training(model, weights_file, output_dir):
"""Loaded saved weights and create the network in the C2 workspace."""
logger = logging.getLogger(__name__)
add_model_training_inputs(model)
if weights_file:
# Override random weight initialization with weights from a saved model
nu.initialize_gpu_from_weights_file(model, weights_file, gpu_id=0)
nu.initialize_gpu_from_old_weights_file(model, weights_file, gpu_id=0)
# Even if we're randomly initializing we still need to synchronize
# parameters across GPUs
nu.broadcast_parameters(model)
workspace.CreateNet(model.net)
logger.info('Outputs saved to: {:s}'.format(os.path.abspath(output_dir)))
dump_proto_files(model, output_dir)
# Start loading mini-batches and enqueuing blobs
model.roi_data_loader.register_sigint_handler()
model.roi_data_loader.start(prefill=True)
return output_dir
示例10: initialize_model_from_cfg
# 需要导入模块: from caffe2.python import workspace [as 别名]
# 或者: from caffe2.python.workspace import CreateNet [as 别名]
def initialize_model_from_cfg(gpu_id=0):
"""Initialize a model from the global cfg. Loads test-time weights and
creates the networks in the Caffe2 workspace.
"""
model = model_builder.create(cfg.MODEL.TYPE, train=False, gpu_id=gpu_id)
net_utils.initialize_gpu_from_weights_file(
model, cfg.TEST.WEIGHTS, gpu_id=gpu_id,
)
model_builder.add_inference_inputs(model)
workspace.CreateNet(model.net)
workspace.CreateNet(model.conv_body_net)
if cfg.MODEL.MASK_ON:
workspace.CreateNet(model.mask_net)
if cfg.MODEL.KEYPOINTS_ON:
workspace.CreateNet(model.keypoint_net)
return model
示例11: setup_model_for_training
# 需要导入模块: from caffe2.python import workspace [as 别名]
# 或者: from caffe2.python.workspace import CreateNet [as 别名]
def setup_model_for_training(model, output_dir):
"""Loaded saved weights and create the network in the C2 workspace."""
logger = logging.getLogger(__name__)
add_model_training_inputs(model)
if cfg.TRAIN.WEIGHTS:
# Override random weight initialization with weights from a saved model
nu.initialize_gpu_from_weights_file(model, cfg.TRAIN.WEIGHTS, gpu_id=0)
# Even if we're randomly initializing we still need to synchronize
# parameters across GPUs
nu.broadcast_parameters(model)
workspace.CreateNet(model.net)
logger.info('Outputs saved to: {:s}'.format(os.path.abspath(output_dir)))
dump_proto_files(model, output_dir)
# Start loading mini-batches and enqueuing blobs
model.roi_data_loader.register_sigint_handler()
model.roi_data_loader.start(prefill=True)
return output_dir