AI Notebooks - Tutoriel - Utiliser ResNet pour la classification d'images (EN)

Comment utiliser a modèle existant pour faire de l'apprentissage par transfert?

Last updated 1st September, 2022.

Objective

This tutorial will allow you to use Transfer Learning to train an existing model on a custom dataset thanks to OVHcloud AI Notebooks.

To show how Transfer Learning can be useful, ResNet50 will be trained on a custom dataset.

USE CASE: Flower Classification

To classify flower images, the Flower Classification dataset will be used. It is available on Kaggle.

Contains information from Flower Classification, which is made available here under the CC0: Public Domain.

Definition

Transfer learning

In Machine Learning, the aim of Transfer Learning is to use the knowledge already acquired to solve a completely new, but related problem. In other words, the technique is to transfer the notions learned on a source dataset to be more efficient in the processing of a new target dataset.

For this tutorial, the goal is to do image classification. An existing model is used: ResNet50.

ResNet50 model

ResNet is a Residual neural Network structure. It is an innovative neural network created for image classification.

The ResNet model architecture allows the training error to be reduced with a deeper network through connection skip.

Residual neural networks ignore some connections and make double or triple layer jumps that contain non-linearities (ReLU).

image

With this method, performance is generally improved.

ResNet has many variants that work on the same concept but have different numbers of layers. Resnet50 is used to refer to the variant that can work with fifty neural network layers. It was trained on more than a million images from the ImageNet database.

Requirements

Instructions

First, you have to create 2 object containers in your OVHcloud Object Storage.

  • The first one contains the non-pre-processed data (base images).
  • The second object container is empty. It is intended to receive the data once processed and split for training.

To know more about how to push your data to Object Storage, please refer to the dedicated documentation.

Then, you can launch your notebook from the OVHcloud Control Panel or via the ovhai CLI.

Launching a Jupyter notebook with "Miniconda" via UI

To launch your notebook from the OVHcloud Control Panel, refer to the following steps.

Code editor

Choose the Jupyterlab code editor.

Framework

In this tutorial, the TensorFlow framework is used.

For this tutorial, you can use the following TensorFlow framework version: tf2.4-py38-cuda11.0-v22-4.

Resources

You can choose the number of CPUs or GPUs you want.

Here, using 1 GPU is sufficient.

Attach a Git container or repository

  1. Attach the object container (from the Object Storage) that contains your dataset for image classification.
  • Mount directory: /workspace/data
  • Permission: read only (RO)
  1. Attach an empty object container to store your data, once it has been processed and split for training, validation and test.
  • Mount directory: /workspace/data-split
  • Permission: read write (RW)
  1. Attach an empty object container to store your model after training.
  • Mount directory: /workspace/saved_model
  • Permission: read write (RW)

To learn more about how to use and manage your data in a notebook with UI, check this documentation.

Launching a Jupyter notebook with TensorFlow via CLI

If you want to launch it with the CLI, choose the jupyterlab editor and the tensorflow framework.

For this tutorial, you can use the following TensorFlow framework version: tf2.4-py38-cuda11.0-v22-4.

To know more about how to use and manage your data in a notebook with the CLI, refer to this documentation.

Choose the number of GPUs (<nb-gpus>) to use in your notebook and use the following command.

ovhai notebook run tensorflow jupyterlab \
        --name <notebook-name> \
        --framework-version tf2.4-py38-cuda11.0-v22-4 \
        --volume <my-data>@<region>/:/workspace/data:RO:cache \
        --volume <my-model>@<region>/:/workspace/saved_model:RW \
        --gpu <nb-gpus>

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

Accessing the notebook

Once the repository has been cloned, find your notebook by following this path: ai-training-examples > notebooks > computer-vision > image-classification > tensorflow > notebook-resnet-transfer-learning-image-classification.ipynb.

A preview of this notebook can be found on GitHub here.

Go further

  • If you want to deploy a Gradio app for Image classification or Sketch recognition, check out this documentation.
  • If you are interested in Computer Vision, familiarise yourself with Object Detection by following this tutorial.

Feedback

Please send us your questions, feedback and suggestions to improve the service:


Cette documentation vous a-t-elle été utile ?

N’hésitez pas à nous proposer des suggestions d’amélioration afin de faire évoluer cette documentation.

Images, contenu, structure… N’hésitez pas à nous dire pourquoi afin de la faire évoluer ensemble !

Vos demandes d’assistance ne seront pas traitées par ce formulaire. Pour cela, utilisez le formulaire "Créer un ticket" .

Merci beaucoup pour votre aide ! Vos retours seront étudiés au plus vite par nos équipes..


Ces guides pourraient également vous intéresser...

OVHcloud Community

Accedez à votre espace communautaire. Posez des questions, recherchez des informations, publiez du contenu et interagissez avec d’autres membres d'OVHcloud Community.

Echanger sur OVHcloud Community

Conformément à la Directive 2006/112/CE modifiée, à partir du 01/01/2015, les prix TTC sont susceptibles de varier selon le pays de résidence du client
(par défaut les prix TTC affichés incluent la TVA française en vigueur).