def _deserialize_function_spec_as_nonmethod(function_spec_proto, coder):
    """Deserialize a FunctionSpec object from its proto representation."""
    typeless_fullargspec = coder.decode_proto(function_spec_proto.fullargspec)

    # Convert a method function into a non method.
    if function_spec_proto.is_method:
        if not typeless_fullargspec.args:
            raise NotImplementedError(
                "Missing support to deserialize a method function without a named "
                "'self' argument.")
        args = typeless_fullargspec.args[1:]
    else:
        args = typeless_fullargspec.args

    fullargspec = tf_inspect.FullArgSpec(
        args=args,
        varargs=typeless_fullargspec.varargs,
        varkw=typeless_fullargspec.varkw,
        defaults=typeless_fullargspec.defaults,
        kwonlyargs=typeless_fullargspec.kwonlyargs,
        kwonlydefaults=typeless_fullargspec.kwonlydefaults,
        annotations=typeless_fullargspec.annotations)
    input_signature = coder.decode_proto(function_spec_proto.input_signature)

    # See `tf.function` and the ExperimentalCompile proto for details.
    experimental_compile = {
        saved_object_graph_pb2.FunctionSpec.ExperimentalCompile.DEFAULT: None,
        saved_object_graph_pb2.FunctionSpec.ExperimentalCompile.ON: True,
        saved_object_graph_pb2.FunctionSpec.ExperimentalCompile.OFF: False,
    }.get(function_spec_proto.experimental_compile)

    return function_lib.FunctionSpec(fullargspec=fullargspec,
                                     is_method=False,
                                     input_signature=input_signature,
                                     experimental_compile=experimental_compile)
def _deserialize_function_spec_as_nonmethod(function_spec_proto, coder):
  """Deserialize a FunctionSpec object from its proto representation."""
  typeless_fullargspec = coder.decode_proto(function_spec_proto.fullargspec)

  # Convert a method function into a non method.
  if function_spec_proto.is_method:
    if not typeless_fullargspec.args:
      raise NotImplementedError(
          "Missing support to deserialize a method function without a named "
          "'self' argument.")
    args = typeless_fullargspec.args[1:]
  else:
    args = typeless_fullargspec.args

  fullargspec = tf_inspect.FullArgSpec(
      args=args,
      varargs=typeless_fullargspec.varargs,
      varkw=typeless_fullargspec.varkw,
      defaults=typeless_fullargspec.defaults,
      kwonlyargs=typeless_fullargspec.kwonlyargs,
      kwonlydefaults=typeless_fullargspec.kwonlydefaults,
      annotations=typeless_fullargspec.annotations)
  input_signature = coder.decode_proto(function_spec_proto.input_signature)
  return function_lib.FunctionSpec(fullargspec=fullargspec,
                                   is_method=False,
                                   args_to_prepend=[],
                                   kwargs_to_include={},
                                   input_signature=input_signature)
Exemplo n.º 3
0
def _deserialize_function_spec(function_spec_proto, coder):
  """Deserialize a FunctionSpec object from its proto representation."""
  fullargspec = coder.decode_proto(function_spec_proto.fullargspec)
  is_method = function_spec_proto.is_method
  args_to_prepend = coder.decode_proto(function_spec_proto.args_to_prepend)
  kwargs_to_include = coder.decode_proto(function_spec_proto.kwargs_to_include)
  input_signature = coder.decode_proto(function_spec_proto.input_signature)
  return function_lib.FunctionSpec(fullargspec, is_method, args_to_prepend,
                                   kwargs_to_include, input_signature)
def _deserialize_function_spec(function_spec_proto, coder):
    """Deserialize a FunctionSpec object from its proto representation."""
    typeless_fullargspec = coder.decode_proto(function_spec_proto.fullargspec)
    fullargspec = tf_inspect.FullArgSpec(
        args=typeless_fullargspec.args,
        varargs=typeless_fullargspec.varargs,
        varkw=typeless_fullargspec.varkw,
        defaults=typeless_fullargspec.defaults,
        kwonlyargs=typeless_fullargspec.kwonlyargs,
        kwonlydefaults=typeless_fullargspec.kwonlydefaults,
        annotations=typeless_fullargspec.annotations)
    is_method = function_spec_proto.is_method
    args_to_prepend = coder.decode_proto(function_spec_proto.args_to_prepend)
    kwargs_to_include = coder.decode_proto(
        function_spec_proto.kwargs_to_include)
    input_signature = coder.decode_proto(function_spec_proto.input_signature)
    return function_lib.FunctionSpec(fullargspec, is_method, args_to_prepend,
                                     kwargs_to_include, input_signature)