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 Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: lra_benchmark-0.1.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5fd26683f60b3dec18c72c95eda018c511d10f4dfa5830dfc1cba1a7dd3d65dc
MD5 b64e08785eb44045defd116bbc52775c
BLAKE2b-256 4379d1dc46b6440f28bb3a0ec8b18fb9fe84f86f23c3f5f61da5597f3a073527

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