AI Notebooks - Tutorial - Use ResNet for image classification

How to use an existing model to do Transfer Learning?

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:


Czy ten przewodnik był pomocny?

Zachęcamy do przesyłania sugestii, które pomogą nam ulepszyć naszą dokumentację.

Obrazy, zawartość, struktura - podziel się swoim pomysłem, my dołożymy wszelkich starań, aby wprowadzić ulepszenia.

Zgłoszenie przesłane za pomocą tego formularza nie zostanie obsłużone. Skorzystaj z formularza "Utwórz zgłoszenie" .

Dziękujemy. Twoja opinia jest dla nas bardzo cenna.


Inne przewodniki, które mogą Cię zainteresować...

OVHcloud Community

Dostęp do OVHcloud Community Przesyłaj pytania, zdobywaj informacje, publikuj treści i kontaktuj się z innymi użytkownikami OVHcloud Community.

Porozmawiaj ze społecznością OVHcloud

Zgodnie z Dyrektywą 2006/112/WE po zmianach, od dnia 1 stycznia 2015 r., ceny brutto mogą różnić się w zależności od kraju zameldowania klienta
(ceny brutto wyświetlane domyślnie zawierają stawkę podatku VAT na terenie Polski).