tlc.core.operations.bb_operations
#
Operations for cropping images using bounding boxes.
Module Contents#
Classes#
Class |
Description |
---|---|
Mixin for operations that use BBCropInterface. |
|
Operation that uses BBCropInterface to crop images and then embeds them using a neural network. |
|
Operation that uses BBCropInterface to crop images and then calculates the average RGB value of the crop. |
|
Operation that uses BBCropInterface to crop images and then returns the cropped image. |
API#
- class tlc.core.operations.bb_operations.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: tlc.core.url.Url, row_idx: int | str = '[row_idx]') pathlib.Path #
Creates a deterministic URL for a crop image.
- class tlc.core.operations.bb_operations.BBCropEmbeddingOperation(embeddings_model: torch.nn.Module | None = None, embeddings_dim: int = 512, transforms: Callable[[PIL.Image.Image], torch.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.
- populate_column_data(calculate_value_context: tlc.core.operations.operation.CalculateValueContext) list[Any] #
- calculate_schema(calculate_schema_context: tlc.core.operations.operation.CalculateSchemaContext) tlc.core.schema.Schema #
- class tlc.core.operations.bb_operations.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: tlc.core.operations.operation.CalculateSchemaContext) tlc.core.schema.Schema #
- class tlc.core.operations.bb_operations.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: tlc.core.operations.operation.CalculateSchemaContext) tlc.core.schema.Schema #