FeatureSpec

See the guides: Dataset

class tflibs.datasets.feature_spec.FeatureSpec(shape)[source]

A class for specifying feature specs of a tflibs.datasets.BaseDataset.

feature_proto(value_dict)[source]

Returns a dict of tf.train.Feature proto corresponding to feature_proto_spec

Parameters:value_dict (dict) – A dict containing values of feature_proto_spec
Returns:A dict of tf.train.Feature
Return type:dict
feature_proto_spec

A property for specifying inner encoding spec of the feature

Returns:The dict containing shape and dtype info
Return type:dict
parse(parent_key, record)[source]

Parse TF-record and returns dict of tf.Tensor

Parameters:
  • parent_key (str) – The key of the feature
  • record (tf.Tensor) – String tensor of TF-record
Returns:

A dict of tensors as specified at feature_proto_spec

Return type:

dict

shape
class tflibs.datasets.feature_spec.IDSpec[source]

Bases: tflibs.datasets.feature_spec.FeatureSpec

A class for specifying unique ID.

create_with_string(string)[source]
feature_proto_spec

A property for specifying inner encoding spec of the feature

Returns:The dict containing shape and dtype info
Return type:dict
parse(parent_key, record)[source]

Parse TF-record and returns tf.Tensor

Parameters:
  • parent_key (str) – The key of the feature
  • record (tf.Tensor) – String tensor of TF-record
Returns:

A scalar tensor containing an id

Return type:

tf.Tensor

class tflibs.datasets.feature_spec.ImageSpec(image_size)[source]

Bases: tflibs.datasets.feature_spec.FeatureSpec

A class for specifying image spec

Parameters:image_size (list|tuple) – The sizes of images
create_with_contents(contents)[source]
create_with_path(path)[source]
create_with_tensor(tensor)[source]
feature_proto_spec

A property for specifying inner encoding spec of the feature

Returns:The dict containing shape and dtype info
Return type:dict
parse(parent_key, record)[source]

Parse TF-record and returns tf.Tensor

Parameters:
  • parent_key (str) – The key of the feature
  • record (tf.Tensor) – String tensor of TF-record
Returns:

A 3-D tensor containing an image

Return type:

tf.Tensor

class tflibs.datasets.feature_spec.LabelSpec(depth, class_names=None)[source]

Bases: tflibs.datasets.feature_spec.FeatureSpec

A class for specifying one-hot label spec

Parameters:
  • depth (int) – The number of labels
  • class_names (list) – A list of str which describes each labels
create_with_index(index)[source]
create_with_label(label)[source]
feature_proto_spec

A property for specifying inner encoding spec of the feature

Returns:The dict containing shape and dtype info
Return type:dict
classmethod from_class_names(class_names)[source]

Create LabelSpec object from a list of names specifying each classes

Parameters:class_names (list) – A list of names specifying each classes
Returns:LabelSpec object
Return type:LabelSpec
parse(parent_key, record)[source]

Parse TF-record and returns tf.Tensor

Parameters:
  • parent_key (str) – The key of the feature
  • record (tf.Tensor) – String tensor of TF-record
Returns:

An 1-D tensor containing label

Return type:

tf.Tensor

class tflibs.datasets.feature_spec.MultiLabelSpec(depth, class_names=None)[source]

Bases: tflibs.datasets.feature_spec.FeatureSpec

A class for specifying multi-label spec

Parameters:
  • depth (int) – The number of labels
  • class_names (list) – A list of str which describes each labels
create_with_labels(labels)[source]
create_with_tensor(tensor)[source]
feature_proto_spec

A property for specifying inner encoding spec of the feature

Returns:The dict containing shape and dtype info
Return type:dict
classmethod from_class_names(class_names)[source]

Create MultiLabelSpec object from a list of names specifying each classes

Parameters:class_names (list) – A list of names specifying each classes
Returns:MultiLabelSpec object
Return type:MultiLabelSpec
parse(parent_key, record)[source]

Parse TF-record and returns tf.Tensor

Parameters:
  • parent_key (str) – The key of the feature
  • record (tf.Tensor) – String tensor of TF-record
Returns:

A 1-D tensor containing label

Return type:

tf.Tensor