Python caffe2.python.workspace.CreateNet() Examples
The following are 30
code examples of caffe2.python.workspace.CreateNet().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
caffe2.python.workspace
, or try the search function
.
Example #1
Source File: test_engine.py From Detectron-Cascade-RCNN with Apache License 2.0 | 6 votes |
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
Example #2
Source File: test_engine.py From KL-Loss with Apache License 2.0 | 6 votes |
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
Example #3
Source File: dlrm_s_caffe2.py From dlrm with MIT License | 6 votes |
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)
Example #4
Source File: test_batch_permutation_op.py From seg_every_thing with Apache License 2.0 | 6 votes |
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 )
Example #5
Source File: train.py From Clustered-Object-Detection-in-Aerial-Image with Apache License 2.0 | 6 votes |
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
Example #6
Source File: test_batch_permutation_op.py From Clustered-Object-Detection-in-Aerial-Image with Apache License 2.0 | 6 votes |
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 )
Example #7
Source File: test_batch_permutation_op.py From KL-Loss with Apache License 2.0 | 6 votes |
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 )
Example #8
Source File: model_utils.py From inference with Apache License 2.0 | 6 votes |
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)
Example #9
Source File: train.py From seg_every_thing with Apache License 2.0 | 6 votes |
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
Example #10
Source File: test_engine.py From seg_every_thing with Apache License 2.0 | 6 votes |
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
Example #11
Source File: test_batch_permutation_op.py From masktextspotter.caffe2 with Apache License 2.0 | 6 votes |
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 )
Example #12
Source File: test_engine.py From masktextspotter.caffe2 with Apache License 2.0 | 6 votes |
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
Example #13
Source File: train_net.py From masktextspotter.caffe2 with Apache License 2.0 | 6 votes |
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
Example #14
Source File: train.py From Detectron-Cascade-RCNN with Apache License 2.0 | 6 votes |
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
Example #15
Source File: test_batch_permutation_op.py From Detectron-Cascade-RCNN with Apache License 2.0 | 6 votes |
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 )
Example #16
Source File: model_utils.py From models with Apache License 2.0 | 6 votes |
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)
Example #17
Source File: train.py From Detectron with Apache License 2.0 | 6 votes |
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
Example #18
Source File: test_batch_permutation_op.py From Detectron with Apache License 2.0 | 6 votes |
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 )
Example #19
Source File: test_engine.py From Detectron with Apache License 2.0 | 6 votes |
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
Example #20
Source File: train.py From Detectron-DA-Faster-RCNN with Apache License 2.0 | 6 votes |
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
Example #21
Source File: test_batch_permutation_op.py From Detectron-DA-Faster-RCNN with Apache License 2.0 | 6 votes |
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 )
Example #22
Source File: test_engine.py From Detectron-DA-Faster-RCNN with Apache License 2.0 | 6 votes |
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
Example #23
Source File: train.py From CBNet with Apache License 2.0 | 6 votes |
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
Example #24
Source File: test_batch_permutation_op.py From CBNet with Apache License 2.0 | 6 votes |
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 )
Example #25
Source File: test_engine.py From CBNet with Apache License 2.0 | 6 votes |
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
Example #26
Source File: test_batch_permutation_op.py From NucleiDetectron with Apache License 2.0 | 6 votes |
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 )
Example #27
Source File: test_engine.py From NucleiDetectron with Apache License 2.0 | 6 votes |
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
Example #28
Source File: train_net.py From NucleiDetectron with Apache License 2.0 | 6 votes |
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
Example #29
Source File: test_batch_permutation_op.py From DetectAndTrack with Apache License 2.0 | 6 votes |
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 )
Example #30
Source File: test_engine.py From DetectAndTrack with Apache License 2.0 | 6 votes |
def initialize_model_from_cfg(): def create_input_blobs(net_def): for op in net_def.op: for blob_in in op.input: if not workspace.HasBlob(blob_in): workspace.CreateBlob(blob_in) model = model_builder.create( cfg.MODEL.TYPE, train=False, init_params=cfg.TEST.INIT_RANDOM_VARS_BEFORE_LOADING) model_builder.add_inputs(model) if cfg.TEST.INIT_RANDOM_VARS_BEFORE_LOADING: workspace.RunNetOnce(model.param_init_net) net_utils.initialize_from_weights_file( model, cfg.TEST.WEIGHTS, broadcast=False) create_input_blobs(model.net.Proto()) workspace.CreateNet(model.net) workspace.CreateNet(model.conv_body_net) if cfg.MODEL.MASK_ON: create_input_blobs(model.mask_net.Proto()) workspace.CreateNet(model.mask_net) if cfg.MODEL.KEYPOINTS_ON: create_input_blobs(model.keypoint_net.Proto()) workspace.CreateNet(model.keypoint_net) return model