diff --git a/.gitignore b/.gitignore index 4dd351b2..8cd92a5a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ dynamic_vino_lib/html/* dynamic_vino_lib/latex/* +.vscode diff --git a/data/images/bus.jpg b/data/images/bus.jpg new file mode 100644 index 00000000..b43e3111 Binary files /dev/null and b/data/images/bus.jpg differ diff --git a/vino_core_lib/CMakeLists.txt b/vino_core_lib/CMakeLists.txt index 1659874b..5c6858db 100644 --- a/vino_core_lib/CMakeLists.txt +++ b/vino_core_lib/CMakeLists.txt @@ -24,7 +24,7 @@ project(vino_core_lib) #################################### ## uncomment below line to get verbose log -## add_definitions(-DLOG_LEVEL_DEBUG) +# add_definitions(-DLOG_LEVEL_DEBUG) #################################### message(STATUS "Looking for inference engine configuration file at: ${CMAKE_PREFIX_PATH}") @@ -180,7 +180,8 @@ add_library(${PROJECT_NAME} SHARED src/models/face_detection_model.cpp src/models/head_pose_detection_model.cpp src/models/object_detection_ssd_model.cpp - # src/models/object_detection_yolov2voc_model.cpp + src/models/object_detection_yolov2voc_model.cpp + src/models/object_detection_yolov5_model.cpp src/models/object_segmentation_model.cpp src/models/person_reidentification_model.cpp src/models/face_reidentification_model.cpp diff --git a/vino_core_lib/include/vino_core_lib/inferences/age_gender_detection.h b/vino_core_lib/include/vino_core_lib/inferences/age_gender_detection.h index ed6f9373..d4fda2ff 100644 --- a/vino_core_lib/include/vino_core_lib/inferences/age_gender_detection.h +++ b/vino_core_lib/include/vino_core_lib/inferences/age_gender_detection.h @@ -77,12 +77,18 @@ class AgeGenderDetection : public BaseInference { public: using Result = vino_core_lib::AgeGenderResult; - AgeGenderDetection(); - ~AgeGenderDetection() override; + AgeGenderDetection(){}; + ~AgeGenderDetection() override {}; + + /** + * @brief Load the face detection model. + */ + void loadNetwork(std::shared_ptr) override; + /** * @brief Load the age gender detection model. */ - void loadNetwork(std::shared_ptr); + // void loadNetwork(std::shared_ptr); /** * @brief Enqueue a frame to this class. * The frame will be buffered but not infered yet. diff --git a/vino_core_lib/include/vino_core_lib/inferences/base_inference.h b/vino_core_lib/include/vino_core_lib/inferences/base_inference.h index 8ded62ba..4cc941a7 100644 --- a/vino_core_lib/include/vino_core_lib/inferences/base_inference.h +++ b/vino_core_lib/include/vino_core_lib/inferences/base_inference.h @@ -26,6 +26,7 @@ #include #include "vino_core_lib/engines/engine.h" +#include "vino_core_lib/vino_factory.h" #include "vino_core_lib/models/base_model.h" #include "vino_core_lib/slog.h" #include "inference_engine.hpp" @@ -106,6 +107,12 @@ class BaseInference * running netwrok on target calculation device. */ void loadEngine(std::shared_ptr engine); + + /** + * @brief Load the face detection model. + */ + virtual void loadNetwork(std::shared_ptr) = 0; + /** * @brief Get the loaded Engine instance. * @return The loaded Engine instance. @@ -215,4 +222,7 @@ class BaseInference }; } // namespace vino_core_lib +#define REG_INFERENCE_FACTORY VinoFactory +#define REG_INFERENCE(T, key) static REG_INFERENCE_FACTORY::TReg gs_inference##_(key) + #endif // VINO_CORE_LIB__INFERENCES__BASE_INFERENCE_H diff --git a/vino_core_lib/include/vino_core_lib/inferences/emotions_detection.h b/vino_core_lib/include/vino_core_lib/inferences/emotions_detection.h index b7e2adda..277bc3c2 100644 --- a/vino_core_lib/include/vino_core_lib/inferences/emotions_detection.h +++ b/vino_core_lib/include/vino_core_lib/inferences/emotions_detection.h @@ -35,6 +35,7 @@ namespace Outputs { class BaseOuput; } + namespace vino_core_lib { /** @@ -68,12 +69,18 @@ class EmotionsDetection : public BaseInference { public: using Result = vino_core_lib::EmotionsResult; - EmotionsDetection(); - ~EmotionsDetection() override; + EmotionsDetection() {}; + ~EmotionsDetection() override {}; + + /** + * @brief Load the face detection model. + */ + void loadNetwork(std::shared_ptr) override; + /** * @brief Load the emotin detection model. */ - void loadNetwork(std::shared_ptr); + // void loadNetwork(std::shared_ptr); /** * @brief Enqueue a frame to this class. * The frame will be buffered but not infered yet. diff --git a/vino_core_lib/include/vino_core_lib/inferences/face_detection.h b/vino_core_lib/include/vino_core_lib/inferences/face_detection.h index d50b8ec4..8b2ac1ef 100644 --- a/vino_core_lib/include/vino_core_lib/inferences/face_detection.h +++ b/vino_core_lib/include/vino_core_lib/inferences/face_detection.h @@ -25,11 +25,10 @@ #include #include #include - #include -#include #include - +#include +#include #include "vino_core_lib/engines/engine.h" #include "vino_core_lib/inferences/base_inference.h" #include "vino_core_lib/inferences/object_detection.h" @@ -47,17 +46,177 @@ namespace vino_core_lib class FaceDetectionResult : public ObjectDetectionResult { public: + friend class ObjectDetection; explicit FaceDetectionResult(const cv::Rect& location); + + std::string getLabel() const + { + return label_; + } + + void setLabel(const std::string& label) + { + label_ = label; + } + /** + * @brief Get the confidence that the detected area is a face. + * @return The confidence value. + */ + float getConfidence() const + { + return confidence_; + } + + void setConfidence(const float& con) + { + confidence_ = con; + } + + bool operator<(const FaceDetectionResult& s2) const + { + return this->confidence_ > s2.confidence_; + } + +private: + std::string label_ = ""; + float confidence_ = -1; }; +class FaceDetectionResultFilter : public BaseFilter +{ +public: + using Result = vino_core_lib::FaceDetectionResult; + + FaceDetectionResultFilter(); + + /** + * @brief Initiate the object detection result filter. + */ + void init() override; + /** + * @brief Set the object detection results into filter. + * @param[in] The object detection results. + */ + void acceptResults(const std::vector& results); + /** + * @brief Get the filtered results' ROIs. + * @return The filtered ROIs. + */ + std::vector getFilteredLocations() override; + +private: + /** + * @brief Decide whether a result is valid for label filter condition. + * @param[in] Result to be decided, filter operator, target label value. + * @return True if valid, false if not. + */ + static bool isValidLabel(const Result& result, const std::string& op, const std::string& target); + /** + * @brief Decide whether a result is valid for confidence filter condition. + * @param[in] Result to be decided, filter operator, target confidence value. + * @return True if valid, false if not. + */ + static bool isValidConfidence(const Result& result, const std::string& op, const std::string& target); + + /** + * @brief Decide whether a result is valid. + * @param[in] Result to be decided. + * @return True if valid, false if not. + */ + bool isValidResult(const Result& result); + + std::map key_to_function_; + std::vector results_; +}; + + + /** * @class FaceDetection * @brief Class to load face detection model and perform face detection. */ -class FaceDetection : public ObjectDetection +class FaceDetection : public BaseInference { public: + using Result = vino_core_lib::FaceDetectionResult; + using Filter = vino_core_lib::FaceDetectionResultFilter; explicit FaceDetection(bool, double); + FaceDetection() + { + enable_roi_constraint_ = true; + show_output_thresh_ = 0.5; + result_filter_ = std::make_shared(); + result_filter_->init(); + }; + + ~FaceDetection() override {}; + + /** + * @brief Load the face detection model. + */ + void loadNetwork(std::shared_ptr) override; + + /** + * @brief Load the face detection model. + */ + // void loadNetwork(std::shared_ptr); + /** + * @brief Enqueue a frame to this class. + * The frame will be buffered but not infered yet. + * @param[in] frame The frame to be enqueued. + * @param[in] input_frame_loc The location of the enqueued frame with respect + * to the frame generated by the input device. + * @return Whether this operation is successful. + */ + bool enqueue(const cv::Mat&, const cv::Rect&) override; + + /** + * @brief This function will fetch the results of the previous inference and + * stores the results in a result buffer array. All buffered frames will be + * cleared. + * @return Whether the Inference object fetches a result this time + */ + bool fetchResults() override; + /** + * @brief Get the length of the buffer result array. + * @return The length of the buffer result array. + */ + int getResultsLength() const override; + /** + * @brief Get the location of result with respect + * to the frame generated by the input device. + * @param[in] idx The index of the result. + */ + const Result* getLocationResult(int idx) const override; + /** + * @brief Show the observed detection result either through image window + or ROS topic. + */ + void observeOutput(const std::shared_ptr& output); + /** + * @brief Get the name of the Inference instance. + * @return The name of the Inference instance. + */ + const std::string getName() const override; + + const std::vector getFilteredROIs(const std::string filter_conditions) const override; + + /** + * @brief Calculate the IoU ratio for the given rectangles. + * @return IoU Ratio of the given rectangles. + */ + static double calcIoU(const cv::Rect& box_1, const cv::Rect& box_2); + +private: + std::shared_ptr valid_model_; + std::shared_ptr result_filter_; + std::vector results_; + int width_ = 0; + int height_ = 0; + int max_proposal_count_; + int object_size_; + double show_output_thresh_ = 0; + bool enable_roi_constraint_ = false; }; } // namespace vino_core_lib #endif // VINO_CORE_LIB__INFERENCES__FACE_DETECTION_H diff --git a/vino_core_lib/include/vino_core_lib/inferences/face_reidentification.h b/vino_core_lib/include/vino_core_lib/inferences/face_reidentification.h index 7f8291ce..76e002c8 100644 --- a/vino_core_lib/include/vino_core_lib/inferences/face_reidentification.h +++ b/vino_core_lib/include/vino_core_lib/inferences/face_reidentification.h @@ -57,11 +57,18 @@ class FaceReidentification : public BaseInference public: using Result = vino_core_lib::FaceReidentificationResult; explicit FaceReidentification(double); + FaceReidentification() {}; ~FaceReidentification() override; + + /** + * @brief Load the face detection model. + */ + void loadNetwork(std::shared_ptr) override; + /** * @brief Load the face reidentification model. */ - void loadNetwork(std::shared_ptr); + // void loadNetwork(std::shared_ptr); /** * @brief Enqueue a frame to this class. * The frame will be buffered but not infered yet. diff --git a/vino_core_lib/include/vino_core_lib/inferences/head_pose_detection.h b/vino_core_lib/include/vino_core_lib/inferences/head_pose_detection.h index a2b61f8f..71a135cb 100644 --- a/vino_core_lib/include/vino_core_lib/inferences/head_pose_detection.h +++ b/vino_core_lib/include/vino_core_lib/inferences/head_pose_detection.h @@ -81,12 +81,18 @@ class HeadPoseDetection : public BaseInference { public: using Result = vino_core_lib::HeadPoseResult; - HeadPoseDetection(); - ~HeadPoseDetection() override; + HeadPoseDetection() {}; + ~HeadPoseDetection() override {}; + + /** + * @brief Load the face detection model. + */ + void loadNetwork(std::shared_ptr) override; + /** * @brief Load the headpose detection model. */ - void loadNetwork(std::shared_ptr); + // void loadNetwork(std::shared_ptr); /** * @brief Enqueue a frame to this class. * The frame will be buffered but not infered yet. diff --git a/vino_core_lib/include/vino_core_lib/inferences/landmarks_detection.h b/vino_core_lib/include/vino_core_lib/inferences/landmarks_detection.h index eaf3a070..917d764e 100644 --- a/vino_core_lib/include/vino_core_lib/inferences/landmarks_detection.h +++ b/vino_core_lib/include/vino_core_lib/inferences/landmarks_detection.h @@ -54,12 +54,18 @@ class LandmarksDetection : public BaseInference { public: using Result = vino_core_lib::LandmarksDetectionResult; - LandmarksDetection(); - ~LandmarksDetection() override; + LandmarksDetection() {}; + ~LandmarksDetection() override {}; + + /** + * @brief Load the face detection model. + */ + void loadNetwork(std::shared_ptr) override; + /** * @brief Load the landmarks detection model. */ - void loadNetwork(std::shared_ptr); + // void loadNetwork(std::shared_ptr); /** * @brief Enqueue a frame to this class. * The frame will be buffered but not infered yet. diff --git a/vino_core_lib/include/vino_core_lib/inferences/license_plate_detection.h b/vino_core_lib/include/vino_core_lib/inferences/license_plate_detection.h index 5aad30fe..2e31a019 100644 --- a/vino_core_lib/include/vino_core_lib/inferences/license_plate_detection.h +++ b/vino_core_lib/include/vino_core_lib/inferences/license_plate_detection.h @@ -54,12 +54,18 @@ class LicensePlateDetection : public BaseInference { public: using Result = vino_core_lib::LicensePlateDetectionResult; - LicensePlateDetection(); - ~LicensePlateDetection() override; + LicensePlateDetection() {}; + ~LicensePlateDetection() override {}; + + /** + * @brief Load the face detection model. + */ + void loadNetwork(std::shared_ptr) override; + /** * @brief Load the license plate detection model. */ - void loadNetwork(std::shared_ptr); + // void loadNetwork(std::shared_ptr); /** * @brief Enqueue a frame to this class. * The frame will be buffered but not infered yet. diff --git a/vino_core_lib/include/vino_core_lib/inferences/object_detection.h b/vino_core_lib/include/vino_core_lib/inferences/object_detection.h index 89baa8ef..c6f9b233 100644 --- a/vino_core_lib/include/vino_core_lib/inferences/object_detection.h +++ b/vino_core_lib/include/vino_core_lib/inferences/object_detection.h @@ -137,11 +137,18 @@ class ObjectDetection : public BaseInference using Result = vino_core_lib::ObjectDetectionResult; using Filter = vino_core_lib::ObjectDetectionResultFilter; explicit ObjectDetection(bool, double); - ~ObjectDetection() override; + ObjectDetection(){}; + ~ObjectDetection() override {}; + + /** + * @brief Load the face detection model. + */ + void loadNetwork(std::shared_ptr) override; + /** * @brief Load the face detection model. */ - void loadNetwork(std::shared_ptr); + // void loadNetwork(std::shared_ptr); /** * @brief Enqueue a frame to this class. * The frame will be buffered but not infered yet. diff --git a/vino_core_lib/include/vino_core_lib/inferences/object_segmentation.h b/vino_core_lib/include/vino_core_lib/inferences/object_segmentation.h index ddacd48e..278e34b9 100644 --- a/vino_core_lib/include/vino_core_lib/inferences/object_segmentation.h +++ b/vino_core_lib/include/vino_core_lib/inferences/object_segmentation.h @@ -72,11 +72,18 @@ class ObjectSegmentation : public BaseInference public: using Result = vino_core_lib::ObjectSegmentationResult; explicit ObjectSegmentation(double); - ~ObjectSegmentation() override; + ObjectSegmentation() {}; + ~ObjectSegmentation() override {}; + + /** + * @brief Load the face detection model. + */ + void loadNetwork(std::shared_ptr) override; + /** * @brief Load the object segmentation model. */ - void loadNetwork(std::shared_ptr); + // void loadNetwork(std::shared_ptr); /** * @brief Enqueue a frame to this class. * The frame will be buffered but not infered yet. diff --git a/vino_core_lib/include/vino_core_lib/inferences/person_attribs_detection.h b/vino_core_lib/include/vino_core_lib/inferences/person_attribs_detection.h index 726bafa3..9e04007c 100644 --- a/vino_core_lib/include/vino_core_lib/inferences/person_attribs_detection.h +++ b/vino_core_lib/include/vino_core_lib/inferences/person_attribs_detection.h @@ -71,11 +71,18 @@ class PersonAttribsDetection : public BaseInference public: using Result = vino_core_lib::PersonAttribsDetectionResult; explicit PersonAttribsDetection(double); - ~PersonAttribsDetection() override; + PersonAttribsDetection() {}; + ~PersonAttribsDetection() override {}; + + /** + * @brief Load the face detection model. + */ + void loadNetwork(std::shared_ptr) override; + /** * @brief Load the person attributes detection model. */ - void loadNetwork(std::shared_ptr); + // void loadNetwork(std::shared_ptr); /** * @brief Enqueue a frame to this class. * The frame will be buffered but not infered yet. diff --git a/vino_core_lib/include/vino_core_lib/inferences/person_reidentification.h b/vino_core_lib/include/vino_core_lib/inferences/person_reidentification.h index da7a4419..26953439 100644 --- a/vino_core_lib/include/vino_core_lib/inferences/person_reidentification.h +++ b/vino_core_lib/include/vino_core_lib/inferences/person_reidentification.h @@ -56,11 +56,18 @@ class PersonReidentification : public BaseInference public: using Result = vino_core_lib::PersonReidentificationResult; explicit PersonReidentification(double); - ~PersonReidentification() override; + PersonReidentification() {}; + ~PersonReidentification() override {}; + + /** + * @brief Load the face detection model. + */ + void loadNetwork(std::shared_ptr) override; + /** * @brief Load the face detection model. */ - void loadNetwork(std::shared_ptr); + // void loadNetwork(std::shared_ptr); /** * @brief Enqueue a frame to this class. * The frame will be buffered but not infered yet. diff --git a/vino_core_lib/include/vino_core_lib/inferences/vehicle_attribs_detection.h b/vino_core_lib/include/vino_core_lib/inferences/vehicle_attribs_detection.h index c95eb942..993370a3 100644 --- a/vino_core_lib/include/vino_core_lib/inferences/vehicle_attribs_detection.h +++ b/vino_core_lib/include/vino_core_lib/inferences/vehicle_attribs_detection.h @@ -59,12 +59,18 @@ class VehicleAttribsDetection : public BaseInference { public: using Result = vino_core_lib::VehicleAttribsDetectionResult; - VehicleAttribsDetection(); - ~VehicleAttribsDetection() override; + VehicleAttribsDetection() {}; + ~VehicleAttribsDetection() override {}; + + /** + * @brief Load the face detection model. + */ + void loadNetwork(std::shared_ptr) override; + /** * @brief Load the vehicle attributes detection model. */ - void loadNetwork(std::shared_ptr); + // void loadNetwork(std::shared_ptr); /** * @brief Enqueue a frame to this class. * The frame will be buffered but not infered yet. diff --git a/vino_core_lib/include/vino_core_lib/inputs/base_input.h b/vino_core_lib/include/vino_core_lib/inputs/base_input.h index e98ae626..4d553edb 100644 --- a/vino_core_lib/include/vino_core_lib/inputs/base_input.h +++ b/vino_core_lib/include/vino_core_lib/inputs/base_input.h @@ -22,6 +22,7 @@ #define VINO_CORE_LIB__INPUTS__BASE_INPUT_H #include +#include "vino_core_lib/vino_factory.h" #include "vino_core_lib/inputs/ros_handler.h" /** @@ -39,6 +40,13 @@ struct Config class BaseInputDevice : public RosHandler { public: + BaseInputDevice() = default; + virtual ~BaseInputDevice() = default; + /** + * @brief Initialize the input device, + * @return Whether the input device is successfully setup. + */ + virtual bool init(const std::string &str) = 0; /** * @brief Initialize the input device, * for cameras, it will turn the camera on and get ready to read frames, @@ -63,7 +71,6 @@ class BaseInputDevice : public RosHandler virtual void config(const Config&) { } - virtual ~BaseInputDevice() = default; /** * @brief Get the width of the frame read from input device. * @return The width of the frame read from input device. @@ -119,4 +126,8 @@ class BaseInputDevice : public RosHandler bool is_init_ = false; }; } // namespace Input + +#define REG_INPUT_FACTORY VinoFactory +#define REG_INPUT(BASE, key) static REG_INPUT_FACTORY::TReg gs_input##_(key) + #endif // VINO_CORE_LIB__INPUTS__BASE_INPUT_H diff --git a/vino_core_lib/include/vino_core_lib/inputs/image_input.h b/vino_core_lib/include/vino_core_lib/inputs/image_input.h index 5792c501..7fd00599 100644 --- a/vino_core_lib/include/vino_core_lib/inputs/image_input.h +++ b/vino_core_lib/include/vino_core_lib/inputs/image_input.h @@ -34,7 +34,15 @@ namespace Input class Image : public BaseInputDevice { public: - explicit Image(const std::string&); + Image() {}; + Image(const std::string &file) : file_(file) {}; + + /** + * @brief Read an image file from the file path. + * @param[in] An image file path. + * @return Whether the input device is successfully setup. + */ + bool init(const std::string &file) override {file_.assign(file); initialize();}; /** * @brief Read an image file from the file path. * @param[in] An image file path. diff --git a/vino_core_lib/include/vino_core_lib/inputs/image_topic.h b/vino_core_lib/include/vino_core_lib/inputs/image_topic.h index 01c9df12..d9ca5a8a 100644 --- a/vino_core_lib/include/vino_core_lib/inputs/image_topic.h +++ b/vino_core_lib/include/vino_core_lib/inputs/image_topic.h @@ -38,6 +38,8 @@ namespace Input class ImageTopic : public BaseInputDevice { public: + ImageTopic() {}; + bool init(const std::string &file) override { initialize();}; bool initialize() override; bool initialize(size_t width, size_t height) override; bool read(cv::Mat* frame) override; diff --git a/vino_core_lib/include/vino_core_lib/inputs/ip_camera.h b/vino_core_lib/include/vino_core_lib/inputs/ip_camera.h index d6508b82..e3c90416 100644 --- a/vino_core_lib/include/vino_core_lib/inputs/ip_camera.h +++ b/vino_core_lib/include/vino_core_lib/inputs/ip_camera.h @@ -34,7 +34,15 @@ namespace Input class IpCamera : public BaseInputDevice { public: - explicit IpCamera(const std::string & ip_uri) : ip_uri_(ip_uri) {} + IpCamera() {}; + IpCamera(const std::string & ip_uri) : ip_uri_(ip_uri) {} + /** + * @brief Initialize the input device, + * for cameras, it will turn the camera on and get ready to read frames, + * for videos, it will open a video file. + * @return Whether the input device is successfully setup. + */ + bool init(const std::string &ip_uri) override {ip_uri_.assign(ip_uri); initialize();}; /** * @brief Initialize the input device, * for cameras, it will turn the camera on and get ready to read frames, diff --git a/vino_core_lib/include/vino_core_lib/inputs/realsense_camera.h b/vino_core_lib/include/vino_core_lib/inputs/realsense_camera.h index b7e5879e..1ff7b91a 100644 --- a/vino_core_lib/include/vino_core_lib/inputs/realsense_camera.h +++ b/vino_core_lib/include/vino_core_lib/inputs/realsense_camera.h @@ -35,6 +35,14 @@ namespace Input class RealSenseCamera : public BaseInputDevice { public: + RealSenseCamera() {}; + /** + * @brief Initialize the input device, + * @brief Initialize the input device, turn the + * camera on and get ready to read frames. + * @return Whether the input device is successfully setup. + */ + bool init(const std::string &ip_uri) override { initialize();}; /** * @brief Initialize the input device, turn the * camera on and get ready to read frames. diff --git a/vino_core_lib/include/vino_core_lib/inputs/standard_camera.h b/vino_core_lib/include/vino_core_lib/inputs/standard_camera.h index 7c87c155..77b1447f 100644 --- a/vino_core_lib/include/vino_core_lib/inputs/standard_camera.h +++ b/vino_core_lib/include/vino_core_lib/inputs/standard_camera.h @@ -40,6 +40,14 @@ namespace Input class StandardCamera : public BaseInputDevice { public: + StandardCamera() {}; + /** + * @brief Initialize the input device, + * @brief Initialize the input device, turn the + * camera on and get ready to read frames. + * @return Whether the input device is successfully setup. + */ + bool init(const std::string &ip_uri) override { initialize();}; /** * @brief Initialize the input device, * for cameras, it will turn the camera on and get ready to read frames, diff --git a/vino_core_lib/include/vino_core_lib/inputs/video_input.h b/vino_core_lib/include/vino_core_lib/inputs/video_input.h index 8580672c..1087d046 100644 --- a/vino_core_lib/include/vino_core_lib/inputs/video_input.h +++ b/vino_core_lib/include/vino_core_lib/inputs/video_input.h @@ -34,7 +34,14 @@ namespace Input class Video : public BaseInputDevice { public: - explicit Video(const std::string&); + Video() {}; + Video(const std::string& video) : video_(video) {}; + /** + * @brief Read a video file from the file path. + * @param[in] An video file path. + * @return Whether the input device is successfully setup. + */ + bool init(const std::string &video) override {video_.assign(video); initialize();}; /** * @brief Read a video file from the file path. * @param[in] An video file path. diff --git a/vino_core_lib/include/vino_core_lib/models/age_gender_detection_model.h b/vino_core_lib/include/vino_core_lib/models/age_gender_detection_model.h index aae2de2d..b754c2d3 100644 --- a/vino_core_lib/include/vino_core_lib/models/age_gender_detection_model.h +++ b/vino_core_lib/include/vino_core_lib/models/age_gender_detection_model.h @@ -34,6 +34,8 @@ namespace Models class AgeGenderDetectionModel : public BaseModel { public: + AgeGenderDetectionModel() {}; + AgeGenderDetectionModel(const std::string& label_loc, const std::string& model_loc, int batch_size = 1); /** * @brief Get the input name. diff --git a/vino_core_lib/include/vino_core_lib/models/attributes/base_attribute.h b/vino_core_lib/include/vino_core_lib/models/attributes/base_attribute.h index 99e801d0..77f343ec 100644 --- a/vino_core_lib/include/vino_core_lib/models/attributes/base_attribute.h +++ b/vino_core_lib/include/vino_core_lib/models/attributes/base_attribute.h @@ -51,6 +51,8 @@ class ModelAttribute std::vector labels; }; + ModelAttribute() {}; + ModelAttribute(const std::string model_name) { attr_.model_name = model_name; diff --git a/vino_core_lib/include/vino_core_lib/models/base_model.h b/vino_core_lib/include/vino_core_lib/models/base_model.h index 4ccb9714..4607b35c 100644 --- a/vino_core_lib/include/vino_core_lib/models/base_model.h +++ b/vino_core_lib/include/vino_core_lib/models/base_model.h @@ -31,6 +31,7 @@ #include #include "inference_engine.hpp" +#include "vino_core_lib/vino_factory.h" #include "vino_core_lib/models/attributes/base_attribute.h" namespace Engines @@ -41,6 +42,7 @@ class Engine; namespace vino_core_lib { class ObjectDetectionResult; +class FaceDetectionResult; } namespace Models @@ -53,6 +55,9 @@ class BaseModel : public ModelAttribute { public: using Ptr = std::shared_ptr; + + BaseModel() {}; + /** * @brief Initialize the class with given .xml, .bin and .labels file. It will * also check whether the number of input and output are fit. @@ -65,6 +70,19 @@ class BaseModel : public ModelAttribute * @return Whether the input device is successfully turned on. */ BaseModel(const std::string& label_loc, const std::string& model_loc, int batch_size = 1); + + /** + * @brief Initialize the class with given .xml, .bin and .labels file. It will + * also check whether the number of input and output are fit. + * @param[in] model_loc The location of model' s .xml file + * (model' s bin file should be the same as .xml file except for extension) + * @param[in] input_num The number of input the network should have. + * @param[in] output_num The number of output the network should have. + * @param[in] batch_size The number of batch size (default: 1) the network should have. + * @param[in] label_loc The location of label' s .label file + * @return Whether the input device is successfully turned on. + */ + void init(const std::string& label_loc, const std::string& model_loc, int batch_size = 1); /** * @brief Get the maximum batch size of the model. @@ -132,13 +150,20 @@ class BaseModel : public ModelAttribute cv::Size frame_size_; }; +#define REG_MODEL_FACTORY VinoFactory +#define REG_MODEL(BASE, key) static REG_MODEL_FACTORY::TReg gs_model##_(key) + class ObjectDetectionModel : public BaseModel { public: + ObjectDetectionModel() {}; + ObjectDetectionModel(const std::string& label_loc, const std::string& model_loc, int batch_size = 1); + virtual bool fetchResults(const std::shared_ptr& engine, std::vector& result, - const float& confidence_thresh = 0.3, const bool& enable_roi_constraint = false) = 0; + const float& confidence_thresh = 0.3, const bool& enable_roi_constraint = false) {}; + virtual bool matToBlob(const cv::Mat& orig_image, const cv::Rect&, float scale_factor, int batch_index, const std::shared_ptr& engine) = 0; }; diff --git a/vino_core_lib/include/vino_core_lib/models/emotion_detection_model.h b/vino_core_lib/include/vino_core_lib/models/emotion_detection_model.h index 100d1348..a8ee8e99 100644 --- a/vino_core_lib/include/vino_core_lib/models/emotion_detection_model.h +++ b/vino_core_lib/include/vino_core_lib/models/emotion_detection_model.h @@ -34,6 +34,8 @@ namespace Models class EmotionDetectionModel : public BaseModel { public: + EmotionDetectionModel() {}; + EmotionDetectionModel(const std::string& label_loc, const std::string& model_loc, int batch_size = 1); /** diff --git a/vino_core_lib/include/vino_core_lib/models/face_detection_model.h b/vino_core_lib/include/vino_core_lib/models/face_detection_model.h index 82a7d190..b67d7451 100644 --- a/vino_core_lib/include/vino_core_lib/models/face_detection_model.h +++ b/vino_core_lib/include/vino_core_lib/models/face_detection_model.h @@ -24,6 +24,8 @@ #include #include "vino_core_lib/models/base_model.h" +#include "vino_core_lib/inferences/face_detection.h" +#include "vino_core_lib/engines/engine_manager.h" namespace Models { @@ -33,15 +35,33 @@ namespace Models */ class FaceDetectionModel : public ObjectDetectionModel { +// class ObjectDetectionResult; +// class FaceDetectionResult; + using Result = vino_core_lib::FaceDetectionResult; + public: + FaceDetectionModel() {}; + FaceDetectionModel(const std::string& label_loc, const std::string& model_loc, int batch_size = 1); - // void checkLayerProperty(const InferenceEngine::CNNNetReader::Ptr &) override; + + bool fetchResults(const std::shared_ptr& engine, + std::vector& results, const float& confidence_thresh = 0.3, + const bool& enable_roi_constraint = false); + + bool enqueue(const std::shared_ptr& engine, const cv::Mat& frame, + const cv::Rect& input_frame_loc) override; + + bool matToBlob(const cv::Mat& orig_image, const cv::Rect&, float scale_factor, int batch_index, + const std::shared_ptr& engine) override; + /** * @brief Get the name of this detection model. * @return Name of the model. */ const std::string getModelCategory() const override; + + bool updateLayerProperty(InferenceEngine::CNNNetwork&) override; }; } // namespace Models -#endif // VINO_CORE_LIB__MODELS__FACE_DETECTION_MODEL_H +#endif // VINO_CORE_LIB__MODELS__FACE_DETECTION_MODEL_H \ No newline at end of file diff --git a/vino_core_lib/include/vino_core_lib/models/face_reidentification_model.h b/vino_core_lib/include/vino_core_lib/models/face_reidentification_model.h index a02844e7..8442fa6a 100644 --- a/vino_core_lib/include/vino_core_lib/models/face_reidentification_model.h +++ b/vino_core_lib/include/vino_core_lib/models/face_reidentification_model.h @@ -29,7 +29,10 @@ namespace Models class FaceReidentificationModel : public BaseModel { public: + FaceReidentificationModel() {}; + FaceReidentificationModel(const std::string& label_loc, const std::string& model_loc, int batch_size = 1); + inline const std::string getInputName() { return input_; diff --git a/vino_core_lib/include/vino_core_lib/models/head_pose_detection_model.h b/vino_core_lib/include/vino_core_lib/models/head_pose_detection_model.h index aceedb21..31138112 100644 --- a/vino_core_lib/include/vino_core_lib/models/head_pose_detection_model.h +++ b/vino_core_lib/include/vino_core_lib/models/head_pose_detection_model.h @@ -34,6 +34,8 @@ namespace Models class HeadPoseDetectionModel : public BaseModel { public: + HeadPoseDetectionModel() {}; + HeadPoseDetectionModel(const std::string& label_loc, const std::string& model_loc, int batch_size = 1); /** diff --git a/vino_core_lib/include/vino_core_lib/models/landmarks_detection_model.h b/vino_core_lib/include/vino_core_lib/models/landmarks_detection_model.h index 69afc695..db258b1d 100644 --- a/vino_core_lib/include/vino_core_lib/models/landmarks_detection_model.h +++ b/vino_core_lib/include/vino_core_lib/models/landmarks_detection_model.h @@ -29,7 +29,10 @@ namespace Models class LandmarksDetectionModel : public BaseModel { public: + LandmarksDetectionModel() {}; + LandmarksDetectionModel(const std::string& label_loc, const std::string& model_loc, int batch_size = 1); + inline const std::string getInputName() { return input_; diff --git a/vino_core_lib/include/vino_core_lib/models/license_plate_detection_model.h b/vino_core_lib/include/vino_core_lib/models/license_plate_detection_model.h index 17af5ed3..142e7ee7 100644 --- a/vino_core_lib/include/vino_core_lib/models/license_plate_detection_model.h +++ b/vino_core_lib/include/vino_core_lib/models/license_plate_detection_model.h @@ -29,7 +29,10 @@ namespace Models class LicensePlateDetectionModel : public BaseModel { public: + LicensePlateDetectionModel() {}; + LicensePlateDetectionModel(const std::string& label_loc, const std::string& model_loc, int batch_size = 1); + inline const std::string getInputName() { return input_; diff --git a/vino_core_lib/include/vino_core_lib/models/object_detection_ssd_model.h b/vino_core_lib/include/vino_core_lib/models/object_detection_ssd_model.h index d539e9f7..cdce6149 100644 --- a/vino_core_lib/include/vino_core_lib/models/object_detection_ssd_model.h +++ b/vino_core_lib/include/vino_core_lib/models/object_detection_ssd_model.h @@ -34,6 +34,8 @@ class ObjectDetectionSSDModel : public ObjectDetectionModel using Result = vino_core_lib::ObjectDetectionResult; public: + ObjectDetectionSSDModel() {}; + ObjectDetectionSSDModel(const std::string& label_loc, const std::string& model_loc, int batch_size = 1); bool fetchResults(const std::shared_ptr& engine, diff --git a/vino_core_lib/include/vino_core_lib/models/object_detection_yolov2voc_model.h b/vino_core_lib/include/vino_core_lib/models/object_detection_yolov2voc_model.h index e619fa56..c1ca3045 100644 --- a/vino_core_lib/include/vino_core_lib/models/object_detection_yolov2voc_model.h +++ b/vino_core_lib/include/vino_core_lib/models/object_detection_yolov2voc_model.h @@ -21,6 +21,8 @@ #define VINO_CORE_LIB__MODELS__OBJECT_DETECTION_YOLOV2VOC_MODEL_H #include #include "vino_core_lib/models/base_model.h" +#include "vino_core_lib/inferences/object_detection.h" +#include "vino_core_lib/engines/engine_manager.h" namespace Models { /** @@ -32,6 +34,8 @@ class ObjectDetectionYolov2Model : public ObjectDetectionModel using Result = vino_core_lib::ObjectDetectionResult; public: + ObjectDetectionYolov2Model() {}; + ObjectDetectionYolov2Model(const std::string& model_loc, int batch_size = 1); bool fetchResults(const std::shared_ptr& engine, @@ -50,6 +54,7 @@ class ObjectDetectionYolov2Model : public ObjectDetectionModel */ const std::string getModelCategory() const override; bool updateLayerProperty(InferenceEngine::CNNNetwork&) override; + protected: int getEntryIndex(int side, int lcoords, int lclasses, int location, int entry); diff --git a/vino_core_lib/include/vino_core_lib/models/object_detection_yolov5_model.h b/vino_core_lib/include/vino_core_lib/models/object_detection_yolov5_model.h new file mode 100644 index 00000000..d5ffc6e2 --- /dev/null +++ b/vino_core_lib/include/vino_core_lib/models/object_detection_yolov5_model.h @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2018 Intel Corporation + * + * 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. + */ +/** + * @brief A header file with declaration for ObjectDetectionModel Class + * @file face_detection_model.h + */ +#ifndef VINO_CORE_LIB__MODELS__OBJECT_DETECTION_YOLOV5VOC_MODEL_H +#define VINO_CORE_LIB__MODELS__OBJECT_DETECTION_YOLOV5VOC_MODEL_H +#include +#include "vino_core_lib/models/base_model.h" +#include "vino_core_lib/inferences/object_detection.h" +#include "vino_core_lib/engines/engine_manager.h" +namespace Models +{ +/** + * @class ObjectDetectionModel + * @brief This class generates the face detection model. + */ +class ObjectDetectionYolov5Model : public ObjectDetectionModel +{ + using Result = vino_core_lib::ObjectDetectionResult; + +public: + ObjectDetectionYolov5Model() {}; + + ObjectDetectionYolov5Model(const std::string& model_loc, int batch_size = 1); + + bool fetchResults(const std::shared_ptr& engine, + std::vector& results, const float& confidence_thresh = 0.3, + const bool& enable_roi_constraint = false) override; + + bool enqueue(const std::shared_ptr& engine, const cv::Mat& frame, + const cv::Rect& input_frame_loc) override; + + bool matToBlob(const cv::Mat& orig_image, const cv::Rect&, float scale_factor, int batch_index, + const std::shared_ptr& engine) override; + + /** + * @brief Get the name of this detection model. + * @return Name of the model. + */ + const std::string getModelCategory() const override; + bool updateLayerProperty(InferenceEngine::CNNNetwork&) override; + + +protected: + int getEntryIndex(int side, int lcoords, int lclasses, int location, int entry); + + double sigmoid(double x); + + std::vector getAnchors(int net_grid); + + bool parseYolov5(const InferenceEngine::Blob::Ptr &blob,int net_grid,float cof_threshold, + std::vector& o_rect, std::vector& o_rect_cof); + + cv::Rect detet2origin(const cv::Rect& dete_rect,float rate_to,int top,int left); + + InferenceEngine::InputInfo::Ptr input_info_ = nullptr; + InferenceEngine::OutputsDataMap outputs_data_map_; +}; +} // namespace Models +#endif // VINO_CORE_LIB__MODELS__OBJECT_DETECTION_YOLOV5VOC_MODEL_H diff --git a/vino_core_lib/include/vino_core_lib/models/object_segmentation_model.h b/vino_core_lib/include/vino_core_lib/models/object_segmentation_model.h index faf0fc88..61086d9e 100644 --- a/vino_core_lib/include/vino_core_lib/models/object_segmentation_model.h +++ b/vino_core_lib/include/vino_core_lib/models/object_segmentation_model.h @@ -28,7 +28,10 @@ namespace Models class ObjectSegmentationModel : public BaseModel { public: + ObjectSegmentationModel() {}; + ObjectSegmentationModel(const std::string& label_loc, const std::string& model_loc, int batch_size = 1); + inline int getMaxProposalCount() const { return max_proposal_count_; diff --git a/vino_core_lib/include/vino_core_lib/models/person_attribs_detection_model.h b/vino_core_lib/include/vino_core_lib/models/person_attribs_detection_model.h index 01e9c01b..b653ccb9 100644 --- a/vino_core_lib/include/vino_core_lib/models/person_attribs_detection_model.h +++ b/vino_core_lib/include/vino_core_lib/models/person_attribs_detection_model.h @@ -29,6 +29,8 @@ namespace Models class PersonAttribsDetectionModel : public BaseModel { public: + PersonAttribsDetectionModel() {}; + PersonAttribsDetectionModel(const std::string& label_loc, const std::string& model_loc, int batch_size = 1); // inline const std::string getInputName() {return input_;} // inline const std::string getOutputName() {return output_;} diff --git a/vino_core_lib/include/vino_core_lib/models/person_reidentification_model.h b/vino_core_lib/include/vino_core_lib/models/person_reidentification_model.h index 6476208f..9c72cf95 100644 --- a/vino_core_lib/include/vino_core_lib/models/person_reidentification_model.h +++ b/vino_core_lib/include/vino_core_lib/models/person_reidentification_model.h @@ -29,7 +29,10 @@ namespace Models class PersonReidentificationModel : public BaseModel { public: + PersonReidentificationModel() {}; + PersonReidentificationModel(const std::string& label_loc, const std::string& model_loc, int batch_size = 1); + inline const std::string getInputName() { return input_; diff --git a/vino_core_lib/include/vino_core_lib/models/vehicle_attribs_detection_model.h b/vino_core_lib/include/vino_core_lib/models/vehicle_attribs_detection_model.h index ad8e5acd..63e9abc2 100644 --- a/vino_core_lib/include/vino_core_lib/models/vehicle_attribs_detection_model.h +++ b/vino_core_lib/include/vino_core_lib/models/vehicle_attribs_detection_model.h @@ -29,7 +29,10 @@ namespace Models class VehicleAttribsDetectionModel : public BaseModel { public: + VehicleAttribsDetectionModel() {}; + VehicleAttribsDetectionModel(const std::string& label_loc, const std::string& model_loc, int batch_size = 1); + inline const std::string getInputName() { return input_; diff --git a/vino_core_lib/include/vino_core_lib/outputs/base_output.h b/vino_core_lib/include/vino_core_lib/outputs/base_output.h index 8270d433..775da5b9 100644 --- a/vino_core_lib/include/vino_core_lib/outputs/base_output.h +++ b/vino_core_lib/include/vino_core_lib/outputs/base_output.h @@ -25,6 +25,7 @@ #include #include +#include "vino_core_lib/vino_factory.h" #include "vino_core_lib/inferences/age_gender_detection.h" #include "vino_core_lib/inferences/base_inference.h" #include "vino_core_lib/inferences/emotions_detection.h" @@ -66,6 +67,8 @@ class BaseOutput explicit BaseOutput(std::string output_name) : output_name_(output_name) { } + + virtual void init(const std::string& pipeline_name) = 0; /** * @brief Generate output content according to the license plate detection result. */ @@ -188,4 +191,7 @@ class BaseOutput std::string output_name_; }; } // namespace Outputs + +#define REG_OUTPUT_FACTORY VinoFactory +#define REG_OUTPUT(BASE, key) static REG_OUTPUT_FACTORY::TReg gs_output##_(key) #endif // VINO_CORE_LIB__OUTPUTS__BASE_OUTPUT_H diff --git a/vino_core_lib/include/vino_core_lib/outputs/image_window_output.h b/vino_core_lib/include/vino_core_lib/outputs/image_window_output.h index f514c0cc..83acb882 100644 --- a/vino_core_lib/include/vino_core_lib/outputs/image_window_output.h +++ b/vino_core_lib/include/vino_core_lib/outputs/image_window_output.h @@ -35,7 +35,11 @@ namespace Outputs class ImageWindowOutput : public BaseOutput { public: - explicit ImageWindowOutput(const std::string& window_name, int focal_length = 950); + ImageWindowOutput() {}; + explicit ImageWindowOutput(const std::string& window_name, int focal_length = 950) {doInit(window_name, 950);}; + + void init(const std::string& window_name) override {doInit(window_name, 950);}; + void doInit(const std::string& window_name, int focal_length = 950); /** * @brief Calculate the camera matrix of a frame for image * window output. diff --git a/vino_core_lib/include/vino_core_lib/outputs/ros_service_output.h b/vino_core_lib/include/vino_core_lib/outputs/ros_service_output.h index 1121a8b6..714322e6 100644 --- a/vino_core_lib/include/vino_core_lib/outputs/ros_service_output.h +++ b/vino_core_lib/include/vino_core_lib/outputs/ros_service_output.h @@ -61,9 +61,11 @@ namespace Outputs class RosServiceOutput : public RosTopicOutput { public: - RosServiceOutput(std::string pipeline_name) : pipeline_name_(pipeline_name) - { - } + RosServiceOutput() {}; + + RosServiceOutput(std::string pipeline_name) : pipeline_name_(pipeline_name) {} + + void init(const std::string& pipeline_name) override {pipeline_name_ = pipeline_name;}; /** * @brief Publish all the detected infomations generated by the accept @@ -85,7 +87,7 @@ class RosServiceOutput : public RosTopicOutput private: const std::string service_name_; - const std::string pipeline_name_; + std::string pipeline_name_; }; } // namespace Outputs #endif // VINO_CORE_LIB__OUTPUTS__ROS_SERVICE_OUTPUT_H diff --git a/vino_core_lib/include/vino_core_lib/outputs/ros_topic_output.h b/vino_core_lib/include/vino_core_lib/outputs/ros_topic_output.h index a2e24385..a36998df 100644 --- a/vino_core_lib/include/vino_core_lib/outputs/ros_topic_output.h +++ b/vino_core_lib/include/vino_core_lib/outputs/ros_topic_output.h @@ -63,7 +63,9 @@ class RosTopicOutput : public BaseOutput { public: RosTopicOutput(){}; - RosTopicOutput(std::string pipeline_name); + RosTopicOutput(const std::string& pipeline_name) : pipeline_name_(pipeline_name){}; + + void init(const std::string& pipeline_name) override; /** * @brief Calculate the camera matrix of a frame. * @param[in] A frame. @@ -149,7 +151,7 @@ class RosTopicOutput : public BaseOutput private: std_msgs::Header getHeader(); - const std::string pipeline_name_; + std::string pipeline_name_; const std::string topic_name_; cv::Mat frame_; ros::NodeHandle nh_; diff --git a/vino_core_lib/include/vino_core_lib/outputs/rviz_output.h b/vino_core_lib/include/vino_core_lib/outputs/rviz_output.h index 6e19d653..f0c4c5bd 100644 --- a/vino_core_lib/include/vino_core_lib/outputs/rviz_output.h +++ b/vino_core_lib/include/vino_core_lib/outputs/rviz_output.h @@ -36,7 +36,10 @@ namespace Outputs class RvizOutput : public BaseOutput { public: - RvizOutput(std::string); + RvizOutput() {}; + RvizOutput(const std::string& pipeline_name) : pipeline_name_(pipeline_name) {}; + + void init(const std::string& pipeline_name) override; /** * @brief Construct frame for rviz * @param[in] A frame. @@ -122,6 +125,7 @@ class RvizOutput : public BaseOutput private: std_msgs::Header getHeader(); + std::string pipeline_name_; ros::NodeHandle nh_; ros::Publisher pub_image_; sensor_msgs::Image::Ptr image_topic_; diff --git a/vino_core_lib/include/vino_core_lib/pipeline_params.h b/vino_core_lib/include/vino_core_lib/pipeline_params.h index c8c606bf..b93b97b3 100644 --- a/vino_core_lib/include/vino_core_lib/pipeline_params.h +++ b/vino_core_lib/include/vino_core_lib/pipeline_params.h @@ -35,14 +35,14 @@ #include "opencv2/opencv.hpp" #include "vino_param_lib/param_manager.h" -const char kInputType_Image[] = "Image"; -const char kInputType_Video[] = "Video"; -const char kInputType_StandardCamera[] = "StandardCamera"; -const char kInputType_IpCamera[] = "IpCamera"; -const char kInputType_CameraTopic[] = "RealSenseCameraTopic"; -const char kInputType_ImageTopic[] = "ImageTopic"; -const char kInputType_RealSenseCamera[] = "RealSenseCamera"; -const char kInputType_ServiceImage[] = "ServiceImage"; +// const char kInputType_Image[] = "Image"; +// const char kInputType_Video[] = "Video"; +// const char kInputType_StandardCamera[] = "StandardCamera"; +// const char kInputType_IpCamera[] = "IpCamera"; +// const char kInputType_CameraTopic[] = "RealSenseCameraTopic"; +// const char kInputType_ImageTopic[] = "ImageTopic"; +// const char kInputType_RealSenseCamera[] = "RealSenseCamera"; +// const char kInputType_ServiceImage[] = "ServiceImage"; const char kOutputTpye_RViz[] = "RViz"; const char kOutputTpye_ImageWindow[] = "ImageWindow"; @@ -56,8 +56,8 @@ const char kInferTpye_HeadPoseEstimation[] = "HeadPoseEstimation"; const char kInferTpye_ObjectDetection[] = "ObjectDetection"; const char kInferTpye_ObjectSegmentation[] = "ObjectSegmentation"; const char kInferTpye_PersonReidentification[] = "PersonReidentification"; -const char kInferTpye_ObjectDetectionTypeSSD[] = "SSD"; -const char kInferTpye_ObjectDetectionTypeYolov2voc[] = "yolov2-voc"; +const char kInferTpye_ObjectDetectionTypeSSD[] = "ObjectDetectionSSD"; +const char kInferTpye_ObjectDetectionTypeYolov2voc[] = "ObjectDetectionYolov2voc"; const char kInferTpye_LandmarksDetection[] = "LandmarksDetection"; const char kInferTpye_FaceReidentification[] = "FaceReidentification"; const char kInferTpye_PersonAttribsDetection[] = "PersonAttribsDetection"; diff --git a/vino_core_lib/include/vino_core_lib/vino_factory.h b/vino_core_lib/include/vino_core_lib/vino_factory.h new file mode 100644 index 00000000..1112894d --- /dev/null +++ b/vino_core_lib/include/vino_core_lib/vino_factory.h @@ -0,0 +1,126 @@ + /* + * Copyright (c) 2018 Intel Corporation + * + * 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. + */ +#pragma once + +#include +#include +#include +#include +#include "vino_core_lib/slog.h" + +template +class VinoFactory +{ +public: + template + struct TReg + { + TReg(KEY key) + { + getFactory().getMap().emplace(key, [] { return new T(); }); + } + + template + TReg(KEY key, Args&&... args) + { + getFactory().getMap().emplace(key, [&] {return new T(std::forward(args)...);}); + } + }; + + static BASE* produce(const KEY& key) + { + auto item = getFactory().getMap().find(key); + + if(item == getFactory().getMap().end()) + { + slog::err << "VinoFactory:Invalid inference key: " << key << ". Please check your key name and type!" << slog::endl; + + + slog::info << "-----------Factory Map---------------" << slog::endl; + + for(auto v : getFactory().getMap()) + { + slog::info << " " << v.first << slog::endl; + } + + slog::info << "-------------------------------------" << slog::endl; + + return nullptr; + } + + return item->second(); + } + + static std::unique_ptr produce_unique(const KEY& key) + { + return std::unique_ptr(produce(key)); + } + + static std::shared_ptr produce_shared(const KEY& key) + { + return std::shared_ptr(produce(key)); + } + + static BASE* find(const KEY& key) + { + auto &instance = getFactory(); + auto item = instance.getMap().find(key); + + if(item == instance.getMap().end()) + { + + slog::err << "VinoFactory: invalid key for find: " << key << ". Please check your key name and type!" << slog::endl; + + + slog::info << "-----------Factory Map---------------" << slog::endl; + + for(auto v : getFactory().getMap()) + { + slog::info << " " << v.first << slog::endl; + } + + slog::info << "-------------------------------------" << slog::endl; + + return nullptr; + } + + return item->second(); + } + +private: + VinoFactory() {}; + virtual ~VinoFactory(){}; + + // Disable Left Value Copy + VinoFactory(const VinoFactory&) = delete; + VinoFactory &operator=(const VinoFactory&) = delete; + + // Disable Move + VinoFactory(VinoFactory&&) = delete; + + static VinoFactory& getFactory() + { + static VinoFactory instance; + return instance; + } + + static std::map>& getMap() + { + return getFactory().map_; + } + + std::map> map_; +}; \ No newline at end of file diff --git a/vino_core_lib/src/inferences/age_gender_detection.cpp b/vino_core_lib/src/inferences/age_gender_detection.cpp index 59064f81..25fabd3e 100644 --- a/vino_core_lib/src/inferences/age_gender_detection.cpp +++ b/vino_core_lib/src/inferences/age_gender_detection.cpp @@ -26,49 +26,51 @@ #include "vino_core_lib/inferences/age_gender_detection.h" #include "vino_core_lib/outputs/base_output.h" +using namespace vino_core_lib; + // AgeGenderResult -vino_core_lib::AgeGenderResult::AgeGenderResult(const cv::Rect& location) : Result(location) -{ -} +AgeGenderResult::AgeGenderResult(const cv::Rect& location) : Result(location) {} -// AgeGender Detection -vino_core_lib::AgeGenderDetection::AgeGenderDetection() : vino_core_lib::BaseInference() +void AgeGenderDetection::loadNetwork(std::shared_ptr network) { -} - -vino_core_lib::AgeGenderDetection::~AgeGenderDetection() = default; + valid_model_ = std::dynamic_pointer_cast(network); -void vino_core_lib::AgeGenderDetection::loadNetwork(std::shared_ptr network) -{ - valid_model_ = network; setMaxBatchSize(network->getMaxBatchSize()); } -bool vino_core_lib::AgeGenderDetection::enqueue(const cv::Mat& frame, const cv::Rect& input_frame_loc) +// // AgeGender Detection +// void AgeGenderDetection::loadNetwork(std::shared_ptr network) +// { +// valid_model_ = network; +// setMaxBatchSize(network->getMaxBatchSize()); +// } + +bool AgeGenderDetection::enqueue(const cv::Mat& frame, const cv::Rect& input_frame_loc) { if (getEnqueuedNum() == 0) { results_.clear(); } - bool succeed = vino_core_lib::BaseInference::enqueue(frame, input_frame_loc, 1, getResultsLength(), + bool succeed = BaseInference::enqueue(frame, input_frame_loc, 1, getResultsLength(), valid_model_->getInputName()); - if (!succeed) - return false; + if (!succeed) return false; + Result r(input_frame_loc); results_.emplace_back(r); return true; } -bool vino_core_lib::AgeGenderDetection::submitRequest() +bool AgeGenderDetection::submitRequest() { - return vino_core_lib::BaseInference::submitRequest(); + return BaseInference::submitRequest(); } -bool vino_core_lib::AgeGenderDetection::fetchResults() +bool AgeGenderDetection::fetchResults() { - bool can_fetch = vino_core_lib::BaseInference::fetchResults(); - if (!can_fetch) - return false; + bool can_fetch = BaseInference::fetchResults(); + + if (!can_fetch) return false; + auto request = getEngine()->getRequest(); InferenceEngine::Blob::Ptr genderBlob = request->GetBlob(valid_model_->getOutputGenderName()); InferenceEngine::Blob::Ptr ageBlob = request->GetBlob(valid_model_->getOutputAgeName()); @@ -78,25 +80,26 @@ bool vino_core_lib::AgeGenderDetection::fetchResults() results_[i].age_ = ageBlob->buffer().as()[i] * 100; results_[i].male_prob_ = genderBlob->buffer().as()[i * 2 + 1]; } + return true; } -int vino_core_lib::AgeGenderDetection::getResultsLength() const +int AgeGenderDetection::getResultsLength() const { return static_cast(results_.size()); } -const vino_core_lib::Result* vino_core_lib::AgeGenderDetection::getLocationResult(int idx) const +const Result* AgeGenderDetection::getLocationResult(int idx) const { return &(results_[idx]); } -const std::string vino_core_lib::AgeGenderDetection::getName() const +const std::string AgeGenderDetection::getName() const { return valid_model_->getModelCategory(); } -void vino_core_lib::AgeGenderDetection::observeOutput(const std::shared_ptr& output) +void AgeGenderDetection::observeOutput(const std::shared_ptr& output) { if (output != nullptr) { @@ -105,7 +108,7 @@ void vino_core_lib::AgeGenderDetection::observeOutput(const std::shared_ptr -vino_core_lib::AgeGenderDetection::getFilteredROIs(const std::string filter_conditions) const +AgeGenderDetection::getFilteredROIs(const std::string filter_conditions) const { if (!filter_conditions.empty()) { @@ -119,3 +122,5 @@ vino_core_lib::AgeGenderDetection::getFilteredROIs(const std::string filter_cond } return filtered_rois; } + +REG_INFERENCE(AgeGenderDetection, "AgeGenderRecognition"); diff --git a/vino_core_lib/src/inferences/base_filter.cpp b/vino_core_lib/src/inferences/base_filter.cpp index 3be94bb0..6d9d7be3 100644 --- a/vino_core_lib/src/inferences/base_filter.cpp +++ b/vino_core_lib/src/inferences/base_filter.cpp @@ -22,16 +22,18 @@ #include #include -vino_core_lib::BaseFilter::BaseFilter() +using namespace vino_core_lib; + +BaseFilter::BaseFilter() { } -bool vino_core_lib::BaseFilter::isValidFilterConditions(const std::string& filter_conditions) +bool BaseFilter::isValidFilterConditions(const std::string& filter_conditions) { return strip(filter_conditions) != ""; } -void vino_core_lib::BaseFilter::acceptFilterConditions(const std::string& filter_conditions) +void BaseFilter::acceptFilterConditions(const std::string& filter_conditions) { if (striped_conditions_.empty()) { @@ -41,7 +43,7 @@ void vino_core_lib::BaseFilter::acceptFilterConditions(const std::string& filter } } -bool vino_core_lib::BaseFilter::isRelationOperator(const std::string& str) +bool BaseFilter::isRelationOperator(const std::string& str) { if (std::find(relation_operators_.begin(), relation_operators_.end(), str) != relation_operators_.end()) { @@ -50,7 +52,7 @@ bool vino_core_lib::BaseFilter::isRelationOperator(const std::string& str) return false; } -bool vino_core_lib::BaseFilter::isLogicOperator(const std::string& str) +bool BaseFilter::isLogicOperator(const std::string& str) { if (std::find(logic_operators_.begin(), logic_operators_.end(), str) != logic_operators_.end()) { @@ -59,7 +61,7 @@ bool vino_core_lib::BaseFilter::isLogicOperator(const std::string& str) return false; } -bool vino_core_lib::BaseFilter::isPriorTo(const std::string& operator1, const std::string& operator2) +bool BaseFilter::isPriorTo(const std::string& operator1, const std::string& operator2) { if (isRelationOperator(operator1) && isLogicOperator(operator2)) { @@ -68,7 +70,7 @@ bool vino_core_lib::BaseFilter::isPriorTo(const std::string& operator1, const st return false; } -std::string vino_core_lib::BaseFilter::boolToStr(bool value) +std::string BaseFilter::boolToStr(bool value) { if (value) { @@ -77,7 +79,7 @@ std::string vino_core_lib::BaseFilter::boolToStr(bool value) return "false"; } -bool vino_core_lib::BaseFilter::strToBool(const std::string& value) +bool BaseFilter::strToBool(const std::string& value) { if (!value.compare("true")) { @@ -94,12 +96,12 @@ bool vino_core_lib::BaseFilter::strToBool(const std::string& value) return false; } -const std::vector& vino_core_lib::BaseFilter::getSuffixConditions() const +const std::vector& BaseFilter::getSuffixConditions() const { return suffix_conditons_; } -bool vino_core_lib::BaseFilter::logicOperation(const std::string& logic1, const std::string& op, +bool BaseFilter::logicOperation(const std::string& logic1, const std::string& op, const std::string& logic2) { if (!op.compare("&&")) @@ -117,7 +119,7 @@ bool vino_core_lib::BaseFilter::logicOperation(const std::string& logic1, const } } -bool vino_core_lib::BaseFilter::stringCompare(const std::string& candidate, const std::string& op, +bool BaseFilter::stringCompare(const std::string& candidate, const std::string& op, const std::string& target) { if (!op.compare("==")) @@ -135,7 +137,7 @@ bool vino_core_lib::BaseFilter::stringCompare(const std::string& candidate, cons } } -bool vino_core_lib::BaseFilter::floatCompare(float candidate, const std::string& op, float target) +bool BaseFilter::floatCompare(float candidate, const std::string& op, float target) { if (!op.compare("<=")) { @@ -160,7 +162,7 @@ bool vino_core_lib::BaseFilter::floatCompare(float candidate, const std::string& } } -float vino_core_lib::BaseFilter::stringToFloat(const std::string& candidate) +float BaseFilter::stringToFloat(const std::string& candidate) { float result = 0; try @@ -174,7 +176,7 @@ float vino_core_lib::BaseFilter::stringToFloat(const std::string& candidate) return result; } -std::vector vino_core_lib::BaseFilter::split(const std::string& filter_conditions) +std::vector BaseFilter::split(const std::string& filter_conditions) { std::vector seperators; seperators.insert(seperators.end(), relation_operators_.begin(), relation_operators_.end()); @@ -209,7 +211,7 @@ std::vector vino_core_lib::BaseFilter::split(const std::string& fil return infix_conditions; } -void vino_core_lib::BaseFilter::infixToSuffix(std::vector& infix_conditions) +void BaseFilter::infixToSuffix(std::vector& infix_conditions) { std::stack operator_stack; for (auto elem : infix_conditions) @@ -252,7 +254,7 @@ void vino_core_lib::BaseFilter::infixToSuffix(std::vector& infix_co } } -std::string vino_core_lib::BaseFilter::strip(const std::string& str) +std::string BaseFilter::strip(const std::string& str) { std::string stripped_string = ""; for (auto character : str) diff --git a/vino_core_lib/src/inferences/base_inference.cpp b/vino_core_lib/src/inferences/base_inference.cpp index 9112d669..84de01ac 100644 --- a/vino_core_lib/src/inferences/base_inference.cpp +++ b/vino_core_lib/src/inferences/base_inference.cpp @@ -23,23 +23,25 @@ #include "vino_core_lib/inferences/base_inference.h" +using namespace vino_core_lib; + // Result -vino_core_lib::Result::Result(const cv::Rect& location) +Result::Result(const cv::Rect& location) { location_ = location; } // BaseInference -vino_core_lib::BaseInference::BaseInference() = default; +BaseInference::BaseInference() = default; -vino_core_lib::BaseInference::~BaseInference() = default; +BaseInference::~BaseInference() = default; -void vino_core_lib::BaseInference::loadEngine(const std::shared_ptr engine) +void BaseInference::loadEngine(const std::shared_ptr engine) { engine_ = engine; } -bool vino_core_lib::BaseInference::submitRequest() +bool BaseInference::submitRequest() { if (engine_->getRequest() == nullptr) { @@ -55,7 +57,7 @@ bool vino_core_lib::BaseInference::submitRequest() return true; } -bool vino_core_lib::BaseInference::SynchronousRequest() +bool BaseInference::SynchronousRequest() { if (engine_->getRequest() == nullptr) { @@ -71,7 +73,7 @@ bool vino_core_lib::BaseInference::SynchronousRequest() return true; } -bool vino_core_lib::BaseInference::fetchResults() +bool BaseInference::fetchResults() { if (results_fetched_) { @@ -81,7 +83,7 @@ bool vino_core_lib::BaseInference::fetchResults() return true; } -void vino_core_lib::BaseInference::addCandidatedModel(std::shared_ptr model) +void BaseInference::addCandidatedModel(std::shared_ptr model) { slog::info << "TESTING in addCandidatedModel()" << slog::endl; if (model != nullptr) diff --git a/vino_core_lib/src/inferences/base_reidentification.cpp b/vino_core_lib/src/inferences/base_reidentification.cpp index b6a19fb4..675d6822 100644 --- a/vino_core_lib/src/inferences/base_reidentification.cpp +++ b/vino_core_lib/src/inferences/base_reidentification.cpp @@ -26,13 +26,15 @@ #include "vino_core_lib/inferences/base_reidentification.h" #include "vino_core_lib/slog.h" +using namespace vino_core_lib; + // Tracker -vino_core_lib::Tracker::Tracker(int max_record_size, double same_track_thresh, double new_track_thresh) +Tracker::Tracker(int max_record_size, double same_track_thresh, double new_track_thresh) : max_record_size_(max_record_size), same_track_thresh_(same_track_thresh), new_track_thresh_(new_track_thresh) { } -int vino_core_lib::Tracker::processNewTrack(const std::vector& feature) +int Tracker::processNewTrack(const std::vector& feature) { int most_similar_id; double similarity = findMostSimilarTrack(feature, most_similar_id); @@ -47,7 +49,7 @@ int vino_core_lib::Tracker::processNewTrack(const std::vector& feature) return most_similar_id; } -double vino_core_lib::Tracker::findMostSimilarTrack(const std::vector& feature, int& most_similar_id) +double Tracker::findMostSimilarTrack(const std::vector& feature, int& most_similar_id) { double max_similarity = 0; most_similar_id = -1; @@ -63,7 +65,7 @@ double vino_core_lib::Tracker::findMostSimilarTrack(const std::vector& fe return max_similarity; } -double vino_core_lib::Tracker::calcSimilarity(const std::vector& feature_a, +double Tracker::calcSimilarity(const std::vector& feature_a, const std::vector& feature_b) { if (feature_a.size() != feature_b.size()) @@ -91,7 +93,7 @@ double vino_core_lib::Tracker::calcSimilarity(const std::vector& feature_ return mul_sum / (sqrt(denom_a) * sqrt(denom_b)); } -void vino_core_lib::Tracker::updateMatchTrack(int track_id, const std::vector& feature) +void Tracker::updateMatchTrack(int track_id, const std::vector& feature) { if (recorded_tracks_.find(track_id) != recorded_tracks_.end()) { @@ -104,7 +106,7 @@ void vino_core_lib::Tracker::updateMatchTrack(int track_id, const std::vector lk(tracks_mtx_); int64_t earlest_time = LONG_MAX; @@ -120,7 +122,7 @@ void vino_core_lib::Tracker::removeEarlestTrack() recorded_tracks_.erase(remove_iter); } -int vino_core_lib::Tracker::addNewTrack(const std::vector& feature) +int Tracker::addNewTrack(const std::vector& feature) { if (recorded_tracks_.size() >= max_record_size_) { @@ -136,13 +138,13 @@ int vino_core_lib::Tracker::addNewTrack(const std::vector& feature) return max_track_id_; } -int64_t vino_core_lib::Tracker::getCurrentTime() +int64_t Tracker::getCurrentTime() { auto tp = std::chrono::time_point_cast(std::chrono::system_clock::now()); return static_cast(tp.time_since_epoch().count()); } -bool vino_core_lib::Tracker::saveTracksToFile(std::string filepath) +bool Tracker::saveTracksToFile(std::string filepath) { std::ofstream outfile(filepath); if (!outfile.is_open()) @@ -164,7 +166,7 @@ bool vino_core_lib::Tracker::saveTracksToFile(std::string filepath) return true; } -bool vino_core_lib::Tracker::loadTracksFromFile(std::string filepath) +bool Tracker::loadTracksFromFile(std::string filepath) { std::ifstream infile(filepath); if (!infile.is_open()) @@ -193,4 +195,4 @@ bool vino_core_lib::Tracker::loadTracksFromFile(std::string filepath) infile.close(); slog::info << "sucessfully load tracks from file: " << filepath << slog::endl; return true; -} +} \ No newline at end of file diff --git a/vino_core_lib/src/inferences/emotions_detection.cpp b/vino_core_lib/src/inferences/emotions_detection.cpp index ca6d1c9f..b40b3da7 100644 --- a/vino_core_lib/src/inferences/emotions_detection.cpp +++ b/vino_core_lib/src/inferences/emotions_detection.cpp @@ -29,31 +29,34 @@ #include "vino_core_lib/outputs/base_output.h" #include "vino_core_lib/slog.h" +using namespace vino_core_lib; + // EmotionsResult -vino_core_lib::EmotionsResult::EmotionsResult(const cv::Rect& location) : Result(location) +EmotionsResult::EmotionsResult(const cv::Rect& location) : Result(location) { } -// Emotions Detection -vino_core_lib::EmotionsDetection::EmotionsDetection() : vino_core_lib::BaseInference() +void EmotionsDetection::loadNetwork(std::shared_ptr network) { -} - -vino_core_lib::EmotionsDetection::~EmotionsDetection() = default; + valid_model_ = std::dynamic_pointer_cast(network); -void vino_core_lib::EmotionsDetection::loadNetwork(const std::shared_ptr network) -{ - valid_model_ = network; setMaxBatchSize(network->getMaxBatchSize()); } -bool vino_core_lib::EmotionsDetection::enqueue(const cv::Mat& frame, const cv::Rect& input_frame_loc) +// // Emotions Detection +// void EmotionsDetection::loadNetwork(const std::shared_ptr network) +// { +// valid_model_ = network; +// setMaxBatchSize(network->getMaxBatchSize()); +// } + +bool EmotionsDetection::enqueue(const cv::Mat& frame, const cv::Rect& input_frame_loc) { if (getEnqueuedNum() == 0) { results_.clear(); } - bool succeed = vino_core_lib::BaseInference::enqueue(frame, input_frame_loc, 1, getResultsLength(), + bool succeed = BaseInference::enqueue(frame, input_frame_loc, 1, getResultsLength(), valid_model_->getInputName()); if (!succeed) { @@ -66,14 +69,14 @@ bool vino_core_lib::EmotionsDetection::enqueue(const cv::Mat& frame, const cv::R return true; } -bool vino_core_lib::EmotionsDetection::submitRequest() +bool EmotionsDetection::submitRequest() { - return vino_core_lib::BaseInference::submitRequest(); + return BaseInference::submitRequest(); } -bool vino_core_lib::EmotionsDetection::fetchResults() +bool EmotionsDetection::fetchResults() { - bool can_fetch = vino_core_lib::BaseInference::fetchResults(); + bool can_fetch = BaseInference::fetchResults(); if (!can_fetch) return false; int label_length = static_cast(valid_model_->getLabels().size()); @@ -109,22 +112,22 @@ bool vino_core_lib::EmotionsDetection::fetchResults() return true; } -int vino_core_lib::EmotionsDetection::getResultsLength() const +int EmotionsDetection::getResultsLength() const { return static_cast(results_.size()); } -const vino_core_lib::Result* vino_core_lib::EmotionsDetection::getLocationResult(int idx) const +const Result* EmotionsDetection::getLocationResult(int idx) const { return &(results_[idx]); } -const std::string vino_core_lib::EmotionsDetection::getName() const +const std::string EmotionsDetection::getName() const { return valid_model_->getModelCategory(); } -void vino_core_lib::EmotionsDetection::observeOutput(const std::shared_ptr& output) +void EmotionsDetection::observeOutput(const std::shared_ptr& output) { if (output != nullptr) { @@ -133,7 +136,7 @@ void vino_core_lib::EmotionsDetection::observeOutput(const std::shared_ptr -vino_core_lib::EmotionsDetection::getFilteredROIs(const std::string filter_conditions) const +EmotionsDetection::getFilteredROIs(const std::string filter_conditions) const { if (!filter_conditions.empty()) { @@ -147,3 +150,6 @@ vino_core_lib::EmotionsDetection::getFilteredROIs(const std::string filter_condi } return filtered_rois; } + +using namespace vino_core_lib; +REG_INFERENCE(EmotionsDetection, "EmotionRecognition"); diff --git a/vino_core_lib/src/inferences/face_detection.cpp b/vino_core_lib/src/inferences/face_detection.cpp index e5fdee5d..e456ccea 100644 --- a/vino_core_lib/src/inferences/face_detection.cpp +++ b/vino_core_lib/src/inferences/face_detection.cpp @@ -24,17 +24,173 @@ #include #include +#include "vino_core_lib/inferences/object_detection.h" #include "vino_core_lib/inferences/face_detection.h" #include "vino_core_lib/outputs/base_output.h" #include "vino_core_lib/slog.h" +using namespace vino_core_lib; + // FaceDetectionResult -vino_core_lib::FaceDetectionResult::FaceDetectionResult(const cv::Rect& location) : ObjectDetectionResult(location) +FaceDetectionResult::FaceDetectionResult(const cv::Rect& location) : ObjectDetectionResult(location) { } // FaceDetection -vino_core_lib::FaceDetection::FaceDetection(bool enable_roi_constraint, double show_output_thresh) - : ObjectDetection(enable_roi_constraint, show_output_thresh) +FaceDetection::FaceDetection(bool enable_roi_constraint, double show_output_thresh) + : show_output_thresh_(show_output_thresh) + , enable_roi_constraint_(enable_roi_constraint) + , BaseInference() +{ + result_filter_ = std::make_shared(); + result_filter_->init(); +} + +void FaceDetection::loadNetwork(std::shared_ptr network) { + valid_model_ = network; + + setMaxBatchSize(network->getMaxBatchSize()); } + +bool FaceDetection::enqueue(const cv::Mat& frame, const cv::Rect& input_frame_loc) +{ + auto model = std::dynamic_pointer_cast(valid_model_); + + if (model == nullptr || getEngine() == nullptr) + { + return false; + } + + if (enqueued_frames_ >= model->getMaxBatchSize()) + { + slog::warn << "Number of " << getName() << "input more than maximum(" << max_batch_size_ + << ") processed by inference" << slog::endl; + return false; + } + + if (!model->enqueue(getEngine(), frame, input_frame_loc)) + { + return false; + } + + // nonsense!! + // Result r(input_frame_loc); + // results_.clear(); + // results_.emplace_back(r); + enqueued_frames_ += 1; + return true; +} + +bool FaceDetection::fetchResults() +{ + bool can_fetch = BaseInference::fetchResults(); + if (!can_fetch) + { + return false; + } + + results_.clear(); + auto model = std::dynamic_pointer_cast(valid_model_); + + return (model != nullptr) && + model->fetchResults(getEngine(), results_, show_output_thresh_, enable_roi_constraint_); +} + +int FaceDetection::getResultsLength() const +{ + return static_cast(results_.size()); +} + +const FaceDetection::Result* FaceDetection::getLocationResult(int idx) const +{ + return &(results_[idx]); +} + +const std::string FaceDetection::getName() const +{ + auto model = std::dynamic_pointer_cast(valid_model_); + return ((model != nullptr) ? model->getModelCategory() : ""); +} + +void FaceDetection::observeOutput(const std::shared_ptr& output) +{ + if (output != nullptr) + { + output->accept(results_); + } +} + +double FaceDetection::calcIoU(const cv::Rect& box_1, const cv::Rect& box_2) +{ + cv::Rect i = box_1 & box_2; + cv::Rect u = box_1 | box_2; + + return static_cast(i.area()) / static_cast(u.area()); +} + +const std::vector +FaceDetection::getFilteredROIs(const std::string filter_conditions) const +{ + if (!result_filter_->isValidFilterConditions(filter_conditions)) + { + std::vector filtered_rois; + for (auto result : results_) + { + filtered_rois.push_back(result.getLocation()); + } + return filtered_rois; + } + result_filter_->acceptResults(results_); + result_filter_->acceptFilterConditions(filter_conditions); + return result_filter_->getFilteredLocations(); +} + +// FaceDetectionResultFilter +FaceDetectionResultFilter::FaceDetectionResultFilter() +{ +} + +void FaceDetectionResultFilter::init() +{ + key_to_function_.insert(std::make_pair("label", isValidLabel)); + key_to_function_.insert(std::make_pair("confidence", isValidConfidence)); +} + +void FaceDetectionResultFilter::acceptResults(const std::vector& results) +{ + results_ = results; +} + +std::vector FaceDetectionResultFilter::getFilteredLocations() +{ + std::vector locations; + for (auto result : results_) + { + if (isValidResult(result)) + { + locations.push_back(result.getLocation()); + } + } + return locations; +} + +bool FaceDetectionResultFilter::isValidLabel(const Result& result, const std::string& op, + const std::string& target) +{ + return stringCompare(result.getLabel(), op, target); +} + +bool FaceDetectionResultFilter::isValidConfidence(const Result& result, const std::string& op, + const std::string& target) +{ + return floatCompare(result.getConfidence(), op, stringToFloat(target)); +} + +bool FaceDetectionResultFilter::isValidResult(const Result& result) +{ + ISVALIDRESULT(key_to_function_, result); +} + +using namespace vino_core_lib; +REG_INFERENCE(FaceDetection, "FaceDetection"); diff --git a/vino_core_lib/src/inferences/face_reidentification.cpp b/vino_core_lib/src/inferences/face_reidentification.cpp index 61277bbb..ce44377f 100644 --- a/vino_core_lib/src/inferences/face_reidentification.cpp +++ b/vino_core_lib/src/inferences/face_reidentification.cpp @@ -24,32 +24,43 @@ #include "vino_core_lib/outputs/base_output.h" #include "vino_core_lib/slog.h" +using namespace vino_core_lib; + // FaceReidentificationResult -vino_core_lib::FaceReidentificationResult::FaceReidentificationResult(const cv::Rect& location) : Result(location) +FaceReidentificationResult::FaceReidentificationResult(const cv::Rect& location) : Result(location) { } // FaceReidentification -vino_core_lib::FaceReidentification::FaceReidentification(double match_thresh) : vino_core_lib::BaseInference() +FaceReidentification::FaceReidentification(double match_thresh) : BaseInference() { - face_tracker_ = std::make_shared(1000, match_thresh, 0.3); + face_tracker_ = std::make_shared(1000, match_thresh, 0.3); } -vino_core_lib::FaceReidentification::~FaceReidentification() = default; -void vino_core_lib::FaceReidentification::loadNetwork( - const std::shared_ptr network) +FaceReidentification::~FaceReidentification() = default; + + +void FaceReidentification::loadNetwork(std::shared_ptr network) { - valid_model_ = network; + valid_model_ = std::dynamic_pointer_cast(network); + setMaxBatchSize(network->getMaxBatchSize()); } -bool vino_core_lib::FaceReidentification::enqueue(const cv::Mat& frame, const cv::Rect& input_frame_loc) +// void FaceReidentification::loadNetwork( +// const std::shared_ptr network) +// { +// valid_model_ = network; +// setMaxBatchSize(network->getMaxBatchSize()); +// } + +bool FaceReidentification::enqueue(const cv::Mat& frame, const cv::Rect& input_frame_loc) { if (getEnqueuedNum() == 0) { results_.clear(); } - if (!vino_core_lib::BaseInference::enqueue(frame, input_frame_loc, 1, 0, valid_model_->getInputName())) + if (!BaseInference::enqueue(frame, input_frame_loc, 1, 0, valid_model_->getInputName())) { return false; } @@ -58,14 +69,14 @@ bool vino_core_lib::FaceReidentification::enqueue(const cv::Mat& frame, const cv return true; } -bool vino_core_lib::FaceReidentification::submitRequest() +bool FaceReidentification::submitRequest() { - return vino_core_lib::BaseInference::submitRequest(); + return BaseInference::submitRequest(); } -bool vino_core_lib::FaceReidentification::fetchResults() +bool FaceReidentification::fetchResults() { - bool can_fetch = vino_core_lib::BaseInference::fetchResults(); + bool can_fetch = BaseInference::fetchResults(); if (!can_fetch) { return false; @@ -90,22 +101,22 @@ bool vino_core_lib::FaceReidentification::fetchResults() return true; } -int vino_core_lib::FaceReidentification::getResultsLength() const +int FaceReidentification::getResultsLength() const { return static_cast(results_.size()); } -const vino_core_lib::Result* vino_core_lib::FaceReidentification::getLocationResult(int idx) const +const Result* FaceReidentification::getLocationResult(int idx) const { return &(results_[idx]); } -const std::string vino_core_lib::FaceReidentification::getName() const +const std::string FaceReidentification::getName() const { return valid_model_->getModelCategory(); } -void vino_core_lib::FaceReidentification::observeOutput(const std::shared_ptr& output) +void FaceReidentification::observeOutput(const std::shared_ptr& output) { if (output != nullptr) { @@ -114,7 +125,7 @@ void vino_core_lib::FaceReidentification::observeOutput(const std::shared_ptr -vino_core_lib::FaceReidentification::getFilteredROIs(const std::string filter_conditions) const +FaceReidentification::getFilteredROIs(const std::string filter_conditions) const { if (!filter_conditions.empty()) { @@ -128,3 +139,6 @@ vino_core_lib::FaceReidentification::getFilteredROIs(const std::string filter_co } return filtered_rois; } + +using namespace vino_core_lib; +REG_INFERENCE(FaceReidentification, "FaceReidentification"); diff --git a/vino_core_lib/src/inferences/head_pose_detection.cpp b/vino_core_lib/src/inferences/head_pose_detection.cpp index 6005739d..ef52505a 100644 --- a/vino_core_lib/src/inferences/head_pose_detection.cpp +++ b/vino_core_lib/src/inferences/head_pose_detection.cpp @@ -25,31 +25,34 @@ #include #include "vino_core_lib/outputs/base_output.h" +using namespace vino_core_lib; + // HeadPoseResult -vino_core_lib::HeadPoseResult::HeadPoseResult(const cv::Rect& location) : Result(location) +HeadPoseResult::HeadPoseResult(const cv::Rect& location) : Result(location) { } -// Head Pose Detection -vino_core_lib::HeadPoseDetection::HeadPoseDetection() : vino_core_lib::BaseInference() +void HeadPoseDetection::loadNetwork(std::shared_ptr network) { -} - -vino_core_lib::HeadPoseDetection::~HeadPoseDetection() = default; + valid_model_ = std::dynamic_pointer_cast(network); -void vino_core_lib::HeadPoseDetection::loadNetwork(std::shared_ptr network) -{ - valid_model_ = network; setMaxBatchSize(network->getMaxBatchSize()); } -bool vino_core_lib::HeadPoseDetection::enqueue(const cv::Mat& frame, const cv::Rect& input_frame_loc) +// // Head Pose Detection +// void HeadPoseDetection::loadNetwork(std::shared_ptr network) +// { +// valid_model_ = network; +// setMaxBatchSize(network->getMaxBatchSize()); +// } + +bool HeadPoseDetection::enqueue(const cv::Mat& frame, const cv::Rect& input_frame_loc) { if (getEnqueuedNum() == 0) { results_.clear(); } - bool succeed = vino_core_lib::BaseInference::enqueue(frame, input_frame_loc, 1, getResultsLength(), + bool succeed = BaseInference::enqueue(frame, input_frame_loc, 1, getResultsLength(), valid_model_->getInputName()); if (!succeed) return false; @@ -58,14 +61,14 @@ bool vino_core_lib::HeadPoseDetection::enqueue(const cv::Mat& frame, const cv::R return true; } -bool vino_core_lib::HeadPoseDetection::submitRequest() +bool HeadPoseDetection::submitRequest() { - return vino_core_lib::BaseInference::submitRequest(); + return BaseInference::submitRequest(); } -bool vino_core_lib::HeadPoseDetection::fetchResults() +bool HeadPoseDetection::fetchResults() { - bool can_fetch = vino_core_lib::BaseInference::fetchResults(); + bool can_fetch = BaseInference::fetchResults(); if (!can_fetch) return false; auto request = getEngine()->getRequest(); @@ -82,22 +85,22 @@ bool vino_core_lib::HeadPoseDetection::fetchResults() return true; } -int vino_core_lib::HeadPoseDetection::getResultsLength() const +int HeadPoseDetection::getResultsLength() const { return static_cast(results_.size()); } -const vino_core_lib::Result* vino_core_lib::HeadPoseDetection::getLocationResult(int idx) const +const Result* HeadPoseDetection::getLocationResult(int idx) const { return &(results_[idx]); } -const std::string vino_core_lib::HeadPoseDetection::getName() const +const std::string HeadPoseDetection::getName() const { return valid_model_->getModelCategory(); } -void vino_core_lib::HeadPoseDetection::observeOutput(const std::shared_ptr& output) +void HeadPoseDetection::observeOutput(const std::shared_ptr& output) { if (output != nullptr) { @@ -106,7 +109,7 @@ void vino_core_lib::HeadPoseDetection::observeOutput(const std::shared_ptr -vino_core_lib::HeadPoseDetection::getFilteredROIs(const std::string filter_conditions) const +HeadPoseDetection::getFilteredROIs(const std::string filter_conditions) const { if (!filter_conditions.empty()) { @@ -120,3 +123,6 @@ vino_core_lib::HeadPoseDetection::getFilteredROIs(const std::string filter_condi } return filtered_rois; } + +using namespace vino_core_lib; +REG_INFERENCE(HeadPoseDetection, "HeadPoseEstimation"); diff --git a/vino_core_lib/src/inferences/landmarks_detection.cpp b/vino_core_lib/src/inferences/landmarks_detection.cpp index cea90fde..2031cd48 100644 --- a/vino_core_lib/src/inferences/landmarks_detection.cpp +++ b/vino_core_lib/src/inferences/landmarks_detection.cpp @@ -23,30 +23,34 @@ #include "vino_core_lib/inferences/landmarks_detection.h" #include "vino_core_lib/outputs/base_output.h" +using namespace vino_core_lib; + // LandmarksDetectionResult -vino_core_lib::LandmarksDetectionResult::LandmarksDetectionResult(const cv::Rect& location) : Result(location) +LandmarksDetectionResult::LandmarksDetectionResult(const cv::Rect& location) : Result(location) { } -// LandmarksDetection -vino_core_lib::LandmarksDetection::LandmarksDetection() : vino_core_lib::BaseInference() +void LandmarksDetection::loadNetwork(std::shared_ptr network) { -} + valid_model_ = std::dynamic_pointer_cast(network); -vino_core_lib::LandmarksDetection::~LandmarksDetection() = default; -void vino_core_lib::LandmarksDetection::loadNetwork(const std::shared_ptr network) -{ - valid_model_ = network; setMaxBatchSize(network->getMaxBatchSize()); } -bool vino_core_lib::LandmarksDetection::enqueue(const cv::Mat& frame, const cv::Rect& input_frame_loc) +// // LandmarksDetection +// void LandmarksDetection::loadNetwork(const std::shared_ptr network) +// { +// valid_model_ = network; +// setMaxBatchSize(network->getMaxBatchSize()); +// } + +bool LandmarksDetection::enqueue(const cv::Mat& frame, const cv::Rect& input_frame_loc) { if (getEnqueuedNum() == 0) { results_.clear(); } - if (!vino_core_lib::BaseInference::enqueue(frame, input_frame_loc, 1, 0, valid_model_->getInputName())) + if (!BaseInference::enqueue(frame, input_frame_loc, 1, 0, valid_model_->getInputName())) { return false; } @@ -55,14 +59,14 @@ bool vino_core_lib::LandmarksDetection::enqueue(const cv::Mat& frame, const cv:: return true; } -bool vino_core_lib::LandmarksDetection::submitRequest() +bool LandmarksDetection::submitRequest() { - return vino_core_lib::BaseInference::submitRequest(); + return BaseInference::submitRequest(); } -bool vino_core_lib::LandmarksDetection::fetchResults() +bool LandmarksDetection::fetchResults() { - bool can_fetch = vino_core_lib::BaseInference::fetchResults(); + bool can_fetch = BaseInference::fetchResults(); if (!can_fetch) { return false; @@ -93,22 +97,22 @@ bool vino_core_lib::LandmarksDetection::fetchResults() return true; } -int vino_core_lib::LandmarksDetection::getResultsLength() const +int LandmarksDetection::getResultsLength() const { return static_cast(results_.size()); } -const vino_core_lib::Result* vino_core_lib::LandmarksDetection::getLocationResult(int idx) const +const Result* LandmarksDetection::getLocationResult(int idx) const { return &(results_[idx]); } -const std::string vino_core_lib::LandmarksDetection::getName() const +const std::string LandmarksDetection::getName() const { return valid_model_->getModelCategory(); } -void vino_core_lib::LandmarksDetection::observeOutput(const std::shared_ptr& output) +void LandmarksDetection::observeOutput(const std::shared_ptr& output) { if (output != nullptr) { @@ -117,7 +121,7 @@ void vino_core_lib::LandmarksDetection::observeOutput(const std::shared_ptr -vino_core_lib::LandmarksDetection::getFilteredROIs(const std::string filter_conditions) const +LandmarksDetection::getFilteredROIs(const std::string filter_conditions) const { if (!filter_conditions.empty()) { @@ -131,3 +135,6 @@ vino_core_lib::LandmarksDetection::getFilteredROIs(const std::string filter_cond } return filtered_rois; } + +using namespace vino_core_lib; +REG_INFERENCE(LandmarksDetection, "LandmarksDetection"); diff --git a/vino_core_lib/src/inferences/license_plate_detection.cpp b/vino_core_lib/src/inferences/license_plate_detection.cpp index 87b4a97f..b94e1651 100644 --- a/vino_core_lib/src/inferences/license_plate_detection.cpp +++ b/vino_core_lib/src/inferences/license_plate_detection.cpp @@ -24,25 +24,29 @@ #include "vino_core_lib/outputs/base_output.h" #include "vino_core_lib/slog.h" +using namespace vino_core_lib; + // LicensePlateDetectionResult -vino_core_lib::LicensePlateDetectionResult::LicensePlateDetectionResult(const cv::Rect& location) : Result(location) +LicensePlateDetectionResult::LicensePlateDetectionResult(const cv::Rect& location) : Result(location) { } -// LicensePlateDetection -vino_core_lib::LicensePlateDetection::LicensePlateDetection() : vino_core_lib::BaseInference() +void LicensePlateDetection::loadNetwork(std::shared_ptr network) { -} + valid_model_ = std::dynamic_pointer_cast(network); -vino_core_lib::LicensePlateDetection::~LicensePlateDetection() = default; -void vino_core_lib::LicensePlateDetection::loadNetwork( - const std::shared_ptr network) -{ - valid_model_ = network; setMaxBatchSize(network->getMaxBatchSize()); } -void vino_core_lib::LicensePlateDetection::fillSeqBlob() +// // LicensePlateDetection +// void LicensePlateDetection::loadNetwork( +// const std::shared_ptr network) +// { +// valid_model_ = network; +// setMaxBatchSize(network->getMaxBatchSize()); +// } + +void LicensePlateDetection::fillSeqBlob() { InferenceEngine::Blob::Ptr seq_blob = getEngine()->getRequest()->GetBlob(valid_model_->getSeqInputName()); int max_sequence_size = seq_blob->getTensorDesc().getDims()[0]; @@ -53,13 +57,13 @@ void vino_core_lib::LicensePlateDetection::fillSeqBlob() std::fill(blob_data + 1, blob_data + max_sequence_size, 1.0f); } -bool vino_core_lib::LicensePlateDetection::enqueue(const cv::Mat& frame, const cv::Rect& input_frame_loc) +bool LicensePlateDetection::enqueue(const cv::Mat& frame, const cv::Rect& input_frame_loc) { if (getEnqueuedNum() == 0) { results_.clear(); } - if (!vino_core_lib::BaseInference::enqueue(frame, input_frame_loc, 1, 0, valid_model_->getInputName())) + if (!BaseInference::enqueue(frame, input_frame_loc, 1, 0, valid_model_->getInputName())) { return false; } @@ -69,14 +73,14 @@ bool vino_core_lib::LicensePlateDetection::enqueue(const cv::Mat& frame, const c return true; } -bool vino_core_lib::LicensePlateDetection::submitRequest() +bool LicensePlateDetection::submitRequest() { - return vino_core_lib::BaseInference::submitRequest(); + return BaseInference::submitRequest(); } -bool vino_core_lib::LicensePlateDetection::fetchResults() +bool LicensePlateDetection::fetchResults() { - bool can_fetch = vino_core_lib::BaseInference::fetchResults(); + bool can_fetch = BaseInference::fetchResults(); if (!can_fetch) { return false; @@ -107,22 +111,22 @@ bool vino_core_lib::LicensePlateDetection::fetchResults() return true; } -int vino_core_lib::LicensePlateDetection::getResultsLength() const +int LicensePlateDetection::getResultsLength() const { return static_cast(results_.size()); } -const vino_core_lib::Result* vino_core_lib::LicensePlateDetection::getLocationResult(int idx) const +const Result* LicensePlateDetection::getLocationResult(int idx) const { return &(results_[idx]); } -const std::string vino_core_lib::LicensePlateDetection::getName() const +const std::string LicensePlateDetection::getName() const { return valid_model_->getModelCategory(); } -void vino_core_lib::LicensePlateDetection::observeOutput(const std::shared_ptr& output) +void LicensePlateDetection::observeOutput(const std::shared_ptr& output) { if (output != nullptr) { @@ -131,7 +135,7 @@ void vino_core_lib::LicensePlateDetection::observeOutput(const std::shared_ptr -vino_core_lib::LicensePlateDetection::getFilteredROIs(const std::string filter_conditions) const +LicensePlateDetection::getFilteredROIs(const std::string filter_conditions) const { if (!filter_conditions.empty()) { @@ -145,3 +149,6 @@ vino_core_lib::LicensePlateDetection::getFilteredROIs(const std::string filter_c } return filtered_rois; } + +using namespace vino_core_lib; +REG_INFERENCE(LicensePlateDetection, "LicensePlateDetection"); diff --git a/vino_core_lib/src/inferences/object_detection.cpp b/vino_core_lib/src/inferences/object_detection.cpp index 5947f675..bfdc2d89 100644 --- a/vino_core_lib/src/inferences/object_detection.cpp +++ b/vino_core_lib/src/inferences/object_detection.cpp @@ -26,30 +26,39 @@ #include "vino_core_lib/inferences/object_detection.h" #include "vino_core_lib/outputs/base_output.h" #include "vino_core_lib/slog.h" + +using namespace vino_core_lib; + // ObjectDetectionResult -vino_core_lib::ObjectDetectionResult::ObjectDetectionResult(const cv::Rect& location) : Result(location) +ObjectDetectionResult::ObjectDetectionResult(const cv::Rect& location) : Result(location) { } // ObjectDetection -vino_core_lib::ObjectDetection::ObjectDetection(bool enable_roi_constraint, double show_output_thresh) +ObjectDetection::ObjectDetection(bool enable_roi_constraint, double show_output_thresh) : show_output_thresh_(show_output_thresh) , enable_roi_constraint_(enable_roi_constraint) - , vino_core_lib::BaseInference() + , BaseInference() { result_filter_ = std::make_shared(); result_filter_->init(); } -vino_core_lib::ObjectDetection::~ObjectDetection() = default; - -void vino_core_lib::ObjectDetection::loadNetwork(std::shared_ptr network) +void ObjectDetection::loadNetwork(std::shared_ptr network) { - valid_model_ = network; + valid_model_ = std::dynamic_pointer_cast(network); setMaxBatchSize(network->getMaxBatchSize()); } -bool vino_core_lib::ObjectDetection::enqueue(const cv::Mat& frame, const cv::Rect& input_frame_loc) + +// void ObjectDetection::loadNetwork(std::shared_ptr network) +// { +// valid_model_ = network; + +// setMaxBatchSize(network->getMaxBatchSize()); +// } + +bool ObjectDetection::enqueue(const cv::Mat& frame, const cv::Rect& input_frame_loc) { if (valid_model_ == nullptr || getEngine() == nullptr) { @@ -76,9 +85,9 @@ bool vino_core_lib::ObjectDetection::enqueue(const cv::Mat& frame, const cv::Rec return true; } -bool vino_core_lib::ObjectDetection::fetchResults() +bool ObjectDetection::fetchResults() { - bool can_fetch = vino_core_lib::BaseInference::fetchResults(); + bool can_fetch = BaseInference::fetchResults(); if (!can_fetch) { return false; @@ -90,22 +99,22 @@ bool vino_core_lib::ObjectDetection::fetchResults() valid_model_->fetchResults(getEngine(), results_, show_output_thresh_, enable_roi_constraint_); } -int vino_core_lib::ObjectDetection::getResultsLength() const +int ObjectDetection::getResultsLength() const { return static_cast(results_.size()); } -const vino_core_lib::ObjectDetection::Result* vino_core_lib::ObjectDetection::getLocationResult(int idx) const +const ObjectDetection::Result* ObjectDetection::getLocationResult(int idx) const { return &(results_[idx]); } -const std::string vino_core_lib::ObjectDetection::getName() const +const std::string ObjectDetection::getName() const { return valid_model_->getModelCategory(); } -void vino_core_lib::ObjectDetection::observeOutput(const std::shared_ptr& output) +void ObjectDetection::observeOutput(const std::shared_ptr& output) { if (output != nullptr) { @@ -114,7 +123,7 @@ void vino_core_lib::ObjectDetection::observeOutput(const std::shared_ptr -vino_core_lib::ObjectDetection::getFilteredROIs(const std::string filter_conditions) const +ObjectDetection::getFilteredROIs(const std::string filter_conditions) const { if (!result_filter_->isValidFilterConditions(filter_conditions)) { @@ -131,22 +140,22 @@ vino_core_lib::ObjectDetection::getFilteredROIs(const std::string filter_conditi } // ObjectDetectionResultFilter -vino_core_lib::ObjectDetectionResultFilter::ObjectDetectionResultFilter() +ObjectDetectionResultFilter::ObjectDetectionResultFilter() { } -void vino_core_lib::ObjectDetectionResultFilter::init() +void ObjectDetectionResultFilter::init() { key_to_function_.insert(std::make_pair("label", isValidLabel)); key_to_function_.insert(std::make_pair("confidence", isValidConfidence)); } -void vino_core_lib::ObjectDetectionResultFilter::acceptResults(const std::vector& results) +void ObjectDetectionResultFilter::acceptResults(const std::vector& results) { results_ = results; } -std::vector vino_core_lib::ObjectDetectionResultFilter::getFilteredLocations() +std::vector ObjectDetectionResultFilter::getFilteredLocations() { std::vector locations; for (auto result : results_) @@ -159,27 +168,30 @@ std::vector vino_core_lib::ObjectDetectionResultFilter::getFilteredLoc return locations; } -bool vino_core_lib::ObjectDetectionResultFilter::isValidLabel(const Result& result, const std::string& op, +bool ObjectDetectionResultFilter::isValidLabel(const Result& result, const std::string& op, const std::string& target) { return stringCompare(result.getLabel(), op, target); } -bool vino_core_lib::ObjectDetectionResultFilter::isValidConfidence(const Result& result, const std::string& op, +bool ObjectDetectionResultFilter::isValidConfidence(const Result& result, const std::string& op, const std::string& target) { return floatCompare(result.getConfidence(), op, stringToFloat(target)); } -bool vino_core_lib::ObjectDetectionResultFilter::isValidResult(const Result& result) +bool ObjectDetectionResultFilter::isValidResult(const Result& result) { ISVALIDRESULT(key_to_function_, result); } -double vino_core_lib::ObjectDetection::calcIoU(const cv::Rect& box_1, const cv::Rect& box_2) +double ObjectDetection::calcIoU(const cv::Rect& box_1, const cv::Rect& box_2) { cv::Rect i = box_1 & box_2; cv::Rect u = box_1 | box_2; return static_cast(i.area()) / static_cast(u.area()); } + +using namespace vino_core_lib; +REG_INFERENCE(ObjectDetection, "ObjectDetection"); diff --git a/vino_core_lib/src/inferences/object_segmentation.cpp b/vino_core_lib/src/inferences/object_segmentation.cpp index ec6d6e84..fd4b58f7 100644 --- a/vino_core_lib/src/inferences/object_segmentation.cpp +++ b/vino_core_lib/src/inferences/object_segmentation.cpp @@ -27,38 +27,47 @@ #include "vino_core_lib/outputs/base_output.h" #include "vino_core_lib/slog.h" +using namespace vino_core_lib; + // ObjectSegmentationResult -vino_core_lib::ObjectSegmentationResult::ObjectSegmentationResult(const cv::Rect& location) : Result(location) +ObjectSegmentationResult::ObjectSegmentationResult(const cv::Rect& location) : Result(location) { } + // ObjectSegmentation -vino_core_lib::ObjectSegmentation::ObjectSegmentation(double show_output_thresh) - : show_output_thresh_(show_output_thresh), vino_core_lib::BaseInference() +ObjectSegmentation::ObjectSegmentation(double show_output_thresh) + : show_output_thresh_(show_output_thresh), BaseInference() { } -vino_core_lib::ObjectSegmentation::~ObjectSegmentation() = default; - -void vino_core_lib::ObjectSegmentation::loadNetwork(const std::shared_ptr network) +void ObjectSegmentation::loadNetwork(std::shared_ptr network) { slog::info << "Loading Network: " << network->getModelCategory() << slog::endl; - valid_model_ = network; + valid_model_ = std::dynamic_pointer_cast(network); + setMaxBatchSize(network->getMaxBatchSize()); } +// void ObjectSegmentation::loadNetwork(const std::shared_ptr network) +// { +// slog::info << "Loading Network: " << network->getModelCategory() << slog::endl; +// valid_model_ = network; +// setMaxBatchSize(network->getMaxBatchSize()); +// } + /** * Deprecated! * This function only support OpenVINO version <=2018R5 */ -bool vino_core_lib::ObjectSegmentation::enqueue_for_one_input(const cv::Mat& frame, const cv::Rect& input_frame_loc) +bool ObjectSegmentation::enqueue_for_one_input(const cv::Mat& frame, const cv::Rect& input_frame_loc) { if (width_ == 0 && height_ == 0) { width_ = frame.cols; height_ = frame.rows; } - if (!vino_core_lib::BaseInference::enqueue(frame, input_frame_loc, 1, 0, valid_model_->getInputName())) + if (!BaseInference::enqueue(frame, input_frame_loc, 1, 0, valid_model_->getInputName())) { return false; } @@ -68,7 +77,7 @@ bool vino_core_lib::ObjectSegmentation::enqueue_for_one_input(const cv::Mat& fra return true; } -bool vino_core_lib::ObjectSegmentation::enqueue(const cv::Mat& frame, const cv::Rect& input_frame_loc) +bool ObjectSegmentation::enqueue(const cv::Mat& frame, const cv::Rect& input_frame_loc) { if (width_ == 0 && height_ == 0) { @@ -98,14 +107,14 @@ bool vino_core_lib::ObjectSegmentation::enqueue(const cv::Mat& frame, const cv:: return true; } -bool vino_core_lib::ObjectSegmentation::submitRequest() +bool ObjectSegmentation::submitRequest() { - return vino_core_lib::BaseInference::submitRequest(); + return BaseInference::submitRequest(); } -bool vino_core_lib::ObjectSegmentation::fetchResults() +bool ObjectSegmentation::fetchResults() { - bool can_fetch = vino_core_lib::BaseInference::fetchResults(); + bool can_fetch = BaseInference::fetchResults(); if (!can_fetch) { return false; @@ -202,22 +211,22 @@ bool vino_core_lib::ObjectSegmentation::fetchResults() return true; } -int vino_core_lib::ObjectSegmentation::getResultsLength() const +int ObjectSegmentation::getResultsLength() const { return static_cast(results_.size()); } -const vino_core_lib::Result* vino_core_lib::ObjectSegmentation::getLocationResult(int idx) const +const Result* ObjectSegmentation::getLocationResult(int idx) const { return &(results_[idx]); } -const std::string vino_core_lib::ObjectSegmentation::getName() const +const std::string ObjectSegmentation::getName() const { return valid_model_->getModelCategory(); } -void vino_core_lib::ObjectSegmentation::observeOutput(const std::shared_ptr& output) +void ObjectSegmentation::observeOutput(const std::shared_ptr& output) { if (output != nullptr) { @@ -226,7 +235,7 @@ void vino_core_lib::ObjectSegmentation::observeOutput(const std::shared_ptr -vino_core_lib::ObjectSegmentation::getFilteredROIs(const std::string filter_conditions) const +ObjectSegmentation::getFilteredROIs(const std::string filter_conditions) const { if (!filter_conditions.empty()) { @@ -240,3 +249,6 @@ vino_core_lib::ObjectSegmentation::getFilteredROIs(const std::string filter_cond } return filtered_rois; } + +using namespace vino_core_lib; +REG_INFERENCE(ObjectSegmentation, "ObjectSegmentation"); diff --git a/vino_core_lib/src/inferences/person_attribs_detection.cpp b/vino_core_lib/src/inferences/person_attribs_detection.cpp index 46728e29..df81de6d 100644 --- a/vino_core_lib/src/inferences/person_attribs_detection.cpp +++ b/vino_core_lib/src/inferences/person_attribs_detection.cpp @@ -24,33 +24,42 @@ #include "vino_core_lib/outputs/base_output.h" #include "vino_core_lib/slog.h" +using namespace vino_core_lib; + // PersonAttribsDetectionResult -vino_core_lib::PersonAttribsDetectionResult::PersonAttribsDetectionResult(const cv::Rect& location) +PersonAttribsDetectionResult::PersonAttribsDetectionResult(const cv::Rect& location) : Result(location) { } // PersonAttribsDetection -vino_core_lib::PersonAttribsDetection::PersonAttribsDetection(double attribs_confidence) - : attribs_confidence_(attribs_confidence), vino_core_lib::BaseInference() +PersonAttribsDetection::PersonAttribsDetection(double attribs_confidence) + : attribs_confidence_(attribs_confidence), BaseInference() { } -vino_core_lib::PersonAttribsDetection::~PersonAttribsDetection() = default; -void vino_core_lib::PersonAttribsDetection::loadNetwork( - const std::shared_ptr network) +void PersonAttribsDetection::loadNetwork(std::shared_ptr network) { - valid_model_ = network; + slog::info << "Loading Network: " << network->getModelCategory() << slog::endl; + valid_model_ = std::dynamic_pointer_cast(network); + setMaxBatchSize(network->getMaxBatchSize()); } -bool vino_core_lib::PersonAttribsDetection::enqueue(const cv::Mat& frame, const cv::Rect& input_frame_loc) +// void PersonAttribsDetection::loadNetwork( +// const std::shared_ptr network) +// { +// valid_model_ = network; +// setMaxBatchSize(network->getMaxBatchSize()); +// } + +bool PersonAttribsDetection::enqueue(const cv::Mat& frame, const cv::Rect& input_frame_loc) { if (getEnqueuedNum() == 0) { results_.clear(); } - if (!vino_core_lib::BaseInference::enqueue(frame, input_frame_loc, 1, 0, valid_model_->getInputName())) + if (!BaseInference::enqueue(frame, input_frame_loc, 1, 0, valid_model_->getInputName())) { return false; } @@ -59,14 +68,14 @@ bool vino_core_lib::PersonAttribsDetection::enqueue(const cv::Mat& frame, const return true; } -bool vino_core_lib::PersonAttribsDetection::submitRequest() +bool PersonAttribsDetection::submitRequest() { - return vino_core_lib::BaseInference::submitRequest(); + return BaseInference::submitRequest(); } /* -bool vino_core_lib::PersonAttribsDetection::fetchResults() +bool PersonAttribsDetection::fetchResults() { - bool can_fetch = vino_core_lib::BaseInference::fetchResults(); + bool can_fetch = BaseInference::fetchResults(); if (!can_fetch) {return false;} bool found_result = false; InferenceEngine::InferRequest::Ptr request = getEngine()->getRequest(); @@ -87,9 +96,9 @@ bool vino_core_lib::PersonAttribsDetection::fetchResults() return true; } */ -bool vino_core_lib::PersonAttribsDetection::fetchResults() +bool PersonAttribsDetection::fetchResults() { - bool can_fetch = vino_core_lib::BaseInference::fetchResults(); + bool can_fetch = BaseInference::fetchResults(); if (!can_fetch) { return false; @@ -136,22 +145,22 @@ bool vino_core_lib::PersonAttribsDetection::fetchResults() return true; } -int vino_core_lib::PersonAttribsDetection::getResultsLength() const +int PersonAttribsDetection::getResultsLength() const { return static_cast(results_.size()); } -const vino_core_lib::Result* vino_core_lib::PersonAttribsDetection::getLocationResult(int idx) const +const Result* PersonAttribsDetection::getLocationResult(int idx) const { return &(results_[idx]); } -const std::string vino_core_lib::PersonAttribsDetection::getName() const +const std::string PersonAttribsDetection::getName() const { return valid_model_->getModelCategory(); } -void vino_core_lib::PersonAttribsDetection::observeOutput(const std::shared_ptr& output) +void PersonAttribsDetection::observeOutput(const std::shared_ptr& output) { if (output != nullptr) { @@ -160,7 +169,7 @@ void vino_core_lib::PersonAttribsDetection::observeOutput(const std::shared_ptr< } const std::vector -vino_core_lib::PersonAttribsDetection::getFilteredROIs(const std::string filter_conditions) const +PersonAttribsDetection::getFilteredROIs(const std::string filter_conditions) const { if (!filter_conditions.empty()) { @@ -174,3 +183,6 @@ vino_core_lib::PersonAttribsDetection::getFilteredROIs(const std::string filter_ } return filtered_rois; } + +using namespace vino_core_lib; +REG_INFERENCE(PersonAttribsDetection, "PersonAttribsDetection"); diff --git a/vino_core_lib/src/inferences/person_reidentification.cpp b/vino_core_lib/src/inferences/person_reidentification.cpp index c18623d5..5d47367b 100644 --- a/vino_core_lib/src/inferences/person_reidentification.cpp +++ b/vino_core_lib/src/inferences/person_reidentification.cpp @@ -24,34 +24,43 @@ #include "vino_core_lib/outputs/base_output.h" #include "vino_core_lib/slog.h" +using namespace vino_core_lib; + // PersonReidentificationResult -vino_core_lib::PersonReidentificationResult::PersonReidentificationResult(const cv::Rect& location) +PersonReidentificationResult::PersonReidentificationResult(const cv::Rect& location) : Result(location) { } // PersonReidentification -vino_core_lib::PersonReidentification::PersonReidentification(double match_thresh) - : vino_core_lib::BaseInference() +PersonReidentification::PersonReidentification(double match_thresh) + : BaseInference() { - person_tracker_ = std::make_shared(1000, match_thresh, 0.3); + person_tracker_ = std::make_shared(1000, match_thresh, 0.3); } -vino_core_lib::PersonReidentification::~PersonReidentification() = default; -void vino_core_lib::PersonReidentification::loadNetwork( - const std::shared_ptr network) +void PersonReidentification::loadNetwork(std::shared_ptr network) { - valid_model_ = network; + slog::info << "Loading Network: " << network->getModelCategory() << slog::endl; + valid_model_ = std::dynamic_pointer_cast(network); + setMaxBatchSize(network->getMaxBatchSize()); } -bool vino_core_lib::PersonReidentification::enqueue(const cv::Mat& frame, const cv::Rect& input_frame_loc) +// void PersonReidentification::loadNetwork( +// const std::shared_ptr network) +// { +// valid_model_ = network; +// setMaxBatchSize(network->getMaxBatchSize()); +// } + +bool PersonReidentification::enqueue(const cv::Mat& frame, const cv::Rect& input_frame_loc) { if (getEnqueuedNum() == 0) { results_.clear(); } - if (!vino_core_lib::BaseInference::enqueue(frame, input_frame_loc, 1, 0, valid_model_->getInputName())) + if (!BaseInference::enqueue(frame, input_frame_loc, 1, 0, valid_model_->getInputName())) { return false; } @@ -60,14 +69,14 @@ bool vino_core_lib::PersonReidentification::enqueue(const cv::Mat& frame, const return true; } -bool vino_core_lib::PersonReidentification::submitRequest() +bool PersonReidentification::submitRequest() { - return vino_core_lib::BaseInference::submitRequest(); + return BaseInference::submitRequest(); } -bool vino_core_lib::PersonReidentification::fetchResults() +bool PersonReidentification::fetchResults() { - bool can_fetch = vino_core_lib::BaseInference::fetchResults(); + bool can_fetch = BaseInference::fetchResults(); if (!can_fetch) { return false; @@ -90,22 +99,22 @@ bool vino_core_lib::PersonReidentification::fetchResults() return true; } -int vino_core_lib::PersonReidentification::getResultsLength() const +int PersonReidentification::getResultsLength() const { return static_cast(results_.size()); } -const vino_core_lib::Result* vino_core_lib::PersonReidentification::getLocationResult(int idx) const +const Result* PersonReidentification::getLocationResult(int idx) const { return &(results_[idx]); } -const std::string vino_core_lib::PersonReidentification::getName() const +const std::string PersonReidentification::getName() const { return valid_model_->getModelCategory(); } -void vino_core_lib::PersonReidentification::observeOutput(const std::shared_ptr& output) +void PersonReidentification::observeOutput(const std::shared_ptr& output) { if (output != nullptr) { @@ -114,7 +123,7 @@ void vino_core_lib::PersonReidentification::observeOutput(const std::shared_ptr< } const std::vector -vino_core_lib::PersonReidentification::getFilteredROIs(const std::string filter_conditions) const +PersonReidentification::getFilteredROIs(const std::string filter_conditions) const { if (!filter_conditions.empty()) { @@ -128,3 +137,6 @@ vino_core_lib::PersonReidentification::getFilteredROIs(const std::string filter_ } return filtered_rois; } + +using namespace vino_core_lib; +REG_INFERENCE(PersonReidentification, "PersonReidentification"); diff --git a/vino_core_lib/src/inferences/vehicle_attribs_detection.cpp b/vino_core_lib/src/inferences/vehicle_attribs_detection.cpp index 13e6d918..72784a85 100644 --- a/vino_core_lib/src/inferences/vehicle_attribs_detection.cpp +++ b/vino_core_lib/src/inferences/vehicle_attribs_detection.cpp @@ -24,32 +24,37 @@ #include "vino_core_lib/outputs/base_output.h" #include "vino_core_lib/slog.h" +using namespace vino_core_lib; + // VehicleAttribsDetectionResult -vino_core_lib::VehicleAttribsDetectionResult::VehicleAttribsDetectionResult(const cv::Rect& location) +VehicleAttribsDetectionResult::VehicleAttribsDetectionResult(const cv::Rect& location) : Result(location) { } -// VehicleAttribsDetection -vino_core_lib::VehicleAttribsDetection::VehicleAttribsDetection() : vino_core_lib::BaseInference() +void VehicleAttribsDetection::loadNetwork(std::shared_ptr network) { -} + slog::info << "Loading Network: " << network->getModelCategory() << slog::endl; + valid_model_ = std::dynamic_pointer_cast(network); -vino_core_lib::VehicleAttribsDetection::~VehicleAttribsDetection() = default; -void vino_core_lib::VehicleAttribsDetection::loadNetwork( - const std::shared_ptr network) -{ - valid_model_ = network; setMaxBatchSize(network->getMaxBatchSize()); } -bool vino_core_lib::VehicleAttribsDetection::enqueue(const cv::Mat& frame, const cv::Rect& input_frame_loc) +// VehicleAttribsDetection +// void VehicleAttribsDetection::loadNetwork( +// const std::shared_ptr network) +// { +// valid_model_ = network; +// setMaxBatchSize(network->getMaxBatchSize()); +// } + +bool VehicleAttribsDetection::enqueue(const cv::Mat& frame, const cv::Rect& input_frame_loc) { if (getEnqueuedNum() == 0) { results_.clear(); } - if (!vino_core_lib::BaseInference::enqueue(frame, input_frame_loc, 1, 0, valid_model_->getInputName())) + if (!BaseInference::enqueue(frame, input_frame_loc, 1, 0, valid_model_->getInputName())) { return false; } @@ -58,14 +63,14 @@ bool vino_core_lib::VehicleAttribsDetection::enqueue(const cv::Mat& frame, const return true; } -bool vino_core_lib::VehicleAttribsDetection::submitRequest() +bool VehicleAttribsDetection::submitRequest() { - return vino_core_lib::BaseInference::submitRequest(); + return BaseInference::submitRequest(); } -bool vino_core_lib::VehicleAttribsDetection::fetchResults() +bool VehicleAttribsDetection::fetchResults() { - bool can_fetch = vino_core_lib::BaseInference::fetchResults(); + bool can_fetch = BaseInference::fetchResults(); if (!can_fetch) { return false; @@ -95,22 +100,22 @@ bool vino_core_lib::VehicleAttribsDetection::fetchResults() return true; } -int vino_core_lib::VehicleAttribsDetection::getResultsLength() const +int VehicleAttribsDetection::getResultsLength() const { return static_cast(results_.size()); } -const vino_core_lib::Result* vino_core_lib::VehicleAttribsDetection::getLocationResult(int idx) const +const Result* VehicleAttribsDetection::getLocationResult(int idx) const { return &(results_[idx]); } -const std::string vino_core_lib::VehicleAttribsDetection::getName() const +const std::string VehicleAttribsDetection::getName() const { return valid_model_->getModelCategory(); } -void vino_core_lib::VehicleAttribsDetection::observeOutput(const std::shared_ptr& output) +void VehicleAttribsDetection::observeOutput(const std::shared_ptr& output) { if (output != nullptr) { @@ -119,7 +124,7 @@ void vino_core_lib::VehicleAttribsDetection::observeOutput(const std::shared_ptr } const std::vector -vino_core_lib::VehicleAttribsDetection::getFilteredROIs(const std::string filter_conditions) const +VehicleAttribsDetection::getFilteredROIs(const std::string filter_conditions) const { if (!filter_conditions.empty()) { @@ -133,3 +138,6 @@ vino_core_lib::VehicleAttribsDetection::getFilteredROIs(const std::string filter } return filtered_rois; } + +using namespace vino_core_lib; +REG_INFERENCE(VehicleAttribsDetection, "VehicleAttribsDetection"); diff --git a/vino_core_lib/src/inputs/image_input.cpp b/vino_core_lib/src/inputs/image_input.cpp index c802ce86..2cba4d55 100644 --- a/vino_core_lib/src/inputs/image_input.cpp +++ b/vino_core_lib/src/inputs/image_input.cpp @@ -23,12 +23,6 @@ #include "vino_core_lib/slog.h" #include -// Image -Input::Image::Image(const std::string& file) -{ - file_.assign(file); -} - bool Input::Image::initialize() { image_ = cv::imread(file_); @@ -65,3 +59,5 @@ void Input::Image::config(const Input::Config& config) slog::info << "Image Input device was reinitialized with new file:" << config.path.c_str() << slog::endl; } } + +REG_INPUT(Image, "image"); \ No newline at end of file diff --git a/vino_core_lib/src/inputs/image_topic.cpp b/vino_core_lib/src/inputs/image_topic.cpp index d5aedef9..6a212586 100644 --- a/vino_core_lib/src/inputs/image_topic.cpp +++ b/vino_core_lib/src/inputs/image_topic.cpp @@ -68,3 +68,5 @@ bool Input::ImageTopic::read(cv::Mat* frame) image_count_.decreaseCounter(); return true; } + +REG_INPUT(ImageTopic, "ImageTopic"); \ No newline at end of file diff --git a/vino_core_lib/src/inputs/ip_camera.cpp b/vino_core_lib/src/inputs/ip_camera.cpp index d4977f5f..05402d79 100644 --- a/vino_core_lib/src/inputs/ip_camera.cpp +++ b/vino_core_lib/src/inputs/ip_camera.cpp @@ -50,4 +50,6 @@ bool Input::IpCamera::read(cv::Mat * frame) cv::resize(*frame, *frame, cv::Size(getWidth(), getHeight()), 0, 0, CV_INTER_AREA); } return retrieved; -} \ No newline at end of file +} + +REG_INPUT(IpCamera, "IpCamera"); \ No newline at end of file diff --git a/vino_core_lib/src/inputs/realsense_camera.cpp b/vino_core_lib/src/inputs/realsense_camera.cpp index 9bd7c0d1..76a7e67e 100644 --- a/vino_core_lib/src/inputs/realsense_camera.cpp +++ b/vino_core_lib/src/inputs/realsense_camera.cpp @@ -106,3 +106,5 @@ void Input::RealSenseCamera::bypassFewFramesOnceInited() } first_read_ = false; } + +REG_INPUT(RealSenseCamera, "RealSenseCamera"); \ No newline at end of file diff --git a/vino_core_lib/src/inputs/standard_camera.cpp b/vino_core_lib/src/inputs/standard_camera.cpp index 426badf4..b8b92d16 100644 --- a/vino_core_lib/src/inputs/standard_camera.cpp +++ b/vino_core_lib/src/inputs/standard_camera.cpp @@ -75,3 +75,5 @@ int Input::StandardCamera::getCameraId() camera_id_ = STANDARD_CAMERA_COUNT; return STANDARD_CAMERA_COUNT; } + +REG_INPUT(StandardCamera, "StandardCamera"); diff --git a/vino_core_lib/src/inputs/video_input.cpp b/vino_core_lib/src/inputs/video_input.cpp index a4f88ee7..06748422 100644 --- a/vino_core_lib/src/inputs/video_input.cpp +++ b/vino_core_lib/src/inputs/video_input.cpp @@ -24,12 +24,6 @@ #include "vino_core_lib/inputs/video_input.h" #include "vino_core_lib/slog.h" -// Video -Input::Video::Video(const std::string& video) -{ - video_.assign(video); -} - bool Input::Video::initialize() { setInitStatus(cap.open(video_)); @@ -61,3 +55,5 @@ bool Input::Video::read(cv::Mat* frame) // setHeader("video_frame"); return cap.retrieve(*frame); } + +REG_INPUT(Video, "Video"); \ No newline at end of file diff --git a/vino_core_lib/src/models/age_gender_detection_model.cpp b/vino_core_lib/src/models/age_gender_detection_model.cpp index 6ef493b9..8ff9d3f5 100644 --- a/vino_core_lib/src/models/age_gender_detection_model.cpp +++ b/vino_core_lib/src/models/age_gender_detection_model.cpp @@ -100,3 +100,5 @@ const std::string Models::AgeGenderDetectionModel::getModelCategory() const { return "Age Gender Detection"; } + +REG_MODEL(AgeGenderDetectionModel, "AgeGenderRecognition"); \ No newline at end of file diff --git a/vino_core_lib/src/models/base_model.cpp b/vino_core_lib/src/models/base_model.cpp index 223eccdc..42d90e46 100644 --- a/vino_core_lib/src/models/base_model.cpp +++ b/vino_core_lib/src/models/base_model.cpp @@ -40,6 +40,27 @@ Models::BaseModel::BaseModel(const std::string& label_loc, const std::string& mo ///net_reader_ = std::make_shared(); } +void Models::BaseModel::init(const std::string& label_loc, const std::string& model_loc, int max_batch_size) +{ + label_loc_ = label_loc; + model_loc_ = model_loc; + max_batch_size_ = max_batch_size; + attr_.model_name = model_loc; + // TODO + // ModelAttribute(model_loc); + + slog::debug << "model location: " << model_loc_ << slog::endl; + + if (model_loc.empty()) + { + throw std::logic_error("model file name is empty!"); + } + + modelInit(); + + ///net_reader_ = std::make_shared(); +} + void Models::BaseModel::modelInit() { slog::info << "Loading network files: " << model_loc_ << slog::endl; diff --git a/vino_core_lib/src/models/emotion_detection_model.cpp b/vino_core_lib/src/models/emotion_detection_model.cpp index 2a556681..0d4125d5 100644 --- a/vino_core_lib/src/models/emotion_detection_model.cpp +++ b/vino_core_lib/src/models/emotion_detection_model.cpp @@ -79,3 +79,5 @@ const std::string Models::EmotionDetectionModel::getModelCategory() const { return "Emotions Detection"; } + +REG_MODEL(EmotionDetectionModel, "EmotionRecognition"); \ No newline at end of file diff --git a/vino_core_lib/src/models/face_detection_model.cpp b/vino_core_lib/src/models/face_detection_model.cpp index b1d4f1b5..075334bf 100644 --- a/vino_core_lib/src/models/face_detection_model.cpp +++ b/vino_core_lib/src/models/face_detection_model.cpp @@ -31,70 +31,185 @@ Models::FaceDetectionModel::FaceDetectionModel(const std::string& label_loc, con { } -#if 0 -void Models::FaceDetectionModel::checkLayerProperty( - const InferenceEngine::CNNNetwork& net_reader) +const std::string Models::FaceDetectionModel::getModelCategory() const { - slog::info << "Checking Face Detection inputs" << slog::endl; - InferenceEngine::InputsDataMap input_info_map(net_reader.getInputsInfo()); - if (input_info_map.size() != 1) { - slog::err << "Face Detection network should have only one input, but we got " - << std::to_string(input_info_map.size()) << "inputs" << slog::endl; - throw std::logic_error("Face Detection network should have only one input"); + return "Face Detection"; +} + +bool Models::FaceDetectionModel::enqueue(const std::shared_ptr& engine, const cv::Mat& frame, + const cv::Rect& input_frame_loc) +{ + if (!this->matToBlob(frame, input_frame_loc, 1, 0, engine)) + { + return false; } - slog::info << "Checking Face Detection outputs" << slog::endl; - InferenceEngine::OutputsDataMap output_info_map(net_reader.getOutputsInfo()); - slog::info << "Checking Face Detection outputs ..." << slog::endl; - if (output_info_map.size() != 1) { - throw std::logic_error("This sample accepts networks having only one output"); + setFrameSize(frame.cols, frame.rows); + return true; +} + +bool Models::FaceDetectionModel::matToBlob(const cv::Mat& orig_image, const cv::Rect&, float scale_factor, + int batch_index, const std::shared_ptr& engine) +{ + if (engine == nullptr) + { + slog::err << "A frame is trying to be enqueued in a NULL Engine." << slog::endl; + return false; + } + + std::string input_name = getInputName(); + slog::debug << "add input image to blob: " << input_name << slog::endl; + InferenceEngine::Blob::Ptr input_blob = engine->getRequest()->GetBlob(input_name); + + InferenceEngine::SizeVector blob_size = input_blob->getTensorDesc().getDims(); + const int width = blob_size[3]; + const int height = blob_size[2]; + const int channels = blob_size[1]; + u_int8_t* blob_data = input_blob->buffer().as(); + + cv::Mat resized_image(orig_image); + if (width != orig_image.size().width || height != orig_image.size().height) + { + cv::resize(orig_image, resized_image, cv::Size(width, height)); + } + int batchOffset = batch_index * width * height * channels; + + for (int c = 0; c < channels; c++) + { + for (int h = 0; h < height; h++) + { + for (int w = 0; w < width; w++) + { + blob_data[batchOffset + c * width * height + h * width + w] = + resized_image.at(h, w)[c] * scale_factor; + } + } } - InferenceEngine::DataPtr & output_data_ptr = output_info_map.begin()->second; - output_ = output_info_map.begin()->first; - slog::info << "Checking Object Detection output ... Name=" << output_ << slog::endl; - - const InferenceEngine::CNNLayerPtr output_layer = - net_reader->getNetwork().getLayerByName(output_.c_str()); - // output layer should have attribute called num_classes - slog::info << "Checking Object Detection num_classes" << slog::endl; - if (output_layer->params.find("num_classes") == output_layer->params.end()) { - throw std::logic_error("Object Detection network output layer (" + output_ + - ") should have num_classes integer attribute"); + + slog::debug << "Convert input image to blob: DONE!" << slog::endl; + return true; +} + +bool Models::FaceDetectionModel::fetchResults(const std::shared_ptr& engine, + std::vector& results, + const float& confidence_thresh, const bool& enable_roi_constraint) +{ + slog::debug << "fetching Infer Resulsts from the given Face model" << slog::endl; + if (engine == nullptr) + { + slog::err << "Trying to fetch results from Engines." << slog::endl; + return false; } - // class number should be equal to size of label vector - // if network has default "background" class, fake is used - const int num_classes = output_layer->GetParamAsInt("num_classes"); - - slog::info << "Checking Object Detection output ... num_classes=" << num_classes << slog::endl; - if (getLabels().size() != num_classes) { - if (getLabels().size() == (num_classes - 1)) { - getLabels().insert(getLabels().begin(), "fake"); - } else { - getLabels().clear(); + + slog::debug << "Fetching Detection Results ..." << slog::endl; + InferenceEngine::InferRequest::Ptr request = engine->getRequest(); + std::string output = getOutputName(); + const float* detections = request->GetBlob(output)->buffer().as(); + + slog::debug << "Analyzing Detection results..." << slog::endl; + auto max_proposal_count = getMaxProposalCount(); + auto object_size = getObjectSize(); + slog::debug << "MaxProprosalCount=" << max_proposal_count << ", ObjectSize=" << object_size << slog::endl; + for (int i = 0; i < max_proposal_count; i++) + { + float image_id = detections[i * object_size + 0]; + if (image_id < 0) + { + // slog::info << "Found objects: " << i << "|" << results.size() << slog::endl; + break; + } + + cv::Rect r; + auto label_num = static_cast(detections[i * object_size + 1]); + std::vector& labels = getLabels(); + auto frame_size = getFrameSize(); + r.x = static_cast(detections[i * object_size + 3] * frame_size.width); + r.y = static_cast(detections[i * object_size + 4] * frame_size.height); + r.width = static_cast(detections[i * object_size + 5] * frame_size.width - r.x); + r.height = static_cast(detections[i * object_size + 6] * frame_size.height - r.y); + + if (enable_roi_constraint) + { + r &= cv::Rect(0, 0, frame_size.width, frame_size.height); + } + + vino_core_lib::FaceDetectionResult result(r); + std::string label = + label_num < labels.size() ? labels[label_num] : std::string("label #") + std::to_string(label_num); + result.setLabel(label); + float confidence = detections[i * object_size + 2]; + if (confidence <= confidence_thresh /* || r.x == 0 */) + { // why r.x needs to be checked? + continue; } + result.setConfidence(confidence); + + results.emplace_back(result); + } + + return true; +} + +bool Models::FaceDetectionModel::updateLayerProperty(InferenceEngine::CNNNetwork& net_reader) +{ + slog::info << "Checking INPUTs for model " << getModelName() << slog::endl; + + InferenceEngine::InputsDataMap input_info_map(net_reader.getInputsInfo()); + if (input_info_map.size() != 1) + { + slog::warn << "This model seems not SSDNet-like, SSDnet has only one input, but we got " + << std::to_string(input_info_map.size()) << "inputs" << slog::endl; + return false; } + + InferenceEngine::InputInfo::Ptr input_info = input_info_map.begin()->second; + input_info->setPrecision(InferenceEngine::Precision::U8); + addInputInfo("input", input_info_map.begin()->first); + + const InferenceEngine::SizeVector input_dims = input_info->getTensorDesc().getDims(); + setInputHeight(input_dims[2]); + setInputWidth(input_dims[3]); + + slog::info << "Checking OUTPUTs for model " << getModelName() << slog::endl; + InferenceEngine::OutputsDataMap output_info_map(net_reader.getOutputsInfo()); + if (output_info_map.size() != 1) + { + slog::warn << "This model seems not SSDNet-like! We got " << std::to_string(output_info_map.size()) + << "outputs, but SSDnet has only one." << slog::endl; + return false; + } + InferenceEngine::DataPtr& output_data_ptr = output_info_map.begin()->second; + addOutputInfo("output", output_info_map.begin()->first); + slog::info << "Checking Object Detection output ... Name=" << output_info_map.begin()->first << slog::endl; + output_data_ptr->setPrecision(InferenceEngine::Precision::FP32); + + // last dimension of output layer should be 7 const InferenceEngine::SizeVector output_dims = output_data_ptr->getTensorDesc().getDims(); - max_proposal_count_ = static_cast(output_dims[2]); - slog::info << "max proposal count is: " << max_proposal_count_ << slog::endl; + setMaxProposalCount(static_cast(output_dims[2])); + slog::info << "max proposal count is: " << getMaxProposalCount() << slog::endl; auto object_size = static_cast(output_dims[3]); - if (object_size != 7) { - throw std::logic_error("Object Detection network output layer should have 7 as a last " - "dimension"); + if (object_size != 7) + { + slog::warn << "This model is NOT SSDNet-like, whose output data for each detected object" + << "should have 7 dimensions, but was " << std::to_string(object_size) << slog::endl; + return false; } setObjectSize(object_size); - if (output_dims.size() != 4) { - throw std::logic_error("Object Detection network output dimensions not compatible shoulld be " - "4, " - "but was " + - std::to_string(output_dims.size())); + if (output_dims.size() != 4) + { + slog::warn << "This model is not SSDNet-like, output dimensions shoulld be 4, but was" + << std::to_string(output_dims.size()) << slog::endl; + return false; } -} -#endif -const std::string Models::FaceDetectionModel::getModelCategory() const -{ - return "Face Detection"; + printAttribute(); + slog::info << "This model is SSDNet-like, Layer Property updated!" << slog::endl; + return true; } + +using namespace Models; + +REG_MODEL(FaceDetectionModel, "FaceDetection"); diff --git a/vino_core_lib/src/models/face_reidentification_model.cpp b/vino_core_lib/src/models/face_reidentification_model.cpp index bcf2c399..dc067dcf 100644 --- a/vino_core_lib/src/models/face_reidentification_model.cpp +++ b/vino_core_lib/src/models/face_reidentification_model.cpp @@ -51,3 +51,5 @@ const std::string Models::FaceReidentificationModel::getModelCategory() const { return "Face Reidentification"; } + +REG_MODEL(FaceReidentificationModel, "FaceReidentification"); diff --git a/vino_core_lib/src/models/head_pose_detection_model.cpp b/vino_core_lib/src/models/head_pose_detection_model.cpp index aee4f956..edd35dcb 100644 --- a/vino_core_lib/src/models/head_pose_detection_model.cpp +++ b/vino_core_lib/src/models/head_pose_detection_model.cpp @@ -76,3 +76,5 @@ const std::string Models::HeadPoseDetectionModel::getModelCategory() const { return "Head Pose Network"; } + +REG_MODEL(HeadPoseDetectionModel, "HeadPoseEstimation"); diff --git a/vino_core_lib/src/models/landmarks_detection_model.cpp b/vino_core_lib/src/models/landmarks_detection_model.cpp index d0c2687b..98fcd565 100644 --- a/vino_core_lib/src/models/landmarks_detection_model.cpp +++ b/vino_core_lib/src/models/landmarks_detection_model.cpp @@ -66,3 +66,5 @@ const std::string Models::LandmarksDetectionModel::getModelCategory() const { return "Landmarks Detection"; } + +REG_MODEL(LandmarksDetectionModel, "LandmarksDetection"); diff --git a/vino_core_lib/src/models/license_plate_detection_model.cpp b/vino_core_lib/src/models/license_plate_detection_model.cpp index 7a7f2e74..4d2911bb 100644 --- a/vino_core_lib/src/models/license_plate_detection_model.cpp +++ b/vino_core_lib/src/models/license_plate_detection_model.cpp @@ -60,3 +60,5 @@ const std::string Models::LicensePlateDetectionModel::getModelCategory() const { return "Vehicle Attributes Detection"; } + +REG_MODEL(LicensePlateDetectionModel, "LicensePlateDetection"); diff --git a/vino_core_lib/src/models/object_detection_ssd_model.cpp b/vino_core_lib/src/models/object_detection_ssd_model.cpp index 582882d9..d52c448f 100644 --- a/vino_core_lib/src/models/object_detection_ssd_model.cpp +++ b/vino_core_lib/src/models/object_detection_ssd_model.cpp @@ -233,3 +233,5 @@ bool Models::ObjectDetectionSSDModel::updateLayerProperty(InferenceEngine::CNNNe slog::info << "This model is SSDNet-like, Layer Property updated!" << slog::endl; return true; } + +REG_MODEL(ObjectDetectionSSDModel, "ObjectDetection_SSD"); diff --git a/vino_core_lib/src/models/object_detection_yolov2voc_model.cpp b/vino_core_lib/src/models/object_detection_yolov2voc_model.cpp index 5b712d13..6eeb1e21 100644 --- a/vino_core_lib/src/models/object_detection_yolov2voc_model.cpp +++ b/vino_core_lib/src/models/object_detection_yolov2voc_model.cpp @@ -22,11 +22,11 @@ #include "vino_core_lib/slog.h" // Validated Object Detection Network Models::ObjectDetectionYolov2Model::ObjectDetectionYolov2Model(const std::string& model_loc, int max_batch_size) - : ObjectDetectionModel(model_loc, max_batch_size) + : ObjectDetectionModel("", model_loc, max_batch_size) { } -bool Models::ObjectDetectionYolov2Model::updateLayerProperty(const InferenceEngine::CNNNetwork& net_reader) +bool Models::ObjectDetectionYolov2Model::updateLayerProperty(InferenceEngine::CNNNetwork& net_reader) { slog::info << "Checking INPUTs for model " << getModelName() << slog::endl; @@ -215,6 +215,9 @@ bool Models::ObjectDetectionYolov2Model::fetchResults(const std::shared_ptr& results, const float& confidence_thresh, const bool& enable_roi_constraint) { +#if 1 + return true; +#else try { if (engine == nullptr) @@ -349,6 +352,7 @@ bool Models::ObjectDetectionYolov2Model::fetchResults(const std::shared_ptr +#include "vino_core_lib/models/object_detection_yolov5_model.h" +#include "vino_core_lib/slog.h" + +Models::ObjectDetectionYolov5Model::ObjectDetectionYolov5Model(const std::string& model_loc, int max_batch_size) + : ObjectDetectionModel("", model_loc, max_batch_size) +{ +} + +bool Models::ObjectDetectionYolov5Model::updateLayerProperty(InferenceEngine::CNNNetwork& net_reader) +{ + slog::info << "Checking INPUTS for Model" << getModelName() << slog::endl; + + auto network = net_reader; + + InferenceEngine::InputsDataMap input_info_map(net_reader.getInputsInfo()); + + if(input_info_map.size() != 1) + { + slog::warn << "This model seems not YoloV5-like, YoloV5 has only one input, but we got " + << std::to_string(input_info_map.size()) << "inputs" << slog::endl; + return false; + } + + input_info_ = input_info_map.begin()->second; + input_info_->setPrecision(InferenceEngine::Precision::FP32); + input_info_->getInputData()->setLayout(InferenceEngine::Layout::NCHW); + + addInputInfo("input", input_info_map.begin()->first); + + const InferenceEngine::SizeVector input_dims = input_info_->getTensorDesc().getDims(); + setInputHeight(input_dims[2]); + setInputWidth(input_dims[3]); + + InferenceEngine::ICNNNetwork::InputShapes inputShapes = network.getInputShapes(); + InferenceEngine::SizeVector& in_size_vector = inputShapes.begin()->second; + + slog::debug << "input size" << inputShapes.size() << slog::endl; + if (inputShapes.size() != 1) + { + slog::warn << "This inference sample should have only one input, but we got" << std::to_string(inputShapes.size()) + << "inputs" << slog::endl; + return false; + } + + network.reshape(inputShapes); + + // output configure + outputs_data_map_ = network.getOutputsInfo(); + + // if (outputs_data_map_.size() != 1) + // { + // slog::warn << "This inference sample should have only one output, but we got" + // << std::to_string(outputs_data_map_.size()) << "outputs" << slog::endl; + // return false; + // } + + addOutputInfo("output", outputs_data_map_.begin()->first); + + for(auto &output : outputs_data_map_) + { + auto output_data_ptr = output.second; + output_data_ptr->setPrecision(InferenceEngine::Precision::FP32); + + const InferenceEngine::SizeVector output_dims = output_data_ptr->getTensorDesc().getDims(); + setMaxProposalCount(static_cast(output_dims[2])); + slog::info << "max proposal count is: " << getMaxProposalCount() << slog::endl; + + auto object_size = static_cast(output_dims[3]); + // if (object_size != 7) + // { + // slog::warn << "This model is NOT SSDNet-like, whose output data for each detected object" + // << "should have 7 dimensions, but was " << std::to_string(object_size) << slog::endl; + // return false; + // } + setObjectSize(object_size); + + // if (output_dims.size() != 4) + // { + // slog::warn << "This model is not SSDNet-like, output dimensions shoulld be 4, but was" + // << std::to_string(output_dims.size()) << slog::endl; + // return false; + // } + + // printAttribute(); + } + + // InferenceEngine::DataPtr& output_data_ptr = outputs_data_map_.begin()->second; + // output_data_ptr->setPrecision(InferenceEngine::Precision::FP32); + slog::info << "Checking YoloV5 Object Detection output ... Name=" << outputs_data_map_.begin()->first << slog::endl; + + // TODO set size + + printAttribute(); + slog::info << "This model is Yolov5-like, Layer Property updated!" << slog::endl; + + return true; +} + +const std::string Models::ObjectDetectionYolov5Model::getModelCategory() const +{ + return "Object Detection YoloV5"; +} + +bool Models::ObjectDetectionYolov5Model::enqueue(const std::shared_ptr& engine, const cv::Mat& frame, + const cv::Rect& input_frame_loc) +{ + setFrameSize(frame.cols, frame.rows); // demo picture is 640 * 640 + + if (!matToBlob(frame, input_frame_loc, 1, 0, engine)) + { + return false; + } + + return true; +} + +bool Models::ObjectDetectionYolov5Model::matToBlob(const cv::Mat& orig_image, const cv::Rect&, float scale_factor, + int batch_index, const std::shared_ptr& engine) +{ + if (engine == nullptr) + { + slog::err << "ObjectDetectionYolov5Model: A frame is trying to be enqueued in a NULL Engine." << slog::endl; + return false; + } + + std::string input_name = getInputName(); + slog::debug << "ObjectDetectionYolov5Model: add input image to blob: " << input_name << slog::endl; + InferenceEngine::Blob::Ptr input_blob = engine->getRequest()->GetBlob(input_name); + + InferenceEngine::LockedMemory blobMapped = InferenceEngine::as(input_blob)->wmap(); + + auto resized_image(orig_image); + + InferenceEngine::SizeVector blob_size = input_blob->getTensorDesc().getDims(); + const int width = blob_size[3]; + const int height = blob_size[2]; + const int channels = blob_size[1]; + + if(width != orig_image.size().width || height != orig_image.size().height) + { + cv::resize(orig_image, resized_image, cv::Size(width, height)); + } + + float* blob_data = blobMapped.as(); + size_t img_size = width*height; + + //nchw + for(size_t row =0; row < height; row++) + { + for(size_t col=0; col < width; col++) + { + for(size_t ch =0; ch < channels; ch++) + { + blob_data[img_size*ch + row*width + col] = float(resized_image.at(row,col)[ch])/255.0f; + } + } + } + + slog::debug << "Convert input image to blob: DONE!" << slog::endl; + + return true; +} + +bool Models::ObjectDetectionYolov5Model::fetchResults(const std::shared_ptr& engine, + std::vector& results, + const float& confidence_thresh, const bool& enable_roi_constraint) +{ + // TODO xiansen + auto confidence_thresh_ = 0.1; + slog::debug << "fetching Infer Resulsts from the given Yolov5 model" << slog::endl; + + if (engine == nullptr) + { + slog::err << "Trying to fetch Yolov5 results from Engines." << slog::endl; + return false; + } + + slog::debug << "Fetching Yolov5 Detection Results ..." << slog::endl; + + InferenceEngine::InferRequest::Ptr request = engine->getRequest(); + std::string output = getOutputName(); + + std::vector origin_rect; + std::vector origin_rect_cof; + + int s[3] = {80,40,20}; + int index=0; + + for (auto &output : outputs_data_map_) + { + auto output_name = output.first; + InferenceEngine::Blob::Ptr blob = request->GetBlob(output_name); + parseYolov5(blob,s[index], confidence_thresh_ ,origin_rect, origin_rect_cof); + ++index; + } + + // TODO xiansen nms_area_threshold + double nms_area_threshold = 0.5; + + //后处理获得最终检测结果 + std::vector final_id; + cv::dnn::NMSBoxes(origin_rect, origin_rect_cof, + confidence_thresh_ ,nms_area_threshold,final_id); + + // 根据final_id获取最终结果 + for(int i=0;i +std::ostream & operator<<(std::ostream &os, const std::vector v) +{ + os << "{"; + + for(auto it: v) + { + os << it << " ,"; + } + + os << "}\n"; + + return os; +} + +//注意此处的阈值是框和物体prob乘积的阈值 +bool Models::ObjectDetectionYolov5Model::parseYolov5(const InferenceEngine::Blob::Ptr &blob, int net_grid, float cof_threshold, + std::vector& o_rect, std::vector& o_rect_cof) +{ + std::vector anchors = getAnchors(net_grid); + InferenceEngine::LockedMemory blobMapped = InferenceEngine::as(blob)->rmap(); + const float *output_blob = blobMapped.as(); + //80个类是85,一个类是6,n个类是n+5 + //int item_size = 6; + int item_size = 85; + size_t anchor_n = 3; + for(int n=0;n max_prob){ + max_prob = tp; + idx = t; + } + } + float cof = box_prob * max_prob; + //对于边框置信度小于阈值的边框,不关心其他数值,不进行计算减少计算量 + if(cof < cof_threshold) + continue; + + x = (sigmoid(x)*2 - 0.5 + j)*640.0f/net_grid; + y = (sigmoid(y)*2 - 0.5 + i)*640.0f/net_grid; + w = pow(sigmoid(w)*2,2) * anchors[n*2]; + h = pow(sigmoid(h)*2,2) * anchors[n*2 + 1]; + + double r_x = x - w/2; + double r_y = y - h/2; + cv::Rect rect(round(r_x),round(r_y),round(w),round(h)); + o_rect.push_back(rect); + o_rect_cof.push_back(cof); + } + } + } + + if(o_rect.size() == 0) + { + return false; + } + + return true; +} + +//以下为工具函数 +// int Models::ObjectDetectionYolov5Model::getEntryIndex(int side, int lcoords, int lclasses, int location, int entry) +// { +// int n = location / (side * side); +// int loc = location % (side * side); +// return n * side * side * (lcoords + lclasses + 1) + entry * side * side + loc; +// } + +double Models::ObjectDetectionYolov5Model::sigmoid(double x) +{ + return (1 / (1 + exp(-x))); +} + +std::vector Models::ObjectDetectionYolov5Model::getAnchors(int net_grid) +{ + std::vector anchors(6); + int a80[6] = {10,13, 16,30, 33,23}; + int a40[6] = {30,61, 62,45, 59,119}; + int a20[6] = {116,90, 156,198, 373,326}; + if(net_grid == 80) + { + anchors.insert(anchors.begin(),a80,a80 + 6); + } + else if(net_grid == 40) + { + anchors.insert(anchors.begin(),a40,a40 + 6); + } + else if(net_grid == 20) + { + anchors.insert(anchors.begin(),a20,a20 + 6); + } + return anchors; +} + + +REG_MODEL(ObjectDetectionYolov5Model, "ObjectDetection_YOLOV5s"); diff --git a/vino_core_lib/src/models/object_segmentation_model.cpp b/vino_core_lib/src/models/object_segmentation_model.cpp index 22b4d785..df4f54cd 100644 --- a/vino_core_lib/src/models/object_segmentation_model.cpp +++ b/vino_core_lib/src/models/object_segmentation_model.cpp @@ -212,3 +212,5 @@ bool Models::ObjectSegmentationModel::updateLayerProperty(InferenceEngine::CNNNe slog::info << "This model is SSDNet-like, Layer Property updated!" << slog::endl; return true; } + +REG_MODEL(ObjectSegmentationModel, "ObjectSegmentation"); diff --git a/vino_core_lib/src/models/person_attribs_detection_model.cpp b/vino_core_lib/src/models/person_attribs_detection_model.cpp index f4e8e618..e9467da8 100644 --- a/vino_core_lib/src/models/person_attribs_detection_model.cpp +++ b/vino_core_lib/src/models/person_attribs_detection_model.cpp @@ -64,3 +64,5 @@ const std::string Models::PersonAttribsDetectionModel::getModelCategory() const { return "Person Attributes Detection"; } + +REG_MODEL(PersonAttribsDetectionModel, "PersonAttribsDetection"); diff --git a/vino_core_lib/src/models/person_reidentification_model.cpp b/vino_core_lib/src/models/person_reidentification_model.cpp index d2c28d3f..afd3f092 100644 --- a/vino_core_lib/src/models/person_reidentification_model.cpp +++ b/vino_core_lib/src/models/person_reidentification_model.cpp @@ -49,3 +49,5 @@ const std::string Models::PersonReidentificationModel::getModelCategory() const { return "Person Reidentification"; } + +REG_MODEL(PersonReidentificationModel, "PersonReidentification"); diff --git a/vino_core_lib/src/models/vehicle_attribs_detection_model.cpp b/vino_core_lib/src/models/vehicle_attribs_detection_model.cpp index a1c5c1b5..753361f2 100644 --- a/vino_core_lib/src/models/vehicle_attribs_detection_model.cpp +++ b/vino_core_lib/src/models/vehicle_attribs_detection_model.cpp @@ -64,3 +64,5 @@ const std::string Models::VehicleAttribsDetectionModel::getModelCategory() const { return "Vehicle Attributes Detection"; } + +REG_MODEL(VehicleAttribsDetectionModel, "VehicleAttribsDetection"); diff --git a/vino_core_lib/src/outputs/image_window_output.cpp b/vino_core_lib/src/outputs/image_window_output.cpp index 7b5a6aee..47bcaf7b 100644 --- a/vino_core_lib/src/outputs/image_window_output.cpp +++ b/vino_core_lib/src/outputs/image_window_output.cpp @@ -29,9 +29,10 @@ #include "vino_core_lib/outputs/image_window_output.h" #include "vino_core_lib/pipeline.h" -Outputs::ImageWindowOutput::ImageWindowOutput(const std::string& output_name, int focal_length) - : BaseOutput(output_name), focal_length_(focal_length) +void Outputs::ImageWindowOutput::doInit(const std::string& output_name, int focal_length) { + output_name_ = output_name; + focal_length_ = focal_length; cv::namedWindow(output_name_, cv::WINDOW_AUTOSIZE); } @@ -348,4 +349,6 @@ void Outputs::ImageWindowOutput::initOutputs(unsigned size) outputs_[i].desc = ""; outputs_[i].scalar = cv::Scalar(255, 0, 0); } -} \ No newline at end of file +} + +REG_OUTPUT(ImageWindowOutput, "ImageWindow"); \ No newline at end of file diff --git a/vino_core_lib/src/outputs/ros_service_output.cpp b/vino_core_lib/src/outputs/ros_service_output.cpp index 3798f433..64083a38 100644 --- a/vino_core_lib/src/outputs/ros_service_output.cpp +++ b/vino_core_lib/src/outputs/ros_service_output.cpp @@ -133,3 +133,5 @@ void Outputs::RosServiceOutput::clearData() // segmented_object_topic_ = nullptr; person_reid_topic_ = nullptr; } + +REG_OUTPUT(RosServiceOutput, "RosService"); \ No newline at end of file diff --git a/vino_core_lib/src/outputs/ros_topic_output.cpp b/vino_core_lib/src/outputs/ros_topic_output.cpp index c2a881ea..9a467ddf 100644 --- a/vino_core_lib/src/outputs/ros_topic_output.cpp +++ b/vino_core_lib/src/outputs/ros_topic_output.cpp @@ -25,8 +25,10 @@ #include #include -Outputs::RosTopicOutput::RosTopicOutput(std::string pipeline_name) : pipeline_name_(pipeline_name) +void Outputs::RosTopicOutput::init(const std::string& pipeline_name) { + pipeline_name_ = pipeline_name; + pub_face_ = nh_.advertise("/openvino_toolkit/" + pipeline_name_ + "/faces", 16); pub_emotion_ = nh_.advertise("/openvino_toolkit/" + pipeline_name_ + "/emotions", 16); pub_age_gender_ = @@ -432,3 +434,5 @@ std_msgs::Header Outputs::RosTopicOutput::getHeader() return header; } #endif // depreated + +REG_OUTPUT(RosTopicOutput, "RosTopic"); \ No newline at end of file diff --git a/vino_core_lib/src/outputs/rviz_output.cpp b/vino_core_lib/src/outputs/rviz_output.cpp index 6ac58b5a..44e332d1 100644 --- a/vino_core_lib/src/outputs/rviz_output.cpp +++ b/vino_core_lib/src/outputs/rviz_output.cpp @@ -25,8 +25,9 @@ #include "vino_core_lib/pipeline.h" #include "vino_core_lib/outputs/rviz_output.h" -Outputs::RvizOutput::RvizOutput(std::string pipeline_name) : BaseOutput(pipeline_name) +void Outputs::RvizOutput::init(const std::string& pipeline_name) { + pipeline_name_ = pipeline_name; image_topic_ = nullptr; pub_image_ = nh_.advertise("/openvino_toolkit/" + pipeline_name + "/images", 16); image_window_output_ = std::make_shared(pipeline_name, 950); @@ -122,3 +123,5 @@ std_msgs::Header Outputs::RvizOutput::getHeader() return header; } #endif // depreated + +REG_OUTPUT(RvizOutput, "RViz"); \ No newline at end of file diff --git a/vino_core_lib/src/pipeline_manager.cpp b/vino_core_lib/src/pipeline_manager.cpp index 8d5b4d91..52c469ee 100644 --- a/vino_core_lib/src/pipeline_manager.cpp +++ b/vino_core_lib/src/pipeline_manager.cpp @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - + /** * @brief a header file with declaration of Pipeline Manager class * @file pipeline_manager.cpp @@ -23,6 +23,7 @@ #include #include #include + #include "vino_core_lib/inferences/age_gender_detection.h" #include "vino_core_lib/inferences/emotions_detection.h" #include "vino_core_lib/inferences/face_detection.h" @@ -32,27 +33,32 @@ #include "vino_core_lib/inferences/vehicle_attribs_detection.h" #include "vino_core_lib/inferences/license_plate_detection.h" #include "vino_core_lib/inferences/landmarks_detection.h" + #include "vino_core_lib/inputs/image_input.h" #include "vino_core_lib/inputs/realsense_camera.h" #include "vino_core_lib/inputs/realsense_camera_topic.h" #include "vino_core_lib/inputs/standard_camera.h" #include "vino_core_lib/inputs/ip_camera.h" #include "vino_core_lib/inputs/video_input.h" + #include "vino_core_lib/models/age_gender_detection_model.h" #include "vino_core_lib/models/emotion_detection_model.h" #include "vino_core_lib/models/face_detection_model.h" #include "vino_core_lib/models/head_pose_detection_model.h" #include "vino_core_lib/models/object_detection_ssd_model.h" -// #include "vino_core_lib/models/object_detection_yolov2voc_model.h" +#include "vino_core_lib/models/object_detection_yolov2voc_model.h" +#include "vino_core_lib/models/object_detection_yolov5_model.h" #include "vino_core_lib/models/face_reidentification_model.h" #include "vino_core_lib/models/person_attribs_detection_model.h" #include "vino_core_lib/models/vehicle_attribs_detection_model.h" #include "vino_core_lib/models/license_plate_detection_model.h" #include "vino_core_lib/models/landmarks_detection_model.h" + #include "vino_core_lib/outputs/image_window_output.h" #include "vino_core_lib/outputs/ros_topic_output.h" #include "vino_core_lib/outputs/rviz_output.h" #include "vino_core_lib/outputs/ros_service_output.h" + #include "vino_core_lib/pipeline.h" #include "vino_core_lib/pipeline_manager.h" #include "vino_core_lib/pipeline_params.h" @@ -120,53 +126,27 @@ std::map> PipelineManager::parseInputDevice(const PipelineData& pdata) { std::map> inputs; - for (auto& name : pdata.params.inputs) + + for (auto& input_name : pdata.params.inputs) { - slog::info << "Parsing InputDvice: " << name << slog::endl; - std::shared_ptr device = nullptr; - if (name == kInputType_RealSenseCamera) + if (input_name.empty()) { - device = std::make_shared(); - } - else if (name == kInputType_StandardCamera) - { - device = std::make_shared(); - } - else if (name == kInputType_IpCamera) - { - if (pdata.params.input_meta != "") - { - device = std::make_shared(pdata.params.input_meta); - } - } - else if (name == kInputType_CameraTopic || name == kInputType_ImageTopic) - { - device = std::make_shared(); - } - else if (name == kInputType_Video) - { - if (pdata.params.input_meta != "") - { - device = std::make_shared(pdata.params.input_meta); - } + continue; } - else if (name == kInputType_Image) + + slog::info << "Parsing InputDvice: " << input_name << slog::endl; + + std::shared_ptr device = REG_INPUT_FACTORY::produce_shared(input_name); + + if (device != nullptr) { - if (pdata.params.input_meta != "") - { - device = std::make_shared(pdata.params.input_meta); - } + device->init(pdata.params.input_meta); + inputs.insert({ input_name, device }); + slog::info << " ... Adding one Input device: " << input_name << slog::endl; } else { - slog::err << "Invalid input device name: " << name << slog::endl; - } - - if (device != nullptr) - { - device->initialize(); - inputs.insert({ name, device }); - slog::info << " ... Adding one Input device: " << name << slog::endl; + slog::err << "Invalid input device input_name: " << input_name << slog::endl; } } @@ -176,34 +156,26 @@ PipelineManager::parseInputDevice(const PipelineData& pdata) std::map> PipelineManager::parseOutput(const PipelineData& pdata) { std::map> outputs; - for (auto& name : pdata.params.outputs) + for (auto& output_name : pdata.params.outputs) { - slog::info << "Parsing Output: " << name << slog::endl; - std::shared_ptr object = nullptr; - if (name == kOutputTpye_RosTopic) - { - object = std::make_shared(pdata.params.name); - } - else if (name == kOutputTpye_ImageWindow) - { - object = std::make_shared(pdata.params.name); - } - else if (name == kOutputTpye_RViz) + if (output_name.empty()) { - object = std::make_shared(pdata.params.name); + continue; } - else if (name == kOutputTpye_RosService) + + slog::info << "Parsing Output: " << output_name << slog::endl; + + std::shared_ptr output = REG_OUTPUT_FACTORY::produce_shared(output_name); + + if (output != nullptr) { - object = std::make_shared(pdata.params.name); + output->init(pdata.params.name); + outputs.insert({ output_name, output }); + slog::info << " ... Adding one Output: " << output_name << slog::endl; } else { - slog::err << "Invalid output name: " << name << slog::endl; - } - if (object != nullptr) - { - outputs.insert({ name, object }); - slog::info << " ... Adding one Output: " << name << slog::endl; + slog::err << "Invalid output output_name: " << output_name << slog::endl; } } @@ -214,252 +186,74 @@ std::map> PipelineManager::parseInference(const Params::ParamManager::PipelineRawData& params) { std::map> inferences; - for (auto& infer : params.infers) + + for (auto& infer_param : params.infers) { - if (infer.name.empty() || infer.model.empty()) + if (infer_param.name.empty() || infer_param.model.empty()) { continue; } - slog::info << "Parsing Inference: " << infer.name << slog::endl; - std::shared_ptr object = nullptr; - if (infer.name == kInferTpye_FaceDetection) - { - object = createFaceDetection(infer); - } - else if (infer.name == kInferTpye_AgeGenderRecognition) - { - object = createAgeGenderRecognition(infer); - } - else if (infer.name == kInferTpye_EmotionRecognition) - { - object = createEmotionRecognition(infer); - } - else if (infer.name == kInferTpye_HeadPoseEstimation) - { - object = createHeadPoseEstimation(infer); - } - else if (infer.name == kInferTpye_ObjectDetection) - { - object = createObjectDetection(infer); - } - else if (infer.name == kInferTpye_ObjectSegmentation) - { - object = createObjectSegmentation(infer); - } - else if (infer.name == kInferTpye_PersonReidentification) - { - object = createPersonReidentification(infer); - } - else if (infer.name == kInferTpye_FaceReidentification) - { - object = createFaceReidentification(infer); - } - else if (infer.name == kInferTpye_PersonAttribsDetection) - { - object = createPersonAttribsDetection(infer); - } - else if (infer.name == kInferTpye_LandmarksDetection) + // Model + std::shared_ptr model = nullptr; + + if(infer_param.model_type.empty() && (infer_param.name.empty())) { - object = createLandmarksDetection(infer); + slog::err << "Model" << infer_param.name << " init failed!!! Please input model name or type."; + // return inferences; } - else if (infer.name == kInferTpye_VehicleAttribsDetection) + + if(!(infer_param.name.empty())) { - object = createVehicleAttribsDetection(infer); + auto key_name = infer_param.name; + + if(!(infer_param.model_type.empty())) + { + key_name = key_name + "_" + infer_param.model_type; + } + + model = REG_MODEL_FACTORY::produce_shared(key_name); } - else if (infer.name == kInferTpye_LicensePlateDetection) + + // void Models::BaseModel::init(const std::string& label_loc, const std::string& model_loc, int max_batch_size) + + slog::debug << "[InferenceRawData]" << slog::endl + << "Name: " << infer_param.name << slog::endl + << "Engine: " << infer_param.engine << slog::endl + << "Model: " << infer_param.model << slog::endl + << "Model_type: " << infer_param.model_type << slog::endl + << "Label: " << infer_param.label << slog::endl + << "Batch: " << infer_param.batch << slog::endl + << "Confidence_threshold: " << infer_param.confidence_threshold << slog::endl + << "Enable_roi_constraint: " << infer_param.enable_roi_constraint << slog::endl; + + if(model != nullptr) { - object = createLicensePlateDetection(infer); + model->init(infer_param.label, infer_param.model, infer_param.batch); } else { - slog::err << "Invalid inference name: " << infer.name << slog::endl; + slog::err << "Model produce failed!!!" << slog::endl; } - if (object != nullptr) + // Engine + auto engine = engine_manager_.createEngine(infer_param.engine, model); + + slog::info << "Parsing Inference: " << infer_param.name << slog::endl; + auto infer = REG_INFERENCE_FACTORY::produce_shared(infer_param.name); + + if(infer != nullptr) { - inferences.insert({ infer.name, object }); - slog::info << " ... Adding one Inference: " << infer.name << slog::endl; + infer->loadNetwork(model); + infer->loadEngine(engine); + inferences.insert({ infer_param.name, infer}); + slog::info << " ... Adding one Inference: " << infer_param.name << slog::endl; } } return inferences; } -std::shared_ptr -PipelineManager::createFaceDetection(const Params::ParamManager::InferenceRawData& infer) -{ - return createObjectDetection(infer); -} - -std::shared_ptr -PipelineManager::createAgeGenderRecognition(const Params::ParamManager::InferenceRawData& param) -{ - auto model = std::make_shared(param.label, param.model, param.batch); - model->modelInit(); - auto engine = engine_manager_.createEngine(param.engine, model); - auto infer = std::make_shared(); - infer->loadNetwork(model); - infer->loadEngine(engine); - - return infer; -} - -std::shared_ptr -PipelineManager::createEmotionRecognition(const Params::ParamManager::InferenceRawData& param) -{ - auto model = std::make_shared(param.label, param.model, param.batch); - model->modelInit(); - auto engine = engine_manager_.createEngine(param.engine, model); - auto infer = std::make_shared(); - infer->loadNetwork(model); - infer->loadEngine(engine); - - return infer; -} - -std::shared_ptr -PipelineManager::createHeadPoseEstimation(const Params::ParamManager::InferenceRawData& param) -{ - auto model = std::make_shared(param.label, param.model, param.batch); - model->modelInit(); - auto engine = engine_manager_.createEngine(param.engine, model); - auto infer = std::make_shared(); - infer->loadNetwork(model); - infer->loadEngine(engine); - - return infer; -} - -std::shared_ptr -PipelineManager::createObjectDetection(const Params::ParamManager::InferenceRawData& infer) -{ - std::shared_ptr object_detection_model; - std::shared_ptr object_inference_ptr; - slog::debug << "for test in createObjectDetection(), model_path =" << infer.model << slog::endl; - if (infer.model_type == kInferTpye_ObjectDetectionTypeSSD) - { - object_detection_model = std::make_shared(infer.label, infer.model, infer.batch); - } - // if (infer.model_type == kInferTpye_ObjectDetectionTypeYolov2voc) - // { - // object_detection_model = std::make_shared(infer.model, infer.batch); - // } - - slog::debug << "for test in createObjectDetection(), Created SSDModel" << slog::endl; - object_inference_ptr = std::make_shared( - infer.enable_roi_constraint, infer.confidence_threshold); // To-do theshold configuration - slog::debug << "for test in createObjectDetection(), before modelInit()" << slog::endl; - object_detection_model->modelInit(); - auto object_detection_engine = engine_manager_.createEngine(infer.engine, object_detection_model); - object_inference_ptr->loadNetwork(object_detection_model); - object_inference_ptr->loadEngine(object_detection_engine); - - return object_inference_ptr; -} - -std::shared_ptr -PipelineManager::createObjectSegmentation(const Params::ParamManager::InferenceRawData& infer) -{ - auto model = std::make_shared(infer.label, infer.model, infer.batch); - model->modelInit(); - slog::info << "Segmentation model initialized." << slog::endl; - auto engine = engine_manager_.createEngine(infer.engine, model); - slog::info << "Segmentation Engine initialized." << slog::endl; - auto segmentation_inference_ptr = std::make_shared(infer.confidence_threshold); - slog::info << "Segmentation Inference instanced." << slog::endl; - segmentation_inference_ptr->loadNetwork(model); - segmentation_inference_ptr->loadEngine(engine); - - return segmentation_inference_ptr; -} - -std::shared_ptr -PipelineManager::createPersonReidentification(const Params::ParamManager::InferenceRawData& infer) -{ - std::shared_ptr person_reidentification_model; - std::shared_ptr reidentification_inference_ptr; - slog::debug << "for test in createPersonReidentification()" << slog::endl; - person_reidentification_model = std::make_shared(infer.label, infer.model, infer.batch); - person_reidentification_model->modelInit(); - slog::info << "Reidentification model initialized" << slog::endl; - auto person_reidentification_engine = engine_manager_.createEngine(infer.engine, person_reidentification_model); - reidentification_inference_ptr = - std::make_shared(infer.confidence_threshold); - reidentification_inference_ptr->loadNetwork(person_reidentification_model); - reidentification_inference_ptr->loadEngine(person_reidentification_engine); - - return reidentification_inference_ptr; -} - -std::shared_ptr -PipelineManager::createVehicleAttribsDetection(const Params::ParamManager::InferenceRawData& infer) -{ - auto model = std::make_shared(infer.label, infer.model, infer.batch); - model->modelInit(); - auto engine = engine_manager_.createEngine(infer.engine, model); - auto vehicle_attribs_ptr = std::make_shared(); - vehicle_attribs_ptr->loadNetwork(model); - vehicle_attribs_ptr->loadEngine(engine); - - return vehicle_attribs_ptr; -} - -std::shared_ptr -PipelineManager::createLicensePlateDetection(const Params::ParamManager::InferenceRawData& infer) -{ - auto model = std::make_shared(infer.label, infer.model, infer.batch); - model->modelInit(); - auto engine = engine_manager_.createEngine(infer.engine, model); - auto license_plate_ptr = std::make_shared(); - license_plate_ptr->loadNetwork(model); - license_plate_ptr->loadEngine(engine); - - return license_plate_ptr; -} - -std::shared_ptr -PipelineManager::createPersonAttribsDetection(const Params::ParamManager::InferenceRawData& infer) -{ - auto model = std::make_shared(infer.label, infer.model, infer.batch); - slog::debug << "for test in createPersonAttributesDetection()" << slog::endl; - model->modelInit(); - auto engine = engine_manager_.createEngine(infer.engine, model); - auto attribs_inference_ptr = std::make_shared(infer.confidence_threshold); - attribs_inference_ptr->loadNetwork(model); - attribs_inference_ptr->loadEngine(engine); - - return attribs_inference_ptr; -} - -std::shared_ptr -PipelineManager::createFaceReidentification(const Params::ParamManager::InferenceRawData& infer) -{ - auto model = std::make_shared(infer.label, infer.model, infer.batch); - slog::debug << "for test in createFaceReidentification()" << slog::endl; - model->modelInit(); - auto engine = engine_manager_.createEngine(infer.engine, model); - auto attribs_inference_ptr = std::make_shared(infer.confidence_threshold); - attribs_inference_ptr->loadNetwork(model); - attribs_inference_ptr->loadEngine(engine); - - return attribs_inference_ptr; -} - -std::shared_ptr -PipelineManager::createLandmarksDetection( - const Params::ParamManager::InferenceRawData & infer) -{ - auto model = std::make_shared(infer.label, infer.model, infer.batch); - model->modelInit(); - auto engine = engine_manager_.createEngine(infer.engine, model); - auto landmarks_inference_ptr = std::make_shared(); - landmarks_inference_ptr->loadNetwork(model); - landmarks_inference_ptr->loadEngine(engine); - - return landmarks_inference_ptr; -} - void PipelineManager::threadPipeline(const char* name) { PipelineData& p = pipelines_[name]; diff --git a/vino_core_lib/src/pipeline_params.cpp b/vino_core_lib/src/pipeline_params.cpp index 8ab8c2b8..0c4c7f28 100644 --- a/vino_core_lib/src/pipeline_params.cpp +++ b/vino_core_lib/src/pipeline_params.cpp @@ -82,7 +82,7 @@ bool PipelineParams::isGetFps() { return false; } - return std::find(params_.inputs.begin(), params_.inputs.end(), kInputType_Image) == params_.inputs.end(); + return std::find(params_.inputs.begin(), params_.inputs.end(), "Image") == params_.inputs.end(); } std::string PipelineParams::findFilterConditions(const std::string& input, const std::string& output) diff --git a/vino_launch/launch/pipeline_object_gdb.launch b/vino_launch/launch/pipeline_object_gdb.launch new file mode 100644 index 00000000..9b525c17 --- /dev/null +++ b/vino_launch/launch/pipeline_object_gdb.launch @@ -0,0 +1,10 @@ + + + + + + + + + diff --git a/vino_launch/launch/pipeline_object_topic.launch.bak b/vino_launch/launch/pipeline_object_topic.launch.bak deleted file mode 100644 index 86bdb4b0..00000000 --- a/vino_launch/launch/pipeline_object_topic.launch.bak +++ /dev/null @@ -1,25 +0,0 @@ - - - - ->>>>>>> 128cd0ffa567e04d86e5a218f07e38767ade639f:vino_launch/launch/pipeline_object_topic.launch.bak - - - - - - - - diff --git a/vino_launch/launch/pipeline_object_yolov5.launch b/vino_launch/launch/pipeline_object_yolov5.launch new file mode 100644 index 00000000..8b1ec40c --- /dev/null +++ b/vino_launch/launch/pipeline_object_yolov5.launch @@ -0,0 +1,10 @@ + + + + + + + + + diff --git a/vino_launch/param/pipeline_object.yaml b/vino_launch/param/pipeline_object.yaml index cb189084..a3622c2b 100644 --- a/vino_launch/param/pipeline_object.yaml +++ b/vino_launch/param/pipeline_object.yaml @@ -5,6 +5,7 @@ Pipelines: - name: ObjectDetection model: /opt/openvino_toolkit/models/public/ssd_mobilenet_v2_coco/FP16/ssd_mobilenet_v2_coco.xml engine: CPU + model_type: SSD label: to/be/set/xxx.labels batch: 1 confidence_threshold: 0.5 diff --git a/vino_launch/param/pipeline_object_yolov5.yaml b/vino_launch/param/pipeline_object_yolov5.yaml new file mode 100644 index 00000000..dbf794d8 --- /dev/null +++ b/vino_launch/param/pipeline_object_yolov5.yaml @@ -0,0 +1,27 @@ +Pipelines: +- name: object + inputs: [StandardCamera] + # inputs: [image] + # input_path: /home/cxs/ros_ws/src/ros_openvino_toolkit/data/images/bus.jpg + infers: + - name: ObjectDetection + model: /opt/openvino_toolkit/models/public/yolo-v5/FP32/yolov5s.xml + engine: CPU + model_type: YOLOV5s + label: to/be/set/xxx.labels + batch: 1 + confidence_threshold: 0.1 + enable_roi_constraint: false # set enable_roi_constraint to false if you don't want to make the inferred ROI (region of interest) constrained into the camera frame + outputs: [ImageWindow, RosTopic, RViz] + connects: + - left: StandardCamera + # - left: image + right: [ObjectDetection] + - left: ObjectDetection + right: [ImageWindow] + - left: ObjectDetection + right: [RosTopic] + - left: ObjectDetection + right: [RViz] + +OpenvinoCommon: diff --git a/vino_param_lib/src/param_manager.cpp b/vino_param_lib/src/param_manager.cpp index f3e5a356..8b85c9b4 100644 --- a/vino_param_lib/src/param_manager.cpp +++ b/vino_param_lib/src/param_manager.cpp @@ -101,10 +101,6 @@ void operator>>(const YAML::Node& node, ParamManager::InferenceRawData& infer) YAML_PARSE(node, "confidence_threshold", infer.confidence_threshold) YAML_PARSE(node, "enable_roi_constraint", infer.enable_roi_constraint) - if (infer.model_type.size() == 0) { - infer.model_type = "SSD"; - } - slog::info << "Inference Params:name=" << infer.name << slog::endl; }