Khadas Docs

Amazing Khadas, always amazes you!

User Tools

Site Tools


Sidebar

products:sbc:vim4:npu:demos:vgg16

This is an old revision of the document!


VGG16 Tensorflow Keras VIM4 Demo 4

VGG16 is a convolution neural net architecture that’s used for image recognition. It utilizes 16 layers with weights and is considered one of the best vision model architectures to date.

Get Source Code

Daipuwei/Mini-VGG-CIFAR10

git clone https://github.com/Daipuwei/Mini-VGG-CIFAR10

Convert Model

Build virtual environment

Follow Docker official docs to install Docker: Install Docker Engine on Ubuntu.

Get Docker.

$ docker pull yanwyb/npu:v1
$ docker run -it --name vim4-npu1 -v $(pwd):/home/khadas/npu \
				-v /etc/localtime:/etc/localtime:ro \
				-v /etc/timezone:/etc/timezone:ro \
				yanwyb/npu:v1

Get convert tool

Download Tool from khadas/vim4_npu_sdk.git.

$ git clone https://gitlab.com/khadas/vim4_npu_sdk

Convert

Keras model can convert rknn model directly. But this demo is to convert tensorflow model(.pb) first, and convert tnesorflow model to rknn model. We use this tool to convert.

git clone https://github.com/amir-abdi/keras_to_tensorflow

Enter vim4_npu_sdk/demo and modify convert_adla.sh as follows.

convert_adla.sh
#!/bin/bash
 
ACUITY_PATH=../bin/
#ACUITY_PATH=../python/tvm/
adla_convert=${ACUITY_PATH}adla_convert
 
 
if [ ! -e "$adla_convert" ]; then
    adla_convert=${ACUITY_PATH}adla_convert.py
fi
 
$adla_convert --model-type tensorflow \
        --model ./model_source/vgg16/vgg16.pb \
        --inputs image_input --input-shapes 32,32,3 \
        --outputs dense_2/Softmax \
        --inference-input-type float32 \
		--inference-output-type float32 \
        --quantize-dtype int8 --outdir tensorflow_output \
        --channel-mean-value "0,0,0,255" \
        --source-file vgg16_dataset.txt \
        --iterations 500 \
        --batch-size 1 \
        --target-platform PRODUCT_PID0XA003

Run convert_adla.sh to generate VIM4 model. The converted model is xxx.adla in tensorflow_output.

$ bash convert_adla.sh

Run NPU

Get source code

Clone the source code from our khadas/vim4_npu_applications.

$ git clone https://github.com/khadas/vim4_npu_applications

Install dependencies

$ sudo apt update
$ sudo apt install libopencv-dev python3-opencv cmake

Compile and run

Picture input demo

Put vgg16_int8.adla in vim4_npu_applications/vgg16/data/.

# Compile
$ cd vim4_npu_applications/vgg16
$ mkdir build
$ cd build
$ cmake ..
$ make
 
# Run
$ sudo ./vgg16 -m ../data/vgg16_int8.adla -p ../data/airplane.jpeg

If your vgg16 model classes is not the same as cifar10, please change data/vgg16_class.txt and the OBJ_CLASS_NUM in include/postprocess.h.

Last modified: 2023/09/17 22:53 by sravan