Skip to main content

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


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

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

File details

Details for the file dmytro_shapovalov_brach_assignment_2026-0.1.0.tar.gz.

File metadata

  • Download URL: dmytro_shapovalov_brach_assignment_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

Hashes for dmytro_shapovalov_brach_assignment_2026-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5da2e17d80b42af916519cb538bb00a469818931848df0c35b0ec159489a1f28
MD5 22d4800809f5b6b6c0c9345c10da8648
BLAKE2b-256 ec1cffdbd2bd22515a6bc9aa6e4db557de021cb8c169bd1f2fa6a0745379f97b

See more details on using hashes here.

File details

Details for the file dmytro_shapovalov_brach_assignment_2026-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: dmytro_shapovalov_brach_assignment_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

Hashes for dmytro_shapovalov_brach_assignment_2026-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6d7800b0c1cbb030dc455be7fa60032871ab91c0d9e2e33b2770026711fb68b5
MD5 8f7da07574fbf12b6f5938f267838a92
BLAKE2b-256 e8bed0b82932c7d27b6e539d64ad9c05850abc2766e91b3aa1feb0c073f09384

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