Skip to content

Commit f06bf05

Browse files
Merge pull request #1639 from fzhar/object_detection_demo_ssd_async_common_pipeline
Unify C++ object detection demos
2 parents f8083be + fde9d75 commit f06bf05

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2361
-1400
lines changed

demos/README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Open Model Zoo Demos
22

3-
The Open Model Zoo demo applications are console applications that demonstrate how you can use the Inference Engine in your applications to solve specific use-cases.
4-
3+
The Open Model Zoo demo applications are console applications that demonstrate how you can use the Inference Engine in your applications to solve specific use-cases
54
The Open Model Zoo includes the following demos:
65

76
- [3D Human Pose Estimation Python\* Demo](./python_demos/human_pose_estimation_3d_demo/README.md) - 3D human pose estimation demo.
@@ -19,6 +18,7 @@ The Open Model Zoo includes the following demos:
1918
- [Image Inpainting Python\* Demo](./python_demos/image_inpainting_demo/README.md) - Demo application for GMCNN inpainting network.
2019
- [Image Retrieval Python\* Demo](./python_demos/image_retrieval_demo/README.md) - The demo demonstrates how to run Image Retrieval models using OpenVINO™.
2120
- [Image Segmentation C++ Demo](./segmentation_demo/README.md) - Inference of image segmentation networks like FCN8 (the demo supports only images as inputs).
21+
- [Image Segmentation Asynchronous C++ Demo](./segmentation_demo_async/README.md) - Inference of image segmentation networks like FCN8, async API showcase, simple OpenCV interoperability (supports video and camera inputs).
2222
- [Image Translation Python\* Demo](./python_demos/image_translation_demo/README.md) - Demo application to synthesize a photo-realistic image based on exemplar image.
2323
- [Instance Segmentation Python\* Demo](./python_demos/instance_segmentation_demo/README.md) - Inference of instance segmentation networks trained in `Detectron` or `maskrcnn-benchmark`.
2424
- [Interactive Face Detection C++ Demo](./interactive_face_detection_demo/README.md) - Face Detection coupled with Age/Gender, Head-Pose, Emotion, and Facial Landmarks detectors. Supports video and camera inputs.
@@ -30,8 +30,7 @@ The Open Model Zoo includes the following demos:
3030
- [Object Detection for CenterNet Python\* Demo](./python_demos/object_detection_demo_centernet/README.md) - Demo application for CenterNet object detection network.
3131
- [Object Detection for Faster R-CNN C++ Demo](./object_detection_demo_faster_rcnn/README.md) - Inference of object detection networks like Faster R-CNN (the demo supports only images as inputs).
3232
- [Object Detection for RetinaFace Python\* Demo](./python_demos/object_detection_demo_retinaface/README.md) - Demo application for RetinaFace face detection model.
33-
- [Object Detection for SSD C++ Demo](./object_detection_demo_ssd_async/README.md) - Demo application for SSD-based Object Detection networks, new Async API performance showcase, and simple OpenCV interoperability (supports video and camera inputs).
34-
- [Object Detection for YOLO V3 C++ Demo](./object_detection_demo_yolov3_async/README.md) - Demo application for YOLOV3-based Object Detection networks, new Async API performance showcase, and simple OpenCV interoperability (supports video and camera inputs).
33+
- [Object Detection C++ Demo](./object_detection_demo/README.md) - Demo application for Object Detection networks (different models architectures are supproted), async API showcase, simple OpenCV interoperability (supports video and camera inputs).
3534
- [Pedestrian Tracker C++ Demo](./pedestrian_tracker_demo/README.md) - Demo application for pedestrian tracking scenario.
3635
- [Security Barrier Camera C++ Demo](./security_barrier_camera_demo/README.md) - Vehicle Detection followed by the Vehicle Attributes and License-Plate Recognition, supports images/video and camera inputs.
3736
- [Speech Recognition Python\* Demo](./python_demos/speech_recognition_demo/README.md) - Speech recognition demo: takes audio file with an English phrase on input, and converts it into text.
@@ -118,7 +117,6 @@ The table below shows the correlation between models, demos, and supported plugi
118117
| vehicle-detection-adas-0002 | any demo that supports SSD\*-based models, above | Supported | Supported | Supported | Supported |
119118
| yolo-v2-tiny-vehicle-detection-0001 | [Object Detection for YOLO V3 Python\* Demo](./python_demos/object_detection_demo_yolov3_async/README.md) | Supported | | | |
120119

121-
122120
Notice that the FPGA support comes through a [heterogeneous execution](https://docs.openvinotoolkit.org/latest/_docs_IE_DG_supported_plugins_HETERO.html), for example, when the post-processing is happening on the CPU.
123121

124122
## Build the Demo Applications

demos/common/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ find_package(InferenceEngine 2.0 REQUIRED)
66
find_package(OpenCV REQUIRED COMPONENTS core imgcodecs videoio)
77

88
add_subdirectory(monitors)
9+
add_subdirectory(models)
10+
add_subdirectory(pipelines)
911

1012
file(GLOB_RECURSE HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/include/*")
1113
file(GLOB_RECURSE SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/*")

demos/common/include/samples/performance_metrics.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,20 @@ class PerformanceMetrics {
3636
double fontScale = 0.75,
3737
cv::Scalar color = {200, 10, 10},
3838
int thickness = 2);
39+
void update(TimePoint lastRequestStartTime);
40+
41+
/// Paints metrics over provided mat
42+
/// @param frame frame to paint over
43+
/// @param position left top corner of text block
44+
/// @param fontScale font scale
45+
/// @param color font color
46+
/// @param thickness font thickness
47+
void paintMetrics(cv::Mat& frame,
48+
cv::Point position = { 15, 30 },
49+
double fontScale = 0.75,
50+
cv::Scalar color = { 200, 10, 10 },
51+
int thickness = 2) const;
52+
3953
Metrics getLast() const;
4054
Metrics getTotal() const;
4155
void printTotal() const;

demos/common/models/CMakeLists.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright (C) 2018-2019 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
#
4+
5+
find_package(OpenCV REQUIRED COMPONENTS core imgproc)
6+
find_package(ngraph REQUIRED)
7+
8+
FILE(GLOB SOURCES ./src/*.cpp)
9+
FILE(GLOB HEADERS ./include/models/*.h)
10+
11+
# Create named folders for the sources within the .vcproj
12+
# Empty name lists them directly under the .vcproj
13+
source_group("src" FILES ${SOURCES})
14+
source_group("include" FILES ${HEADERS})
15+
16+
add_library(models STATIC ${SOURCES} ${HEADERS})
17+
target_include_directories(models PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
18+
target_link_libraries(models PRIVATE ngraph::ngraph gflags ${InferenceEngine_LIBRARIES} common opencv_core opencv_imgproc)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
// Copyright (C) 2018-2020 Intel Corporation
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
*/
16+
#pragma once
17+
#include "models/model_base.h"
18+
#include "opencv2/core.hpp"
19+
20+
class DetectionModel : public ModelBase {
21+
public:
22+
/// Constructor
23+
/// @param modelFileName name of model to load
24+
/// @param confidenceThreshold - threshold to eleminate low-confidence detections.
25+
/// Any detected object with confidence lower than this threshold will be ignored.
26+
/// @param useAutoResize - if true, image will be resized by IE.
27+
/// Otherwise, image will be preprocessed and resized using OpenCV routines.
28+
/// @param labels - array of labels for every class. If this array is empty or contains less elements
29+
/// than actual classes number, default "Label #N" will be shown for missing items.
30+
DetectionModel(const std::string& modelFileName, float confidenceThreshold, bool useAutoResize, const std::vector<std::string>& labels);
31+
32+
virtual std::shared_ptr<InternalModelData> preprocess(const InputData& inputData, InferenceEngine::InferRequest::Ptr& request) override;
33+
34+
static std::vector<std::string> loadLabels(const std::string& labelFilename);
35+
36+
protected:
37+
std::vector<std::string> labels;
38+
39+
size_t netInputHeight = 0;
40+
size_t netInputWidth = 0;
41+
42+
bool useAutoResize;
43+
float confidenceThreshold;
44+
45+
std::string getLabelName(int labelID) { return (size_t)labelID < labels.size() ? labels[labelID] : std::string("Label #") + std::to_string(labelID); }
46+
};
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
// Copyright (C) 2018-2020 Intel Corporation
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
*/
16+
17+
#pragma once
18+
#include "detection_model.h"
19+
class ModelSSD : public DetectionModel {
20+
public:
21+
/// Constructor
22+
/// @param modelFileName name of model to load
23+
/// @param confidenceThreshold - threshold to eleminate low-confidence detections.
24+
/// Any detected object with confidence lower than this threshold will be ignored.
25+
/// @param useAutoResize - if true, image will be resized by IE.
26+
/// Otherwise, image will be preprocessed and resized using OpenCV routines.
27+
/// @param labels - array of labels for every class. If this array is empty or contains less elements
28+
/// than actual classes number, default "Label #N" will be shown for missing items.
29+
ModelSSD(const std::string& modelFileName,
30+
float confidenceThreshold, bool useAutoResize,
31+
const std::vector<std::string>& labels = std::vector<std::string>());
32+
33+
std::shared_ptr<InternalModelData> preprocess(const InputData& inputData, InferenceEngine::InferRequest::Ptr& request);
34+
virtual std::unique_ptr<ResultBase> postprocess(InferenceResult& infResult) override;
35+
36+
protected:
37+
virtual void prepareInputsOutputs(InferenceEngine::CNNNetwork& cnnNetwork) override;
38+
size_t maxProposalCount = 0;
39+
size_t objectSize = 0;
40+
};
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
// Copyright (C) 2018-2020 Intel Corporation
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
*/
16+
17+
#pragma once
18+
#include "detection_model.h"
19+
20+
namespace ngraph {
21+
namespace op {
22+
namespace v0 {
23+
class RegionYolo;
24+
}
25+
using v0::RegionYolo;
26+
}
27+
}
28+
29+
class ModelYolo3 : public DetectionModel {
30+
protected:
31+
class Region {
32+
public:
33+
int num = 0;
34+
int classes = 0;
35+
int coords = 0;
36+
std::vector<float> anchors;
37+
38+
Region(const std::shared_ptr<ngraph::op::RegionYolo>& regionYolo);
39+
};
40+
41+
public:
42+
/// Constructor.
43+
/// @param modelFileName name of model to load
44+
/// @param confidenceThreshold - threshold to eleminate low-confidence detections.
45+
/// Any detected object with confidence lower than this threshold will be ignored.
46+
/// @param useAutoResize - if true, image will be resized by IE.
47+
/// Otherwise, image will be preprocessed and resized using OpenCV routines.
48+
/// @param useAdvancedPostprocessing - if true, an advanced algorithm for filtering/postprocessing will be used
49+
/// (with better processing of multiple crossing objects). Otherwise, classic algorithm will be used.
50+
/// @param boxIOUThreshold - threshold to treat separate output regions as one object for filtering
51+
/// during postprocessing (only one of them should stay). The default value is 0.4
52+
/// @param labels - array of labels for every class. If this array is empty or contains less elements
53+
/// than actual classes number, default "Label #N" will be shown for missing items.
54+
ModelYolo3(const std::string& modelFileName, float confidenceThreshold, bool useAutoResize,
55+
bool useAdvancedPostprocessing = false, float boxIOUThreshold = 0.4, const std::vector<std::string>& labels = std::vector<std::string>());
56+
57+
std::unique_ptr<ResultBase> postprocess(InferenceResult& infResult) override;
58+
59+
protected:
60+
virtual void prepareInputsOutputs(InferenceEngine::CNNNetwork& cnnNetwork) override;
61+
62+
void parseYOLOV3Output(const std::string& output_name, const InferenceEngine::Blob::Ptr& blob,
63+
const unsigned long resized_im_h, const unsigned long resized_im_w, const unsigned long original_im_h,
64+
const unsigned long original_im_w, std::vector<DetectedObject>& objects);
65+
66+
static int calculateEntryIndex(int side, int lcoords, int lclasses, int location, int entry);
67+
static double intersectionOverUnion(const DetectedObject& o1, const DetectedObject& o2);
68+
69+
std::map<std::string, Region> regions;
70+
double boxIOUThreshold;
71+
bool useAdvancedPostprocessing;
72+
};
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
// Copyright (C) 2018-2020 Intel Corporation
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
*/
16+
17+
#pragma once
18+
#include <opencv2/core.hpp>
19+
20+
struct InputData {
21+
virtual ~InputData() {}
22+
23+
template<class T> T& asRef() {
24+
return dynamic_cast<T&>(*this);
25+
}
26+
27+
template<class T> const T& asRef() const {
28+
return dynamic_cast<const T&>(*this);
29+
}
30+
};
31+
32+
struct ImageInputData : public InputData {
33+
cv::Mat inputImage;
34+
35+
ImageInputData() {}
36+
ImageInputData(const cv::Mat& img) {
37+
inputImage = img;
38+
}
39+
};
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
// Copyright (C) 2018-2020 Intel Corporation
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
*/
16+
17+
#pragma once
18+
struct InternalModelData {
19+
virtual ~InternalModelData(){}
20+
21+
template<class T> T& asRef() {
22+
return dynamic_cast<T&>(*this);
23+
}
24+
25+
template<class T> const T& asRef() const {
26+
return dynamic_cast<const T&>(*this);
27+
}
28+
};
29+
30+
struct InternalImageModelData : public InternalModelData {
31+
InternalImageModelData(int width, int height) {
32+
inputImgWidth = width;
33+
inputImgHeight = height;
34+
}
35+
36+
int inputImgWidth;
37+
int inputImgHeight;
38+
};
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
// Copyright (C) 2018-2020 Intel Corporation
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
*/
16+
17+
#pragma once
18+
#include "input_data.h"
19+
#include "results.h"
20+
21+
class ModelBase {
22+
public:
23+
ModelBase(const std::string& modelFileName) { this->modelFileName = modelFileName; }
24+
virtual ~ModelBase() {}
25+
26+
virtual void prepareInputsOutputs(InferenceEngine::CNNNetwork& cnnNetwork) = 0;
27+
virtual std::shared_ptr<InternalModelData> preprocess(const InputData& inputData, InferenceEngine::InferRequest::Ptr& request) = 0;
28+
virtual std::unique_ptr<ResultBase> postprocess(InferenceResult& infResult) = 0;
29+
virtual void onLoadCompleted(InferenceEngine::ExecutableNetwork* execNetwork, const std::vector<InferenceEngine::InferRequest::Ptr>& requests) {
30+
this->execNetwork = execNetwork; }
31+
const std::vector<std::string>& getOutputsNames() const { return outputsNames; }
32+
const std::vector<std::string>& getInputsNames() const { return inputsNames; }
33+
34+
std::string getModelFileName() { return modelFileName; }
35+
36+
protected:
37+
std::vector<std::string> inputsNames;
38+
std::vector<std::string> outputsNames;
39+
InferenceEngine::ExecutableNetwork* execNetwork;
40+
std::string modelFileName;
41+
};

0 commit comments

Comments
 (0)