Skip to main content

Buy Me A Coffee Twitter Twitter PyPI version Downloads

image

cudacanvas : PyTorch Tensor Image Display in CUDA

(Real-time PyTorch Tensor Image Visualisation in CUDA, Eliminating CPU Transfer)

CudaCanvas is a simple Python module that eliminates CPU transfer for Pytorch tensors for displaying and rendering images in the training or evaluation phase, ideal for machine learning scientists and engineers.

Simplified version that directly displays the image without explicit window creation (cudacanvas >= v1.0.1)

import torch
import cudacanvas


#REPLACE THIS with you training loop
while (True):

    #REPLACE THIS with you training code and generation of data
    noise_image = torch.rand((4, 500, 500), device="cuda")

    #Visualise your data in real-time
    cudacanvas.im_show(noise_image)

    #OPTIONAL: Terminate training when the window is closed
    if cudacanvas.should_close():
        cudacanvas.clean_up()
        #end process if the window is closed
        break

You can visualise the latent of Stable Diffusion during sampling in real-time whilst waiting for the steps to finish

import warnings
warnings.filterwarnings("ignore")
from diffusers import StableDiffusionPipeline
import torch
import cudacanvas

def display_tensors(pipe, step, timestep, callback_kwargs):
    latents = callback_kwargs["latents"]

    with torch.no_grad():
        image = pipe.vae.decode(latents / pipe.vae.config.scaling_factor, return_dict=False)[0]
        image = image - image.min()
        image = image / image.max()
    
    cudacanvas.im_show(image.squeeze(0))
    
    if cudacanvas.should_close():
        cudacanvas.clean_up()
        pipe._interrupt = True
    
    return callback_kwargs

pipeline = StableDiffusionPipeline.from_pretrained(
    "stabilityai/stable-diffusion-2-1-base",
    torch_dtype=torch.float16,
    variant="fp16"
).to("cuda")

image = pipeline(
    prompt="A croissant shaped like a cute bear.",
    negative_prompt="Deformed, ugly, bad anatomy",
    callback_on_step_end=display_tensors,
    callback_on_step_end_tensor_inputs=["latents"],
).images[0]

cudacanvas.clean_up()

Installation

Before instllation make sure you have torch with cuda support already installed on your machine

We aligned pytorch and cuda version with our package the supporting packages are torch (2.0.1, 2.1.2 and 2.2.2) and (11.8 and 12.1)

Identify your current torch and cuda version

import torch
torch.__version__

Depending on your torch and cuda you can install the relevant cudacanvas package, for the latest one matching the latest pytorch package you can simply download the latest package

pip install cudacanvas

For other torch and cuda packages put the torch and cuda version after that cudacanvas version for example for 2.1.2+cu118 the Cudacanvas package you require is 1.0.1.post212118

pip install cudacanvas==1.0.1.post212118 --force-reinstall

Support

Also support my channel ☕ ☕ : https://www.buymeacoffee.com/outofai

Metadata

Release files for cudacanvas 1.0.1.post250124

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

Built distributions (wheels)

Table of built distributions (wheels) for cudacanvas 1.0.1.post250124
File Actions
cudacanvas-1.0.1.post250124-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details for cudacanvas-1.0.1.post250124-cp311-cp311-win_amd64.whl
cudacanvas-1.0.1.post250124-cp311-cp311-manylinux2014_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ x86-64 Details for cudacanvas-1.0.1.post250124-cp311-cp311-manylinux2014_x86_64.whl
cudacanvas-1.0.1.post250124-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details for cudacanvas-1.0.1.post250124-cp310-cp310-win_amd64.whl
cudacanvas-1.0.1.post250124-cp310-cp310-manylinux2014_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.17+ x86-64 Details for cudacanvas-1.0.1.post250124-cp310-cp310-manylinux2014_x86_64.whl
cudacanvas-1.0.1.post250124-cp39-cp39-win_amd64.whl CPython 3.9 CPython 3.9 Windows x86-64 Details for cudacanvas-1.0.1.post250124-cp39-cp39-win_amd64.whl
cudacanvas-1.0.1.post250124-cp39-cp39-manylinux2014_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.17+ x86-64 Details for cudacanvas-1.0.1.post250124-cp39-cp39-manylinux2014_x86_64.whl

Total release size: 545.6 kB

Release files / cudacanvas-1.0.1.post250124-cp311-cp311-win_amd64.whl

Download URL cudacanvas-1.0.1.post250124-cp311-cp311-win_amd64.whl
Size 99.3 kB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
41981602634f1fe2bdecf401964c9e64f73d05240ac2139369f35b54315434fc
BLAKE2b-256 checksum
How to use checksums
9dc92ae2ebfb79c2c378619f04d799f72b5e2a1942ec0ee1d0ae2ceffef52f61
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.11

Release files / cudacanvas-1.0.1.post250124-cp311-cp311-manylinux2014_x86_64.whl

Download URL cudacanvas-1.0.1.post250124-cp311-cp311-manylinux2014_x86_64.whl
Size 84.4 kB
Tags CPython 3.11 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
36946957efa7454500a482cb587467a2647dc766b74a7dc9e5b420a673f54318
BLAKE2b-256 checksum
How to use checksums
89e180c319085d829ec8c04487f0b09418b32f5e0d4a697e6e718939d0c73226
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.11

Release files / cudacanvas-1.0.1.post250124-cp310-cp310-win_amd64.whl

Download URL cudacanvas-1.0.1.post250124-cp310-cp310-win_amd64.whl
Size 98.2 kB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
657b1286b481b7fcb2bb3829fc7c3dc6667088ca0292560424b62b84686f89f8
BLAKE2b-256 checksum
How to use checksums
03d5df076870ecaa07412d1f5ac0228f6c2009146eab705616a18d702ff41522
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.11

Release files / cudacanvas-1.0.1.post250124-cp310-cp310-manylinux2014_x86_64.whl

Download URL cudacanvas-1.0.1.post250124-cp310-cp310-manylinux2014_x86_64.whl
Size 82.8 kB
Tags CPython 3.10 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
b23cc0e49b880a60fb8ca1fbea3fef167dcc0f4531e82818128300ce66084313
BLAKE2b-256 checksum
How to use checksums
e6f4ba74675390cffd455705819c380b6d3e6ae932fe37db68cd7e86b321bce8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.11

Release files / cudacanvas-1.0.1.post250124-cp39-cp39-win_amd64.whl

Download URL cudacanvas-1.0.1.post250124-cp39-cp39-win_amd64.whl
Size 98.5 kB
Tags CPython 3.9 Windows x86-64
SHA-256 checksum
How to use checksums
9c4d0f2526fee9aabed1fb81614d8f2e4fe102c446c608e820cb9fe2095b3853
BLAKE2b-256 checksum
How to use checksums
ca557aa15f1bf8ad44beba1f0fb3127f34fcb251dd39aff239ee3992766e9546
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.11

Release files / cudacanvas-1.0.1.post250124-cp39-cp39-manylinux2014_x86_64.whl

Download URL cudacanvas-1.0.1.post250124-cp39-cp39-manylinux2014_x86_64.whl
Size 82.4 kB
Tags CPython 3.9 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
66c02406d4d15c5cd0889362af5197a31bd229f2d1998c978f16682a89366b32
BLAKE2b-256 checksum
How to use checksums
f04981dccf22a27acc7fce7499c0ddf6125a094c7870343eaa3a15f7c7e9d4ad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.11

Security for cudacanvas 1.0.1.post250124

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.

Release history Release notifications | RSS feed

This release
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