Generated Java code for TensorFlow protocol buffers, providing type-safe access to TensorFlow's structured data formats including MetaGraphDef, ConfigProto, and other core TensorFlow data structures.
npx @tessl/cli install tessl/maven-org-tensorflow--proto@1.15.00
# TensorFlow Proto
1
2
Generated Java code for TensorFlow protocol buffers, providing type-safe access to TensorFlow's structured data formats including MetaGraphDef, ConfigProto, and other core TensorFlow data structures. This package serves as a foundational dependency for TensorFlow Java API applications that need to serialize, deserialize, or manipulate TensorFlow protocol buffer messages.
3
4
## Package Information
5
6
- **Package Name**: org.tensorflow:proto
7
- **Package Type**: maven
8
- **Language**: Java
9
- **Installation**: Add to your Maven pom.xml:
10
11
```xml
12
<dependency>
13
<groupId>org.tensorflow</groupId>
14
<artifactId>proto</artifactId>
15
<version>1.15.0</version>
16
</dependency>
17
```
18
19
For Gradle:
20
21
```gradle
22
implementation 'org.tensorflow:proto:1.15.0'
23
```
24
25
## Core Imports
26
27
```java
28
import org.tensorflow.framework.*;
29
import org.tensorflow.example.*;
30
import org.tensorflow.util.*;
31
import org.tensorflow.distruntime.*;
32
import com.google.protobuf.ByteString;
33
```
34
35
Common specific imports:
36
37
```java
38
import org.tensorflow.framework.TensorProto;
39
import org.tensorflow.framework.GraphDef;
40
import org.tensorflow.framework.NodeDef;
41
import org.tensorflow.framework.ConfigProto;
42
import org.tensorflow.framework.MetaGraphDef;
43
import org.tensorflow.framework.DataType;
44
import org.tensorflow.framework.TensorShapeProto;
45
import org.tensorflow.framework.AttrValue;
46
import org.tensorflow.example.Example;
47
import org.tensorflow.example.Feature;
48
import org.tensorflow.example.Features;
49
import org.tensorflow.example.FloatList;
50
import org.tensorflow.example.Int64List;
51
import org.tensorflow.example.BytesList;
52
import com.google.protobuf.ByteString;
53
```
54
55
## Basic Usage
56
57
```java
58
import org.tensorflow.framework.*;
59
60
// Create a tensor proto with float values
61
TensorProto tensor = TensorProto.newBuilder()
62
.setDtype(DataType.DT_FLOAT)
63
.setTensorShape(TensorShapeProto.newBuilder()
64
.addDim(TensorShapeProto.Dim.newBuilder().setSize(3)))
65
.addFloatVal(1.0f)
66
.addFloatVal(2.0f)
67
.addFloatVal(3.0f)
68
.build();
69
70
// Create a simple graph with one node
71
GraphDef graph = GraphDef.newBuilder()
72
.addNode(NodeDef.newBuilder()
73
.setName("input")
74
.setOp("Placeholder")
75
.putAttr("dtype", AttrValue.newBuilder()
76
.setType(DataType.DT_FLOAT).build()))
77
.build();
78
79
// Create training example
80
Example example = Example.newBuilder()
81
.setFeatures(Features.newBuilder()
82
.putFeature("height", Feature.newBuilder()
83
.setFloatList(FloatList.newBuilder().addValue(175.5f))
84
.build())
85
.putFeature("weight", Feature.newBuilder()
86
.setFloatList(FloatList.newBuilder().addValue(68.2f))
87
.build()))
88
.build();
89
```
90
91
## Architecture
92
93
The TensorFlow Proto package is organized around several key areas:
94
95
- **Core Framework**: Primary data structures for graphs, tensors, operations, and configurations (`org.tensorflow.framework`)
96
- **Data Examples**: Normalized formats for training and inference data (`org.tensorflow.example`)
97
- **Distributed Runtime**: Service interfaces and messages for distributed TensorFlow execution (`org.tensorflow.distruntime`)
98
- **Utilities**: Event logging and other utility types (`org.tensorflow.util`)
99
- **Protocol Buffer Pattern**: All classes follow the standard Protocol Buffer Java pattern with immutable message objects and mutable Builder classes
100
101
## Capabilities
102
103
### Core Framework Types
104
105
The fundamental data structures for TensorFlow graphs, tensors, operations, and session configuration. Essential for any application working with TensorFlow models or computation graphs.
106
107
```java { .api }
108
class TensorProto {
109
DataType getDtype();
110
TensorShapeProto getTensorShape();
111
ByteString getTensorContent();
112
List<Float> getFloatValList();
113
List<Integer> getIntValList();
114
// ... other type-specific accessors
115
}
116
117
class GraphDef {
118
List<NodeDef> getNodeList();
119
VersionDef getVersions();
120
FunctionDefLibrary getLibrary();
121
}
122
123
class NodeDef {
124
String getName();
125
String getOp();
126
List<String> getInputList();
127
String getDevice();
128
Map<String, AttrValue> getAttrMap();
129
}
130
```
131
132
[Core Framework](./core-framework.md)
133
134
### Data Examples and Features
135
136
Normalized data formats for representing training examples, feature vectors, and structured data inputs for machine learning models.
137
138
```java { .api }
139
class Example {
140
Features getFeatures();
141
}
142
143
class Feature {
144
BytesList getBytesList();
145
FloatList getFloatList();
146
Int64List getInt64List();
147
KindCase getKindCase();
148
}
149
150
class Features {
151
Map<String, Feature> getFeatureMap();
152
}
153
```
154
155
[Data Examples](./data-examples.md)
156
157
### Model Configuration and Persistence
158
159
Configuration objects and data structures for TensorFlow sessions, saved models, and model metadata management.
160
161
```java { .api }
162
class ConfigProto {
163
Map<String, Integer> getDeviceCountMap();
164
int getIntraOpParallelismThreads();
165
int getInterOpParallelismThreads();
166
GPUOptions getGpuOptions();
167
boolean getAllowSoftPlacement();
168
}
169
170
class MetaGraphDef {
171
MetaInfoDef getMetaInfoDef();
172
GraphDef getGraphDef();
173
SaverDef getSaverDef();
174
Map<String, CollectionDef> getCollectionDefMap();
175
Map<String, SignatureDef> getSignatureDefMap();
176
}
177
178
class SavedModel {
179
long getSavedModelSchemaVersion();
180
List<MetaGraphDef> getMetaGraphsList();
181
}
182
```
183
184
[Configuration and Persistence](./config-persistence.md)
185
186
### Distributed Runtime Services
187
188
Service interfaces and message types for distributed TensorFlow execution across multiple devices and machines.
189
190
```java { .api }
191
// Master Service Messages
192
class CreateSessionRequest {
193
GraphDef getGraphDef();
194
ConfigProto getConfig();
195
}
196
197
class RunStepRequest {
198
String getSessionHandle();
199
List<String> getFeedList();
200
List<String> getFetchList();
201
}
202
203
// Worker Service Messages
204
class RegisterGraphRequest {
205
String getSessionHandle();
206
GraphDef getGraphDef();
207
}
208
```
209
210
[Distributed Runtime](./distributed-runtime.md)
211
212
### Utility Types
213
214
Event logging, debugging, and other utility data structures for TensorFlow operations monitoring and analysis.
215
216
```java { .api }
217
class Event {
218
double getWallTime();
219
long getStep();
220
String getFileVersion();
221
ByteString getGraphDef();
222
Summary getSummary();
223
WhatCase getWhatCase();
224
}
225
```
226
227
[Utilities](./utilities.md)
228
229
## Common Types
230
231
### DataType Enum
232
233
```java { .api }
234
enum DataType {
235
DT_INVALID(0),
236
DT_FLOAT(1), // 32-bit float
237
DT_DOUBLE(2), // 64-bit double
238
DT_INT32(3), // 32-bit integer
239
DT_UINT8(4), // Unsigned 8-bit integer
240
DT_INT16(5), // 16-bit integer
241
DT_INT8(6), // 8-bit integer
242
DT_STRING(7), // String
243
DT_COMPLEX64(8), // Single-precision complex
244
DT_INT64(9), // 64-bit integer
245
DT_BOOL(10), // Boolean
246
DT_QINT8(11), // Quantized 8-bit integer
247
DT_QUINT8(12), // Quantized unsigned 8-bit
248
DT_QINT32(13), // Quantized 32-bit integer
249
DT_BFLOAT16(14), // Brain floating point 16-bit
250
DT_QINT16(15), // Quantized 16-bit integer
251
DT_QUINT16(16), // Quantized unsigned 16-bit
252
DT_UINT16(17), // Unsigned 16-bit integer
253
DT_COMPLEX128(18), // Double-precision complex
254
DT_HALF(19), // 16-bit float
255
DT_RESOURCE(20), // Resource handle
256
DT_VARIANT(21), // Arbitrary C++ data types
257
DT_UINT32(22), // Unsigned 32-bit integer
258
DT_UINT64(23), // Unsigned 64-bit integer
259
260
// Reference types (for parameters)
261
DT_FLOAT_REF(101),
262
DT_DOUBLE_REF(102),
263
DT_INT32_REF(103),
264
DT_UINT8_REF(104),
265
DT_INT16_REF(105),
266
DT_INT8_REF(106),
267
DT_STRING_REF(107),
268
DT_COMPLEX64_REF(108),
269
DT_INT64_REF(109),
270
DT_BOOL_REF(110),
271
DT_QINT8_REF(111),
272
DT_QUINT8_REF(112),
273
DT_QINT32_REF(113),
274
DT_BFLOAT16_REF(114),
275
DT_QINT16_REF(115),
276
DT_QUINT16_REF(116),
277
DT_UINT16_REF(117),
278
DT_COMPLEX128_REF(118),
279
DT_HALF_REF(119),
280
DT_RESOURCE_REF(120),
281
DT_VARIANT_REF(121),
282
DT_UINT32_REF(122),
283
DT_UINT64_REF(123);
284
}
285
```
286
287
### AttrValue
288
289
```java { .api }
290
class AttrValue {
291
ByteString getS(); // String value
292
long getI(); // Integer value
293
float getF(); // Float value
294
boolean getB(); // Boolean value
295
DataType getType(); // Type value
296
TensorShapeProto getShape(); // Shape value
297
TensorProto getTensor(); // Tensor value
298
ListValue getList(); // List value
299
ValueCase getValueCase(); // Which value is set
300
}
301
```
302
303
### TensorShapeProto
304
305
```java { .api }
306
class TensorShapeProto {
307
List<Dim> getDimList();
308
boolean getUnknownRank();
309
310
static class Dim {
311
long getSize();
312
String getName();
313
}
314
}
315
```