# blackonnx

This package purpose is to allow the use of NN models generated by AutoML services ([Google Cloud Vision](https://cloud.google.com/vision/overview/docs#automl-vision),
[Azure custom Vision](https://azure.microsoft.com/en-us/services/cognitive-services/custom-vision-service/)),
to an [Actcast](https://actcast.io/) application.

The format for NN models in Actcast is [nnoir](https://github.com/Idein/nnoir), and the tool [nnoir-onnx](https://pypi.org/project/nnoir-onnx/) allows conversion from [ONNX](https://github.com/onnx/onnx) format to nnoir.

Some ONNX operators used in AutoML-generated models may not be supported by nnoir-onnx, and using this package allows the conversion by modifying an onnx model by replacing unsupported nodes to equivalent supported ones.

See #Examples section for use samples.

## Installation

```bash
pip3 install blackonnx
```

## Usage

In a python script:

```python
import onnx
from blackonnx import fix

model = onnx.load("path/to/mymodel.onnx")  # open onnx model

fix.fix_quantize(model)  # apply fixes in-place
.
.
.

onnx.save(model, "mymodel_fixed.onnx")  # save fixed model
```

or using commd line:

```bash
user~$ blackonnx -o mymodel_fixed.onnx path/to/mymodel.onnx --fixes fix_quantize 
```

Omitting `fixes` argument applies all fixes (in alphabetical order).
For models created with Google Cloud Vision, the recommanded fixes are

```bash
... --fixes fix_quantize 
```

And for Azure custom vision models:

```bash
... --fixes fix_postprocess 
```

## Example

Follow the instructions in `examples/tutorial.md` for details.

## Origin of the Name

The name `blackonnx` comes from [black onyx](https://en.wikipedia.org/wiki/Onyx) because of the property: artificially colored to black. Our IR is nnoir, which comes from black in french.
We mean this tool adapt onnx models for nnoir.
