Skip to main content

cjm-diffusers-utils

Install

pip install cjm_diffusers_utils

How to use

pil_to_latent

from cjm_diffusers_utils.core import pil_to_latent
from PIL import Image  # For working with images
from torchvision import transforms  # PyTorch module for image transformations
# Import diffusers AutoencoderKL
from diffusers import AutoencoderKL
model_name = "stabilityai/stable-diffusion-2-1"
vae = AutoencoderKL.from_pretrained(model_name, subfolder="vae")
img_path = img_path = '../images/cat.jpg'
src_img = Image.open(img_path).convert('RGB')
print(f"Source Image Size: {src_img.size}")

img_latents = pil_to_latent(src_img, vae)
print(f"Latent Dimensions: {img_latents.shape}")
Source Image Size: (768, 512)
Latent Dimensions: torch.Size([1, 4, 64, 96])

latent_to_pil

from cjm_diffusers_utils.core import latent_to_pil
decoded_img = latent_to_pil(img_latents, vae)
print(f"Decoded Image Size: {decoded_img.size}")
Decoded Image Size: (768, 512)

text_to_emb

from cjm_diffusers_utils.core import text_to_emb
# Import the `CLIPTextModel`, `CLIPTokenizer`
from transformers import CLIPTextModel, CLIPTokenizer
# Load the tokenizer for the specified model
tokenizer = CLIPTokenizer.from_pretrained(model_name, subfolder="tokenizer")
# Load the text encoder for the specified model
text_encoder = CLIPTextModel.from_pretrained(model_name, subfolder="text_encoder")
prompt = "A cat sitting on the floor."
text_emb = text_to_emb(prompt, tokenizer, text_encoder)
text_emb.shape
torch.Size([2, 77, 1024])

prepare_noise_scheduler

from cjm_diffusers_utils.core import prepare_noise_scheduler
from diffusers import DDIMScheduler
noise_scheduler = DDIMScheduler.from_pretrained(model_name, subfolder='scheduler')
print(f"Number of timesteps: {len(noise_scheduler.timesteps)}")
print(noise_scheduler.timesteps[:10])

noise_scheduler = prepare_noise_scheduler(noise_scheduler, 70, 1.0)
print(f"Number of timesteps: {len(noise_scheduler.timesteps)}")
print(noise_scheduler.timesteps[:10])
Number of timesteps: 1000
tensor([999, 998, 997, 996, 995, 994, 993, 992, 991, 990])
Number of timesteps: 70
tensor([967, 953, 939, 925, 911, 897, 883, 869, 855, 841])

prepare_depth_mask

from cjm_diffusers_utils.core import prepare_depth_mask
depth_map_path = '../images/depth-cat.png'
depth_map = Image.open(depth_map_path)
print(f"Depth map size: {depth_map.size}")

depth_mask = prepare_depth_mask(depth_map)
depth_mask.shape, depth_mask.min(), depth_mask.max()
Depth map size: (768, 512)

(torch.Size([1, 1, 64, 96]), tensor(-1.), tensor(1.))

Metadata

Release files for cjm-diffusers-utils 0.0.1

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-diffusers-utils 0.0.1
File Size Uploaded Provenance Actions
cjm-diffusers-utils-0.0.1.tar.gz 7.1 kB Without provenance Details for cjm-diffusers-utils-0.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cjm-diffusers-utils 0.0.1
File Interpreter ABI Platform Actions
cjm_diffusers_utils-0.0.1-py3-none-any.whl Python 3 none any Details for cjm_diffusers_utils-0.0.1-py3-none-any.whl

Total release size: 15.3 kB

Release files / cjm-diffusers-utils-0.0.1.tar.gz

Download URL cjm-diffusers-utils-0.0.1.tar.gz
Size 7.1 kB
Tags Source
SHA-256 checksum
How to use checksums
17a5dc87a57d204be6b8cc1201994452b191994f9f482054f4872db80dfb4bbc
BLAKE2b-256 checksum
How to use checksums
71a94a829206ae5d2441815b6219abb6621108e29b82a594e99427e4feb0e32e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.15

Release files / cjm_diffusers_utils-0.0.1-py3-none-any.whl

Download URL cjm_diffusers_utils-0.0.1-py3-none-any.whl
Size 8.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7e0e40ba414c2452ae6b776b733000e33a1a0c4438027fc9a3e67bd3c7be0529
BLAKE2b-256 checksum
How to use checksums
8ead05996b116d86f7f4c6b1594af69cf240f83d6968b001d147a1318e73d248
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.15

Security for cjm-diffusers-utils 0.0.1

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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