Skip to content

Commit 21a3c84

Browse files
authored
Merge pull request #57 from Interplai/add_yolov3
Adds yolov3 model using tvm to AutowareAuto
2 parents c7ae922 + e48cada commit 21a3c84

File tree

7 files changed

+678
-0
lines changed

7 files changed

+678
-0
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# YOLO V3 Darknet Conversion to Keras
2+
3+
The network definition and weights come from [darknet
4+
website](https://pjreddie.com/darknet/yolo/). It is converted to the keras model using [this](https://github.com/qqwweee/keras-yolo3) repository.
5+
6+
It has been converted to onnx format
7+
using [tf2onnx](https://github.com/onnx/tensorflow-onnx).
8+
9+
## Executing the model
10+
11+
All commands should be run from the root of the model zoo directory.
12+
13+
1.Compile a local image of `autoware/model-zoo-tvm-cli`
14+
15+
```bash
16+
$./scripts/tvm_cli/build.sh
17+
```
18+
19+
2.Compile the model by running the TVM CLI script in a docker container
20+
21+
```bash
22+
$ MODEL_DIR=$(pwd)/perception/camera_obstacle_detection/yolo_v3/tensorflow_fp32_coco/
23+
$ export MODEL_DIR
24+
$ docker run \
25+
-it --rm \
26+
-v ${MODEL_DIR}:${MODEL_DIR} -w ${MODEL_DIR} \
27+
-u $(id -u ${USER}):$(id -g ${USER}) \
28+
autoware/model-zoo-tvm-cli:local \
29+
compile \
30+
--config ${MODEL_DIR}/definition.yaml \
31+
--output_path ${MODEL_DIR}/execute_model/build
32+
```
33+
34+
3.Compile the c++ pipeline
35+
36+
```bash
37+
$ docker run \
38+
-it --rm \
39+
-v ${MODEL_DIR}:${MODEL_DIR} -w ${MODEL_DIR}/execute_model/build \
40+
-u $(id -u ${USER}):$(id -g ${USER}) \
41+
--entrypoint "" \
42+
autoware/model-zoo-tvm-cli:local \
43+
bash -c "cmake .. && make -j"
44+
```
45+
46+
4.Download a sample image and copy some files needed for decoding detections
47+
48+
```bash
49+
$ curl https://raw.githubusercontent.com/pjreddie/darknet/master/data/dog.jpg \
50+
> ${MODEL_DIR}/execute_model/build/test_image_0.jpg
51+
$ cp ${MODEL_DIR}/model_files/labels.txt ${MODEL_DIR}/execute_model/build/
52+
$ cp ${MODEL_DIR}/model_files/anchors.csv ${MODEL_DIR}/execute_model/build/
53+
```
54+
55+
5.Run the detection pipeline inside a docker container. The output result can be obtained in two ways:
56+
57+
- **Save as an image**: saves the result of the pipeline as an image file in the build directory, the filename `output.jpg` can be changed in the command if needed:
58+
59+
```bash
60+
$ docker run \
61+
-it --rm \
62+
--net=host \
63+
-v ${MODEL_DIR}:${MODEL_DIR} \
64+
-w ${MODEL_DIR}/execute_model/build \
65+
--entrypoint "" \
66+
autoware/model-zoo-tvm-cli:local \
67+
./execute_model output.jpg
68+
```
69+
70+
- **Display in a X11 window**: X draw calls are forwarded to the host so the detection results can be displayed in a X11 window.
71+
72+
```bash
73+
$ docker run \
74+
-it --rm \
75+
-v /tmp/.X11-unix:/tmp/.X11-unix:rw \
76+
-v ${HOME}/.Xauthority:${HOME}/.Xauthority:rw \
77+
-e XAUTHORITY=${HOME}/.Xauthority \
78+
-e DISPLAY=$DISPLAY \
79+
--net=host \
80+
-v ${MODEL_DIR}:${MODEL_DIR} \
81+
-w ${MODEL_DIR}/execute_model/build \
82+
--entrypoint "" \
83+
autoware/model-zoo-tvm-cli:local \
84+
./execute_model
85+
```
86+
87+
For more information about getting the TVM docker image, see the TVM CLI
88+
[documentation](../../../../scripts/tvm_cli/README.md).
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
version: 1
2+
enable_testing: true
3+
network:
4+
filename: ./model_files/yolov3-416.onnx
5+
framework: ONNX
6+
provenance: ./README.md
7+
training: COCO dataset, https://pjreddie.com/darknet/yolo/
8+
model_license: Apache-2.0
9+
data_license: CC-BY-4.0
10+
network_parameters:
11+
datatype: float32
12+
input_nodes:
13+
- name: input
14+
description: Camera Image RGB
15+
shape:
16+
- 1
17+
- 416
18+
- 416
19+
- 3
20+
output_nodes:
21+
- name: conv2d_58
22+
description:
23+
shape:
24+
- 1
25+
- 13
26+
- 13
27+
- 255
28+
29+
- name: conv2d_66
30+
description:
31+
shape:
32+
- 1
33+
- 26
34+
- 26
35+
- 255
36+
37+
- name: conv2d_74
38+
description:
39+
shape:
40+
- 1
41+
- 52
42+
- 52
43+
- 255
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Copyright 2021 Apex.AI, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
#    http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
cmake_minimum_required(VERSION 3.0)
16+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
17+
set(CMAKE_CXX_STANDARD 14)
18+
19+
project(execute_model)
20+
21+
find_package( OpenCV REQUIRED )
22+
23+
file(GLOB SRC_FILES "*.cpp")
24+
25+
set(TVM_ROOT /usr/tvm)
26+
set(DMLC_CORE ${TVM_ROOT}/3rdparty/dmlc-core)
27+
set(DLPACK ${TVM_ROOT}/3rdparty/dlpack)
28+
29+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O3")
30+
31+
add_executable(${CMAKE_PROJECT_NAME}
32+
${ROS_NODE_FILE}
33+
${SRC_FILES}
34+
)
35+
36+
target_link_libraries(${CMAKE_PROJECT_NAME}
37+
${OpenCV_LIBS}
38+
dl
39+
pthread
40+
tvm_runtime
41+
)
42+
43+
target_include_directories (${CMAKE_PROJECT_NAME} PRIVATE
44+
${TVM_ROOT}/include
45+
${DMLC_CORE}/include
46+
${DLPACK}/include
47+
)

0 commit comments

Comments
 (0)