Skip to main content

A flexible few-shot classifier toolkit.

Project description

Few-Shot Classifier Library

A lightweight Python library for image classification using few-shot learning. Given a small number of support images per class, this library classifies query images based on visual similarity using learnable embeddings.

Features

  • No training required — works directly with pretrained backbones
  • Supports multiple popular models: ResNet, MobileNet, EfficientNet, DenseNet, and more
  • Accepts individual images or batches for prediction
  • Automatically detects image type: handles RGB and Grayscale images as required by the model
  • Returns class indices or original labels (if provided)
  • Easy integration with PyTorch pipelines

Installation

Install directly from PyPI:


pip install fewshotlib

Or, if not yet published, install locally from source:


git clone https://github.com/RohitXJ/few-shot-lib.git
cd fewshotlib
pip install .

How to Use


from fewshotlib import FewShotClassifier
from PIL import Image

# Load a model checkpoint (must be generated using our model creation utility)

model_path = 'model.pt'
classifier = FewShotClassifier(model_path)

# Predict from a single image file

result = classifier.predict('test_image.png')
print(result)

# Predict from a batch of image files

results = classifier.predict(['img1.png', 'img2.png'])
print(results)

# Predict and return the original class label (if available)

result = classifier.predict('test_image.png')
print(result['label'])  \# outputs the original label, if present

Notes

  • If your model.pt file contains labels from the prototype creation step, you will receive the corresponding original label for each prediction.
  • The library automatically handles input images in RGB or Grayscale formats and applies the necessary preprocessing for the chosen backbone model.
  • Supports file paths to images (recommended). For power users, you may load a PIL image and pass it directly, but file path input is default.

Generate model.pt

To create a compatible model.pt file for this library, use our companion tool (coming soon):


https://github.com/RohitXJ/few-shot-web

This tool lets you select a few images per class and generates a .pt file storing class prototypes and labels.

License

This project is licensed under a Custom Research and Educational Use License.

You are permitted to use, copy, modify, and distribute this software only for research and educational purposes. Commercial use is strictly prohibited without prior written permission from the author.

See the LICENSE file for full terms.

For commercial inquiries, contact: gomesrohit92@gmail.com

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

fewshotlib-0.1.1.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

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

fewshotlib-0.1.1-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file fewshotlib-0.1.1.tar.gz.

File metadata

  • Download URL: fewshotlib-0.1.1.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for fewshotlib-0.1.1.tar.gz
Algorithm Hash digest
SHA256 04a6414915d70b461c5dc991332bc263af4e84eec43a2d38b4f19faf5f6cf3be
MD5 9784892658de017454282917357ccda7
BLAKE2b-256 12db951527848a52d62a134944c0abfe299dbd407d87e0a855f8c69c3c42d592

See more details on using hashes here.

File details

Details for the file fewshotlib-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: fewshotlib-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for fewshotlib-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7a2a7ffeb01355731255a66c19999a6bb176be6e7f8b9bc71995ed863478c3fd
MD5 2958bd44e52fcb1ebc65484b65bb2537
BLAKE2b-256 41c2453f34acb5762a6c7b9d8014771481b0a75f891041e4e2b38815ff38fb3c

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