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.1.tar.gz (3.8 kB view hashes)

Uploaded Source

Built Distribution

pytorch_image-1.0.1-py3-none-any.whl (4.3 kB view hashes)

Uploaded Python 3

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