Htypes

“htype” is the class of a tensor: image, bounding box, generic tensor, etc.

When not specified, the unspecified options will be inferred from the data:

>>> ds.create_tensor("my_tensor")
>>> ds.my_tensor.append(1)
>>> ds.my_tensor.dtype
int64

If you know beforehand, you can use htype at creation:

>>> ds.create_tensor("my_tensor", htype="image", sample_compression=None)

Specifying an htype allows for strict settings and error handling, and it is critical for increasing the performance of hub datasets containing rich data such as images and videos.

Supported htypes and their respective defaults are:

HTYPE

DTYPE

COMPRESSION

image

uint8

None

image.rgb

uint8

None

image.gray

uint8

None

class_label

uint32

None

bbox

float32

None

video

uint8

None

binary_mask

bool

None

segment_mask

uint32

None

keypoints_coco

int32

None

point

int32

None

audio

float64

None

text

str

None

json

Any

None

list

List

None

dicom

None

dcm

link

str

None

sequence

None

None

Sequence htype

  • A special meta htype for tensors where each sample is a sequence. The items in the sequence are samples of another htype.

  • It is a wrapper htype that can wrap other htypes like sequence[image], sequence[video], sequence[text], etc.

Examples

>>> ds.create_tensor("seq", htype="sequence")
>>> ds.seq.append([1, 2, 3])
>>> ds.seq.append([4, 5, 6])
>>> ds.seq.numpy()
array([[[1],
        [2],
        [3]],
       [[4],
        [5],
        [6]]])
>>> ds.create_tensor("image_seq", htype="sequence[image]", sample_compression="jpg")
>>> ds.image_seq.append([hub.read("img01.jpg"), hub.read("img02.jpg")])