当前位置: 首页>>代码示例>>Python>>正文


Python workspace.CreateBlob方法代码示例

本文整理汇总了Python中caffe2.python.workspace.CreateBlob方法的典型用法代码示例。如果您正苦于以下问题:Python workspace.CreateBlob方法的具体用法?Python workspace.CreateBlob怎么用?Python workspace.CreateBlob使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在caffe2.python.workspace的用法示例。


在下文中一共展示了workspace.CreateBlob方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_net

# 需要导入模块: from caffe2.python import workspace [as 别名]
# 或者: from caffe2.python.workspace import CreateBlob [as 别名]
def get_net(data_loader, name):
    logger = logging.getLogger(__name__)
    blob_names = data_loader.get_output_names()
    net = core.Net(name)
    net.type = 'dag'
    for gpu_id in range(cfg.NUM_GPUS):
        with core.NameScope('gpu_{}'.format(gpu_id)):
            with core.DeviceScope(muji.OnGPU(gpu_id)):
                for blob_name in blob_names:
                    blob = core.ScopedName(blob_name)
                    workspace.CreateBlob(blob)
                net.DequeueBlobs(
                    data_loader._blobs_queue_name, blob_names)
    logger.info("Protobuf:\n" + str(net.Proto()))

    return net 
开发者ID:yihui-he,项目名称:KL-Loss,代码行数:18,代码来源:test_loader.py

示例2: initialize_model_from_cfg

# 需要导入模块: from caffe2.python import workspace [as 别名]
# 或者: from caffe2.python.workspace import CreateBlob [as 别名]
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 
开发者ID:facebookresearch,项目名称:DetectAndTrack,代码行数:27,代码来源:test_engine.py

示例3: create_blobs_if_not_existed

# 需要导入模块: from caffe2.python import workspace [as 别名]
# 或者: from caffe2.python.workspace import CreateBlob [as 别名]
def create_blobs_if_not_existed(blob_names):
    existd_names = set(workspace.Blobs())
    for xx in blob_names:
        if xx not in existd_names:
            workspace.CreateBlob(str(xx)) 
开发者ID:facebookarchive,项目名称:models,代码行数:7,代码来源:model_utils.py

示例4: create_input_blobs

# 需要导入模块: from caffe2.python import workspace [as 别名]
# 或者: from caffe2.python.workspace import CreateBlob [as 别名]
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) 
开发者ID:facebookarchive,项目名称:models,代码行数:7,代码来源:utils2.py

示例5: create_enqueue_blobs

# 需要导入模块: from caffe2.python import workspace [as 别名]
# 或者: from caffe2.python.workspace import CreateBlob [as 别名]
def create_enqueue_blobs(self):
        blob_names = self.get_output_names()
        enqueue_blob_names = [
            '{}_enqueue_{}'.format(b, self._loader_id) for b in blob_names
        ]
        for gpu_id in range(self._num_gpus):
            with c2_utils.NamedCudaScope(gpu_id):
                for blob in enqueue_blob_names:
                    workspace.CreateBlob(core.ScopedName(blob))
        return enqueue_blob_names 
开发者ID:yihui-he,项目名称:KL-Loss,代码行数:12,代码来源:loader.py

示例6: create_input_blobs_for_net

# 需要导入模块: from caffe2.python import workspace [as 别名]
# 或者: from caffe2.python.workspace import CreateBlob [as 别名]
def create_input_blobs_for_net(net_def):
    for op in net_def.op:
        for blob_in in op.input:
            if not workspace.HasBlob(blob_in):
                workspace.CreateBlob(blob_in) 
开发者ID:yihui-he,项目名称:KL-Loss,代码行数:7,代码来源:model_convert_utils.py

示例7: add_training_inputs

# 需要导入模块: from caffe2.python import workspace [as 别名]
# 或者: from caffe2.python.workspace import CreateBlob [as 别名]
def add_training_inputs(model, roidb=None):
    """Create network input ops and blobs used for training. To be called
    *after* model_builder.create().
    """
    # Implementation notes:
    #   Typically, one would create the input ops and then the rest of the net.
    #   However, creating the input ops depends on loading the dataset, which
    #   can take a few minutes for COCO.
    #   We prefer to avoid waiting so debugging can fail fast.
    #   Thus, we create the net *without input ops* prior to loading the
    #   dataset, and then add the input ops after loading the dataset.
    #   Since we defer input op creation, we need to do a little bit of surgery
    #   to place the input ops at the start of the network op list.
    assert model.train, 'Training inputs can only be added to a trainable model'
    if roidb is not None:
        # To make debugging easier you can set cfg.DATA_LOADER.NUM_THREADS = 1
        model.roi_data_loader = RoIDataLoader(
            roidb,
            num_loaders=cfg.DATA_LOADER.NUM_THREADS,
            minibatch_queue_size=cfg.DATA_LOADER.MINIBATCH_QUEUE_SIZE,
            blobs_queue_capacity=cfg.DATA_LOADER.BLOBS_QUEUE_CAPACITY
        )
    orig_num_op = len(model.net._net.op)
    blob_names = roi_data_minibatch.get_minibatch_blob_names(is_training=True)
    for gpu_id in range(cfg.NUM_GPUS):
        with c2_utils.NamedCudaScope(gpu_id):
            for blob_name in blob_names:
                workspace.CreateBlob(core.ScopedName(blob_name))
            model.net.DequeueBlobs(
                model.roi_data_loader._blobs_queue_name, blob_names
            )
    # A little op surgery to move input ops to the start of the net
    diff = len(model.net._net.op) - orig_num_op
    new_op = model.net._net.op[-diff:] + model.net._net.op[:-diff]
    del model.net._net.op[:]
    model.net._net.op.extend(new_op) 
开发者ID:yihui-he,项目名称:KL-Loss,代码行数:38,代码来源:model_builder.py

示例8: add_inference_inputs

# 需要导入模块: from caffe2.python import workspace [as 别名]
# 或者: from caffe2.python.workspace import CreateBlob [as 别名]
def add_inference_inputs(model):
    """Create network input blobs used for inference."""

    def create_input_blobs_for_net(net_def):
        for op in net_def.op:
            for blob_in in op.input:
                if not workspace.HasBlob(blob_in):
                    workspace.CreateBlob(blob_in)

    create_input_blobs_for_net(model.net.Proto())
    if cfg.MODEL.MASK_ON:
        create_input_blobs_for_net(model.mask_net.Proto())
    if cfg.MODEL.KEYPOINTS_ON:
        create_input_blobs_for_net(model.keypoint_net.Proto())


# ---------------------------------------------------------------------------- #
# ********************** DEPRECATED FUNCTIONALITY BELOW ********************** #
# ---------------------------------------------------------------------------- #

# ---------------------------------------------------------------------------- #
# Hardcoded functions to create various types of common models
#
#            *** This type of model definition is deprecated ***
#            *** Use the generic composable versions instead ***
#
# ---------------------------------------------------------------------------- # 
开发者ID:yihui-he,项目名称:KL-Loss,代码行数:29,代码来源:model_builder.py

示例9: add_inputs

# 需要导入模块: from caffe2.python import workspace [as 别名]
# 或者: from caffe2.python.workspace import CreateBlob [as 别名]
def add_inputs(model, data_loader, suffix):
    blob_names = data_loader.get_blob_names()
    queue_name = data_loader._blobs_queue_name

    def input_fn(model):
        for blob_name in blob_names:
            workspace.CreateBlob(scope.CurrentNameScope() + blob_name)
        model.DequeueBlobs(queue_name, blob_names)
        model.StopGradient('data{}'.format(suffix), 'data{}'.format(suffix))

    return input_fn 
开发者ID:facebookresearch,项目名称:video-long-term-feature-banks,代码行数:13,代码来源:model_builder_video.py

示例10: create_threads

# 需要导入模块: from caffe2.python import workspace [as 别名]
# 或者: from caffe2.python.workspace import CreateBlob [as 别名]
def create_threads(self):
        # "worker" threads to construct (partial) minibatches and put them on
        # minibatch queue in CPU memory (limited by queue size).
        self._worker_ids = self.get_worker_ids()
        self._workers = [
            threading.Thread(
                target=self.minibatch_loader,
                name='worker_{}'.format(worker_id),
                args=[worker_id],
            ) for worker_id in self._worker_ids
        ]

        # Create one BlobsQueue per GPU which holds the training data in GPU
        # memory and feeds to the net.
        root_gpu_id = cfg.ROOT_GPU_ID
        for gpu_id in range(root_gpu_id, root_gpu_id + self._num_gpus):
            with core.NameScope('gpu_{}'.format(gpu_id)):
                self.create_blobs_queue(
                    queue_name=self._blobs_queue_name,
                    num_blobs=len(self._blobs_idx_map),
                    capacity=self._gpu_blobs_queue_capacity
                )

        # Launch enqueuer threads.
        blob_names = self._blobs_idx_map.keys()
        enqueue_blobs_names = [
            '{}_{}_enqueue'.format(self._split, blob_name)
            for blob_name in blob_names
        ]
        for gpu_id in range(root_gpu_id, root_gpu_id + self._num_gpus):
            with core.NameScope('gpu_{}'.format(gpu_id)):
                with core.DeviceScope(
                    core.DeviceOption(caffe2_pb2.CUDA, gpu_id)
                ):
                    for blob_list in enqueue_blobs_names:
                        for blob in blob_list:
                            scoped_blob_name = scope.CurrentNameScope() + blob
                            workspace.CreateBlob(scoped_blob_name)
        self._enqueuer = threading.Thread(
            target=self.enqueue_blobs_thread, args=(0, enqueue_blobs_names)
        ) 
开发者ID:facebookresearch,项目名称:video-long-term-feature-banks,代码行数:43,代码来源:dataloader.py

示例11: add_training_inputs

# 需要导入模块: from caffe2.python import workspace [as 别名]
# 或者: from caffe2.python.workspace import CreateBlob [as 别名]
def add_training_inputs(model, roidb=None):
    """Create network input ops and blobs used for training. To be called
    *after* model_builder.create().
    """
    # Implementation notes:
    #   Typically, one would create the input ops and then the rest of the net.
    #   However, creating the input ops depends on loading the dataset, which
    #   can take a few minutes for COCO.
    #   We prefer to avoid waiting so debugging can fail fast.
    #   Thus, we create the net *without input ops* prior to loading the
    #   dataset, and then add the input ops after loading the dataset.
    #   Since we defer input op creation, we need to do a little bit of surgery
    #   to place the input ops at the start of the network op list.
    assert model.train, 'Training inputs can only be added to a trainable model'
    if roidb is not None:
        # To make debugging easier you can set cfg.DATA_LOADER.NUM_THREADS = 1
        model.roi_data_loader = RoIDataLoader(
            roidb, num_loaders=cfg.DATA_LOADER.NUM_THREADS
        )
    orig_num_op = len(model.net._net.op)
    blob_names = roi_data.minibatch.get_minibatch_blob_names(
        is_training=True
    )
    for gpu_id in range(cfg.NUM_GPUS):
        with c2_utils.NamedCudaScope(gpu_id):
            for blob_name in blob_names:
                workspace.CreateBlob(core.ScopedName(blob_name))
            model.net.DequeueBlobs(
                model.roi_data_loader._blobs_queue_name, blob_names
            )
    # A little op surgery to move input ops to the start of the net
    diff = len(model.net._net.op) - orig_num_op
    new_op = model.net._net.op[-diff:] + model.net._net.op[:-diff]
    del model.net._net.op[:]
    model.net._net.op.extend(new_op) 
开发者ID:ronghanghu,项目名称:seg_every_thing,代码行数:37,代码来源:model_builder.py


注:本文中的caffe2.python.workspace.CreateBlob方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。