A simple PyTorch wrapper for image classification using a pretrained ResNet18 model
Project description
Vision Model Package: ResNet18 Wrapper
This package provides a simple, production-ready interface for image classification using a pretrained ResNet18 model. It is designed to be easily installable and used for quick inference tasks.
Installation
The package can be installed via pip:
pip install Dmytro-Shapovalov-brach-assignment-2026
Quick Start
from my_package import ModelWrapper
# Initialize the model (weights are loaded automatically)
inferer = ModelWrapper()
# Run prediction
img_path = "test_image.jpg"
predict = inferer.predict(img_path)
print(f"Predicted Class Index: {predict}")
API reference
-
ModelWrapper(model_path=None)
The main class for managing the model and inference.
model_path: Optional path to a custom .pth file. If None, it automatically loads the weights.pth bundled with the package.
-
ModelWrapper.predict(image_path)
Performs the full inference pipeline on a single image.
Input: str path to the image file.
Returns: int representing the predicted class index.
Process: Handles image loading (PIL), resizing (224x224), normalization (ImageNet stats), and tensor conversion (Torch)
Evaluation Proposal
To evaluate this model on a specific image classification task, I would use a standard validation pipeline to evaluate both accuracy and robustness.
-
Dataset: A separate test set relevant to the task.
-
Metrics:
Accuracy: measures the percentage of correct predictions.
F1-Score: evaluates performance across potentially imbalanced classes.
Inference Latency: measures the average time taken for a single prediction.
-
Pipeline:
Data Loading: using torchvision.datasets and DataLoader feed images in batches.
Inference Mode: setting the model to .eval() and using torch.no_grad() to disable gradient calculation and save memory.
Comparison: comparing predicted indices against ground truth labels to generate a confusion matrix.
Reporting: aggregating results to identify specific classes where the model might be underperforming.
-
Evaluation Pseudocode:
model.eval() results = [] with torch.no_grad(): for images, labels in test_loader: outputs = model(images) preds = torch.argmax(outputs, dim=1) results.extend((preds == labels).tolist()) accuracy = sum(results) / len(results) print(f"Test Accuracy: {accuracy:.2%}")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file brach_assignment_bp_2026-0.1.0.tar.gz.
File metadata
- Download URL: brach_assignment_bp_2026-0.1.0.tar.gz
- Upload date:
- Size: 41.4 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.11 {"installer":{"name":"uv","version":"0.11.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2e26738cb83c12c2455693e85bb0e992ba963d42ab54155733e53af0c522f856
|
|
| MD5 |
f11d76bf79ca5a1aa833db5eedf1b7ce
|
|
| BLAKE2b-256 |
807c77520e28a62e95e13252a29b8630855db78ab632ea280c999cdcaff2bb21
|
File details
Details for the file brach_assignment_bp_2026-0.1.0-py3-none-any.whl.
File metadata
- Download URL: brach_assignment_bp_2026-0.1.0-py3-none-any.whl
- Upload date:
- Size: 41.4 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.11 {"installer":{"name":"uv","version":"0.11.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f0c658e114479659f639efc5b577e9b01a1d5803fea8d4e206cb7f2888825bfd
|
|
| MD5 |
b03a70e55d0c42dd711c78d8ce0c2c21
|
|
| BLAKE2b-256 |
2fdd6e6496411c64d23a98834ff9a24da7fc774549dcb7fba9b51c53b520e5df
|