Quick Start: Machine Learning Lab

This tutorial will show you how to:

  • Start a machine learning lab for YOLOv5 object detection.

  • Train the model and monitor the resource consumption.

  • Visualize the model training results.

Preparation

Make sure there is a project for you to run a lab. Otherwise, create a new project:

  1. Go to the projects page by clicking on the Projects item in the left menu.

    ../_images/goto_projects.png
  2. Click on the NEW button.

    ../_images/btn_new.png
  3. In the new project dialog, input the project name as my-proj.

  4. Click on the CREATE button.

    ../_images/add_project_21.png
  5. The new project will be displayed.

    ../_images/add_project_31.png

Create a YOLOv5 Lab

We will start a lab to train a YOLOv5 ML model. MLSteam has built-in image object detection models for YOLO, which saves lots of efforts. Simply create a lab from template.

  1. Go to the project page by clicking on the project card.

    ../_images/goto_project.png
  2. Click on the Lab item in the left menu.

    ../_images/goto_lab.png
  3. Click on the NEW button.

    ../_images/btn_new.png
  4. Click on the YOLOv5 Trainer template.

    ../_images/add_lab_11.png
  5. In the new lab dialog, input the following fields:

    • name: my-yolov5-lab

    • flavor: small

  6. Click on the CREATE button.

    ../_images/add_lab_21.png
  7. The newly created lab is now displayed with status running.

    ../_images/add_lab_3.png

Before training the model, we need to enlarge the shared memory size to 8 GB for the lab:

  1. Go to the lab page by clicking on the JupyterLab icon. The lab interactive environment will be opened.

    ../_images/run_lab_1.png
  2. Click on the settings button.

  3. Expand the Configuration section in the side bar and set 8 in the Shared Memory field.

    ../_images/set_shm_1.png ../_images/set_shm_2.png
  4. The lab will be restarted with the new setting.

Train the Model

We will then train the model in the lab by creating a Python notebook.

  1. Create the model training notebook by clicking on the Python 3 (ipkernel) launcher under the Notebook section.

    ../_images/run_lab_2.png
  2. Copy the lines below into the first cell in the notebook.

    # Setup
    !git clone https://github.com/ultralytics/yolov5  # clone
    %cd yolov5
    %pip install -qr requirements.txt  # install
    
    import torch
    from yolov5 import utils
    display = utils.notebook_init()  # checks
    
    ../_images/run_lab_3a.png
  3. Click on the insert button to insert a second cell.

    ../_images/run_lab_3b.png
  4. Copy the lines below into the second cell.

    # Inference
    !python detect.py --weights yolov5s.pt --img 640 --conf 0.25 --source data/images
    display.Image(filename='runs/detect/exp/zidane.jpg', width=600)
    
  5. Insert the third cell. Copy the lines below into this cell.

    # Train YOLOv5s on COCO128 for 3 epochs
    !python train.py --img 640 --batch 16 --epochs 3 --data coco128.yaml --weights yolov5s.pt --cache
    

    The notebook should now look like this:

    ../_images/run_lab_3c.png
  6. Train the model by clicking on the menu item: RunRestart Kernel and Run All Cells.

    ../_images/run_lab_4a.png

    Alternatively, click on the toolbar icon.

    ../_images/run_lab_4b.png
  7. Click on the Restart button.

    ../_images/run_lab_4c.png
  8. The training program will start running cell by cell.

    ../_images/run_lab_5.png
  9. You could also monitor the real-time resource utilization by clicking on the top area. A watch window will be opened.

    ../_images/run_lab_6.png

Visualize the Model Training Results

After the previous model training experiment, here we will submit a training job and then view the training results:

  1. Click on the more button.

  2. Click on the Submit track menu item.

    ../_images/submit_job_1U.png
  3. Click on the SUBMIT button.

    ../_images/submit_job_2U.png
  4. A new browser window will be opened, listing the track for the submitted job.

  5. Go to the track page by clicking on the link of the track.

    ../_images/view_job_track_1U.png
  6. Wait for one minute while the training results are accumulated.

  7. Click on the SWITCH TO TENSORBOARD button.

    ../_images/view_job_track_2U.png
  8. Congratulations! The YOLOv5 model training results are displayed in the TensorBoard page. You may adjust the settings to view the results in different ways.

    ../_images/view_job_track_3.png