Skip to main content

Minimalistic library designed to be an interface for the model input with a lightweight `Image` class.

Project description

pytorch-image

Minimalistic library designed to be an interface for the model input with a lightweight Image class.

from my_model import MyModel, Image

image = Image.from_numpy(numpy_image)
predictions = model(image)

It also offers a simple interface for essential image operations such as loading, resizing, augmenting, and saving.

Installation

pip install pytorch-image
poetry add pytorch-image

Usage

from pytorch_image import Image
import albumentations


image = Image.open("path/to/image.png")

image.augment(albumentations.HorizontalFlip())

image.torch()

Available Methods

The Image class provides the following methods:

Class Methods

  • Image.open(path): Open an image file and create an Image instance.
  • Image.from_pil_image(pil_image): Create an Image instance from a PIL Image.
  • Image.from_numpy(numpy_image): Create an Image instance from a NumPy array. Expects HWC format, uint8 (0-255).
  • Image.from_torch(torch_tensor): Create an Image instance from a PyTorch tensor. Expects NCHW format, float (0-1).
  • Image.cat(images, dim=0): Concatenate multiple Image instances.

Instance Methods

  • resize(shape, mode="bicubic", align_corners=None, antialias=None): Resize the image.
  • augment(augmenter): Apply augmentations to the image.
  • map(func): Apply a function to the image data.
  • replace(**kwargs): Create a new Image instance with replaced attributes.
  • torch(): Get the image data as a PyTorch tensor.
  • numpy(): Get the image data as a NumPy array.
  • representation(): Get a normalized representation of the image data.
  • save(path): Save the image to a file.
  • pil_image(): Convert the image to a PIL Image.

Properties and Special Methods

  • shape: Get the shape of the image data.
  • __len__(): Get the number of images in the batch.
  • __iter__(): Iterate over images in the batch.
  • __getitem__(index): Get a specific image from the batch.
  • _repr_png_(): Get a PNG representation for Jupyter notebook display.

For detailed information on each method, please refer to the docstrings in the source code.

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

pytorch_image-1.0.2.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

pytorch_image-1.0.2-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file pytorch_image-1.0.2.tar.gz.

File metadata

  • Download URL: pytorch_image-1.0.2.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.9.20 Linux/6.8.0-1014-azure

File hashes

Hashes for pytorch_image-1.0.2.tar.gz
Algorithm Hash digest
SHA256 29c40ea3d778f7fd54e47d1f3e1d1e0e4eaa734ef5de392b3a099804438d0e38
MD5 b1678267345410d682be0109497faaf6
BLAKE2b-256 afe52b9547ae127d311287a4c416a2bf683fc3f0f6ce9b2e156817bec2973175

See more details on using hashes here.

File details

Details for the file pytorch_image-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: pytorch_image-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.9.20 Linux/6.8.0-1014-azure

File hashes

Hashes for pytorch_image-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d64363159ac96e3a6715ee03f550fb8b71e81606912f5fe0f4455b5d7980ca5d
MD5 64a1cfbdca2364187dfa56dff6dbd47e
BLAKE2b-256 295b7f933d67fb94dfb5baa8b8f9f6b503da48ef1dcc85c00d204a2b634a9127

See more details on using hashes here.

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