cjm-torchvision-tfms
Install
pip install cjm_torchvision_tfms
How to use
from PIL import Image
img_path = './images/call-hand-gesture.png'
# Open the associated image file as a RGB image
sample_img = Image.open(img_path).convert('RGB')
# Print the dimensions of the image
print(f"Image Dims: {sample_img.size}")
# Show the image
sample_img
Image Dims: (384, 512)
from cjm_torchvision_tfms.core import ResizeMax, PadSquare, CustomTrivialAugmentWide
import torch
from torchvision import transforms
from cjm_pytorch_utils.core import tensor_to_pil
from cjm_pil_utils.core import stack_imgs
target_sz = 384
print(f"Source image: {sample_img.size}")
# Create a `ResizeMax` object
resize_max = ResizeMax(max_sz=target_sz)
# Convert the cropped image to a tensor
img_tensor = transforms.PILToTensor()(sample_img)[None]
print(f"Image tensor: {img_tensor.shape}")
# Resize the tensor
resized_tensor = resize_max(img_tensor)
print(f"Padded tensor: {resized_tensor.shape}")
# Display the updated image
tensor_to_pil(resized_tensor)
Source image: (384, 512)
Image tensor: torch.Size([1, 3, 512, 384])
Padded tensor: torch.Size([1, 3, 384, 288])
print(f"Resized tensor: {resized_tensor.shape}")
# Create a `PadSquare` object
pad_square = PadSquare(shift=True)
# Pad the tensor
padded_tensor = pad_square(resized_tensor)
print(f"Padded tensor: {padded_tensor.shape}")
# Display the updated image
stack_imgs([tensor_to_pil(pad_square(resized_tensor)) for i in range(3)])
Resized tensor: torch.Size([3, 384, 288])
Padded tensor: torch.Size([3, 384, 384])
num_bins = 31
custom_augmentation_space = {
# Identity operation doesn't change the image
"Identity": (torch.tensor(0.0), False),
# Distort the image along the x or y axis, respectively.
"ShearX": (torch.linspace(0.0, 0.25, num_bins), True),
"ShearY": (torch.linspace(0.0, 0.25, num_bins), True),
# Move the image along the x or y axis, respectively.
"TranslateX": (torch.linspace(0.0, 32.0, num_bins), True),
"TranslateY": (torch.linspace(0.0, 32.0, num_bins), True),
# Rotate operation: rotates the image.
"Rotate": (torch.linspace(0.0, 45.0, num_bins), True),
# Adjust brightness, color, contrast,and sharpness respectively.
"Brightness": (torch.linspace(0.0, 0.75, num_bins), True),
"Color": (torch.linspace(0.0, 0.99, num_bins), True),
"Contrast": (torch.linspace(0.0, 0.99, num_bins), True),
"Sharpness": (torch.linspace(0.0, 0.99, num_bins), True),
# Reduce the number of bits used to express the color in each channel of the image.
"Posterize": (8 - (torch.arange(num_bins) / ((num_bins - 1) / 6)).round().int(), False),
# Invert all pixel values above a threshold.
"Solarize": (torch.linspace(255.0, 0.0, num_bins), False),
# Maximize the image contrast by setting the darkest color to black and the lightest to white.
"AutoContrast": (torch.tensor(0.0), False),
# Equalize the image histogram to improve its contrast.
"Equalize": (torch.tensor(0.0), False),
}
# Create a `CustomTrivialAugmentWide` object
trivial_aug = CustomTrivialAugmentWide(op_meta=custom_augmentation_space)
# Pad the tensor
aug_tensor = trivial_aug(resized_tensor)
print(f"Augmented tensor: {aug_tensor.shape}")
# Display the updated image
stack_imgs([tensor_to_pil(trivial_aug(resized_tensor)) for i in range(3)])
Augmented tensor: torch.Size([3, 384, 288])
Metadata
Release files for cjm-torchvision-tfms 0.0.26
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| cjm_torchvision_tfms-0.0.26.tar.gz | 28.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| cjm_torchvision_tfms-0.0.26-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 63.5 kB
Release files / cjm_torchvision_tfms-0.0.26.tar.gz
| Download URL | cjm_torchvision_tfms-0.0.26.tar.gz |
|---|---|
| Size | 28.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dfc35f018e9e0b392a01ee922ed771b7ea8a3f43d11515126fc442e48e2baada
|
|
BLAKE2b-256 checksum How to use checksums |
086edec852d3ea4d383c38b4ee60d556cf0dbebdccc25cf2622bff71b62370d5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.11
|
Release files / cjm_torchvision_tfms-0.0.26-py3-none-any.whl
| Download URL | cjm_torchvision_tfms-0.0.26-py3-none-any.whl |
|---|---|
| Size | 34.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
10dae5d80f7c1e89c7f5f14059081524a812ae17e8a95ffecc64409db5721eed
|
|
BLAKE2b-256 checksum How to use checksums |
e035639c6c2522d0f785d73c2f8a70e226caedbf8b0dbc8085c2d4c946173d08
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.11
|
Security for cjm-torchvision-tfms 0.0.26
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.