@@ -16,10 +16,10 @@ computer vision communities.
16
16
17
17
## Features
18
18
19
- Tensor2Robot is a library for training, evaluation, and inference of large-scale
20
- deep neural networks, tailored specifically for neural networks relating to
21
- robotic perception and control. It is based on the [ TensorFlow ] ( tensorflow.org )
22
- deep learning framework.
19
+ Tensor2Robot (T2R) is a library for training, evaluation, and inference of
20
+ large-scale deep neural networks, tailored specifically for neural networks
21
+ relating to robotic perception and control. It is based on the
22
+ [ TensorFlow ] ( tensorflow.org ) deep learning framework.
23
23
24
24
A common task in robotics research involves adding a new sensor modality or new
25
25
label tensor to a neural network graph. This involves 1) changing what data is
@@ -40,67 +40,69 @@ labels of the model. Example preprocessors can be found in
40
40
41
41
## Design Decisions
42
42
43
- - Scalability: This codebase is designed for training large-scale, real-world
44
- robotic perception models with algorithms that do not require a tight
45
- perception-action-learning loop (supervised learning, off-policy reinforcement
46
- learning of large computer vision models). An example setup might involve
47
- multiple GPUs pulling data asynchronously from a replay buffer and training
48
- with an off-policy RL algorithm, while data collection agents periodically
49
- update their checkpoints and push experiences to the same replay buffer.
43
+ - Scalability: This codebase is designed for training large-scale, real-world
44
+ robotic perception models with algorithms that do not require a tight
45
+ perception-action-learning loop (supervised learning, off-policy reinforcement
46
+ learning of large computer vision models). An example setup might involve
47
+ multiple GPUs pulling data asynchronously from a replay buffer and training
48
+ with an off-policy RL algorithm, while data collection agents periodically
49
+ update their checkpoints and push experiences to the same replay buffer.
50
50
This can also be run on a single workstation for smaller-scale experiments.
51
51
52
- - Due to the sizes of models we work with (e.g. grasping from vision) Inference
53
- is assumed to be within 1-10Hz and without real-time guarantees. If you are
54
- doing reinforcement learning with small networks (e.g. two-layer perceptron)
55
- with on-policy RL (e.g. PPO), or require hard real-time guarantees, this is
56
- probably not the right codebase to use. We recommend using
57
- [ TF-Agents] ( https://github.com/tensorflow/agents ) or
52
+ - T2R is * NOT* a general-purpose reinforcement learning library. Due to the
53
+ sizes of models we work with (e.g. grasping from vision) Inference is assumed
54
+ to be within 1-10Hz and without real-time guarantees, and training is assumed
55
+ to be distributed by default. If you are doing reinforcement learning with small
56
+ networks (e.g. two-layer perceptron) with on-policy RL (e.g. PPO), or require
57
+ hard real-time guarantees, this is probably not the right codebase to use. We
58
+ recommend using
59
+ [ TF-Agents] ( https://github.com/tensorflow/agents ) or
58
60
[ Dopamine] ( https://github.com/google/dopamine ) for those use cases.
59
61
60
- - Minimize boilerplate: Tensor2Robot Models auto-generate their own data input
61
- pipelines and provide sensible defaults for optimizers, common architectures
62
- (actors, critics), and train/eval scaffolding. Models automatically work with
63
- both GPUs and TPUs (via ` TPUEstimator ` ), parsing bmp/gif/jpeg/png-encoded
62
+ - Minimize boilerplate: Tensor2Robot Models auto-generate their own data input
63
+ pipelines and provide sensible defaults for optimizers, common architectures
64
+ (actors, critics), and train/eval scaffolding. Models automatically work with
65
+ both GPUs and TPUs (via ` TPUEstimator ` ), parsing bmp/gif/jpeg/png-encoded
64
66
images.
65
67
66
- - gin-configurable: [ Gin-Config] ( https://github.com/google/gin-config ) is used
68
+ - gin-configurable: [ Gin-Config] ( https://github.com/google/gin-config ) is used
67
69
to configure models, policies, and other experiment hyperparameters.
68
70
69
71
## Quickstart
70
72
73
+ Requirements: Python 3.
74
+
71
75
```
72
76
git clone https://github.com/google/tensor2robot
73
- cd tensor2robot
74
- pip install -r requirements.txt
75
- # Collect some data with a random policy.
76
- # TODO(b/128694019) - finish example.
77
- # Train a model.
78
- # TODO(b/128694019) - finish example.
79
- # Evaluate a policy that uses the model.
80
- # TODO(b/128694019) - finish example.
77
+ # Optional: Create a virtualenv
78
+ python3 -m venv ~/venv
79
+ source ~/venv/bin/activate
80
+ pip install -r tensor2robot/requirements.txt
81
+ python -m tensor2robot.research.pose_env.pose_env_test
82
+ python -m tensor2robot.research.pose_env.pose_env_models_test
81
83
```
82
84
83
85
84
- ## TFModel
86
+ ## T2RModel
85
87
86
- To use Tensor2Robot, a user defines a ` TFModel ` object that define their input
87
- requirements by specifications - one for their features (feature_spec) and one
88
+ To use Tensor2Robot, a user defines a ` T2RModel ` object that define their input
89
+ requirements by specifications - one for their features (feature_spec) and one
88
90
for their labels (label_spec):
89
91
90
- These specifications define all required and optional tensors in order to call
91
- the model_fn. An input pipeline parameterized with the model's input pipeline
92
+ These specifications define all required and optional tensors in order to call
93
+ the model_fn. An input pipeline parameterized with the model's input pipeline
92
94
will ensure that all required specifications are fulfilled. ** Note** : we always
93
95
omit the batch dimension and only specify the shape of a single element.
94
96
95
- At training time, the TFModel provides ` model_train_fn ` or ` model_eval_fn ` as
96
- the ` model_fn ` argument ` tf.estimator.Estimator ` class. Both ` model_train_fn `
97
- and ` model_eval_fn ` are defined with respect to the features, labels, and
98
- outputs of ` inference_network_fn ` , which presumably implements the shared
97
+ At training time, the T2RModel provides ` model_train_fn ` or ` model_eval_fn ` as
98
+ the ` model_fn ` argument ` tf.estimator.Estimator ` class. Both ` model_train_fn `
99
+ and ` model_eval_fn ` are defined with respect to the features, labels, and
100
+ outputs of ` inference_network_fn ` , which presumably implements the shared
99
101
portions of the train/eval graphs.
100
102
101
103
102
104
``` bash
103
- class MyModel(TFModel ):
105
+ class MyModel(T2RModel ):
104
106
def get_feature_specification(self, mode):
105
107
spec = tensorspec_utils.TensorSpecStruct ()
106
108
spec[' state' ] = ExtendedTensorSpec(
@@ -140,28 +142,28 @@ numpy_feed_dict. We ensure that the name is unique within the whole spec, unless
140
142
the specs match, otherwise we cannot guarantee the mapping functionality.
141
143
142
144
143
- ### Benefits of Inheriting a TFModel
145
+ ### Benefits of Inheriting a T2RModel
144
146
145
147
- Self-contained input specifications for features and labels.
146
148
- Auto-generated ` tf.data.Dataset ` pipelines for
147
149
` tf.train.Examples ` and ` tf.train.SequenceExamples ` .
148
- - For policy inference, TFModels can generate placeholders or export
150
+ - For policy inference, T2RModels can generate placeholders or export
149
151
` SavedModel ` s that are hermetic and can be used with ` ExportSavedModelPolicy ` .
150
152
- Automatic construction of ` model_fn ` for Estimator for training and evaluation
151
- graphs that share a single ` inference_network_fn ` .
152
- - It is possible to compose multiple models' ` inference_network_fn ` and
153
- ` model_train_fn ` together under a single model. This abstraction allows us to
153
+ graphs that share a single ` inference_network_fn ` .
154
+ - It is possible to compose multiple models' ` inference_network_fn ` and
155
+ ` model_train_fn ` together under a single model. This abstraction allows us to
154
156
implement generic Meta-Learning models (e.g. MAML) that call their sub-model's
155
157
` model_train_fn ` .
156
158
- Automatic support for distributed training on GPUs and TPUs.
157
159
158
160
159
161
### Policies and Placeholders
160
162
161
- For performance reasons, policy inference is done by a vanilla ` session.run() `
162
- or a ` predict_fn ` call on the output of a model, instead of Estimator.predict.
163
- ` tensorspec_utils.make_placeholders ` automatically creates placeholders from a
164
- spec structure which can be used in combination with a matching hierarchy of
163
+ For performance reasons, policy inference is done by a vanilla ` session.run() `
164
+ or a ` predict_fn ` call on the output of a model, instead of Estimator.predict.
165
+ ` tensorspec_utils.make_placeholders ` automatically creates placeholders from a
166
+ spec structure which can be used in combination with a matching hierarchy of
165
167
numpy inputs to create a feed_dict.
166
168
167
169
``` bash
@@ -174,6 +176,12 @@ feed_dict = inference_model.MakeFeedDict(placeholders, numpy_inputs)
174
176
# This can be passed to a sess.run function to evaluate the model.
175
177
```
176
178
179
+ If you use ` TFExportedSavedModelPolicy ` , note that your T2RModel should not query
180
+ the static batch shape (` x.shape[0] ` ) in the graph. This is because placeholder
181
+ generation creates inputs with unknown batch shape, causing static shape
182
+ retrieval to fail. Instead, use ` tf.shape(x)[0] ` to access batch shapes
183
+ dynamically.
184
+
177
185
## Working with Tensor Specifications
178
186
179
187
** Specifications** can be a hierarchical data structure of either
@@ -285,19 +293,19 @@ for key, value in simple_spec.items():
285
293
286
294
# ## Sequential Inputs
287
295
288
- Tensor2Robot can parse both ` tf.train.Example` and ` tf.train.SequenceExample`
289
- protos (useful for training recurrent models like LSTMs). To declare a model
296
+ Tensor2Robot can parse both ` tf.train.Example` and ` tf.train.SequenceExample`
297
+ protos (useful for training recurrent models like LSTMs). To declare a model
290
298
whose data is parsed from SequenceExamples, set ` is_sequence=True` .
291
299
292
300
` ` ` bash
293
301
spec[' state' ] = ExtendedTensorSpec(
294
302
shape=(8,128), dtype=tf.float32, name=' s' , is_sequence=True)
295
303
` ` `
296
304
297
- This will result in a parsed tensor of shape ` (b, ? , 8, 128)` where b is the
298
- batch size and the second dimension is the unknown sequence length (only known
299
- at run-time). Note that if ` is_sequence=True` for any ExtendedTensorSpec in the
300
- TensorSpecStruct, the proto will be assumed to be a SequenceExample (and
305
+ This will result in a parsed tensor of shape ` (b, ? , 8, 128)` where b is the
306
+ batch size and the second dimension is the unknown sequence length (only known
307
+ at run-time). Note that if ` is_sequence=True` for any ExtendedTensorSpec in the
308
+ TensorSpecStruct, the proto will be assumed to be a SequenceExample (and
301
309
non-sequential Tensors will be assumed to reside in example.context).
302
310
303
311
@@ -391,5 +399,5 @@ hierarchical structure.
391
399
392
400
# # Disclaimer
393
401
394
- This is not an official Google product. External support not guaranteed.
395
- Please file a GitHub issue before working on a pull request .
402
+ This is not an official Google product. External support not guaranteed. The API
403
+ may change subject to Alphabet needs. File a GitHub issue if you have questions .
0 commit comments