Apply to speak at TensorFlow World. Deadline April 23rd. Propose talk

tfds.features.ClassLabel

Class ClassLabel

Inherits From: FeatureConnector

Defined in core/features/class_label_feature.py.

FeatureConnector for integer class labels.

__init__

__init__(
    num_classes=None,
    names=None,
    names_file=None
)

Constructs a ClassLabel FeatureConnector.

There are 3 ways to define a ClassLabel, which correspond to the 3 arguments: * num_classes: create 0 to (num_classes-1) labels * names: a list of label strings * names_file: a file containing the list of labels.

Args:

  • num_classes: int, number of classes. All labels must be < num_classes.
  • names: list<str>, string names for the integer classes. The order in which the names are provided is kept.
  • names_file: str, path to a file with names for the integer classes, one per line.

Properties

dtype

Return the dtype (or dict of dtype) of this FeatureConnector.

names

num_classes

serialized_keys

List of the flattened feature keys after serialization.

shape

Return the shape (or dict of shape) of this FeatureConnector.

Methods

decode_example

decode_example(tfexample_data)

encode_example

encode_example(example_data)

get_serialized_info

get_serialized_info()

Return the tf-example features for the adapter, as stored on disk.

This function indicates how this feature is encoded on file internally. The DatasetBuilder are written on disk as tf.train.Example proto.

Ex:

return {
    'image': tf.VarLenFeature(tf.uint8):
    'height': tf.FixedLenFeature((), tf.int32),
    'width': tf.FixedLenFeature((), tf.int32),
}

FeatureConnector which are not containers should return the feature proto directly:

return tf.FixedLenFeature((64, 64), tf.uint8)

If not defined, the retuned values are automatically deduced from the get_tensor_info function.

Returns:

  • features: Either a dict of feature proto object, or a feature proto object

get_tensor_info

get_tensor_info()

int2str

int2str(int_value)

Conversion integer => class name string.

load_metadata

load_metadata(
    data_dir,
    feature_name=None
)

See base class for details.

save_metadata

save_metadata(
    data_dir,
    feature_name=None
)

See base class for details.

str2int

str2int(str_value)

Conversion class name string => integer.