Skip to content

Sample

Sample

Interface for Sample objects.

Sample

Sample(sample_table: SampleTable)

Bases: ABC

Interface to a dataset sample.

It is usually returned by a query to the dataset.

for sample in dataset:
    ...

Access sample's metadata via the metadata property, which provides a dictionary-like interface to get and set metadata key-value pairs.

some_value = sample.metadata["some_key"]
sample.metadata["another_key"] = "new_value"

Access sample's tags via the tags property.

sample.tags = ["tag1", "tag2"]  # Replace all tags
print(f"Current tags: {sample.tags}")
sample.add_tag("tag_3")
sample.remove_tag("tag_1")

Parameters:

Name Type Description Default
sample_table SampleTable

The SampleTable SQLAlchemy model instance.

required

annotations property

annotations: list[Annotation]

Returns all annotations.

captions property writable

captions: list[str]

Returns the text of all captions.

dataset_id property

dataset_id: UUID

Get the dataset ID this sample belongs to.

Returns:

Type Description
UUID

The UUID of the dataset.

metadata property

metadata: SampleMetadata

Get dictionary-like access to sample metadata.

Returns:

Type Description
SampleMetadata

A dictionary-like object for accessing metadata.

sample_id property

sample_id: UUID

Sample ID.

sample_table property

sample_table: SampleTable

Returns the SampleTable associated with this Sample.

tags property writable

tags: set[str]

Get the tag names associated with this sample.

Returns:

Type Description
set[str]

A set of tag names as strings.

add_annotation

add_annotation(annotation: CreateAnnotation) -> None

Add an annotation to this sample.

Parameters:

Name Type Description Default
annotation CreateAnnotation

The annotation to add.

required

add_caption

add_caption(text: str) -> None

Add a caption to this sample.

Parameters:

Name Type Description Default
text str

The text of the caption to add.

required

add_tag

add_tag(name: str) -> None

Add a tag to this sample.

If the tag doesn't exist, it will be created first.

Parameters:

Name Type Description Default
name str

The name of the tag to add.

required

delete_annotation

delete_annotation(annotation: Annotation) -> None

Delete an annotation from this sample.

Parameters:

Name Type Description Default
annotation Annotation

The annotation to delete.

required

get_object_session

get_object_session() -> Session

Get the database session for this sample.

Returns:

Type Description
Session

The SQLModel session.

Raises:

Type Description
RuntimeError

If no active session is found.

remove_tag

remove_tag(name: str) -> None

Remove a tag from this sample.

Parameters:

Name Type Description Default
name str

The name of the tag to remove.

required

ImageSample

Definition of ImageSample class, representing a dataset image sample.

ImageSample

ImageSample(inner: ImageTable)

Bases: Sample

Interface to a dataset image sample.

Many properties of the sample are directly accessible as attributes of this class.

print(f"Sample file name: {sample.file_name}")
print(f"Sample file path: {sample.file_path_abs}")
print(f"Sample width: {sample.width}")
print(f"Sample height: {sample.height}")

Parameters:

Name Type Description Default
inner ImageTable

The ImageTable SQLAlchemy model instance.

required

annotations property

annotations: list[Annotation]

Returns all annotations.

captions property writable

captions: list[str]

Returns the text of all captions.

created_at class-attribute instance-attribute

created_at = DBField(col(created_at))

Creation timestamp

dataset_id property

dataset_id: UUID

Get the dataset ID this sample belongs to.

Returns:

Type Description
UUID

The UUID of the dataset.

file_name class-attribute instance-attribute

file_name = DBField(col(file_name))

Image file name

file_path_abs class-attribute instance-attribute

file_path_abs = DBField(col(file_path_abs))

Absolute path to image

height class-attribute instance-attribute

height = DBField(col(height))

Image height (px)

metadata property

metadata: SampleMetadata

Get dictionary-like access to sample metadata.

Returns:

Type Description
SampleMetadata

A dictionary-like object for accessing metadata.

sample_id property

sample_id: UUID

Sample ID.

sample_table property

sample_table: SampleTable

Returns the SampleTable associated with this Sample.

tags property writable

tags: set[str]

Get the tag names associated with this sample.

Returns:

Type Description
set[str]

A set of tag names as strings.

updated_at class-attribute instance-attribute

updated_at = DBField(col(updated_at))

Timestamp of the latest update

width class-attribute instance-attribute

width = DBField(col(width))

Image width (px)

add_annotation

add_annotation(annotation: CreateAnnotation) -> None

Add an annotation to this sample.

Parameters:

Name Type Description Default
annotation CreateAnnotation

The annotation to add.

required

add_caption

add_caption(text: str) -> None

Add a caption to this sample.

Parameters:

Name Type Description Default
text str

The text of the caption to add.

required

add_tag

add_tag(name: str) -> None

Add a tag to this sample.

If the tag doesn't exist, it will be created first.

Parameters:

Name Type Description Default
name str

The name of the tag to add.

required

delete_annotation

delete_annotation(annotation: Annotation) -> None

Delete an annotation from this sample.

Parameters:

Name Type Description Default
annotation Annotation

The annotation to delete.

required

get_object_session

get_object_session() -> Session

Get the database session for this sample.

Returns:

Type Description
Session

The SQLModel session.

Raises:

Type Description
RuntimeError

If no active session is found.

remove_tag

remove_tag(name: str) -> None

Remove a tag from this sample.

Parameters:

Name Type Description Default
name str

The name of the tag to remove.

required

VideoSample

Definition of VideoSample class, representing a dataset video sample.

VideoSample

VideoSample(inner: VideoTable)

Bases: Sample

Interface to a dataset video sample.

Many properties of the sample are directly accessible as attributes of this class.

print(f"Sample file name: {sample.file_name}")
print(f"Sample file path: {sample.file_path_abs}")
print(f"Sample width: {sample.width}")
print(f"Sample height: {sample.height}")
print(f"Sample duration (seconds): {sample.duration_s}")
print(f"Sample FPS: {sample.fps}")

Parameters:

Name Type Description Default
inner VideoTable

The VideoTable SQLAlchemy model instance.

required

annotations property

annotations: list[Annotation]

Returns all annotations.

captions property writable

captions: list[str]

Returns the text of all captions.

dataset_id property

dataset_id: UUID

Get the dataset ID this sample belongs to.

Returns:

Type Description
UUID

The UUID of the dataset.

duration_s class-attribute instance-attribute

duration_s = DBField(col(duration_s))

Video duration in seconds

file_name class-attribute instance-attribute

file_name = DBField(col(file_name))

Video file name

file_path_abs class-attribute instance-attribute

file_path_abs = DBField(col(file_path_abs))

Absolute path to video

fps class-attribute instance-attribute

fps = DBField(col(fps))

Video FPS

height class-attribute instance-attribute

height = DBField(col(height))

Video height (px)

metadata property

metadata: SampleMetadata

Get dictionary-like access to sample metadata.

Returns:

Type Description
SampleMetadata

A dictionary-like object for accessing metadata.

sample_id property

sample_id: UUID

Sample ID.

sample_table property

sample_table: SampleTable

Returns the SampleTable associated with this Sample.

tags property writable

tags: set[str]

Get the tag names associated with this sample.

Returns:

Type Description
set[str]

A set of tag names as strings.

width class-attribute instance-attribute

width = DBField(col(width))

Video width (px)

add_annotation

add_annotation(annotation: CreateAnnotation) -> None

Add an annotation to this sample.

Parameters:

Name Type Description Default
annotation CreateAnnotation

The annotation to add.

required

add_caption

add_caption(text: str) -> None

Add a caption to this sample.

Parameters:

Name Type Description Default
text str

The text of the caption to add.

required

add_tag

add_tag(name: str) -> None

Add a tag to this sample.

If the tag doesn't exist, it will be created first.

Parameters:

Name Type Description Default
name str

The name of the tag to add.

required

delete_annotation

delete_annotation(annotation: Annotation) -> None

Delete an annotation from this sample.

Parameters:

Name Type Description Default
annotation Annotation

The annotation to delete.

required

get_object_session

get_object_session() -> Session

Get the database session for this sample.

Returns:

Type Description
Session

The SQLModel session.

Raises:

Type Description
RuntimeError

If no active session is found.

remove_tag

remove_tag(name: str) -> None

Remove a tag from this sample.

Parameters:

Name Type Description Default
name str

The name of the tag to remove.

required