Metadata-Version: 2.4
Name: onnx_opcounter
Version: 0.1.0
Summary: ONNX flops / params counter
Author: Grigory Malivenko
License-Expression: Apache-2.0
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=2.5
Requires-Dist: onnx>=1.22
Provides-Extra: runtime
Requires-Dist: onnxruntime>=1.29; extra == "runtime"
Provides-Extra: test
Requires-Dist: pytest>=9.1; extra == "test"
Requires-Dist: pytest-xdist>=3.8; extra == "test"
Requires-Dist: torch>=2.14; extra == "test"
Requires-Dist: onnxruntime>=1.29; extra == "test"
Dynamic: license-file

# ONNX Operations Counter [WIP]

[![GitHub License](https://img.shields.io/badge/Apache-2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![Downloads](https://pepy.tech/badge/onnx_opcounter)](https://pepy.tech/project/onnx_opcounter)
![PyPI](https://img.shields.io/pypi/v/onnx_opcounter.svg)

Counts number of parameters / MACs for ONNX models. 

## Installation

Requires Python 3.12 or newer.

```bash
pip install onnx_opcounter
```

`calculate_macs` normally relies on ONNX shape inference. For the rare models where
shape inference fails, it falls back to running the model to discover intermediate
shapes, which additionally needs onnxruntime:

```bash
pip install onnx_opcounter[runtime]
```

## Basic Usage

### Using CLI (calculate number of parameters)
```bash
onnx_opcounter {path_to_onnx_model}
```

### Using CLI (calculate number of parameters and MACs)
```bash
onnx_opcounter --calculate-macs {path_to_onnx_model}
```

### Using API
```python
from onnx_opcounter import calculate_params
import onnx

model = onnx.load_model('./path/to/onnx/model')
params = calculate_params(model)

print('Number of params:', params)
```

## License
The software is covered by Apache License 2.0.
