Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cpp/DarknetDetection/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ set(CMAKE_CXX_STANDARD 11)

include(../ComponentSetup.cmake)

find_package(OpenCV 3.4.7 EXACT REQUIRED PATHS /opt/opencv-3.4.7 COMPONENTS opencv_core opencv_highgui)
find_package(OpenCV 4.5.0 EXACT REQUIRED PATHS /opt/opencv-4.5.0 COMPONENTS opencv_core opencv_highgui)


find_package(mpfComponentInterface REQUIRED)
Expand All @@ -42,7 +42,7 @@ find_package(Qt4 REQUIRED)
get_plugin_build_location(DarknetDetection pluginLocation)

if (DEFINED ENV{MPF_DISABLE_CUDA_BUILD})
set(DARKNET_BUILD_CUDA OFF)
set(DARKNET_BUILD_CUDA OFF)
message(
"The CUDA version of Darknet will not be built because the MPF_DISABLE_CUDA_BUILD environment variable was set.")
else()
Expand Down Expand Up @@ -86,4 +86,4 @@ endif()
add_executable(sample_darknet_detector sample_darknet_detector.cpp)
target_link_libraries(sample_darknet_detector mpfDarknetDetection)

add_subdirectory(test)
add_subdirectory(test)
39 changes: 21 additions & 18 deletions cpp/DarknetDetection/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,9 @@ RUN mkdir /weights && curl --location https://pjreddie.com/media/files/yolov3.we
# Build Component
FROM ${BUILD_REGISTRY}openmpf_cpp_component_build:${BUILD_TAG} as build_component

RUN yum-config-manager --add-repo http://developer.download.nvidia.com/compute/cuda/repos/rhel7/x86_64 \
&& VERSION=9-0-9.0.176-1 \
&& yum install -y --nogpgcheck cuda-minimal-build-$VERSION cuda-cublas-dev-$VERSION cuda-curand-dev-$VERSION \
RUN yum install --nogpgcheck -y cuda-curand-dev-10-2 \
&& yum clean all \
&& rm -rf /var/cache/yum/* \
&& ln -s cuda-9.0 /usr/local/cuda \
&& echo '/usr/local/cuda/lib64' >> /etc/ld.so.conf.d/cuda.conf
&& rm -rf /var/cache/yum/*;

COPY . .

Expand All @@ -53,18 +49,7 @@ RUN if [ "${RUN_TESTS,,}" == true ]; then cd $BUILD_DIR/test && ./DarknetDetecti


####################################################
FROM ${BUILD_REGISTRY}openmpf_cpp_executor:${BUILD_TAG}

RUN yum-config-manager --add-repo http://developer.download.nvidia.com/compute/cuda/repos/rhel7/x86_64 \
&& yum install -y --nogpgcheck cuda-cudart-9-0-9.0.176-1 \
&& yum clean all \
&& rm -rf /var/cache/yum/* \
&& ln -s cuda-9.0 /usr/local/cuda \
&& echo '/usr/local/cuda/lib64' >> /etc/ld.so.conf.d/cuda.conf

# Environment variables required by nvidia runtime.
ENV NVIDIA_VISIBLE_DEVICES all
ENV NVIDIA_DRIVER_CAPABILITIES compute,utility
FROM ${BUILD_REGISTRY}openmpf_cpp_executor:${BUILD_TAG} as darknet_component

COPY --from=download_weights /weights $PLUGINS_DIR/DarknetDetection/models

Expand All @@ -83,3 +68,21 @@ LABEL org.label-schema.license="Apache 2.0" \
org.label-schema.vcs-url="https://github.com/openmpf/openmpf-components" \
org.label-schema.vendor="MITRE"


####################################################
FROM darknet_component as sample_executable

COPY --from=build_component $BUILD_DIR/sample_darknet_detector /opt/mpf/

COPY --from=build_component $BUILD_DIR/test/data /opt/mpf/test-data

RUN ln -s /opt/mpf/plugins /opt/mpf/plugin

ENV LD_LIBRARY_PATH $PLUGINS_DIR/DarknetDetection/lib

ENTRYPOINT ["/opt/mpf/sample_darknet_detector"]


####################################################
# Set final image when no --target specified.
FROM darknet_component
9 changes: 3 additions & 6 deletions cpp/DarknetDetection/darknet_lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ set(DARKNET_LIB_SRC_FILES
src/yolo_layer.c
src/iseg_layer.c)

find_package(OpenCV 3.4.7 EXACT REQUIRED PATHS /opt/opencv-3.4.7 COMPONENTS opencv_core opencv_highgui)

set(CMAKE_POSITION_INDEPENDENT_CODE ON)

# Darknet fails to compile when all optimizations are disabled, which is the default for debug builds.
Expand All @@ -91,9 +89,8 @@ else()
endif()

add_library(darknet_lib ${DARKNET_LIB_SRC_FILES})
target_compile_definitions(darknet_lib PUBLIC -DOPENCV)
target_include_directories(darknet_lib PUBLIC include)
target_link_libraries(darknet_lib m pthread ${OpenCV_LIBS})
target_link_libraries(darknet_lib m pthread)


if (DARKNET_BUILD_CUDA)
Expand Down Expand Up @@ -125,9 +122,9 @@ if (DARKNET_BUILD_CUDA)

CUDA_ADD_LIBRARY(darknet_lib_cuda ${DARKNET_LIB_SRC_FILES} ${DARKNET_CUDA_SRC_FILES})
CUDA_ADD_CUBLAS_TO_TARGET(darknet_lib_cuda)
target_compile_definitions(darknet_lib_cuda PUBLIC -DOPENCV -DGPU)
target_compile_definitions(darknet_lib_cuda PUBLIC -DGPU)

target_include_directories(darknet_lib_cuda PUBLIC include ${CUDA_INCLUDE_DIRS})
target_link_libraries(darknet_lib_cuda m pthread ${OpenCV_LIBS} ${CUDA_curand_LIBRARY})
target_link_libraries(darknet_lib_cuda m pthread ${CUDA_curand_LIBRARY})
endif()

2 changes: 1 addition & 1 deletion cpp/DarknetDetection/darknet_wrapper/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ project(darknet-wrapper)
set(CMAKE_CXX_STANDARD 11)


find_package(OpenCV 3.4.7 EXACT REQUIRED PATHS /opt/opencv-3.4.7 COMPONENTS opencv_core opencv_highgui)
find_package(OpenCV 4.5.0 EXACT REQUIRED PATHS /opt/opencv-4.5.0 COMPONENTS opencv_core opencv_highgui)

find_package(mpfComponentInterface REQUIRED)
find_package(mpfDetectionComponentApi REQUIRED)
Expand Down
19 changes: 19 additions & 0 deletions cpp/DarknetDetection/sample_darknet_detector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include <QCoreApplication>
#include <iomanip>
#include <chrono>
#include <opencv2/core/cuda.hpp>


#include "DarknetDetection.h"

Expand All @@ -37,9 +39,26 @@ using namespace MPF::COMPONENT;
void print_tracks(const std::vector<MPFVideoTrack> &tracks);

int main(int argc, char* argv[]) {
if (argc == 2) {
std::string arg1 = argv[1];
if (arg1 == "gpu-info") {
int cuda_device_count = cv::cuda::getCudaEnabledDeviceCount();
std::cout << "Cuda device count: " << cuda_device_count << std::endl;
if (cuda_device_count > 0) {
for (int i = 0; i < cuda_device_count; i++) {
std::cout << "==== Device #" << i << " ====" << std::endl;
cv::cuda::printCudaDeviceInfo(i);
std::cout << "=================================" << std::endl;
}
}
return EXIT_SUCCESS;
}
}

if (argc < 3) {
std::cout << "Usage: " << argv[0] << " <uri> <model_name> [gpu_index]" << std::endl;
std::cout << "Usage: " << argv[0] << " <uri> <model_name> <start_frame> <end_frame> [gpu_index] [queue_capacity]" << std::endl;
std::cout << "Usage: " << argv[0] << " gpu-info" << std::endl;
return 1;
}

Expand Down
4 changes: 2 additions & 2 deletions cpp/DarknetDetection/test/test_darknet_detection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@


#include <gtest/gtest.h>
#include <opencv2/imgcodecs.hpp>
#include <opencv/cv.hpp>

#include <opencv2/core.hpp>

#include <MPFDetectionComponent.h>
#include <MPFVideoCapture.h>
Expand Down
7 changes: 4 additions & 3 deletions cpp/DlibFaceDetection/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ project(dlib-face-detection)
set(CMAKE_CXX_STANDARD 11)

set(USE_AVX_INSTRUCTIONS ON)
set(DLIB_DIR /apps/source/dlib-sources/dlib-18.18/dlib)
set(DLIB_USE_CUDA OFF)
set(DLIB_DIR /apps/source/dlib-sources/dlib-19.20/dlib)
include(${DLIB_DIR}/cmake)
set_property(TARGET dlib PROPERTY POSITION_INDEPENDENT_CODE ON)

include(../ComponentSetup.cmake)

find_package(OpenCV 3.4.7 EXACT REQUIRED PATHS /opt/opencv-3.4.7 COMPONENTS opencv_highgui)
find_package(OpenCV 4.5.0 EXACT REQUIRED PATHS /opt/opencv-4.5.0 COMPONENTS opencv_highgui)
find_package(mpfComponentInterface REQUIRED)
find_package(mpfDetectionComponentApi REQUIRED)
find_package(mpfComponentUtils REQUIRED)
Expand All @@ -56,4 +57,4 @@ configure_mpf_component(DlibFaceDetection TARGETS mpfDlibFaceDetection)
add_subdirectory(test)

add_executable(sample_dlib_face_detector sample_dlib_face_detector.cpp)
target_link_libraries(sample_dlib_face_detector mpfDlibFaceDetection)
target_link_libraries(sample_dlib_face_detector mpfDlibFaceDetection)
4 changes: 2 additions & 2 deletions cpp/DlibFaceDetection/DlibFaceDetection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ vector<MPFImageLocation> DlibFaceDetection::GetDetectionsFromImageData(const MPF
if (verbosity > 0) {
// Draw a rectangle onto the input image for each detection
if (imshow_on) {
namedWindow("original image", CV_WINDOW_AUTOSIZE);
namedWindow("original image", cv::WINDOW_AUTOSIZE);
imshow("original image", image);
waitKey(5);
}
Expand All @@ -679,7 +679,7 @@ vector<MPFImageLocation> DlibFaceDetection::GetDetectionsFromImageData(const MPF
cv::rectangle(image, object, CV_RGB(0, 0, 0), 2);
}
if (imshow_on) {
namedWindow("new image", CV_WINDOW_AUTOSIZE);
namedWindow("new image", cv::WINDOW_AUTOSIZE);
imshow("new image", image);
//0 waits indefinitely for input, which could cause problems when run as a component
waitKey(5);
Expand Down
2 changes: 1 addition & 1 deletion cpp/DlibFaceDetection/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ RUN yum install --assumeyes bzip2 \
&& rm --recursive /var/cache/yum/*

RUN mkdir --parents /apps/source/dlib-sources; \
curl --location 'http://dlib.net/files/dlib-18.18.tar.bz2' \
curl --location 'http://dlib.net/files/dlib-19.20.tar.bz2' \
| tar --extract --bzip2 --directory /apps/source/dlib-sources


Expand Down
3 changes: 2 additions & 1 deletion cpp/KeywordTagging/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ message("Package in ${PACKAGE_DIR}")
find_package(mpfComponentInterface REQUIRED)
find_package(mpfDetectionComponentApi REQUIRED)
find_package(mpfComponentUtils REQUIRED)
find_package(OpenCV 3.4.7 EXACT REQUIRED PATHS /opt/opencv-3.4.7 COMPONENTS opencv_core)
find_package(OpenCV 4.5.0 EXACT REQUIRED PATHS /opt/opencv-4.5.0 COMPONENTS opencv_core)

find_package(Qt4 REQUIRED)

find_package(Boost 1.53.0 COMPONENTS regex locale filesystem)
Expand Down
2 changes: 1 addition & 1 deletion cpp/OalprLicensePlateTextDetection/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ set(CMAKE_CXX_STANDARD 11)

include(../ComponentSetup.cmake)

find_package(OpenCV 3.4.7 EXACT REQUIRED PATHS /opt/opencv-3.4.7)
find_package(OpenCV 4.5.0 EXACT REQUIRED PATHS /opt/opencv-4.5.0 COMPONENTS opencv_core)
find_package(mpfComponentInterface REQUIRED)
find_package(mpfDetectionComponentApi REQUIRED)
find_package(mpfComponentUtils REQUIRED)
Expand Down
11 changes: 8 additions & 3 deletions cpp/OalprLicensePlateTextDetection/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,17 @@ RUN mkdir /tmp/tesseract; \

RUN mkdir /tmp/oalpr; \
cd /tmp/oalpr; \
curl --location 'https://github.com/openalpr/openalpr/archive/6ead2fb8f72ac1929a2e04912c5795af0bf37761.tar.gz' \
curl --location 'https://github.com/openalpr/openalpr/archive/386895386781f04ef056e93dd70d9ec36f72d350.tar.gz' \
| tar --extract --gzip; \
cd openalpr-6ead2fb8f72ac1929a2e04912c5795af0bf37761/src; \
cd openalpr-386895386781f04ef056e93dd70d9ec36f72d350/src; \
# The following sed command will need to be modified when upgrading OALPR.
# Line 101 of the OALPR CMakeLists.txt contains: FIND_PACKAGE( OpenCV REQUIRED )
# That pulls in a bunch of OpenCV libraries that OALPR doesn't need.
sed -i '101s/.*/ FIND_PACKAGE( OpenCV REQUIRED COMPONENTS opencv_core opencv_imgcodecs opencv_highgui opencv_objdetect opencv_video)/' \
CMakeLists.txt; \
mkdir build; \
cd build; \
cmake3 -DCMAKE_CXX_STANDARD=11 -DCMAKE_CXX_STANDARD_REQUIRED=ON -DWITH_DAEMON=OFF \
cmake3 -DCMAKE_CXX_STANDARD=11 -DCMAKE_CXX_STANDARD_REQUIRED=ON -DWITH_DAEMON=OFF -DWITH_GPU_DETECTOR=false \
-DCMAKE_INSTALL_PREFIX:PATH=/usr/local -DLeptonica_LIB=/usr/local/lib/libleptonica.so ..; \
make install -j "$(nproc)"; \
rm --recursive /tmp/oalpr
Expand Down
2 changes: 1 addition & 1 deletion cpp/OcvDnnDetection/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ set(CMAKE_CXX_STANDARD 11)

include(../ComponentSetup.cmake)

find_package(OpenCV 3.4.7 EXACT REQUIRED PATHS /opt/opencv-3.4.7
find_package(OpenCV 4.5.0 EXACT REQUIRED PATHS /opt/opencv-4.5.0
COMPONENTS opencv_dnn)

find_package(mpfComponentInterface REQUIRED)
Expand Down
20 changes: 18 additions & 2 deletions cpp/OcvDnnDetection/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ ARG RUN_TESTS=false
RUN if [ "${RUN_TESTS,,}" == true ]; then cd $BUILD_DIR/test && ./OcvDnnDetectionTest; fi



FROM ${BUILD_REGISTRY}openmpf_cpp_executor:${BUILD_TAG} as install_component
FROM ${BUILD_REGISTRY}openmpf_cpp_executor:${BUILD_TAG} as ocv_dnn_component

ENV COMPONENT_LOG_NAME ocv-dnn-detection.log

Expand All @@ -53,3 +52,20 @@ LABEL org.label-schema.license="Apache 2.0" \
org.label-schema.url="https://openmpf.github.io" \
org.label-schema.vcs-url="https://github.com/openmpf/openmpf-components" \
org.label-schema.vendor="MITRE"


FROM ocv_dnn_component as sample_executable

COPY --from=build_component $BUILD_DIR/sample_ocv_dnn_classifier /opt/mpf/

COPY --from=build_component $BUILD_DIR/test/data /opt/mpf/test-data

RUN ln -s /opt/mpf/plugins /opt/mpf/plugin

ENV LD_LIBRARY_PATH $PLUGINS_DIR/OcvDnnDetection/lib

ENTRYPOINT ["/opt/mpf/sample_ocv_dnn_classifier"]


# Set final image when no --target specified.
FROM ocv_dnn_component
51 changes: 50 additions & 1 deletion cpp/OcvDnnDetection/OcvDnnDetection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/dnn.hpp>
#include <opencv2/core/cuda.hpp>


#include <log4cxx/logmanager.h>
#include <log4cxx/xml/domconfigurator.h>
Expand Down Expand Up @@ -525,9 +527,48 @@ MPF_COMPONENT_CREATOR(OcvDnnDetection);
MPF_COMPONENT_DELETER();



bool set_cuda_device_if_requested(const Properties &props, const log4cxx::LoggerPtr &logger) {
int cuda_device_id = DetectionComponentUtils::GetProperty(props, "CUDA_DEVICE_ID", -1);
if (cuda_device_id < 0) {
return false;
}

int cuda_device_count = cv::cuda::getCudaEnabledDeviceCount();
if (cuda_device_count > 0 && cuda_device_id < cuda_device_count) {
LOG4CXX_INFO(logger, "Running job on CUDA device: " << cuda_device_id);
cv::cuda::setDevice(cuda_device_id);
return true;
}

std::string error_message;
if (cuda_device_count < 0) {
error_message = "Could not run job on GPU because the CUDA driver is not installed or is the wrong version.";
}
else if (cuda_device_count == 0) {
error_message = "Could not run job on GPU because OpenCV was compiled without CUDA support.";
}
else {
error_message = "Could not run job on GPU because CUDA_DEVICE_ID was set to " + std::to_string(cuda_device_id)
+ " but only " + std::to_string(cuda_device_count)
+ " CUDA devices were detected, making the maximum device id "
+ std::to_string(cuda_device_count - 1) + ".";
}

bool fallback_to_cpu = DetectionComponentUtils::GetProperty(
props, "FALLBACK_TO_CPU_WHEN_GPU_PROBLEM", false);
if (fallback_to_cpu) {
LOG4CXX_WARN(logger, error_message << " Running job on CPU instead.");
return false;
}
throw MPFDetectionException(MPFDetectionError::MPF_GPU_ERROR, error_message);
}



OcvDnnDetection::OcvDnnJobConfig::OcvDnnJobConfig(const Properties &props,
const MPF::COMPONENT::ModelsIniParser<ModelSettings> &model_parser,
const log4cxx::LoggerPtr &logger) {
const log4cxx::LoggerPtr &logger) {

using namespace DetectionComponentUtils;

Expand All @@ -544,11 +585,14 @@ OcvDnnDetection::OcvDnnJobConfig::OcvDnnJobConfig(const Properties &props,

class_names = readClassNames(settings.synset_file);

bool cuda_enabled = set_cuda_device_if_requested(props, logger);

// Import the model
// For models that do not support or require a config file, ModelsIniParser
// will assign the empty string as default to settings.model_config_file.
// OpenCV DNN's readNet ignores the config file when it is passed an empty
// string path, so we need not check whether the file exists.
// If using GPU version, cv::cuda::setDevice(cuda_device_id); MUST be called before cv::dnn::readNet.
net = cv::dnn::readNet(settings.model_binary_file, settings.model_config_file);
if (net.empty()) {
throw MPFDetectionException(
Expand All @@ -557,6 +601,11 @@ OcvDnnDetection::OcvDnnJobConfig::OcvDnnJobConfig(const Properties &props,
+ ") and model_binary (" + settings.model_binary_file + ").");
}

if (cuda_enabled) {
net.setPreferableTarget(cv::dnn::DNN_TARGET_CUDA);
net.setPreferableBackend(cv::dnn::DNN_BACKEND_CUDA);
}

LOG4CXX_DEBUG(logger, "Created neural network");

resize_size = cv::Size(GetProperty(props, "RESIZE_WIDTH", 224), GetProperty(props, "RESIZE_HEIGHT", 224));
Expand Down
Loading