diff --git a/perception/traffic_light_recognition/traffic_light_ssd_fine_detector/CMakeLists.txt b/perception/traffic_light_recognition/traffic_light_ssd_fine_detector/CMakeLists.txt index b5ce716513693..8e8b30a4dda41 100644 --- a/perception/traffic_light_recognition/traffic_light_ssd_fine_detector/CMakeLists.txt +++ b/perception/traffic_light_recognition/traffic_light_ssd_fine_detector/CMakeLists.txt @@ -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) @@ -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() @@ -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} @@ -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() diff --git a/perception/traffic_light_recognition/traffic_light_ssd_fine_detector/README.md b/perception/traffic_light_recognition/traffic_light_ssd_fine_detector/README.md index 097220a35db5d..cd2fccca54253 100644 --- a/perception/traffic_light_recognition/traffic_light_ssd_fine_detector/README.md +++ b/perception/traffic_light_recognition/traffic_light_ssd_fine_detector/README.md @@ -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. \ No newline at end of file diff --git a/perception/traffic_light_recognition/traffic_light_ssd_fine_detector/include/traffic_light_ssd_fine_detector/nodelet.hpp b/perception/traffic_light_recognition/traffic_light_ssd_fine_detector/include/traffic_light_ssd_fine_detector/nodelet.hpp index bd35ca01bcd97..13958a5c41ce9 100644 --- a/perception/traffic_light_recognition/traffic_light_ssd_fine_detector/include/traffic_light_ssd_fine_detector/nodelet.hpp +++ b/perception/traffic_light_recognition/traffic_light_ssd_fine_detector/include/traffic_light_ssd_fine_detector/nodelet.hpp @@ -62,7 +62,7 @@ class TrafficLightSSDFineDetectorNodelet : public rclcpp::Node const std::vector & in_imgs, const int num_rois, std::vector & data); bool cnnOutput2BoxDetection( const float * scores, const float * boxes, const int tlr_id, - const std::vector & in_imgs, const int num_rois, std::vector & detctions); + const std::vector & in_imgs, const int num_rois, std::vector & 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(