Skip to main content

Easily map images (as `PIL.Images`) to features (as `np.ndarray`) from pretrained vision models.

Project description

enczoo: easily extract image features from pretrained vision models

CI

enczoo is a Python library with a simple goal: to make it as easy as possible to map images (as PIL.Images) to features (as numpy arrays) from state-of-the-art vision models, such as Imagenet-pretrained ResNet50 and CLIP ViT-B/16.

Installation

enczoo requires Python 3.12 or above, and is installed using the wonderful uv project manager. Once you have uv installed, just run the following command in your project:

uv add enczoo

Usage

import enczoo
from PIL import Image

image = Image.open('my-image.png')
model = enczoo.ResNet50(
    layer_name='avgpool',
    # device=gpu
) 
features = model.compute_features(images=[image]) # np.ndarray
# Want another layer? Check out: print(enczoo.ResNet50.layer_names)

Available models

Pixels
  • Family: raw pixels
  • Returns: float32 RGB pixels after preprocessing
  • Output shape: [B, 224, 224, 3]
  • Academic reference: none; this is an enczoo convenience encoder
AlexNet
  • Family: ImageNet-pretrained CNN
  • Returns: intermediate activations from the requested layer
  • Output shape: depends on layer_name
  • Layer selection: inspect enczoo.AlexNet.layer_names
  • Academic reference: AlexNet, "ImageNet Classification with Deep Convolutional Neural Networks" (Krizhevsky et al., 2012)
ResNet50
  • Family: ImageNet-pretrained CNN
  • Returns: intermediate activations from the requested layer
  • Output shape: depends on layer_name
  • Layer selection: inspect enczoo.ResNet50.layer_names
  • Academic reference: ResNet, "Deep Residual Learning for Image Recognition" (He et al., 2015)
RobustResNet50
  • Family: adversarially robust ImageNet ResNet-50
  • Returns: intermediate activations from the requested layer
  • Output shape: depends on layer_name
  • Layer selection: inspect enczoo.RobustResNet50.layer_names
  • Weights: downloaded on first use from the released ImageNet L2 epsilon-3.0 checkpoint
  • Academic reference: Engstrom et al., "Robustness (Python Library)" release checkpoint via the MadryLab model weights
ConvNeXtB
  • Family: ImageNet-pretrained CNN
  • Returns: intermediate activations from the requested layer
  • Output shape: depends on layer_name
  • Layer selection: inspect enczoo.ConvNeXtB.layer_names
  • Academic reference: ConvNeXt, "A ConvNet for the 2020s" (Liu et al., 2022)
CLIPResNet50
  • Family: CLIP ResNet visual encoder
  • Returns: intermediate activations from the requested visual layer
  • Output shape: depends on layer_name
  • Layer selection: inspect enczoo.CLIPResNet50.layer_names
  • Academic reference: CLIP, "Learning Transferable Visual Models From Natural Language Supervision" (Radford et al., 2021)
CLIPViTB16
  • Family: CLIP vision transformer
  • Returns: the model's pooled CLS-based image embedding
  • Output shape: [B, 768]
  • Academic reference: CLIP, "Learning Transferable Visual Models From Natural Language Supervision" (Radford et al., 2021)
DINOv2ViTB14
  • Family: self-supervised vision transformer
  • Returns: the model's pooled CLS-based image embedding
  • Output shape: [B, 768]
  • Academic reference: DINOv2, "DINOv2: Learning Robust Visual Features without Supervision" (Oquab et al., 2023)
AligNetViTB16
  • Family: AlignNet-aligned vision transformer
  • Returns: the SavedModel feature tensor selected from the exported pre_logits output
  • Output shape: depends on the downloaded model
  • Weights: downloaded on first use and cached under ENCZOO_CACHE_DIR or the platform cache directory
  • Academic reference: Muttenthaler et al. 2025; weights come from the AlignNet model release
ImageNetViTB16
  • Family: ImageNet-pretrained vision transformer from the AlignNet release
  • Returns: the SavedModel feature tensor selected from the exported pre_logits output
  • Output shape: depends on the downloaded model
  • Weights: downloaded on first use and cached under ENCZOO_CACHE_DIR or the platform cache directory
  • Academic reference: Muttenthaler et al. 2025; weights come from the AlignNet model release
UnaligNetViTB16
  • Family: unaligned vision transformer from the AlignNet release
  • Returns: the SavedModel feature tensor selected from the exported pre_logits output
  • Output shape: depends on the downloaded model
  • Weights: downloaded on first use and cached under ENCZOO_CACHE_DIR or the platform cache directory
  • Academic reference: Muttenthaler et al. 2025; weights come from the AlignNet model release

Why develop enczoo?

Under the hood, enczoo solves several tiny problems which make correctly computing image features more annoying and error-prone than it should be. For example, enczoo automatically:

  • performs model-specific image transforms ("was it -1 to 1, 0 to 1, or 0-255...?"),
  • ensures images are in RGB format
  • puts the model in inference, not training, mode
  • turns off autograd
  • returns tensors as np.ndarray (no more detach().cpu().numpy())
  • resizes the image while preserving aspect ratio
  • and more!

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

enczoo-0.1.6.dev1.tar.gz (1.4 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

enczoo-0.1.6.dev1-py3-none-any.whl (1.4 MB view details)

Uploaded Python 3

File details

Details for the file enczoo-0.1.6.dev1.tar.gz.

File metadata

  • Download URL: enczoo-0.1.6.dev1.tar.gz
  • Upload date:
  • Size: 1.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.12

File hashes

Hashes for enczoo-0.1.6.dev1.tar.gz
Algorithm Hash digest
SHA256 9785452ed662d8d263a9e46b870e9077b2e9b77dcddc4a1fdc7d33a83361e99f
MD5 b5d5672d56d1cae26f989e5949940490
BLAKE2b-256 6c05eeb3b57ef0ff8f988d86ec8a41d1400c9c28ce815c78bb61d8162b0092b1

See more details on using hashes here.

File details

Details for the file enczoo-0.1.6.dev1-py3-none-any.whl.

File metadata

File hashes

Hashes for enczoo-0.1.6.dev1-py3-none-any.whl
Algorithm Hash digest
SHA256 5e1fe637c90f20cc959905e34749455290e0a70e4e6ab2e17189f78b5d8312ae
MD5 ce41a952706ab00acb11656f2b7bb32d
BLAKE2b-256 e21791b8921364074a8e6db17f2cdc99cb3c6bd86fa36052ab55b5aa3bb78b95

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page