python - Why "CopyFrom" is used during the creation of the constant Tensor? -
during creation process of constant tensor there following line:
tensor_value.tensor.copyfrom( tensor_util.make_tensor_proto(value, dtype=dtype, shape=shape))
copyfrom
creates copy of newly created tensor proto. looks waste of resource coping since make_tensor_proto
, according doc, creates new object. more sufficient, next:
tensor_value.tensor = tensor_util.make_tensor_proto(value, dtype=dtype, shape=shape)
this should not create new object, plus valid usage of oneof protobuf fields.
you cannot assign proto field of proto explained in doc: https://developers.google.com/protocol-buffers/docs/reference/python-generated
you cannot assign value embedded message field. instead, assigning value field within child message implies setting message field in parent.
if remove copyfrom, following error:
attributeerror: assignment not allowed field "tensor" in protocol message object.
Comments
Post a Comment