---
title: "AI Notebooks - Tutorial - Fine-Tune and export an AI model to ONNX"
description: "Learn how to fine-tune a PyTorch model and export it in ONNX (Open Neural Network Exchange) format."
url: https://docs.us.ovhcloud.com/en/public-cloud/ai-machine-learning/ai-notebooks-finetune-model-export-onnx
lang: en
---
> For AI agents: the complete documentation index is available at https://docs.us.ovhcloud.com/en/llms.txt, the full documentation bundle is available at https://docs.us.ovhcloud.com/en/llms-full.txt.

# AI Notebooks - Tutorial - Fine-Tune and export an AI model to ONNX

**Learn how to fine-tune a PyTorch model and export it in ONNX ([Open Neural Network Exchange](https://onnx.ai/)) format.**

For this purpose, we use an **image classification** model: [DenseNet](https://pytorch.org/hub/pytorch_vision_densenet/).

**Note:**

DenseNet models are pre-trained on the [ImageNet](https://www.image-net.org/) dataset.

The goal is to fine-tune a **DenseNet121** model to classify daily life images with the **CIFAR-10** dataset. It is composed of 10 classes:

- airplane
- automobile
- bird
- cat
- deer
- dog
- frog
- horse
- ship
- truck

_Find out more information about CIFAR-10 dataset on the following [link](https://www.cs.toronto.edu/~kriz/cifar.html)._

At the end of training, the DenseNet model is saved in PyTorch format (`.pth`). It will then be transformed into ONNX.

Exporting your model in ONNX format allows you to **optimize the inference** of a Machine Learning model.

 

## Requirements

- Access to the [OVHcloud Control Panel](https://manager.us.ovhcloud.com/)
- An AI Notebooks project created inside a [Public Cloud project](https://us.ovhcloud.com/public-cloud/) in your OVHcloud account
- A user for AI Notebooks
- A [Kaggle](https://www.kaggle.com/) account to download the dataset

 

## Instructions

You can launch the notebook from the [OVHcloud Control Panel](https://manager.us.ovhcloud.com/) or via the [ovhai CLI](https://docs.us.ovhcloud.com/en/public-cloud/ai-machine-learning/cli-run-notebook.md).

 

### Launching a Jupyter notebook with "Conda" via UI (Control Panel)

To launch your notebook from the [OVHcloud Control Panel](https://manager.us.ovhcloud.com/), refer to the following steps.

 

#### Code editor

Choose the `Jupyterlab` code editor.

 

#### Framework

In this tutorial, the `conda` framework is used.

 

#### Resources

Using GPUs is recommended to train the image classification model: **densenet121**.

**Note:**

Here, using `1 GPU` is sufficient.

 

### Launching a Jupyter notebook with "conda" via CLI

_If you have not used our CLI yet, follow [this guide](https://docs.us.ovhcloud.com/en/public-cloud/ai-machine-learning/cli-install-client.md) to install it._

If you want to launch your notebook with the OVHcloud AI CLI, choose the `jupyterlab` editor and the `conda` framework.

To access the different versions of `conda` available, run the following command:

```console
ovhai capabilities framework get conda -o yaml
```

You will also need to choose the number of GPUs to use in your notebook, using `<nb-gpus>`.

To launch your notebook, run the following command:

```console
ovhai notebook run conda jupyterlab \
        --name <notebook-name> \
        --framework-version conda-py310-cuda11.8-v22-4 \
        --gpu <nb-gpus>
```

You can then reach your notebook’s URL once the notebook is running.

 

### Accessing the notebooks

Once our [AI examples repository](https://github.com/ovh/ai-training-examples/) has been cloned in your environment, find the fine-tuning notebook tutorial by following this path: `ai-training-examples` > `notebooks` > `go-further` > `onnx` > `notebook_finetune_densenet_export_onnx.ipynb`.

A preview of this notebook can be found on GitHub [here](https://github.com/ovh/ai-training-examples/blob/main/notebooks/go-further/onnx/notebook_finetune_densenet_export_onnx.ipynb).

 

## Go further

Browse all the [AI & Machine Learning guides](https://docs.us.ovhcloud.com/en/public-cloud/ai-machine-learning/landing-page-ai-machine-learning.md).

Browse the rest of the [OVHcloud US documentation](https://docs.us.ovhcloud.com/en/index.md) for guides on our other products and services.

Learn more about [AI & Machine Learning](https://us.ovhcloud.com/public-cloud/ai-machine-learning/) on the OVHcloud US website.

If you need training or technical assistance to implement our solutions, contact your sales representative or click on [this link](https://us.ovhcloud.com/professional-services/) to get a quote and ask our Professional Services experts for a custom analysis of your project.
