Takes the net_params returned from TranslateModel, and wrap it as an init net that contain GivenTensorFill. This is a very simple feature that only works with float tensors, and is only intended to be used in an environment where you want a single initialization file - for more comp
(net_params, input_name)
| 284 | |
| 285 | |
| 286 | def ConvertTensorProtosToInitNet(net_params, input_name): |
| 287 | """Takes the net_params returned from TranslateModel, and wrap it as an |
| 288 | init net that contain GivenTensorFill. |
| 289 | |
| 290 | This is a very simple feature that only works with float tensors, and is |
| 291 | only intended to be used in an environment where you want a single |
| 292 | initialization file - for more complex cases, use a db to store the |
| 293 | parameters. |
| 294 | """ |
| 295 | init_net = caffe2_pb2.NetDef() |
| 296 | for tensor in net_params.protos: |
| 297 | if len(tensor.float_data) == 0: |
| 298 | raise RuntimeError( |
| 299 | "Only float tensors are supported in this util.") |
| 300 | op = core.CreateOperator( |
| 301 | "GivenTensorFill", [], [tensor.name], |
| 302 | arg=[ |
| 303 | utils.MakeArgument("shape", list(tensor.dims)), |
| 304 | utils.MakeArgument("values", tensor.float_data)]) |
| 305 | init_net.op.extend([op]) |
| 306 | init_net.op.extend([core.CreateOperator("ConstantFill", [], [input_name], shape=[1])]) |
| 307 | return init_net |
| 308 | |
| 309 | |
| 310 | def BaseTranslate(layer, caffe2_type): |
no test coverage detected
searching dependent graphs…