Skip to content

Commit f4103c4

Browse files
authored
Merge pull request #1 from openvinotoolkit/master
updating my fork
2 parents b1ff98b + 9296a37 commit f4103c4

File tree

68 files changed

+2540
-461
lines changed

Some content is hidden

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

68 files changed

+2540
-461
lines changed

ci/requirements-conversion.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ keras-preprocessing==1.1.2
5252
# via tensorflow
5353
markdown==3.3.4
5454
# via tensorboard
55+
mxnet==1.2.0 ; sys_platform == 'win32'
5556
mxnet==1.7.0.post2 ; sys_platform != "win32"
5657
# via -r ${INTEL_OPENVINO_DIR}/deployment_tools/model_optimizer/requirements_mxnet.txt
5758
networkx==2.5

demos/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ else()
6060
set(COMPILER_IS_GCC_LIKE FALSE)
6161
endif()
6262

63+
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm64.*|aarch64.*|AARCH64.*)")
64+
set(AARCH64 ON)
65+
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm.*|ARM.*)")
66+
set(ARM ON)
67+
endif()
68+
if(ARM AND NOT CMAKE_CROSSCOMPILING)
69+
add_compile_options(-march=armv7-a)
70+
endif()
71+
6372
set(CMAKE_CXX_STANDARD 11)
6473
set(CMAKE_CXX_STANDARD_REQUIRED ON)
6574
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

demos/classification_demo/cpp/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The demo visualize OpenVINO performance on inference of neural networks for imag
66

77
On startup, the application reads command line parameters and loads a classification network to the Inference Engine for execution. It might take some time for demo to read all input images. Then the demo performs inference to classify the images and places them on grid.
88

9-
The demo starts in "Testing mode" with fixed grid size. After calculating the average FPS result, it will switch to normal mode and grid will be readjusted depending on model performance. Bigger grid means higher performance.
9+
The demo starts in "Testing mode" with fixed grid size. After calculating the average FPS result, it will switch to normal mode and grid will be readjusted depending on model performance. Bigger grid means higher performance. You can repeat testing by pressing "Space" or "R" button.
1010

1111
When "ground truth" data applied, the color coding for the text, drawn above each image, shows whether the classification was correct: green means correct class prediction, red means wrong.
1212

demos/classification_demo/cpp/grid_mat.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ class GridMat {
3131
currSourceId{0} {
3232
cv::Size size(static_cast<int>(std::round(sqrt(1. * targetFPS * aspectRatio.width / aspectRatio.height))),
3333
static_cast<int>(std::round(sqrt(1. * targetFPS * aspectRatio.height / aspectRatio.width))));
34+
if (size.width == 0 || size.height == 0) {
35+
size = {1, 1}; // set minimum possible grid size
36+
}
3437
int minCellSize = std::min(maxDisp.width / size.width, maxDisp.height / size.height);
3538
cellSize = cv::Size(minCellSize, minCellSize);
3639

demos/classification_demo/cpp/main.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,15 @@ int main(int argc, char *argv[]) {
311311
if (27 == key || 'q' == key || 'Q' == key) { // Esc
312312
keepRunning = false;
313313
}
314+
else if (32 == key || 'r' == key || 'R' == key) { // press space or r to restart testing if needed
315+
isTestMode = true;
316+
framesNum = 0;
317+
framesNumOnCalculationStart = 0;
318+
correctPredictionsCount = 0;
319+
accuracy = 0;
320+
elapsedSeconds = std::chrono::steady_clock::duration(0);
321+
startTime = std::chrono::steady_clock::now();
322+
}
314323
else {
315324
presenter.handleKey(key);
316325
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
// Copyright (C) 2020-2021 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 <vector>
19+
#include "detection_model.h"
20+
#include <utils/nms.hpp>
21+
#include <string>
22+
23+
class ModelRetinaFacePT : public DetectionModel {
24+
public:
25+
struct Box {
26+
float cX;
27+
float cY;
28+
float width;
29+
float height;
30+
};
31+
32+
struct Rect {
33+
float left;
34+
float top;
35+
float right;
36+
float bottom;
37+
38+
float getWidth() const { return (right - left) + 1.0f; }
39+
float getHeight() const { return (bottom - top) + 1.0f; }
40+
float getXCenter() const { return left + (getWidth() - 1.0f) / 2.0f; }
41+
float getYCenter() const { return top + (getHeight() - 1.0f) / 2.0f; }
42+
};
43+
44+
/// Loads model and performs required initialization
45+
/// @param model_name name of model to load
46+
/// @param confidenceThreshold - threshold to eliminate low-confidence detections.
47+
/// Any detected object with confidence lower than this threshold will be ignored.
48+
/// @param useAutoResize - if true, image will be resized by IE.
49+
/// @param boxIOUThreshold - threshold for NMS boxes filtering, varies in [0.0, 1.0] range.
50+
ModelRetinaFacePT(const std::string& modelFileName, float confidenceThreshold, bool useAutoResize, float boxIOUThreshold);
51+
std::unique_ptr<ResultBase> postprocess(InferenceResult& infResult) override;
52+
53+
protected:
54+
size_t landmarksNum;
55+
const float boxIOUThreshold;
56+
float variance[2] = { 0.1f, 0.2f };
57+
58+
enum EOutputType {
59+
OT_BBOX,
60+
OT_SCORES,
61+
OT_LANDMARK,
62+
OT_MAX
63+
};
64+
65+
std::vector<ModelRetinaFacePT::Box> priors;
66+
67+
std::vector<size_t> filterByScore(const InferenceEngine::MemoryBlob::Ptr& rawData, const float confidenceThreshold);
68+
std::vector<float> getFilteredScores(const InferenceEngine::MemoryBlob::Ptr& rawData, const std::vector<size_t>& indicies);
69+
std::vector<cv::Point2f> getFilteredLandmarks(const InferenceEngine::MemoryBlob::Ptr& rawData,
70+
const std::vector<size_t>& indicies, int imgWidth, int imgHeight);
71+
std::vector<ModelRetinaFacePT::Box> generatePriorData();
72+
std::vector<ModelRetinaFacePT::Rect> getFilteredProposals(const InferenceEngine::MemoryBlob::Ptr& rawData,
73+
const std::vector<size_t>& indicies, int imgWidth, int imgHeight);
74+
75+
void prepareInputsOutputs(InferenceEngine::CNNNetwork& cnnNetwork) override;
76+
};

demos/common/cpp/models/include/models/detection_model_yolo.h

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,29 @@ namespace ngraph {
2626
}
2727
}
2828

29-
class ModelYolo3 : public DetectionModel {
29+
class ModelYolo : public DetectionModel {
3030
protected:
3131
class Region {
3232
public:
3333
int num = 0;
3434
int classes = 0;
3535
int coords = 0;
3636
std::vector<float> anchors;
37+
int outputWidth = 0;
38+
int outputHeight = 0;
3739

3840
Region(const std::shared_ptr<ngraph::op::RegionYolo>& regionYolo);
41+
Region(int classes, int coords, const std::vector<float>& anchors, const std::vector<int64_t>& masks, int outputWidth, int outputHeight);
3942
};
4043

4144
public:
45+
enum YoloVersion {
46+
YOLO_V1V2,
47+
YOLO_V3,
48+
YOLO_V4,
49+
YOLO_V4_TINY
50+
};
51+
4252
/// Constructor.
4353
/// @param modelFileName name of model to load
4454
/// @param confidenceThreshold - threshold to eliminate low-confidence detections.
@@ -51,22 +61,28 @@ class ModelYolo3 : public DetectionModel {
5161
/// during postprocessing (only one of them should stay). The default value is 0.5
5262
/// @param labels - array of labels for every class. If this array is empty or contains less elements
5363
/// 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 = true, float boxIOUThreshold = 0.5, const std::vector<std::string>& labels = std::vector<std::string>());
64+
/// @param anchors - vector of anchors coordinates. Required for YOLOv4, for other versions it may be omitted.
65+
/// @param masks - vector of masks values. Required for YOLOv4, for other versions it may be omitted.
66+
ModelYolo(const std::string& modelFileName, float confidenceThreshold, bool useAutoResize,
67+
bool useAdvancedPostprocessing = true, float boxIOUThreshold = 0.5, const std::vector<std::string>& labels = std::vector<std::string>(),
68+
const std::vector<float>& anchors = std::vector<float>(), const std::vector<int64_t>& masks = std::vector<int64_t>());
5669

5770
std::unique_ptr<ResultBase> postprocess(InferenceResult& infResult) override;
5871

5972
protected:
6073
void prepareInputsOutputs(InferenceEngine::CNNNetwork& cnnNetwork) override;
6174

62-
void parseYOLOV3Output(const std::string& output_name, const InferenceEngine::Blob::Ptr& blob,
75+
void parseYOLOOutput(const std::string& output_name, const InferenceEngine::Blob::Ptr& blob,
6376
const unsigned long resized_im_h, const unsigned long resized_im_w, const unsigned long original_im_h,
6477
const unsigned long original_im_w, std::vector<DetectedObject>& objects);
6578

66-
static int calculateEntryIndex(int side, int lcoords, int lclasses, int location, int entry);
79+
static int calculateEntryIndex(int entriesNum, int lcoords, int lclasses, int location, int entry);
6780
static double intersectionOverUnion(const DetectedObject& o1, const DetectedObject& o2);
6881

6982
std::map<std::string, Region> regions;
7083
double boxIOUThreshold;
7184
bool useAdvancedPostprocessing;
85+
YoloVersion yoloVersion;
86+
const std::vector<float> presetAnchors;
87+
const std::vector<int64_t> presetMasks;
7288
};

0 commit comments

Comments
 (0)