Skip to content

Commit

Permalink
Ros2 v0.8.0 traffic light ssd fine detector (autowarefoundation#260)
Browse files Browse the repository at this point in the history
* fix typos in perception (autowarefoundation#862)

* update README.md in perception (autowarefoundation#1007)

* update traffic light recognition model (autowarefoundation#1086)

* update traffic light recognition model

* download model when hash has changed

* fix CMakeLists

* udpate tl model to scale ai dataset one (autowarefoundation#1118)

Co-authored-by: Kazuki Miyahara <[email protected]>
Co-authored-by: Satoshi Tanaka <[email protected]>
Co-authored-by: Taichi Higashide <[email protected]>
  • Loading branch information
4 people authored and wep21 committed Jan 30, 2021
1 parent 3f99fec commit a95e615
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ if (CUDA_FOUND)
${CUDA_TOOLKIT_ROOT_DIR}/lib
)
if (CUDA_VERBOSE)
message("CUDA is available!")
message("CUDA Libs: ${CUDA_LIBRARIES}")
message("CUDA Headers: ${CUDA_INCLUDE_DIRS}")
message(STATUS "CUDA is available!")
message(STATUS "CUDA Libs: ${CUDA_LIBRARIES}")
message(STATUS "CUDA Headers: ${CUDA_INCLUDE_DIRS}")
endif ()
set(CUDA_AVAIL ON)
else()
message("CUDA NOT FOUND")
message(STATUS "CUDA NOT FOUND")
set(CUDA_AVAIL OFF)
endif (CUDA_FOUND)

Expand All @@ -45,15 +45,15 @@ find_library(NVONNXPARSER nvonnxparser)
find_library(NVINFER_PLUGIN NAMES nvinfer_plugin)
if(NVINFER AND NVONNXPARSER AND NVINFER_PLUGIN)
if (CUDA_VERBOSE)
message("TensorRT is available!")
message("NVINFER: ${NVINFER}")
message("NVPARSERS: ${NVPARSERS}")
message("NVINFER_PLUGIN: ${NVINFER_PLUGIN}")
message("NVONNXPARSER: ${NVONNXPARSER}")
message(STATUS "TensorRT is available!")
message(STATUS "NVINFER: ${NVINFER}")
message(STATUS "NVPARSERS: ${NVPARSERS}")
message(STATUS "NVINFER_PLUGIN: ${NVINFER_PLUGIN}")
message(STATUS "NVONNXPARSER: ${NVONNXPARSER}")
endif ()
set(TRT_AVAIL ON)
else()
message("TensorRT is NOT Available")
message(STATUS "TensorRT is NOT Available")
set(TRT_AVAIL OFF)
endif()

Expand All @@ -67,38 +67,56 @@ PATH_SUFFIXES lib lib64 bin
DOC "CUDNN library." )
if(CUDNN_LIBRARY)
if (CUDA_VERBOSE)
message("CUDNN is available!")
message("CUDNN_LIBRARY: ${CUDNN_LIBRARY}")
message(STATUS "CUDNN is available!")
message(STATUS "CUDNN_LIBRARY: ${CUDNN_LIBRARY}")
endif ()
set(CUDNN_AVAIL ON)
else()
message("CUDNN is NOT Available")
message(STATUS "CUDNN is NOT Available")
set(CUDNN_AVAIL OFF)
endif()

# Download caffemodel and prototxt
set(PRETRAINED_MODEL_LINK "https://drive.google.com/uc?id=1USFDPRH9JrVdGoqt27qHjRgittwc0kcO")
set(PRETRAINED_MODEL_HASH 34ce7f2cbacbf6da8bc35769f027b73f)
set(LAMP_LABEL_LINK "https://drive.google.com/uc?id=1hPcKvKgKz0fqEo0cNAXH7roEletqZErL")
set(LAMP_LABEL_HASH e9f45efb02f2a9aa8ac27b3d5c164905)

find_program(GDOWN_AVAIL "gdown")
if (NOT GDOWN_AVAIL)
message("gdown: command not found. External files could not be downloaded.")
message(STATUS "gdown: command not found. External files could not be downloaded.")
endif()
set(PATH "${CMAKE_CURRENT_SOURCE_DIR}/data")
if (NOT EXISTS "${PATH}")
execute_process(COMMAND mkdir -p ${PATH})
endif()

set(FILE "${PATH}/mb2-ssd-lite-tlr.onnx")
message(STATUS "Checking and downloading mb2-ssd-lite-tlr.onnx")
if (NOT EXISTS "${FILE}")
if (EXISTS "${FILE}")
file(MD5 "${FILE}" EXISTING_FILE_HASH)
if (NOT "${PRETRAINED_MODEL_HASH}" EQUAL "${EXISTING_FILE_HASH}")
message(STATUS "... file hash changed. Downloading now ...")
execute_process(COMMAND gdown --quiet "${PRETRAINED_MODEL_LINK}" -O ${PATH}/mb2-ssd-lite-tlr.onnx)
endif()
else()
message(STATUS "... file does not exist. Downloading now ...")
execute_process(COMMAND gdown "https://drive.google.com/uc?id=1PGxVstVV_sVOLEEyl47m5lNXdLy_Iyob" -O ${PATH}/mb2-ssd-lite-tlr.onnx)
execute_process(COMMAND gdown --quiet "${PRETRAINED_MODEL_LINK}" -O ${PATH}/mb2-ssd-lite-tlr.onnx)
endif()

set(FILE "${PATH}/voc_labels_tl.txt")
message(STATUS "Checking and downloading voc_labels_tl.txt")
if (NOT EXISTS "${FILE}")
if (EXISTS "${FILE}")
file(MD5 "${FILE}" EXISTING_FILE_HASH)
if (NOT "${LAMP_LABEL_HASH}" EQUAL "${EXISTING_FILE_HASH}")
message(STATUS "... file does not exist. Downloading now ...")
execute_process(COMMAND gdown --quiet "${LAMP_LABEL_LINK}" -O ${PATH}/voc_labels_tl.txt)
endif()
else()
message(STATUS "... file does not exist. Downloading now ...")
execute_process(COMMAND gdown "https://drive.google.com/uc?id=1hPcKvKgKz0fqEo0cNAXH7roEletqZErL" -O ${PATH}/voc_labels_tl.txt)
execute_process(COMMAND gdown --quiet "${LAMP_LABEL_LINK}" -O ${PATH}/voc_labels_tl.txt)
endif()


if(TRT_AVAIL AND CUDA_AVAIL AND CUDNN_AVAIL)
include_directories(
${OpenCV_INCLUDE_DIRS}
Expand Down Expand Up @@ -146,6 +164,6 @@ if(TRT_AVAIL AND CUDA_AVAIL AND CUDNN_AVAIL)
)

else()
message("TrafficLightSSDFineDetector won't be built, CUDA and/or TensorRT were not found.")
message(STATUS "TrafficLightSSDFineDetector won't be built, CUDA and/or TensorRT were not found.")
endif()

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
### Note
There's a fine detector implementation of Mobilenet SSD.
# traffic\_light\_ssd\_fine\_detector

The model of Mobilenet SSD is based on [pytorch-ssd] (https://github.com/qfgaohao/pytorch-ssd).
This is a traffic light fine detector implementation of MobileNetV2 + SSDLite.

## Training
The model of Mobilenet SSD used in this package was trained by [AutowareMLPlatform/detection_2d](https://github.com/tier4/AutowareMLPlatform/tree/master/tasks/detection_2d)
The trained model is based on [pytorch-ssd](https://github.com/qfgaohao/pytorch-ssd).

## Reference

M. Sandler, A. Howard, M. Zhu, A. Zhmoginov and L. Chen, "MobileNetV2: Inverted Residuals and Linear Bottlenecks," 2018 IEEE/CVF Conference on Computer Vision and Pattern Recognition, Salt Lake City, UT, 2018, pp. 4510-4520, doi: 10.1109/CVPR.2018.00474.

## model detail
TODO: atach AWS URL here for quick reference when, where and how the model was trained.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class TrafficLightSSDFineDetectorNodelet : public rclcpp::Node
const std::vector<cv::Mat> & in_imgs, const int num_rois, std::vector<float> & data);
bool cnnOutput2BoxDetection(
const float * scores, const float * boxes, const int tlr_id,
const std::vector<cv::Mat> & in_imgs, const int num_rois, std::vector<Detection> & detctions);
const std::vector<cv::Mat> & in_imgs, const int num_rois, std::vector<Detection> & detections);
bool rosMsg2CvMat(const sensor_msgs::msg::Image::ConstSharedPtr image_msg, cv::Mat & image);
bool fitInFrame(cv::Point & lt, cv::Point & rb, const cv::Size & size);
void cvRect2TlRoiMsg(
Expand Down

0 comments on commit a95e615

Please sign in to comment.