Khadas Docs

Amazing Khadas, always amazes you!

User Tools

Site Tools


products:sbc:vim4:npu:demos:densenet

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
products:sbc:vim4:npu:demos:densenet [2024/01/04 04:59]
louis
products:sbc:vim4:npu:demos:densenet [2024/01/04 21:23] (current)
louis old revision restored (2023/09/20 01:13)
Line 62: Line 62:
 ``` ```
  
-The model input is grayscale image, so before quantification, you should convert your quantification picture into grayscale image and save in ''npy'' file. +Enter ''vim4_npu_sdk/demo'' and modify ''convert_adla.sh'' as follows. We should quantize the model to **int16** because it is very inaccurate with **int8**.
- +
-```python convert_picture.py +
-import numpy as np +
-import cv2 +
-import os +
- +
-image_path = "./image/" +
-save_path = "./data/" +
- +
-for i in os.listdir(image_path): +
-    image = cv2.imread(image_path + i, 0) +
-    image = image / 255.0 +
-    image = np.expand_dims(image, axis=0).astype(np.float32) +
-    np.save(save_path + i.split(".")[0] + ".npy", image) +
-``` +
- +
-Enter ''vim4_npu_sdk/demo'' and modify ''convert_adla.sh'' as follows.+
  
 ```bash convert_adla.sh ```bash convert_adla.sh
Line 98: Line 81:
         --input-shapes  "1,32,280"  \         --input-shapes  "1,32,280"  \
         --dtypes "float32" \         --dtypes "float32" \
-        --quantize-dtype int8 --outdir onnx_output  \+        --inference-input-type float32 \ 
 + --inference-output-type float32 \ 
 +        --quantize-dtype int16 --outdir onnx_output  \
         --channel-mean-value "0,0,0,255"  \         --channel-mean-value "0,0,0,255"  \
         --source-file ./densenet_ctc_dataset.txt  \         --source-file ./densenet_ctc_dataset.txt  \
         --iterations 500 \         --iterations 500 \
         --disable-per-channel False \         --disable-per-channel False \
-        --inference-input-type float32 \ 
-        --inference-output-type float32 \ 
         --batch-size 1 --target-platform PRODUCT_PID0XA003         --batch-size 1 --target-platform PRODUCT_PID0XA003
 ``` ```
- 
-<WRAP important > 
-Please prepare about 500 pictures for quantification. If the pictures size is smaller than model input size, please resize pictures to input size before quantification. 
-</WRAP> 
  
 Run ''convert_adla.sh'' to generate the VIM4 model. The converted model is ''xxx.adla'' in ''onnx_output''. Run ''convert_adla.sh'' to generate the VIM4 model. The converted model is ''xxx.adla'' in ''onnx_output''.
Line 127: Line 106:
 $ git clone https://github.com/khadas/vim4_npu_applications $ git clone https://github.com/khadas/vim4_npu_applications
 ``` ```
- 
-<WRAP important > 
-If your kernel version is 5.4 or earlier, please use tag ''ddk-1.7.5.5''. Tag ''ddk-2.3.6.7'' is for 5.15. 
-</WRAP> 
  
 ==== Install dependencies ==== ==== Install dependencies ====
Last modified: 2024/01/04 04:59 by louis