MCPcopy Create free account
hub / github.com/PeizeSun/SparseR-CNN / get_params_from_init_net

Function get_params_from_init_net

detectron2/export/shared.py:340–366  ·  view source on GitHub ↗

Take the output blobs from init_net by running it. Outputs: params: dict from blob name to numpy array device_options: dict from blob name to the device option of its creating op

(
    init_net: caffe2_pb2.NetDef,
)

Source from the content-addressed store, hash-verified

338
339
340def get_params_from_init_net(
341 init_net: caffe2_pb2.NetDef,
342) -> [Dict[str, Any], Dict[str, caffe2_pb2.DeviceOption]]:
343 """
344 Take the output blobs from init_net by running it.
345 Outputs:
346 params: dict from blob name to numpy array
347 device_options: dict from blob name to the device option of its creating op
348 """
349 # NOTE: this assumes that the params is determined by producer op with the
350 # only exception be CopyGPUToCPU which is CUDA op but returns CPU tensor.
351 def _get_device_option(producer_op):
352 if producer_op.type == "CopyGPUToCPU":
353 return caffe2_pb2.DeviceOption()
354 else:
355 return producer_op.device_option
356
357 with ScopedWS("__get_params_from_init_net__", is_reset=True, is_cleanup=True) as ws:
358 ws.RunNetOnce(init_net)
359 params = {b: fetch_any_blob(b) for b in init_net.external_output}
360 ssa, versions = core.get_ssa(init_net)
361 producer_map = get_producer_map(ssa)
362 device_options = {
363 b: _get_device_option(init_net.op[producer_map[(b, versions[b])][0]])
364 for b in init_net.external_output
365 }
366 return params, device_options
367
368
369def _updater_raise(op, input_types, output_types):

Callers 1

Calls 4

ScopedWSClass · 0.85
fetch_any_blobFunction · 0.85
get_producer_mapFunction · 0.85
_get_device_optionFunction · 0.85

Tested by

no test coverage detected