pixano_inference.impls._helpers
Torch helpers re-exported for the built-in torch backends.
The implementations live in :mod:pixano_inference.frameworks.torch; they are re-exported
here for the built-in (transformers-based) backends that import them.
convert_image_pil_to_tensor(image, device, size=None)
Convert a PIL image to a (C, H, W) float tensor, optionally resizing 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/frameworks/torch.py
encode_mask_to_rle(mask)
Encode a binary mask tensor 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/frameworks/torch.py
resolve_device(config)
Return the torch device for a deployment config (see :func:resolve_device_from_num_gpus).
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/frameworks/torch.py
should_compile(device, requested)
Decide whether to torch.compile a model.
torch.compile needs a working compiler and only pays off on GPU; on CPU it is often a
slow no-win and can fail outright. So honour an explicit compile param when given, else
auto-detect: compile only on CUDA devices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device
|
Any
|
The resolved torch device (or a device string). |
required |
requested
|
bool | None
|
The user's |
required |
Returns:
| Type | Description |
|---|---|
bool
|
Whether to compile the model. |