Skip to main content

A library for benchmarking lightweight Vision Transformers following the LRA methodology

Project description

Sure, I can provide you with a detailed README.md file and guide you through the steps to publish your library to PyPI.

LRA Benchmark for Image Classification on CIFAR-10

The LRA Benchmark for Image Classification on CIFAR-10 is a project that provides a benchmark for evaluating image classification models on the CIFAR-10 dataset. It includes a set of pre-defined models, as well as a framework for running benchmark experiments and reporting key metrics.

Project Structure

The project is structured as follows:

lra_benchmark/
├── lra_benchmark/
│   ├── models/
│   │   ├── base_model.py
│   │   └── tiny_vit.py
│   ├── dataset.py
│   ├── benchmark.py
│   ├── config.py
│   └── utils/
│       └── optimizer.py
├── examples/
│   └── benchmark_example.py
├── tests/
├── setup.py
└── README.md
  • lra_benchmark/models/: Contains the implementation of the base model class (BaseModel) and the pre-defined model architectures, such as TinyViT.
  • lra_benchmark/dataset.py: Provides functions for loading the CIFAR-10 dataset.
  • lra_benchmark/benchmark.py: Defines the LRABenchmark class and the run_benchmark function, which are used to run the benchmark experiments.
  • lra_benchmark/config.py: Defines the configuration options for the benchmark experiments.
  • lra_benchmark/utils/optimizer.py: Provides utilities for creating optimizers.
  • examples/benchmark_example.py: An example script that demonstrates how to use the library to run a benchmark experiment.
  • tests/: Contains unit tests for the library.
  • setup.py: The setup file for packaging and distributing the library.
  • README.md: The project's documentation.

Using Your Own Models

To use your own model with the LRA Benchmark, you'll need to create a new model class that inherits from the BaseModel class. Here's an example:

from lra_benchmark.models.base_model import BaseModel
import torch.nn as nn

class MyModel(BaseModel):
    def __init__(self, img_size=32, num_classes=10):
        super().__init__()
        self.conv1 = nn.Conv2d(3, 32, kernel_size=3, stride=1, padding=1)
        self.relu = nn.ReLU()
        self.pool = nn.MaxPool2d(kernel_size=2, stride=2)
        self.fc = nn.Linear(32 * 8 * 8, num_classes)

    def forward(self, x):
        x = self.conv1(x)
        x = self.relu(x)
        x = self.pool(x)
        x = x.view(x.size(0), -1)
        x = self.fc(x)
        return x

Once you've defined your custom model, you can use it in the same way as the TinyViT model in the benchmark_example.py script:

from lra_benchmark.models.my_model import MyModel
from lra_benchmark.config import LRABenchmarkConfig
from lra_benchmark.dataset import get_cifar10_datasets
from lra_benchmark.benchmark import run_benchmark

config = LRABenchmarkConfig(batch_size=128, max_epochs=5)
train_loader, val_loader, test_loader = get_cifar10_datasets(config.batch_size, config.num_workers)

model = MyModel(img_size=32, num_classes=10)
metrics = run_benchmark(config, model, train_loader, val_loader, test_loader)

print(f"Test Accuracy: {metrics['test_accuracy']:.2%}")
print(f"Test Loss: {metrics['test_loss']:.4f}")
print(f"Model Size: {metrics['model_size']} parameters")
print(f"Inference Time: {metrics['inference_time']:.4f} seconds")

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

lra_benchmark-0.1.2.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

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

lra_benchmark-0.1.2-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file lra_benchmark-0.1.2.tar.gz.

File metadata

  • Download URL: lra_benchmark-0.1.2.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.4

File hashes

Hashes for lra_benchmark-0.1.2.tar.gz
Algorithm Hash digest
SHA256 01fa8c093530ad31466a032762761ec7005eb5e6f80c89ebce9c35966fcbc78a
MD5 6a80be7ff21474c937628f498f3c0bee
BLAKE2b-256 60fb351250807dabf8582a44304500929158e212321eb61ede1a9f9e3e3881cf

See more details on using hashes here.

File details

Details for the file lra_benchmark-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: lra_benchmark-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.4

File hashes

Hashes for lra_benchmark-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3e112c29e49104a9a327d8fb154a6f0b77909e624ee4593c85fdac8ad322fed4
MD5 ddd1577769b8502a03628ffcbbb74528
BLAKE2b-256 4328b162f27c2a699fffe4f81e733f1375563eb85902c1d16057a4731f5763b8

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