Skip to content

Latest commit

 

History

History

Q04_fish_classification

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Fish Classification Application

Application: Overview

The fish classification application allows to classify between 31 different fish species. Label List

The application could be used to classify fishes during fish farming, or from certain areas on the sea/river through drones, etc.

It has 4 modes of running.

Mode RZ/V2L RZ/V2H
MIPI Camera Supported -
USB Camera Supported Supported
Image Supported Supported
Video Supported Supported
Web App Supported
(Link to readme)
Supported
(Link to readme)

Supported Product

  • RZ/V2L Evaluation Board Kit (RZ/V2L EVK)
  • RZ/V2H Evaluation Board Kit (RZ/V2H EVK)

Demo

Following is the demo for RZ/V2H EVK.

Application: Requirements

Hardware Requirements

For Equipment Details
RZ/V2L RZ/V2L EVK Evaluation Board Kit for RZ/V2L.
Includes followings.
  • MIPI Camera Module(Google Coral Camera)
    Used as a camera input source.
  • MicroUSB to Serial Cable for serial communication.
AC Adapter USB Power Delivery adapter for the board power supply.
MicroHDMI Cable Used to connect the HDMI Monitor and the board.
RZ/V2L EVK has microHDMI port.
RZ/V2H RZ/V2H EVK Evaluation Board Kit for RZ/V2H.
AC Adapter USB Power Delivery adapter for the board power supply.
100W is required.
HDMI Cable Used to connect the HDMI Monitor and the board.
RZ/V2H EVK has HDMI port.
USB Camera Used as a camera input source.
Common USB Cable Type-C Connect AC adapter and the board.
HDMI Monitor Used to display the graphics of the board.
microSD card Used as the filesystem.
Must have over 4GB capacity of blank space.
Operating Environment: Transcend UHS-I microSD 300S 16GB
Linux PC Used to build application and setup microSD card.
Operating Environment: Ubuntu 20.04
SD card reader Used for setting up microSD card.
USB Hub Used to connect USB Keyboard and USB Mouse to the board.
USB Keyboard Used to type strings on the terminal of board.
USB Mouse Used to operate the mouse on the screen of board.

Note: All external devices will be attached to the board and does not require any driver installation (Plug n Play Type)

Connect the hardware as shown below.

RZ/V2L EVK RZ/V2H EVK

Note 1: When using the keyboard connected to RZ/V Evaluation Board, the keyboard layout and language are fixed to English.
Note 2: For RZ/V2H EVK, there are USB 2.0 and USB 3.0 ports.
USB camera needs to be connected to appropriate port based on its requirement.

Application: Build Stage

Note: User can skip to the next stage (deploy) if they do not want to build the application.
All pre-built binaries are provided.

Prerequisites

This section expects the user to have completed Step 5 of Getting Started Guide provided by Renesas.

After completion of the guide, the user is expected of following things.

  • AI SDK setup is done.

  • Following docker container is running on the host machine.

    Board Docker container
    RZ/V2L EVK rzv2l_ai_sdk_container
    RZ/V2H EVK rzv2h_ai_sdk_container

    Note: Docker environment is required for building the sample application.

Application File Generation

  1. On your host machine, copy the repository from the GitHub to the desired location.

    1. It is recommended to copy/clone the repository on the data folder, which is mounted on the Docker container.
    cd <path_to_data_folder_on_host>/data
    git clone https://github.com/renesas-rz/rzv_ai_sdk.git

    Note: This command will download the whole repository, which include all other applications.
    If you have already downloaded the repository of the same version, you may not need to run this command.

  2. Run (or start) the docker container and open the bash terminal on the container.
    E.g., for RZ/V2L, use the rzv2l_ai_sdk_container as the name of container created from rzv2l_ai_sdk_image docker image.

    Note that all the build steps/commands listed below are executed on the docker container bash terminal.

  3. Set your clone directory to the environment variable.

    export PROJECT_PATH=/drp-ai_tvm/data/rzv_ai_sdk
  4. Go to the application source code directory.

    cd ${PROJECT_PATH}/Q04_fish_classification/src
  5. Create and move to the build directory.

    mkdir -p build && cd build
  6. Build the application by following the commands below.
    For RZ/V2L

    cmake -DCMAKE_TOOLCHAIN_FILE=./toolchain/runtime.cmake ..
    make -j$(nproc)

    For RZ/V2H

    cmake -DCMAKE_TOOLCHAIN_FILE=./toolchain/runtime.cmake -DV2H=ON ..
    make -j$(nproc)
  7. The following application file would be generated in the ${PROJECT_PATH}/Q04_fish_classification/src/build directory

    • fish_classification

Application: Deploy Stage

Prerequisites

This section expects the user to have completed Step 7-1 of Getting Started Guide provided by Renesas.

After completion of the guide, the user is expected of following things.

  • microSD card setup is done.

File Configuration

For the ease of deployment all the deployable file and folders are provided in following folders.

Board EXE_DIR
RZ/V2L EVK exe_v2l
RZ/V2H EVK exe_v2h

Each folder contains following items.

File Details
fish_classification_model Model object files for deployment.
fish_class_list.txt Label list for Fish classes
Bangus.jpg sample image
output.mp4 sample video
fish_classification application file.

Instruction

  1. Copy the following files to the /home/root/tvm directory of the rootfs (SD Card) for the board.

    File Details
    All files in EXE_DIR directory Including deploy.so file.
    fish_classification application file Generated the file according to Application File Generation
  2. Check if libtvm_runtime.so exists under /usr/lib64 directory of the rootfs (SD card) on the board.

  3. Folder structure in the rootfs (SD Card) would look like:

    |-- usr
    |   `-- lib64
    |       `-- libtvm_runtime.so
    `-- home
        `-- root
            `-- tvm
                |-- fish_classification_model
                |   |-- deploy.json
                |   |-- deploy.params
                |   `-- deploy.so
                |-- Bangus.jpg
                |-- fish_class_list.txt
                |-- fish_classification
                `-- output.mp4
    

Note: The directory name could be anything instead of tvm. If you copy the whole EXE_DIR folder on the board, you are not required to rename it tvm.

Application: Run Stage

Prerequisites

This section expects the user to have completed Step 7-3 of Getting Started Guide provided by Renesas.

After completion of the guide, the user is expected of following things.

  • The board setup is done.
  • The board is booted with microSD card, which contains the application file.

Instruction

  1. On Board terminal, go to the tvm directory of the rootfs.

    cd /home/root/tvm/
  2. Run the application.

    • For Image Mode
    ./fish_classification IMAGE Bangus.jpg

    Note: Tested with image file format .png and .jpg

    • For USB Camera Mode
    ./fish_classification USB
    • For MIPI Camera Mode [RZ/V2L only]
    ./fish_classification MIPI
    • For VIDEO Mode
    ./fish_classification VIDEO output.mp4

    Note: Tested with video file format .mp4 and .avi

  3. Following window shows up on HDMI screen.

    RZ/V2L EVK RZ/V2H EVK

    On application window, following information is displayed.

    • Camera capture
    • Classification result (class name and score.)
    • Processing time taken for AI inference.
    • Frames per Second
    • Top 5 Classification Results (Based on the score)
  4. To terminate the application, follow the termination method below.

    • For RZ/V2L, press Esc key to terminate the application.
    • For RZ/V2H, switch the application window to the terminal by using Super(windows key)+Tab and press ENTER key on the terminal of the board.

Application: Configuration

AI Model

==========================================================================================
Layer (type:depth-idx)                   Output Shape              Param #
==========================================================================================
├─Sequential: 1-1                        [-1, 512, 7, 7]           --
|    └─Conv2d: 2-1                       [-1, 64, 112, 112]        9,408
|    └─BatchNorm2d: 2-2                  [-1, 64, 112, 112]        128
|    └─ReLU: 2-3                         [-1, 64, 112, 112]        --
|    └─MaxPool2d: 2-4                    [-1, 64, 56, 56]          --
|    └─Sequential: 2-5                   [-1, 64, 56, 56]          --
|    |    └─BasicBlock: 3-1              [-1, 64, 56, 56]          73,984
|    |    └─BasicBlock: 3-2              [-1, 64, 56, 56]          73,984
|    |    └─BasicBlock: 3-3              [-1, 64, 56, 56]          73,984
|    └─Sequential: 2-6                   [-1, 128, 28, 28]         --
|    |    └─BasicBlock: 3-4              [-1, 128, 28, 28]         230,144
|    |    └─BasicBlock: 3-5              [-1, 128, 28, 28]         295,424
|    |    └─BasicBlock: 3-6              [-1, 128, 28, 28]         295,424
|    |    └─BasicBlock: 3-7              [-1, 128, 28, 28]         295,424
|    └─Sequential: 2-7                   [-1, 256, 14, 14]         --
|    |    └─BasicBlock: 3-8              [-1, 256, 14, 14]         919,040
|    |    └─BasicBlock: 3-9              [-1, 256, 14, 14]         1,180,672
|    |    └─BasicBlock: 3-10             [-1, 256, 14, 14]         1,180,672
|    |    └─BasicBlock: 3-11             [-1, 256, 14, 14]         1,180,672
|    |    └─BasicBlock: 3-12             [-1, 256, 14, 14]         1,180,672
|    |    └─BasicBlock: 3-13             [-1, 256, 14, 14]         1,180,672
|    └─Sequential: 2-8                   [-1, 512, 7, 7]           --
|    |    └─BasicBlock: 3-14             [-1, 512, 7, 7]           3,673,088
|    |    └─BasicBlock: 3-15             [-1, 512, 7, 7]           4,720,640
|    |    └─BasicBlock: 3-16             [-1, 512, 7, 7]           4,720,640
├─Sequential: 1-2                        [-1, 31]                  --
|    └─AdaptiveConcatPool2d: 2-9         [-1, 1024, 1, 1]          --
|    |    └─AdaptiveMaxPool2d: 3-17      [-1, 512, 1, 1]           --
|    |    └─AdaptiveAvgPool2d: 3-18      [-1, 512, 1, 1]           --
|    └─Flatten: 2-10                     [-1, 1024]                --
|    └─BatchNorm1d: 2-11                 [-1, 1024]                2,048
|    └─Dropout: 2-12                     [-1, 1024]                --
|    └─Linear: 2-13                      [-1, 512]                 524,288
|    └─ReLU: 2-14                        [-1, 512]                 --
|    └─BatchNorm1d: 2-15                 [-1, 512]                 1,024
|    └─Dropout: 2-16                     [-1, 512]                 --
|    └─Linear: 2-17                      [-1, 31]                  15,872
==========================================================================================
Total params: 21,827,904
Trainable params: 21,827,904
Non-trainable params: 0
Total mult-adds (G): 3.71
==========================================================================================
Input size (MB): 0.57
Forward/backward pass size (MB): 54.38
Params size (MB): 83.27
Estimated Total Size (MB): 138.21

Dataset

'Bangus', 'Big Head Carp', 'Black Spotted Barb', 'Catfish', 'Climbing Perch', 'Fourfinger Threadfin', 'Freshwater Eel', 'Glass Perchlet', 'Goby', 'Gold Fish', 'Gourami', 'Grass Carp', 'Green Spotted Puffer', 'Indian Carp', 'Indo-Pacific Tarpon', 'Jaguar Gapote', 'Janitor Fish', 'Knifefish', 'Long-Snouted Pipefish', 'Mosquito Fish', 'Mudfish', 'Mullet', 'Pangasius', 'Perch', 'Scat Fish', 'Silver Barb', 'Silver Carp','Silver Perch', 'Snakehead', 'Tenpounder', 'Tilapia'

Dataset properties: The total number of images: 13,304 image Training set size: 8791 images Test set size: 2751 images The number of classes: 1760

Dataset-Link

AI inference time

Board AI inference time
RZ/V2L EVK Approximately 50 ms
RZ/V2H EVK Approximately 4 ms

Processing

Processing Details
Pre-processing Processed by CPU.
Inference Processed by DRP-AI and CPU.
Post-processing Processed by CPU.

Image buffer size

Board Camera capture buffer size HDMI output buffer size
RZ/V2L EVK VGA (640x480) in YUYV format HD (1280x720) in BGRA format
RZ/V2H EVK VGA (640x480) in YUYV format FHD (1920x1080) in BGRA format

Reference

License

Apache License 2.0
For third party OSS library, please see the source code file itself.