MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / _write_object_proto

Function _write_object_proto

tensorflow/python/saved_model/save.py:633–670  ·  view source on GitHub ↗

Saves an object into SavedObject proto.

(obj, proto, asset_file_def_index)

Source from the content-addressed store, hash-verified

631
632
633def _write_object_proto(obj, proto, asset_file_def_index):
634 """Saves an object into SavedObject proto."""
635 if isinstance(obj, tracking.TrackableAsset):
636 proto.asset.SetInParent()
637 proto.asset.asset_file_def_index = asset_file_def_index[obj]
638 elif resource_variable_ops.is_resource_variable(obj):
639 proto.variable.SetInParent()
640 if not obj.name.endswith(":0"):
641 raise ValueError("Cowardly refusing to save variable %s because of"
642 " unexpected suffix which won't be restored.")
643 proto.variable.name = meta_graph._op_name(obj.name) # pylint: disable=protected-access
644 proto.variable.trainable = obj.trainable
645 proto.variable.dtype = obj.dtype.as_datatype_enum
646 proto.variable.synchronization = obj.synchronization.value
647 proto.variable.aggregation = obj.aggregation.value
648 proto.variable.shape.CopyFrom(obj.shape.as_proto())
649 elif isinstance(obj, def_function.Function):
650 proto.function.CopyFrom(
651 function_serialization.serialize_function(obj))
652 elif isinstance(obj, defun.ConcreteFunction):
653 proto.bare_concrete_function.CopyFrom(
654 function_serialization.serialize_bare_concrete_function(obj))
655 elif isinstance(obj, _CapturedConstant):
656 proto.constant.operation = obj.graph_tensor.op.name
657 elif isinstance(obj, tracking.CapturableResource):
658 proto.resource.device = obj._resource_device # pylint: disable=protected-access
659 else:
660 registered_type_proto = revived_types.serialize(obj)
661 if registered_type_proto is None:
662 # Fallback for types with no matching registration
663 # pylint:disable=protected-access
664 registered_type_proto = saved_object_graph_pb2.SavedUserObject(
665 identifier=obj._object_identifier,
666 version=versions_pb2.VersionDef(
667 producer=1, min_consumer=1, bad_consumers=[]),
668 metadata=obj._tracking_metadata)
669 # pylint:enable=protected-access
670 proto.user_object.CopyFrom(registered_type_proto)
671
672
673@tf_export("saved_model.save",

Callers 1

_serialize_object_graphFunction · 0.85

Calls 3

as_protoMethod · 0.80
CopyFromMethod · 0.45
serializeMethod · 0.45

Tested by

no test coverage detected