Detectron setup_model_for_training

本文详细介绍了如何在Caffe框架中为训练过程创建输入操作和blob,特别强调了在网络构建之后加载数据集的重要性,以及如何通过调整输入操作的位置来优化网络结构。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

流程如上

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
        )                                                         #设置model的roi_data_loader
    orig_num_op = len(model.net._net.op)                          #查看op的熟练
    blob_names = roi_data.minibatch.get_minibatch_blob_names(     #获得roi_data部分的blob names
        is_training=True
    )
    print(orig_num_op)
    print(len(blob_names))
    
    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))         #先来创建基于roi_data的blob
            model.net.DequeueBlobs(
                model.roi_data_loader._blobs_queue_name, blob_names      #把_blobs_queue_name的队列里面的blob_names的blob送出队列
            )
    # 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]
    #pdb.set_trace()
    del model.net._net.op[:]
    model.net._net.op.extend(new_op)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值