• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1syntax = "proto3";
2
3import "tensorflow/core/framework/tensor_shape.proto";
4import "tensorflow/core/framework/types.proto";
5
6package tensorflow;
7
8// `StructuredValue` represents a dynamically typed value representing various
9// data structures that are inspired by Python data structures typically used in
10// TensorFlow functions as inputs and outputs.
11//
12// For example when saving a Layer there may be a `training` argument. If the
13// user passes a boolean True/False, that switches between two concrete
14// TensorFlow functions. In order to switch between them in the same way after
15// loading the SavedModel, we need to represent "True" and "False".
16//
17// A more advanced example might be a function which takes a list of
18// dictionaries mapping from strings to Tensors. In order to map from
19// user-specified arguments `[{"a": tf.constant(1.)}, {"q": tf.constant(3.)}]`
20// after load to the right saved TensorFlow function, we need to represent the
21// nested structure and the strings, recording that we have a trace for anything
22// matching `[{"a": tf.TensorSpec(None, tf.float32)}, {"q": tf.TensorSpec([],
23// tf.float64)}]` as an example.
24//
25// Likewise functions may return nested structures of Tensors, for example
26// returning a dictionary mapping from strings to Tensors. In order for the
27// loaded function to return the same structure we need to serialize it.
28//
29// This is an ergonomic aid for working with loaded SavedModels, not a promise
30// to serialize all possible function signatures. For example we do not expect
31// to pickle generic Python objects, and ideally we'd stay language-agnostic.
32message StructuredValue {
33  // The kind of value.
34  oneof kind {
35    // Represents None.
36    NoneValue none_value = 1;
37
38    // Represents a double-precision floating-point value (a Python `float`).
39    double float64_value = 11;
40    // Represents a signed integer value, limited to 64 bits.
41    // Larger values from Python's arbitrary-precision integers are unsupported.
42    sint64 int64_value = 12;
43    // Represents a string of Unicode characters stored in a Python `str`.
44    // In Python 3, this is exactly what type `str` is.
45    // In Python 2, this is the UTF-8 encoding of the characters.
46    // For strings with ASCII characters only (as often used in TensorFlow code)
47    // there is effectively no difference between the language versions.
48    // The obsolescent `unicode` type of Python 2 is not supported here.
49    string string_value = 13;
50    // Represents a boolean value.
51    bool bool_value = 14;
52
53    // Represents a TensorShape.
54    tensorflow.TensorShapeProto tensor_shape_value = 31;
55    // Represents an enum value for dtype.
56    tensorflow.DataType tensor_dtype_value = 32;
57    // Represents a value for tf.TensorSpec.
58    TensorSpecProto tensor_spec_value = 33;
59
60    // Represents a list of `Value`.
61    ListValue list_value = 51;
62    // Represents a tuple of `Value`.
63    TupleValue tuple_value = 52;
64    // Represents a dict `Value`.
65    DictValue dict_value = 53;
66    // Represents Python's namedtuple.
67    NamedTupleValue named_tuple_value = 54;
68  }
69}
70
71// Represents None.
72message NoneValue {}
73
74// Represents a Python list.
75message ListValue {
76  repeated StructuredValue values = 1;
77}
78
79// Represents a Python tuple.
80message TupleValue {
81  repeated StructuredValue values = 1;
82}
83
84// Represents a Python dict keyed by `str`.
85// The comment on Unicode from Value.string_value applies analogously.
86message DictValue {
87  map<string, StructuredValue> fields = 1;
88}
89
90// Represents a (key, value) pair.
91message PairValue {
92  string key = 1;
93  StructuredValue value = 2;
94}
95
96// Represents Python's namedtuple.
97message NamedTupleValue {
98  string name = 1;
99  repeated PairValue values = 2;
100}
101
102// A protobuf to tf.TensorSpec.
103message TensorSpecProto {
104  string name = 1;
105  tensorflow.TensorShapeProto shape = 2;
106  tensorflow.DataType dtype = 3;
107};
108