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
Built Distribution
Close
Hashes for cjm_pytorch_utils-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d467fc66625e3cda82cf0b202d3a35877ce95c1fa6fcc77d73caad03c653c384 |
|
MD5 | 2a1738340bb7411c8a2e2bcd119838bf |
|
BLAKE2b-256 | 68f2069a7bbb79a926ed14fb7f8c01528f1971007fc25d2ca99cfbfcfe1541d4 |