Transforms Module¶
Classification_Inference_Transform
¶
A transformation class to preprocess images for classification inference. This includes resizing, normalization, and conversion to a tensor.
Source code in PytorchWildlife/data/transforms.py
__call__(img)
¶
Applies the transformation on the provided image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
img
|
Image
|
Input image in PIL format. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
torch.Tensor: Transformed image. |
Source code in PytorchWildlife/data/transforms.py
__init__(target_size=224, **kwargs)
¶
Initializes the transform.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target_size
|
int
|
Desired size for the height and width after resizing. |
224
|
Source code in PytorchWildlife/data/transforms.py
MegaDetector_v5_Transform
¶
A transformation class to preprocess images for the MegaDetector v5 model. This includes resizing, transposing, and normalization operations. This is a required transformation for the YoloV5 model.
Source code in PytorchWildlife/data/transforms.py
__call__(np_img)
¶
Applies the transformation on the provided image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
np_img
|
ndarray
|
Input image as a numpy array or PIL Image. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
torch.Tensor: Transformed image. |
Source code in PytorchWildlife/data/transforms.py
__init__(target_size=1280, stride=32)
¶
Initializes the transform.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target_size
|
int
|
Desired size for the image's longest side after resizing. |
1280
|
stride
|
int
|
Stride value for resizing. |
32
|
Source code in PytorchWildlife/data/transforms.py
letterbox(im, new_shape=(640, 640), color=(114, 114, 114), auto=False, scaleFill=False, scaleup=True, stride=32)
¶
Resize and pad an image to a desired shape while keeping the aspect ratio unchanged.
This function is commonly used in object detection tasks to prepare images for models like YOLOv5. It resizes the image to fit into the new shape with the correct aspect ratio and then pads the rest.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
im
|
Image or Tensor
|
The input image. It can be a PIL image or a PyTorch tensor. |
required |
new_shape
|
tuple
|
The target size of the image, in the form (height, width). Defaults to (640, 640). |
(640, 640)
|
color
|
tuple
|
The color used for padding. Defaults to (114, 114, 114). |
(114, 114, 114)
|
auto
|
bool
|
Adjust padding to ensure the padded image dimensions are a multiple of the stride. Defaults to False. |
False
|
scaleFill
|
bool
|
If True, scales the image to fill the new shape, ignoring the aspect ratio. Defaults to False. |
False
|
scaleup
|
bool
|
Allow the function to scale up the image. Defaults to True. |
True
|
stride
|
int
|
The stride used in the model. The padding is adjusted to be a multiple of this stride. Defaults to 32. |
32
|
Returns:
Type | Description |
---|---|
Tensor
|
torch.Tensor: The transformed image with padding applied. |