Skip to main content

cjm-pytorch-utils

Install

pip install cjm_pytorch_utils

How to use

set_seed

from cjm_pytorch_utils.core import set_seed
seed = 1234
set_seed(seed)

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

iterate_modules

from cjm_pytorch_utils.core import iterate_modules
import torch
from torchvision import models
vgg = models.vgg16(weights=models.VGG16_Weights.IMAGENET1K_V1).features

for index, module in enumerate(iterate_modules(vgg)):
    if type(module) == torch.nn.modules.activation.ReLU:
        print(f"{index}: {module}")
1: ReLU(inplace=True)
3: ReLU(inplace=True)
6: ReLU(inplace=True)
8: ReLU(inplace=True)
11: ReLU(inplace=True)
13: ReLU(inplace=True)
15: ReLU(inplace=True)
18: ReLU(inplace=True)
20: ReLU(inplace=True)
22: ReLU(inplace=True)
25: ReLU(inplace=True)
27: ReLU(inplace=True)
29: ReLU(inplace=True)

tensor_stats_df

from cjm_pytorch_utils.core import tensor_stats_df
tensor_stats_df(torch.randn(1, 3, 256, 256))
<style scoped> .dataframe tbody tr th:only-of-type { vertical-align: middle; } .dataframe tbody tr th { vertical-align: top; } .dataframe thead th { text-align: right; } </style>
0
mean 0.003342
std 0.99868
min -4.558271
max 4.815985
shape (1, 3, 256, 256)

get_torch_device

from cjm_pytorch_utils.core import get_torch_device
get_torch_device()
'cuda'

denorm_img_tensor

from cjm_pytorch_utils.core import denorm_img_tensor
tensor_to_pil(img_tensor)

tensor_to_pil(denorm_img_tensor(img_tensor, [0.5], [0.5]))

Metadata

Release files for cjm-pytorch-utils 0.0.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cjm-pytorch-utils 0.0.8
File Size Uploaded Provenance
cjm_pytorch_utils-0.0.8.tar.gz 8.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for cjm-pytorch-utils 0.0.8
File Interpreter ABI Platform
cjm_pytorch_utils-0.0.8-py3-none-any.whl Python 3 none any Details

Total release size: 16.6 kB

Release files / cjm_pytorch_utils-0.0.8.tar.gz

Download URL cjm_pytorch_utils-0.0.8.tar.gz
Size 8.3 kB
Tags Source
SHA-256 checksum
How to use checksums
a7ddc70630509190b7d4e1c2b151533e89a10f7ca84255639dd3a5d2e4dc8f11
BLAKE2b-256 checksum
How to use checksums
b67351804cccd2797d45aa0b131189456ac100af76b211b08350d72b60f62100
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.10.14

Release files / cjm_pytorch_utils-0.0.8-py3-none-any.whl

Download URL cjm_pytorch_utils-0.0.8-py3-none-any.whl
Size 8.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
406608c10ac5a022f16f5d2ba8dd843fdfe338809fe975987538b83bf8f0c172
BLAKE2b-256 checksum
How to use checksums
6a1fbfe678df47d83fa600287da3fe19de8c7e4817f3ff9bbb493301fae843c2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.10.14

Security for cjm-pytorch-utils 0.0.8

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page