Skip to main content

Some utility functions for working with PyTorch.

Project description

cjm-pytorch-utils

Install

pip install cjm_pytorch_utils

How to use

pil_to_tensor

from cjm_pytorch_utils.core import pil_to_tensor
from PIL import Image
from torchvision import transforms
img_path = img_path = '../images/cat.jpg'
src_img = Image.open(img_path).convert('RGB')
print(f"Source Image Size: {src_img.size}")

img_tensor = pil_to_tensor(src_img, [0.5], [0.5])
img_tensor.shape, img_tensor.min(), img_tensor.max()
Source Image Size: (768, 512)

(torch.Size([1, 3, 512, 768]), tensor(-1.), tensor(1.))

tensor_to_pil

from cjm_pytorch_utils.core import tensor_to_pil
tensor_img = tensor_to_pil(transforms.ToTensor()(src_img))
tensor_img

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cjm-pytorch-utils-0.0.1.tar.gz (5.0 kB view hashes)

Uploaded Source

Built Distribution

cjm_pytorch_utils-0.0.1-py3-none-any.whl (5.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page