pixano_inference.impls._helpers
Shared utility functions for built-in model implementations.
convert_image_pil_to_tensor(image, device, size=None)
Convert an image in PIL format to a PyTorch tensor and optionally resize it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Any
|
PIL image. |
required |
device
|
'torch.device'
|
Torch device. |
required |
size
|
int | None
|
Optional target size (both height and width). |
None
|
Returns:
| Type | Description |
|---|---|
'Tensor'
|
Image as a |
Source code in pixano_inference/impls/_helpers.py
encode_mask_to_rle(mask)
Encode a binary mask using RLE.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mask
|
'Tensor'
|
A binary mask of shape (height, width). |
required |
Returns:
| Type | Description |
|---|---|
dict[str, list[int]]
|
RLE encoded mask as a dictionary. |
Source code in pixano_inference/impls/_helpers.py
pad_points_and_labels(points, labels)
Pad ragged point/label lists to uniform length.
Adapted from HuggingFace's SAM processing (Apache-2.0 License).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
list[list[list[int]]]
|
Point prompts |
required |
labels
|
list[list[int]] | None
|
Label prompts |
required |
Returns:
| Type | Description |
|---|---|
tuple[ndarray, ndarray | None]
|
Tuple of |
Source code in pixano_inference/impls/_helpers.py
resolve_device(config)
Return torch.device('cuda') when a GPU is requested and available, else CPU.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
ModelDeploymentConfig
|
Model deployment configuration. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
A |
Source code in pixano_inference/impls/_helpers.py
resolve_torch_dtype(dtype_str)
Map a dtype string to a torch.dtype.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dtype_str
|
str
|
One of |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Corresponding |
Raises:
| Type | Description |
|---|---|
ValueError
|
If dtype_str is not recognised. |
Source code in pixano_inference/impls/_helpers.py
validate_prompts(points, labels, boxes)
Validate point/label/box prompts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
list[list[list[int]]] | None
|
Point prompts |
required |
labels
|
list[list[int]] | None
|
Label prompts |
required |
boxes
|
list[list[int]] | None
|
Box prompts |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
On any validation failure. |