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,
)
| 338 | |
| 339 | |
| 340 | def 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 | |
| 369 | def _updater_raise(op, input_types, output_types): |
no test coverage detected