Skip to content

Commit 42368de

Browse files
committed
Library Launched on PyPI
1 parent 09d84d5 commit 42368de

File tree

9 files changed

+137
-123
lines changed

9 files changed

+137
-123
lines changed

LICENSE

Lines changed: 0 additions & 121 deletions
This file was deleted.

LICENSE.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Custom License for fewshotlib
2+
3+
Copyright (c) 2025 Rohit Gomes
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the “Software”), to use,
7+
copy, modify, and distribute the Software for research and educational purposes only,
8+
subject to the following conditions:
9+
10+
1. The Software may not be used, copied, modified, or distributed for
11+
any commercial purpose without explicit written permission from the author.
12+
13+
2. The above copyright notice and this permission notice shall be included in
14+
all copies or substantial portions of the Software.
15+
16+
3. Any use of the Software must give appropriate credit to the author.
17+
18+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
19+
20+
For licensing or commercial use inquiries, contact: [email protected]

README.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Few-Shot Classifier Library
2+
3+
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.
4+
5+
## Features
6+
7+
- No training required — works directly with pretrained backbones
8+
- Supports multiple popular models: ResNet, MobileNet, EfficientNet, DenseNet, and more
9+
- Accepts individual images or batches for prediction
10+
- **Automatically detects image type:** handles RGB and Grayscale images as required by the model
11+
- Returns class indices or original labels (if provided)
12+
- Easy integration with PyTorch pipelines
13+
14+
## Installation
15+
16+
Install directly from PyPI:
17+
18+
```
19+
20+
pip install fewshotlib
21+
22+
```
23+
24+
Or, if not yet published, install locally from source:
25+
26+
```
27+
28+
git clone https://github.com/RohitXJ/few-shot-lib.git
29+
cd fewshotlib
30+
pip install .
31+
32+
```
33+
34+
## How to Use
35+
36+
```
37+
38+
from fewshotlib import FewShotClassifier
39+
from PIL import Image
40+
41+
# Load a model checkpoint (must be generated using our model creation utility)
42+
43+
model_path = 'model.pt'
44+
classifier = FewShotClassifier(model_path)
45+
46+
# Predict from a single image file
47+
48+
result = classifier.predict('test_image.png')
49+
print(result)
50+
51+
# Predict from a batch of image files
52+
53+
results = classifier.predict(['img1.png', 'img2.png'])
54+
print(results)
55+
56+
# Predict and return the original class label (if available)
57+
58+
result = classifier.predict('test_image.png')
59+
print(result['label']) \# outputs the original label, if present
60+
61+
```
62+
63+
## Notes
64+
65+
- If your `model.pt` file contains labels from the prototype creation step, you will receive the corresponding original label for each prediction.
66+
- The library automatically handles input images in RGB or Grayscale formats and applies the necessary preprocessing for the chosen backbone model.
67+
- 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.
68+
69+
## Generate `model.pt`
70+
71+
To create a compatible `model.pt` file for this library, use our companion tool (coming soon):
72+
73+
```
74+
75+
https://github.com/RohitXJ/few-shot-web
76+
77+
```
78+
79+
This tool lets you select a few images per class and generates a `.pt` file storing class prototypes and labels.
80+
81+
## License
82+
83+
This project is licensed under a **Custom Research and Educational Use License**.
84+
85+
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.
86+
87+
See the [LICENSE](./LICENSE) file for full terms.
88+
89+
For commercial inquiries, contact: [[email protected]](mailto:[email protected])
90+

__init__.py

Whitespace-only changes.

fewshotlib/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .fewshotlib import FewShotClassifier
File renamed without changes.

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["setuptools>=61.0.0", "wheel"]
3+
build-backend = "setuptools.build_meta"

setup.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from setuptools import setup, find_packages
2+
3+
with open("README.md", "r", encoding="utf-8") as fh:
4+
long_description = fh.read()
5+
6+
setup(
7+
name="fewshotlib",
8+
version="0.1.1",
9+
author="Rohit Gomes",
10+
author_email="[email protected]",
11+
description="A flexible few-shot classifier toolkit.",
12+
long_description=long_description,
13+
long_description_content_type="text/markdown",
14+
packages=find_packages(include=["fewshotlib"]),
15+
install_requires=[
16+
"torch>=1.10.0",
17+
"torchvision>=0.11.0",
18+
"Pillow",
19+
],
20+
python_requires=">=3.8",
21+
)

testing/test1.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
def test_model_loading():
1010
try:
1111
classifier = FewShotClassifier(model_path=MODEL_PATH)
12-
print("Model loaded successfully.")
12+
print("Model loaded successfully.")
1313

1414
print(f"Encoder: {type(classifier.encoder)}")
1515
print(f"Prototypes shape: {classifier.prototypes.shape}")
@@ -19,7 +19,7 @@ def test_model_loading():
1919
print("No labels found in checkpoint.")
2020

2121
except Exception as e:
22-
print(f"Model loading failed: {e}")
22+
print(f"Model loading failed: {e}")
2323

2424
if __name__ == "__main__":
2525
test_model_loading()

0 commit comments

Comments
 (0)