流程如上
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)