コード例 #1
0
def serialize_function(function, node_ids):
    """Build a SavedFunction proto."""
    coder = nested_structure_coder.StructureCoder()
    proto = saved_object_graph_pb2.SavedFunction()

    function_spec_proto = _serialize_function_spec(function.function_spec,
                                                   coder)
    proto.function_spec.CopyFrom(function_spec_proto)
    all_concrete_functions = \
        function._list_all_concrete_functions_for_serialization()  # pylint: disable=protected-access
    for concrete_function in all_concrete_functions:
        bound_inputs = []
        try:
            for capture in concrete_function.captured_inputs:
                bound_inputs.append(node_ids[capture])
        except KeyError:
            # TODO(andresp): Would it better to throw an exception?
            logging.warning(
                "Concrete function %s not added to object based saved model as it "
                "captures tensor %s which is unsupported or not reachable from root.",
                concrete_function.name, capture)
            continue
        signature_args, signature_kwargs = \
            concrete_function.structured_input_signature
        del signature_kwargs
        concrete_function_proto = proto.concrete_function.add()
        concrete_function_proto.name = concrete_function.name
        concrete_function_proto.canonicalized_input_signature.CopyFrom(
            coder.encode_structure(signature_args))
        structured_outputs = func_graph_module.convert_structure_to_signature(
            concrete_function.structured_outputs)
        concrete_function_proto.output_signature.CopyFrom(
            coder.encode_structure(structured_outputs))
        concrete_function_proto.bound_inputs.extend(bound_inputs)
    return proto
コード例 #2
0
def serialize_function(function):
  """Build a SavedFunction proto."""
  coder = nested_structure_coder.StructureCoder()
  proto = saved_object_graph_pb2.SavedFunction()

  function_spec_proto = _serialize_function_spec(function.function_spec, coder)
  proto.function_spec.CopyFrom(function_spec_proto)
  all_concrete_functions = \
      function._list_all_concrete_functions_for_serialization()  # pylint: disable=protected-access
  for concrete_function in all_concrete_functions:
    proto.concrete_functions.append(concrete_function.name)
  return proto
コード例 #3
0
def serialize_function(function, node_ids):
    """Build a SavedFunction proto."""
    coder = nested_structure_coder.StructureCoder()
    proto = saved_object_graph_pb2.SavedFunction()

    function_spec_proto = _serialize_function_spec(function.function_spec,
                                                   coder)
    proto.function_spec.CopyFrom(function_spec_proto)
    all_concrete_functions = \
        function._list_all_concrete_functions_for_serialization()  # pylint: disable=protected-access
    for concrete_function in all_concrete_functions:
        concrete_function_proto = serialize_concrete_function(
            concrete_function, node_ids)
        if concrete_function_proto is not None:
            proto.concrete_function.add().CopyFrom(concrete_function_proto)
    return proto