tf.train.Feature

Used in tf.train.Example protos. Contains a list of values.

Used in the notebooks

Used in the tutorials

An Example proto is a representation of the following python type:

Dict[str,
     Union[List[bytes],
           List[int64],
           List[float]]]

This proto implements the Union.

The contained list can be one of three types:

int_feature = tf.train.Feature(
    int64_list=tf.train.Int64List(value=[1, 2, 3, 4]))
float_feature = tf.train.Feature(
    float_list=tf.train.FloatList(value=[1., 2., 3., 4.]))
bytes_feature = tf.train.Feature(
    bytes_list=tf.train.BytesList(value=[b"abc", b"1234"]))

example = tf.train.Example(
    features=tf.train.Features(feature={
        'my_ints': int_feature,
        'my_floats': float_feature,
        'my_bytes': bytes_feature,
    }))

Use tf.io.parse_example to extract tensors from a serialized Example proto:

tf.io.parse_example(
    example.SerializeToString(),
    features = {
        'my_ints': tf.io.RaggedFeature(dtype=tf.int64),
        'my_floats': tf.io.RaggedFeature(dtype=tf.float32),
        'my_bytes': tf.io.RaggedFeature(dtype=tf.string)})
{&#x27;my_bytes': <tf.Tensor: shape=(2,), dtype=string,
                         numpy=array([b&#x27;abc', b'1234'], dtype=object)>,
 &#x27;my_floats': <tf.Tensor: shape=(4,), dtype=float32,
                          numpy=array([1., 2., 3., 4.], dtype=float32)>,
 &#x27;my_ints': <tf.Tensor: shape=(4,), dtype=int64,
                        numpy=array([1, 2, 3, 4])>}

bytes_list BytesList bytes_list
float_list FloatList float_list
int64_list Int64List int64_list