---
# System prepended metadata

title: Amba - darknet to amba
tags: [amba, darknet]

---

# Amba - darknet to amba
###### tags: `darknet`
## initial environment gcc
```
source SDK2.5/Package/cv2x_linux_sdk_2.5/ambarella//build/env/aarch64-linaro-gcc.env
```
> TOOLCHAIN    PATH: /usr/local/linaro-aarch64-2018.08-gcc8.2
TOOLCHAIN    NANE: aarch64-linux-gnu-gcc
TOOLCHAIN VERSION: 8.2.1

## initial environment cv25 cnn

```
source /usr/local/amba-cv-tools-2.1.8-20200117.ubuntu-18.04/env/cv25.env
source  SDK2.5/CV2x_Toolchain/cv2x_cnngen_samples_20200304/build/env/cv25.env
```
> =================================================
> AmbaCnnUtils Version: cv2.1.8.2.550
    CnnUtils Version: cv2.1.8.2.550
     Cavalry Version: version 2.1.7 ( HASH c5db5f1 )
         Vas Version: cv22.1.8.2.550
=================================================
============================================================
CV TOOLCHAIN    PATH: /usr/local/amba-cv-tools-2.1.8-20200117.ubuntu-18.04
CV TOOLCHAIN VERSION: 2.1.8-20200117


## darknet to amba

#### 有frozen graph 檔, 剪枝output layer
用 netorn 看input/output layer name
```
graph_surgery.py tf -p (convert_weights_pb_jl.py 產出的檔案).pb -o tiny_yolov3_frozen_exhaust_0811.pb -isrc "i:inputs|is:416,416,3" -on "detector/yolo-v3-tiny/Conv_10/Conv2D,detector/yolo-v3-tiny/Conv_11/Conv2D"
```

#### 檔案放置
```
cd SDK2.5/CV2x_Toolchain/cv2x_cnngen_samples_20200304/tensorflow/demo_networks/tiny_yolo_v3
# model 放置處
cd models
# 影像資料放置處(jpg檔) 大約200張
cd dra_img
```

#### 轉 amba

```
cd SDK2.5/CV2x_Toolchain/cv2x_cnngen_samples_20200304/
vim .config
```

.config file 內容直接貼上
```config=
BUILD_CNNGEN_TENSORFLOW_NETWORKS=y
BUILD_CNNGEN_TENSORFLOW_DEMO_NETWORKS=y
BUILD_CNNGEN_TENSORFLOW_DEMO_TINY_YOLOV3=y
CONFIG_CNNGEN_TENSORFLOW_DEMO_TINY_YOLOV3_MODEL="tiny_yolov3_frozen_exhaust_0811.pb"
CONFIG_CNNGEN_TENSORFLOW_DEMO_TINY_YOLOV3_PARSER_OPTION="-c act-force-fx16,coeff-force-fx16"
CONFIG_CNNGEN_TENSORFLOW_DEMO_TINY_YOLOV3_IN_NODE="inputs"
CONFIG_CNNGEN_TENSORFLOW_DEMO_TINY_YOLOV3_IN_H_W="416,416"
CONFIG_CNNGEN_TENSORFLOW_DEMO_TINY_YOLOV3_IN_MEAN="0.0,0.0,0.0"
CONFIG_CNNGEN_TENSORFLOW_DEMO_TINY_YOLOV3_IN_SCALE="1"
CONFIG_CNNGEN_TENSORFLOW_DEMO_TINY_YOLOV3_IN_IS_BGR=0
CONFIG_CNNGEN_TENSORFLOW_DEMO_TINY_YOLOV3_OUT_NODE="detector/yolo-v3-tiny/Conv_10/Conv2D,detector/yolo-v3-tiny/Conv_11/Conv2D"
CONFIG_CNNGEN_TENSORFLOW_DEMO_TINY_YOLOV3_OUT_FORMAT="fp32"
```
> 精度調整
> CONFIG_CNNGEN_TENSORFLOW_DEMO_TINY_YOLOV3_PARSER_OPTION
> int16: act-force-fx16,coeff-force-fx16 
> int8: act-force-fx8,coeff-force-fx8
> 詳細自己看 spec SDK2.5/Document/Ambarella_CV2x_Flexible_Linux_SDK2.5.6_Document_VIVOTEK/Ambarella_CV2x_UG_Flexible_Linux_SDK2.5_CNNGen_Development_Flow.pdf

cavalry mode (轉換成 amba device 讀的模型檔)
```
make run_mode=cavalry
```
> 產出位置 out/tensorflow/demo_networks/tf_tiny_yolov3/cavalry_tf_tiny_yolov3/tf_tiny_yolov3_cavalry.bin