tlc.core.operations.bb_operations¶

Operations for cropping images using bounding boxes.

Module Contents¶

Classes¶

Class

Description

BBCropEmbeddingOperation

Operation that uses BBCropInterface to crop images and then embeds them using a neural network.

BBCropMixin

Mixin for operations that use BBCropInterface.

BBCropOperation

Operation that uses BBCropInterface to crop images and then returns the cropped image.

BBCropRGBAverageOperation

Operation that uses BBCropInterface to crop images and then calculates the average RGB value of the crop.

API¶

class BBCropEmbeddingOperation(
embeddings_model: Module | None = None,
embeddings_dim: int = 512,
transforms: Callable[[Image], Tensor] | None = None,
batch_size: int = 16,
num_workers: int = 0,
)¶

Bases: tlc.core.operations.operation.GlobalOperation, tlc.core.operations.bb_operations.BBCropMixin

Operation that uses BBCropInterface to crop images and then embeds them using a neural network.

The embedder network can be provided as an argument, or a default ResNet18 model will be used.

Parameters:
  • embeddings_model – The neural network to use for embedding. If None, a default ResNet18 model will be used.

  • embeddings_dim – The dimensionality of the embeddings produced by the neural network.

  • transforms – A callable that transforms a PIL image into a tensor.

  • batch_size – The batch size to use when embedding images.

  • num_workers – The number of workers to use when embedding images.

calculate_schema(
calculate_schema_context: CalculateSchemaContext,
) Schema¶
populate_column_data(
calculate_value_context: CalculateValueContext,
) list[Any]¶
class BBCropMixin¶

Mixin for operations that use BBCropInterface.

Provides helper-functionality and re-use of written crop images between operations.

static create_crop_url(
input_table_url: Url,
row_idx: int | str = '[row_idx]',
) Path¶

Creates a deterministic URL for a crop image.

static get_bb_columns(
input_schemas: dict[str, Schema],
) list[str]¶
static get_image_url_columns(
input_schemas: dict[str, Schema],
) list[str]¶
class BBCropOperation¶

Bases: tlc.core.operations.operation.LocalOperation, tlc.core.operations.bb_operations.BBCropMixin

Operation that uses BBCropInterface to crop images and then returns the cropped image.

Filenames for image crops are deterministic based on the input table and row index. If the image already exists, it will be loaded from disk instead of being re-cropped.

calculate_schema(
calculate_schema_context: CalculateSchemaContext,
) Schema¶
calculate_single_value(
row: Mapping[str, Any],
calculate_value_context: CalculateValueContext,
) Any¶
class BBCropRGBAverageOperation¶

Bases: tlc.core.operations.operation.LocalOperation, tlc.core.operations.bb_operations.BBCropMixin

Operation that uses BBCropInterface to crop images and then calculates the average RGB value of the crop.

The average RGB values are returned as a dictionary with keys “red_avg”, “green_avg”, and “blue_avg”.

calculate_schema(
calculate_schema_context: CalculateSchemaContext,
) Schema¶
calculate_single_value(
row: Mapping[str, Any],
calculate_value_context: CalculateValueContext,
) Any¶