tf_agents.utils.example_encoding.get_example_encoder
Stay organized with collections
Save and categorize content based on your preferences.
Get example encoder function for the given spec.
tf_agents.utils.example_encoding.get_example_encoder(
spec, compress_image=False, image_quality=95
)
Given a spec, returns an example encoder function. The example encoder
function takes a nest of np.array feature values as input and returns a
TF Example proto.
Example |
spec = {
'lidar': array_spec.ArraySpec((900,), np.float32),
'joint_positions': {
'arm': array_spec.ArraySpec((7,), np.float32),
'hand': array_spec.BoundedArraySpec((3, 3), np.int32, -1, 1)
},
}
example_encoder = get_example_encoder(spec)
serialized = example_encoder({
'lidar': np.zeros((900,), np.float32),
'joint_positions': {
'arm': np.array([0.0, 1.57, 0.707, 0.2, 0.0, -1.57, 0.0],
np.float32),
'hand': np.ones((3, 3), np.int32)
},
})
|
The returned example encoder function requires that the feature nest passed
has the shape and exact dtype specified in the spec. For example, it is
an error to pass an array with np.float64 dtype where np.float32 is expected.
Args |
spec
|
list/tuple/nest of ArraySpecs describing a single example.
|
compress_image
|
Whether to compress image. It is assumed that any uint8
tensor of rank 3 with shape (w,h,c) is an image.
|
image_quality
|
An optional int. Defaults to 95. Quality of the compression
from 0 to 100 (higher is better and slower).
|
Returns |
Function
encoder(features_nest of np.arrays) -> tf.train.Example
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-04-26 UTC.
[null,null,["Last updated 2024-04-26 UTC."],[],[],null,["# tf_agents.utils.example_encoding.get_example_encoder\n\n\u003cbr /\u003e\n\n|-------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/utils/example_encoding.py#L32-L106) |\n\nGet example encoder function for the given spec. \n\n tf_agents.utils.example_encoding.get_example_encoder(\n spec, compress_image=False, image_quality=95\n )\n\nGiven a spec, returns an example encoder function. The example encoder\nfunction takes a nest of np.array feature values as input and returns a\nTF Example proto.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Example ------- ||\n|---|---|\n| spec = { 'lidar': array_spec.ArraySpec((900,), np.float32), 'joint_positions': { 'arm': array_spec.ArraySpec((7,), np.float32), 'hand': array_spec.BoundedArraySpec((3, 3), np.int32, -1, 1) }, } \u003cbr /\u003e example_encoder = get_example_encoder(spec) serialized = example_encoder({ 'lidar': np.zeros((900,), np.float32), 'joint_positions': { 'arm': np.array(\\[0.0, 1.57, 0.707, 0.2, 0.0, -1.57, 0.0\\], np.float32), 'hand': np.ones((3, 3), np.int32) }, }) ||\n\n\u003cbr /\u003e\n\nThe returned example encoder function requires that the feature nest passed\nhas the shape and exact dtype specified in the spec. For example, it is\nan error to pass an array with np.float64 dtype where np.float32 is expected.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|------------------|----------------------------------------------------------------------------------------------------------|\n| `spec` | list/tuple/nest of ArraySpecs describing a single example. |\n| `compress_image` | Whether to compress image. It is assumed that any uint8 tensor of rank 3 with shape (w,h,c) is an image. |\n| `image_quality` | An optional int. Defaults to 95. Quality of the compression from 0 to 100 (higher is better and slower). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| Function \u003cbr /\u003e encoder(features_nest of np.arrays) -\u003e tf.train.Example \u003cbr /\u003e ||\n\n\u003cbr /\u003e"]]