MCPcopy Create free account
hub / github.com/pytorch/pytorch / ConvertTensorProtosToInitNet

Function ConvertTensorProtosToInitNet

caffe2/python/caffe_translator.py:286–307  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

284
285
286def 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
310def BaseTranslate(layer, caffe2_type):

Callers 1

Calls 2

listFunction · 0.85
extendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…