• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1syntax = "proto3";
2
3package tensorflow;
4
5import "tensorflow/core/framework/tensor.proto";
6import "tensorflow/core/framework/tensor_shape.proto";
7import "tensorflow/core/framework/types.proto";
8
9option go_package = "github.com/tensorflow/tensorflow/tensorflow/go/core/protobuf/for_core_protos_go_proto";
10
11// `StructuredValue` represents a dynamically typed value representing various
12// data structures that are inspired by Python data structures typically used in
13// TensorFlow functions as inputs and outputs.
14//
15// For example when saving a Layer there may be a `training` argument. If the
16// user passes a boolean True/False, that switches between two concrete
17// TensorFlow functions. In order to switch between them in the same way after
18// loading the SavedModel, we need to represent "True" and "False".
19//
20// A more advanced example might be a function which takes a list of
21// dictionaries mapping from strings to Tensors. In order to map from
22// user-specified arguments `[{"a": tf.constant(1.)}, {"q": tf.constant(3.)}]`
23// after load to the right saved TensorFlow function, we need to represent the
24// nested structure and the strings, recording that we have a trace for anything
25// matching `[{"a": tf.TensorSpec(None, tf.float32)}, {"q": tf.TensorSpec([],
26// tf.float64)}]` as an example.
27//
28// Likewise functions may return nested structures of Tensors, for example
29// returning a dictionary mapping from strings to Tensors. In order for the
30// loaded function to return the same structure we need to serialize it.
31//
32// This is an ergonomic aid for working with loaded SavedModels, not a promise
33// to serialize all possible function signatures. For example we do not expect
34// to pickle generic Python objects, and ideally we'd stay language-agnostic.
35message StructuredValue {
36  // The kind of value.
37  oneof kind {
38    // Represents None.
39    NoneValue none_value = 1;
40
41    // Represents a double-precision floating-point value (a Python `float`).
42    double float64_value = 11;
43    // Represents a signed integer value, limited to 64 bits.
44    // Larger values from Python's arbitrary-precision integers are unsupported.
45    sint64 int64_value = 12;
46    // Represents a string of Unicode characters stored in a Python `str`.
47    // In Python 3, this is exactly what type `str` is.
48    // In Python 2, this is the UTF-8 encoding of the characters.
49    // For strings with ASCII characters only (as often used in TensorFlow code)
50    // there is effectively no difference between the language versions.
51    // The obsolescent `unicode` type of Python 2 is not supported here.
52    string string_value = 13;
53    // Represents a boolean value.
54    bool bool_value = 14;
55
56    // Represents a TensorShape.
57    tensorflow.TensorShapeProto tensor_shape_value = 31;
58    // Represents an enum value for dtype.
59    tensorflow.DataType tensor_dtype_value = 32;
60    // Represents a value for tf.TensorSpec.
61    TensorSpecProto tensor_spec_value = 33;
62    // Represents a value for tf.TypeSpec.
63    TypeSpecProto type_spec_value = 34;
64    // Represents a value for tf.BoundedTensorSpec.
65    BoundedTensorSpecProto bounded_tensor_spec_value = 35;
66
67    // Represents a list of `Value`.
68    ListValue list_value = 51;
69    // Represents a tuple of `Value`.
70    TupleValue tuple_value = 52;
71    // Represents a dict `Value`.
72    DictValue dict_value = 53;
73    // Represents Python's namedtuple.
74    NamedTupleValue named_tuple_value = 54;
75  }
76}
77
78// Represents None.
79message NoneValue {}
80
81// Represents a Python list.
82message ListValue {
83  repeated StructuredValue values = 1;
84}
85
86// Represents a Python tuple.
87message TupleValue {
88  repeated StructuredValue values = 1;
89}
90
91// Represents a Python dict keyed by `str`.
92// The comment on Unicode from Value.string_value applies analogously.
93message DictValue {
94  map<string, StructuredValue> fields = 1;
95}
96
97// Represents a (key, value) pair.
98message PairValue {
99  string key = 1;
100  StructuredValue value = 2;
101}
102
103// Represents Python's namedtuple.
104message NamedTupleValue {
105  string name = 1;
106  repeated PairValue values = 2;
107}
108
109// A protobuf to represent tf.TensorSpec.
110message TensorSpecProto {
111  string name = 1;
112  tensorflow.TensorShapeProto shape = 2;
113  tensorflow.DataType dtype = 3;
114}
115
116// A protobuf to represent tf.BoundedTensorSpec.
117message BoundedTensorSpecProto {
118  string name = 1;
119  tensorflow.TensorShapeProto shape = 2;
120  tensorflow.DataType dtype = 3;
121  tensorflow.TensorProto minimum = 4;
122  tensorflow.TensorProto maximum = 5;
123}
124
125// Represents a tf.TypeSpec
126message TypeSpecProto {
127  enum TypeSpecClass {
128    UNKNOWN = 0;
129    SPARSE_TENSOR_SPEC = 1;   // tf.SparseTensorSpec
130    INDEXED_SLICES_SPEC = 2;  // tf.IndexedSlicesSpec
131    RAGGED_TENSOR_SPEC = 3;   // tf.RaggedTensorSpec
132    TENSOR_ARRAY_SPEC = 4;    // tf.TensorArraySpec
133    DATA_DATASET_SPEC = 5;    // tf.data.DatasetSpec
134    DATA_ITERATOR_SPEC = 6;   // IteratorSpec from data/ops/iterator_ops.py
135    OPTIONAL_SPEC = 7;        // tf.OptionalSpec
136    PER_REPLICA_SPEC = 8;     // PerReplicaSpec from distribute/values.py
137    VARIABLE_SPEC = 9;        // tf.VariableSpec
138    ROW_PARTITION_SPEC = 10;  // RowPartitionSpec from ragged/row_partition.py
139    reserved 11;
140  }
141  TypeSpecClass type_spec_class = 1;
142
143  // The value returned by TypeSpec._serialize().
144  StructuredValue type_state = 2;
145
146  // This is currently redundant with the type_spec_class enum, and is only
147  // used for error reporting.  In particular, if you use an older binary to
148  // load a newer model, and the model uses a TypeSpecClass that the older
149  // binary doesn't support, then this lets us display a useful error message.
150  string type_spec_class_name = 3;
151}
152