Initial setup for CLion

This commit is contained in:
2026-03-28 16:54:11 +11:00
parent 239cc02591
commit 7b4134133c
1136 changed files with 811916 additions and 0 deletions

View File

@@ -0,0 +1,94 @@
/*
// Copyright (C) 2021-2024 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 <stddef.h>
#include <memory>
#include <vector>
#include <opencv2/core.hpp>
struct Peak {
explicit Peak(const cv::Point2f& keypoint = cv::Point2f(-1, -1), const float score = 0.0f, const float tag = 0.0f)
: keypoint(keypoint),
score(score),
tag(tag) {}
cv::Point2f keypoint;
float score;
float tag;
};
class Pose {
public:
explicit Pose(size_t numJoints) : peaks(numJoints) {}
void add(size_t index, Peak peak) {
peaks[index] = peak;
sum += peak.score;
poseTag = poseTag * static_cast<float>(validPointsNum) + peak.tag;
poseCenter = poseCenter * static_cast<float>(validPointsNum) + peak.keypoint;
validPointsNum += 1;
poseTag = poseTag / static_cast<float>(validPointsNum);
poseCenter = poseCenter / static_cast<float>(validPointsNum);
}
float getPoseTag() const {
return poseTag;
}
float getMeanScore() const {
return sum / static_cast<float>(size());
}
Peak& getPeak(size_t index) {
return peaks[index];
}
cv::Point2f& getPoseCenter() {
return poseCenter;
}
size_t size() const {
return peaks.size();
}
private:
std::vector<Peak> peaks;
cv::Point2f poseCenter = cv::Point2f(0.f, 0.f);
int validPointsNum = 0;
float poseTag = 0;
float sum = 0;
};
void findPeaks(const std::vector<cv::Mat>& nmsHeatMaps,
const std::vector<cv::Mat>& aembdsMaps,
std::vector<std::vector<Peak>>& allPeaks,
size_t jointId,
size_t maxNumPeople,
float detectionThreshold);
std::vector<Pose> matchByTag(std::vector<std::vector<Peak>>& allPeaks,
size_t maxNumPeople,
size_t numJoints,
float tagThreshold);
void adjustAndRefine(std::vector<Pose>& allPoses,
const std::vector<cv::Mat>& heatMaps,
const std::vector<cv::Mat>& aembdsMaps,
int poseId,
float delta);

View File

@@ -0,0 +1,57 @@
/*
// Copyright (C) 2020-2024 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 <stddef.h>
#include <memory>
#include <string>
#include <vector>
#include "models/image_model.h"
namespace ov {
class Model;
} // namespace ov
struct InferenceResult;
struct ResultBase;
class ClassificationModel : public ImageModel {
public:
/// Constructor
/// @param modelFileName name of model to load.
/// @param nTop - number of top results.
/// Any detected object with confidence lower than this threshold will be ignored.
/// @param useAutoResize - if true, image will be resized by openvino.
/// Otherwise, image will be preprocessed and resized using OpenCV routines.
/// @param labels - array of labels for every class.
/// @param layout - model input layout
ClassificationModel(const std::string& modelFileName,
size_t nTop,
bool useAutoResize,
const std::vector<std::string>& labels,
const std::string& layout = "");
std::unique_ptr<ResultBase> postprocess(InferenceResult& infResult) override;
static std::vector<std::string> loadLabels(const std::string& labelFilename);
protected:
size_t nTop;
std::vector<std::string> labels;
void prepareInputsOutputs(std::shared_ptr<ov::Model>& model) override;
};

View File

@@ -0,0 +1,52 @@
/*
// Copyright (C) 2020-2024 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 <stddef.h>
#include <string>
#include <vector>
#include "models/image_model.h"
class DetectionModel : public ImageModel {
public:
/// Constructor
/// @param modelFileName name of model to load
/// @param confidenceThreshold - threshold to eliminate low-confidence detections.
/// Any detected object with confidence lower than this threshold will be ignored.
/// @param useAutoResize - if true, image will be resized by openvino.
/// Otherwise, image will be preprocessed and resized using OpenCV routines.
/// @param labels - array of labels for every class. If this array is empty or contains less elements
/// than actual classes number, default "Label #N" will be shown for missing items.
/// @param layout - model input layout
DetectionModel();
DetectionModel(const std::string& modelFileName,
float confidenceThreshold,
bool useAutoResize,
const std::vector<std::string>& labels,
const std::string& layout = "");
static std::vector<std::string> loadLabels(const std::string& labelFilename);
protected:
float confidenceThreshold;
std::vector<std::string> labels;
std::string getLabelName(size_t labelID) {
return labelID < labels.size() ? labels[labelID] : std::string("Label #") + std::to_string(labelID);
}
};

View File

@@ -0,0 +1,59 @@
/*
// Copyright (C) 2020-2024 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 <memory>
#include <string>
#include <vector>
#include "models/detection_model.h"
namespace ov {
class InferRequest;
class Model;
} // namespace ov
struct InferenceResult;
struct InputData;
struct InternalModelData;
struct ResultBase;
class ModelCenterNet : public DetectionModel {
public:
struct BBox {
float left;
float top;
float right;
float bottom;
float getWidth() const {
return (right - left) + 1.0f;
}
float getHeight() const {
return (bottom - top) + 1.0f;
}
};
static const int INIT_VECTOR_SIZE = 200;
ModelCenterNet(const std::string& modelFileName,
float confidenceThreshold,
const std::vector<std::string>& labels = std::vector<std::string>(),
const std::string& layout = "");
std::shared_ptr<InternalModelData> preprocess(const InputData& inputData, ov::InferRequest& request) override;
std::unique_ptr<ResultBase> postprocess(InferenceResult& infResult) override;
protected:
void prepareInputsOutputs(std::shared_ptr<ov::Model>& model) override;
};

View File

@@ -0,0 +1,55 @@
/*
// Copyright (C) 2020-2024 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 <stddef.h>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include <utils/nms.hpp>
#include "models/detection_model.h"
namespace ov {
class Model;
} // namespace ov
struct InferenceResult;
struct ResultBase;
class ModelFaceBoxes : public DetectionModel {
public:
static const int INIT_VECTOR_SIZE = 200;
ModelFaceBoxes(const std::string& modelFileName,
float confidenceThreshold,
bool useAutoResize,
float boxIOUThreshold,
const std::string& layout = "");
std::unique_ptr<ResultBase> postprocess(InferenceResult& infResult) override;
protected:
size_t maxProposalsCount;
const float boxIOUThreshold;
const std::vector<float> variance;
const std::vector<int> steps;
const std::vector<std::vector<int>> minSizes;
std::vector<Anchor> anchors;
void prepareInputsOutputs(std::shared_ptr<ov::Model>& model) override;
void priorBoxes(const std::vector<std::pair<size_t, size_t>>& featureMaps);
};

View File

@@ -0,0 +1,74 @@
/*
// Copyright (C) 2020-2024 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 <map>
#include <memory>
#include <string>
#include <vector>
#include <utils/nms.hpp>
#include "models/detection_model.h"
namespace ov {
class Model;
} // namespace ov
struct InferenceResult;
struct ResultBase;
class ModelRetinaFace : public DetectionModel {
public:
static const int LANDMARKS_NUM = 5;
static const int INIT_VECTOR_SIZE = 200;
/// Loads model and performs required initialization
/// @param model_name name of model to load
/// @param confidenceThreshold - threshold to eliminate low-confidence detections.
/// Any detected object with confidence lower than this threshold will be ignored.
/// @param useAutoResize - if true, image will be resized by openvino.
/// @param boxIOUThreshold - threshold for NMS boxes filtering, varies in [0.0, 1.0] range.
/// @param layout - model input layout
ModelRetinaFace(const std::string& model_name,
float confidenceThreshold,
bool useAutoResize,
float boxIOUThreshold,
const std::string& layout = "");
std::unique_ptr<ResultBase> postprocess(InferenceResult& infResult) override;
protected:
struct AnchorCfgLine {
int stride;
std::vector<int> scales;
int baseSize;
std::vector<int> ratios;
};
bool shouldDetectMasks;
bool shouldDetectLandmarks;
const float boxIOUThreshold;
const float maskThreshold;
float landmarkStd;
enum OutputType { OUT_BOXES, OUT_SCORES, OUT_LANDMARKS, OUT_MASKSCORES, OUT_MAX };
std::vector<std::string> separateOutputsNames[OUT_MAX];
const std::vector<AnchorCfgLine> anchorCfg;
std::map<int, std::vector<Anchor>> anchorsFpn;
std::vector<std::vector<Anchor>> anchors;
void generateAnchorsFpn();
void prepareInputsOutputs(std::shared_ptr<ov::Model>& model) override;
};

View File

@@ -0,0 +1,81 @@
/*
// Copyright (C) 2021-2024 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 <stddef.h>
#include <memory>
#include <string>
#include <vector>
#include <opencv2/core/types.hpp>
#include <utils/nms.hpp>
#include "models/detection_model.h"
namespace ov {
class Model;
class Tensor;
} // namespace ov
struct InferenceResult;
struct ResultBase;
class ModelRetinaFacePT : public DetectionModel {
public:
struct Box {
float cX;
float cY;
float width;
float height;
};
/// Loads model and performs required initialization
/// @param model_name name of model to load
/// @param confidenceThreshold - threshold to eliminate low-confidence detections.
/// Any detected object with confidence lower than this threshold will be ignored.
/// @param useAutoResize - if true, image will be resized by openvino.
/// @param boxIOUThreshold - threshold for NMS boxes filtering, varies in [0.0, 1.0] range.
/// @param layout - model input layout
ModelRetinaFacePT(const std::string& modelFileName,
float confidenceThreshold,
bool useAutoResize,
float boxIOUThreshold,
const std::string& layout = "");
std::unique_ptr<ResultBase> postprocess(InferenceResult& infResult) override;
protected:
size_t landmarksNum;
const float boxIOUThreshold;
float variance[2] = {0.1f, 0.2f};
enum OutputType { OUT_BOXES, OUT_SCORES, OUT_LANDMARKS, OUT_MAX };
std::vector<ModelRetinaFacePT::Box> priors;
std::vector<size_t> filterByScore(const ov::Tensor& scoresTensor, const float confidenceThreshold);
std::vector<float> getFilteredScores(const ov::Tensor& scoresTensor, const std::vector<size_t>& indicies);
std::vector<cv::Point2f> getFilteredLandmarks(const ov::Tensor& landmarksTensor,
const std::vector<size_t>& indicies,
int imgWidth,
int imgHeight);
std::vector<ModelRetinaFacePT::Box> generatePriorData();
std::vector<Anchor> getFilteredProposals(const ov::Tensor& boxesTensor,
const std::vector<size_t>& indicies,
int imgWidth,
int imgHeight);
void prepareInputsOutputs(std::shared_ptr<ov::Model>& model) override;
};

View File

@@ -0,0 +1,73 @@
/*
// Copyright (C) 2020-2024 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 <stddef.h>
#include <memory>
#include <string>
#include <vector>
#include "models/detection_model.h"
namespace ov {
class InferRequest;
class Model;
} // namespace ov
struct InferenceResult;
struct InputData;
struct InternalModelData;
struct ResultBase;
class ModelSSD : public DetectionModel {
public:
ModelSSD();
/// Constructor
/// @param modelFileName name of model to load
/// @param confidenceThreshold - threshold to eliminate low-confidence detections.
/// Any detected object with confidence lower than this threshold will be ignored.
/// @param useAutoResize - if true, image will be resized by openvino.
/// Otherwise, image will be preprocessed and resized using OpenCV routines.
/// @param labels - array of labels for every class. If this array is empty or contains less elements
/// than actual classes number, default "Label #N" will be shown for missing items.
/// @param layout - model input layout
ModelSSD(const std::string& modelFileName,
float confidenceThreshold,
bool useAutoResize,
const std::vector<std::string>& labels = std::vector<std::string>(),
const std::string& layout = "");
void Initialise(const std::string& modelFileName,
float _confidenceThreshold,
bool useAutoResize,
const std::vector<std::string>& _labels = std::vector<std::string>(),
const std::string& layout = "")
{
ImageModel::Initalise(modelFileName, useAutoResize, layout),
confidenceThreshold = confidenceThreshold;
labels = _labels;
}
std::shared_ptr<InternalModelData> preprocess(const InputData& inputData, ov::InferRequest& request) override;
std::unique_ptr<ResultBase> postprocess(InferenceResult& infResult) override;
protected:
std::unique_ptr<ResultBase> postprocessSingleOutput(InferenceResult& infResult);
std::unique_ptr<ResultBase> postprocessMultipleOutputs(InferenceResult& infResult);
void prepareInputsOutputs(std::shared_ptr<ov::Model>& model) override;
void prepareSingleOutput(std::shared_ptr<ov::Model>& model);
void prepareMultipleOutputs(std::shared_ptr<ov::Model>& model);
size_t objectSize = 0;
size_t detectionsNumId = 0;
};

View File

@@ -0,0 +1,107 @@
/*
// Copyright (C) 2020-2024 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 <stddef.h>
#include <stdint.h>
#include <map>
#include <memory>
#include <string>
#include <vector>
#include <openvino/op/region_yolo.hpp>
#include <openvino/openvino.hpp>
#include "models/detection_model.h"
struct DetectedObject;
struct InferenceResult;
struct ResultBase;
class ModelYolo : public DetectionModel {
protected:
class Region {
public:
int num = 0;
size_t classes = 0;
int coords = 0;
std::vector<float> anchors;
size_t outputWidth = 0;
size_t outputHeight = 0;
Region(const std::shared_ptr<ov::op::v0::RegionYolo>& regionYolo);
Region(size_t classes,
int coords,
const std::vector<float>& anchors,
const std::vector<int64_t>& masks,
size_t outputWidth,
size_t outputHeight);
};
public:
enum YoloVersion { YOLO_V1V2, YOLO_V3, YOLO_V4, YOLO_V4_TINY, YOLOF };
/// Constructor.
/// @param modelFileName name of model to load
/// @param confidenceThreshold - threshold to eliminate low-confidence detections.
/// Any detected object with confidence lower than this threshold will be ignored.
/// @param useAutoResize - if true, image will be resized by openvino.
/// Otherwise, image will be preprocessed and resized using OpenCV routines.
/// @param useAdvancedPostprocessing - if true, an advanced algorithm for filtering/postprocessing will be used
/// (with better processing of multiple crossing objects). Otherwise, classic algorithm will be used.
/// @param boxIOUThreshold - threshold to treat separate output regions as one object for filtering
/// during postprocessing (only one of them should stay). The default value is 0.5
/// @param labels - array of labels for every class. If this array is empty or contains less elements
/// than actual classes number, default "Label #N" will be shown for missing items.
/// @param anchors - vector of anchors coordinates. Required for YOLOv4, for other versions it may be omitted.
/// @param masks - vector of masks values. Required for YOLOv4, for other versions it may be omitted.
/// @param layout - model input layout
ModelYolo(const std::string& modelFileName,
float confidenceThreshold,
bool useAutoResize,
bool useAdvancedPostprocessing = true,
float boxIOUThreshold = 0.5,
const std::vector<std::string>& labels = std::vector<std::string>(),
const std::vector<float>& anchors = std::vector<float>(),
const std::vector<int64_t>& masks = std::vector<int64_t>(),
const std::string& layout = "");
std::unique_ptr<ResultBase> postprocess(InferenceResult& infResult) override;
protected:
void prepareInputsOutputs(std::shared_ptr<ov::Model>& model) override;
void parseYOLOOutput(const std::string& output_name,
const ov::Tensor& tensor,
const unsigned long resized_im_h,
const unsigned long resized_im_w,
const unsigned long original_im_h,
const unsigned long original_im_w,
std::vector<DetectedObject>& objects);
static int calculateEntryIndex(int entriesNum, int lcoords, size_t lclasses, int location, int entry);
static double intersectionOverUnion(const DetectedObject& o1, const DetectedObject& o2);
std::map<std::string, Region> regions;
double boxIOUThreshold;
bool useAdvancedPostprocessing;
bool isObjConf = 1;
YoloVersion yoloVersion;
const std::vector<float> presetAnchors;
const std::vector<int64_t> presetMasks;
ov::Layout yoloRegionLayout = "NCHW";
};

View File

@@ -0,0 +1,50 @@
/*
// Copyright (C) 2022-2024 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 <string>
#include <vector>
#include <openvino/openvino.hpp>
#include "models/detection_model.h"
class ModelYoloV3ONNX: public DetectionModel {
public:
/// Constructor.
/// @param modelFileName name of model to load
/// @param confidenceThreshold - threshold to eliminate low-confidence detections.
/// Any detected object with confidence lower than this threshold will be ignored.
/// @param labels - array of labels for every class. If this array is empty or contains less elements
/// than actual classes number, default "Label #N" will be shown for missing items.
/// @param layout - model input layout
ModelYoloV3ONNX(const std::string& modelFileName,
float confidenceThreshold,
const std::vector<std::string>& labels = std::vector<std::string>(),
const std::string& layout = "");
std::unique_ptr<ResultBase> postprocess(InferenceResult& infResult) override;
std::shared_ptr<InternalModelData> preprocess(const InputData& inputData, ov::InferRequest& request) override;
protected:
void prepareInputsOutputs(std::shared_ptr<ov::Model>& model) override;
std::string boxesOutputName;
std::string scoresOutputName;
std::string indicesOutputName;
static const int numberOfClasses = 80;
};

View File

@@ -0,0 +1,54 @@
/*
// Copyright (C) 2022-2024 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 <memory>
#include <string>
#include <vector>
#include <openvino/openvino.hpp>
#include "models/detection_model.h"
class ModelYoloX: public DetectionModel {
public:
/// Constructor.
/// @param modelFileName name of model to load
/// @param confidenceThreshold - threshold to eliminate low-confidence detections.
/// Any detected object with confidence lower than this threshold will be ignored.
/// @param boxIOUThreshold - threshold to treat separate output regions as one object for filtering
/// during postprocessing (only one of them should stay). The default value is 0.5
/// @param labels - array of labels for every class. If this array is empty or contains less elements
/// than actual classes number, default "Label #N" will be shown for missing items.
/// @param layout - model input layout
ModelYoloX(const std::string& modelFileName,
float confidenceThreshold,
float boxIOUThreshold = 0.5,
const std::vector<std::string>& labels = std::vector<std::string>(),
const std::string& layout = "");
std::unique_ptr<ResultBase> postprocess(InferenceResult& infResult) override;
std::shared_ptr<InternalModelData> preprocess(const InputData& inputData, ov::InferRequest& request) override;
protected:
void prepareInputsOutputs(std::shared_ptr<ov::Model>& model) override;
void setStridesGrids();
float boxIOUThreshold;
std::vector<std::pair<size_t, size_t>> grids;
std::vector<size_t> expandedStrides;
static const size_t numberOfClasses = 80;
};

View File

@@ -0,0 +1,89 @@
/*
// Copyright (C) 2021-2024 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 <memory>
#include <string>
#include <vector>
#include <opencv2/core.hpp>
#include <utils/image_utils.h>
#include "models/image_model.h"
namespace ov {
class InferRequest;
class Model;
class Shape;
} // namespace ov
struct HumanPose;
struct InferenceResult;
struct InputData;
struct InternalModelData;
struct ResultBase;
class HpeAssociativeEmbedding : public ImageModel {
public:
/// Constructor
/// @param modelFileName name of model to load
/// @param aspectRatio - the ratio of input width to its height.
/// @param targetSize - the length of a short image side used for model reshaping.
/// @param confidenceThreshold - threshold to eliminate low-confidence poses.
/// Any pose with confidence lower than this threshold will be ignored.
/// @param layout - model input layout
HpeAssociativeEmbedding(const std::string& modelFileName,
double aspectRatio,
int targetSize,
float confidenceThreshold,
const std::string& layout = "",
float delta = 0.0,
RESIZE_MODE resizeMode = RESIZE_KEEP_ASPECT);
std::unique_ptr<ResultBase> postprocess(InferenceResult& infResult) override;
std::shared_ptr<InternalModelData> preprocess(const InputData& inputData, ov::InferRequest& request) override;
protected:
void prepareInputsOutputs(std::shared_ptr<ov::Model>& model) override;
cv::Size inputLayerSize;
double aspectRatio;
int targetSize;
float confidenceThreshold;
float delta;
std::string embeddingsTensorName;
std::string heatmapsTensorName;
std::string nmsHeatmapsTensorName;
static const int numJoints = 17;
static const int stride = 32;
static const int maxNumPeople = 30;
static const cv::Vec3f meanPixel;
static const float detectionThreshold;
static const float tagThreshold;
void changeInputSize(std::shared_ptr<ov::Model>& model);
std::string findTensorByName(const std::string& tensorName, const std::vector<std::string>& outputsNames);
std::vector<cv::Mat> split(float* data, const ov::Shape& shape);
std::vector<HumanPose> extractPoses(std::vector<cv::Mat>& heatMaps,
const std::vector<cv::Mat>& aembdsMaps,
const std::vector<cv::Mat>& nmsHeatMaps) const;
};

View File

@@ -0,0 +1,78 @@
/*
// Copyright (C) 2020-2024 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 <stddef.h>
#include <memory>
#include <string>
#include <vector>
#include <opencv2/core.hpp>
#include "models/image_model.h"
namespace ov {
class InferRequest;
class Model;
} // namespace ov
struct HumanPose;
struct InferenceResult;
struct InputData;
struct InternalModelData;
struct ResultBase;
class HPEOpenPose : public ImageModel {
public:
/// Constructor
/// @param modelFileName name of model to load
/// @param aspectRatio - the ratio of input width to its height.
/// @param targetSize - the height used for model reshaping.
/// @param confidenceThreshold - threshold to eliminate low-confidence keypoints.
/// @param layout - model input layout
HPEOpenPose(const std::string& modelFileName,
double aspectRatio,
int targetSize,
float confidenceThreshold,
const std::string& layout = "");
std::unique_ptr<ResultBase> postprocess(InferenceResult& infResult) override;
std::shared_ptr<InternalModelData> preprocess(const InputData& inputData, ov::InferRequest& request) override;
static const size_t keypointsNumber = 18;
protected:
void prepareInputsOutputs(std::shared_ptr<ov::Model>& model) override;
static const int minJointsNumber = 3;
static const int stride = 8;
static const int upsampleRatio = 4;
static const cv::Vec3f meanPixel;
static const float minPeaksDistance;
static const float midPointsScoreThreshold;
static const float foundMidPointsRatioThreshold;
static const float minSubsetScore;
cv::Size inputLayerSize;
double aspectRatio;
int targetSize;
float confidenceThreshold;
std::vector<HumanPose> extractPoses(const std::vector<cv::Mat>& heatMaps, const std::vector<cv::Mat>& pafs) const;
void resizeFeatureMaps(std::vector<cv::Mat>& featureMaps) const;
void UpdateAspectRatio(double aRatio) { aspectRatio = aRatio; }
void changeInputSize(std::shared_ptr<ov::Model>& model);
};

View File

@@ -0,0 +1,58 @@
/*
// Copyright (C) 2021-2024 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 <stddef.h>
#include <memory>
#include <string>
#include "models/model_base.h"
#include "utils/image_utils.h"
namespace ov {
class InferRequest;
} // namespace ov
struct InputData;
struct InternalModelData;
class ImageModel : public ModelBase {
public:
/// Constructor
/// @param modelFileName name of model to load
/// @param useAutoResize - if true, image is resized by openvino
/// @param layout - model input layout
ImageModel();
ImageModel(const std::string& modelFileName, bool useAutoResize, const std::string& layout = "");
std::shared_ptr<InternalModelData> preprocess(const InputData& inputData, ov::InferRequest& request) override;
void updateImageSize(const cv::Size& inputImgSize) override {
netInputHeight = inputImgSize.height;
netInputWidth = inputImgSize.width;
}
void Initalise(const std::string& _modelFileName, bool _useAutoResize, const std::string& _layout = "") {
useAutoResize = _useAutoResize;
ModelBase::Initilise(modelFileName, _layout);
}
protected:
bool useAutoResize;
size_t netInputHeight = 0;
size_t netInputWidth = 0;
cv::InterpolationFlags interpolationMode = cv::INTER_LINEAR;
RESIZE_MODE resizeMode = RESIZE_FILL;
};

View File

@@ -0,0 +1,41 @@
/*
// Copyright (C) 2020-2024 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 <opencv2/opencv.hpp>
struct InputData {
virtual ~InputData() {}
template <class T>
T& asRef() {
return dynamic_cast<T&>(*this);
}
template <class T>
const T& asRef() const {
return dynamic_cast<const T&>(*this);
}
};
struct ImageInputData : public InputData {
cv::Mat inputImage;
ImageInputData() {}
ImageInputData(const cv::Mat& img) {
inputImage = img;
}
};

View File

@@ -0,0 +1,48 @@
/*
// Copyright (C) 2020-2024 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
struct InternalModelData {
virtual ~InternalModelData() {}
template <class T>
T& asRef() {
return dynamic_cast<T&>(*this);
}
template <class T>
const T& asRef() const {
return dynamic_cast<const T&>(*this);
}
};
struct InternalImageModelData : public InternalModelData {
InternalImageModelData(int width, int height) : inputImgWidth(width), inputImgHeight(height) {}
int inputImgWidth;
int inputImgHeight;
};
struct InternalScaleData : public InternalImageModelData {
InternalScaleData(int width, int height, float scaleX, float scaleY)
: InternalImageModelData(width, height),
scaleX(scaleX),
scaleY(scaleY) {}
float scaleX;
float scaleY;
};

View File

@@ -0,0 +1,55 @@
/*
// Copyright (C) 2021-2024 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 writingb 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 <memory>
#include <string>
#include <opencv2/core/types.hpp>
#include "models/image_model.h"
namespace ov {
class InferRequest;
class Model;
} // namespace ov
struct InferenceResult;
struct InputData;
struct InternalModelData;
struct ResultBase;
class JPEGRestorationModel : public ImageModel {
public:
/// Constructor
/// @param modelFileName name of model to load
/// @param inputImgSize size of image to set model input shape
/// @param jpegCompression flag allows to perform compression before the inference
/// @param layout - model input layout
JPEGRestorationModel(const std::string& modelFileName,
const cv::Size& inputImgSize,
bool jpegCompression,
const std::string& layout = "");
std::shared_ptr<InternalModelData> preprocess(const InputData& inputData, ov::InferRequest& request) override;
std::unique_ptr<ResultBase> postprocess(InferenceResult& infResult) override;
protected:
void prepareInputsOutputs(std::shared_ptr<ov::Model>& model) override;
void changeInputSize(std::shared_ptr<ov::Model>& model);
static const size_t stride = 8;
bool jpegCompression = false;
};

View File

@@ -0,0 +1,87 @@
/*
// Copyright (C) 2020-2024 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 <map>
#include <memory>
#include <string>
#include <vector>
#include <openvino/openvino.hpp>
#include <utils/args_helper.hpp>
#include <utils/config_factory.h>
#include <utils/ocv_common.hpp>
struct InferenceResult;
struct InputData;
struct InternalModelData;
struct ResultBase;
class ModelBase {
public:
ModelBase() {};
ModelBase(const std::string& modelFileName, const std::string& layout = "")
: modelFileName(modelFileName),
inputsLayouts(parseLayoutString(layout)) {}
virtual ~ModelBase() {}
virtual std::shared_ptr<InternalModelData> preprocess(const InputData& inputData, ov::InferRequest& request) = 0;
// Virtual method to be overridden in derived classes
virtual void updateImageSize(const cv::Size& inputImgSize) {
// Optionally leave empty or add any base logic here
}
virtual ov::CompiledModel compileModel(const ModelConfig& config, ov::Core& core);
virtual void onLoadCompleted(const std::vector<ov::InferRequest>& requests) {}
virtual std::unique_ptr<ResultBase> postprocess(InferenceResult& infResult) = 0;
void Initilise(const std::string& _modelFileName, const std::string& _layout = "") {
modelFileName = _modelFileName;
inputsLayouts = parseLayoutString(_layout);
}
const std::vector<std::string>& getOutputsNames() const {
return outputsNames;
}
const std::vector<std::string>& getInputsNames() const {
return inputsNames;
}
std::string getModelFileName() {
return modelFileName;
}
void setInputsPreprocessing(bool reverseInputChannels,
const std::string& meanValues,
const std::string& scaleValues) {
this->inputTransform = InputTransform(reverseInputChannels, meanValues, scaleValues);
}
protected:
virtual void prepareInputsOutputs(std::shared_ptr<ov::Model>& model) = 0;
virtual void setBatch(std::shared_ptr<ov::Model>& model);
std::shared_ptr<ov::Model> prepareModel(ov::Core& core);
InputTransform inputTransform = InputTransform();
std::vector<std::string> inputsNames;
std::vector<std::string> outputsNames;
ov::CompiledModel compiledModel;
std::string modelFileName;
ModelConfig config = {};
std::map<std::string, ov::Layout> inputsLayouts;
ov::Layout getInputLayout(const ov::Output<ov::Node>& input);
};

View File

@@ -0,0 +1,62 @@
/*
// Copyright (C) 2020-2024 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 <stddef.h>
#include <vector>
#include <opencv2/core.hpp>
struct HumanPose;
struct Peak {
Peak(const int id = -1, const cv::Point2f& pos = cv::Point2f(), const float score = 0.0f);
int id;
cv::Point2f pos;
float score;
};
struct HumanPoseByPeaksIndices {
explicit HumanPoseByPeaksIndices(const int keypointsNumber);
std::vector<int> peaksIndices;
int nJoints;
float score;
};
struct TwoJointsConnection {
TwoJointsConnection(const int firstJointIdx, const int secondJointIdx, const float score);
int firstJointIdx;
int secondJointIdx;
float score;
};
void findPeaks(const std::vector<cv::Mat>& heatMaps,
const float minPeaksDistance,
std::vector<std::vector<Peak>>& allPeaks,
int heatMapId,
float confidenceThreshold);
std::vector<HumanPose> groupPeaksToPoses(const std::vector<std::vector<Peak>>& allPeaks,
const std::vector<cv::Mat>& pafs,
const size_t keypointsNumber,
const float midPointsScoreThreshold,
const float foundMidPointsRatioThreshold,
const int minJointsNumber,
const float minSubsetScore);

View File

@@ -0,0 +1,122 @@
/*
// Copyright (C) 2020-2024 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 <map>
#include <memory>
#include <string>
#include <vector>
#include <opencv2/core.hpp>
#include <openvino/openvino.hpp>
#include "internal_model_data.h"
struct MetaData;
struct ResultBase {
ResultBase(int64_t frameId = -1, const std::shared_ptr<MetaData>& metaData = nullptr)
: frameId(frameId),
metaData(metaData) {}
virtual ~ResultBase() {}
int64_t frameId;
std::shared_ptr<MetaData> metaData;
bool IsEmpty() {
return frameId < 0;
}
template <class T>
T& asRef() {
return dynamic_cast<T&>(*this);
}
template <class T>
const T& asRef() const {
return dynamic_cast<const T&>(*this);
}
};
struct InferenceResult : public ResultBase {
std::shared_ptr<InternalModelData> internalModelData;
std::map<std::string, ov::Tensor> outputsData;
/// Returns the first output tensor
/// This function is a useful addition to direct access to outputs list as many models have only one output
/// @returns first output tensor
ov::Tensor getFirstOutputTensor() {
if (outputsData.empty()) {
throw std::out_of_range("Outputs map is empty.");
}
return outputsData.begin()->second;
}
/// Returns true if object contains no valid data
/// @returns true if object contains no valid data
bool IsEmpty() {
return outputsData.empty();
}
};
struct ClassificationResult : public ResultBase {
ClassificationResult(int64_t frameId = -1, const std::shared_ptr<MetaData>& metaData = nullptr)
: ResultBase(frameId, metaData) {}
struct Classification {
unsigned int id;
std::string label;
float score;
Classification(unsigned int id, const std::string& label, float score) : id(id), label(label), score(score) {}
};
std::vector<Classification> topLabels;
};
struct DetectedObject : public cv::Rect2f {
size_t labelID;
std::string label;
float confidence;
};
struct DetectionResult : public ResultBase {
DetectionResult(int64_t frameId = -1, const std::shared_ptr<MetaData>& metaData = nullptr)
: ResultBase(frameId, metaData) {}
std::vector<DetectedObject> objects;
};
struct RetinaFaceDetectionResult : public DetectionResult {
RetinaFaceDetectionResult(int64_t frameId = -1, const std::shared_ptr<MetaData>& metaData = nullptr)
: DetectionResult(frameId, metaData) {}
std::vector<cv::Point2f> landmarks;
};
struct ImageResult : public ResultBase {
ImageResult(int64_t frameId = -1, const std::shared_ptr<MetaData>& metaData = nullptr)
: ResultBase(frameId, metaData) {}
cv::Mat resultImage;
};
struct HumanPose {
std::vector<cv::Point2f> keypoints;
float score;
};
struct HumanPoseResult : public ResultBase {
HumanPoseResult(int64_t frameId = -1, const std::shared_ptr<MetaData>& metaData = nullptr)
: ResultBase(frameId, metaData) {}
std::vector<HumanPose> poses;
};

View File

@@ -0,0 +1,50 @@
/*
// Copyright (C) 2020-2024 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 writingb 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 <memory>
#include <string>
#include <vector>
#include "models/image_model.h"
namespace ov {
class Model;
} // namespace ov
struct InferenceResult;
struct ResultBase;
#pragma once
class SegmentationModel : public ImageModel {
public:
/// Constructor
/// @param modelFileName name of model to load
/// @param useAutoResize - if true, image will be resized by openvino.
/// Otherwise, image will be preprocessed and resized using OpenCV routines.
/// @param layout - model input layout
SegmentationModel(const std::string& modelFileName, bool useAutoResize, const std::string& layout = "");
static std::vector<std::string> loadLabels(const std::string& labelFilename);
std::unique_ptr<ResultBase> postprocess(InferenceResult& infResult) override;
protected:
void prepareInputsOutputs(std::shared_ptr<ov::Model>& model) override;
int outHeight = 0;
int outWidth = 0;
int outChannels = 0;
};

View File

@@ -0,0 +1,43 @@
/*
// Copyright (C) 2021-2024 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 writingb 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 <memory>
#include <string>
#include "models/image_model.h"
namespace ov {
class InferRequest;
class Model;
} // namespace ov
struct InferenceResult;
struct InputData;
struct InternalModelData;
struct ResultBase;
class StyleTransferModel : public ImageModel {
public:
/// Constructor
/// @param modelFileName name of model to load
/// @param layout - model input layout
StyleTransferModel(const std::string& modelFileName, const std::string& layout = "");
std::unique_ptr<ResultBase> postprocess(InferenceResult& infResult) override;
protected:
void prepareInputsOutputs(std::shared_ptr<ov::Model>& model) override;
};

View File

@@ -0,0 +1,59 @@
/*
// Copyright (C) 2021-2024 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 writingb 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 <memory>
#include <string>
#include <opencv2/core/types.hpp>
#include "models/image_model.h"
namespace ov {
class InferRequest;
class Model;
} // namespace ov
struct InferenceResult;
struct InputData;
struct InternalModelData;
struct ResultBase;
class SuperResolutionModel : public ImageModel {
public:
/// Constructor
/// @param modelFileName name of model to load
/// @param layout - model input layout
SuperResolutionModel(const std::string& modelFileName,
const cv::Size& inputImgSize,
const std::string& layout = "");
std::shared_ptr<InternalModelData> preprocess(const InputData& inputData, ov::InferRequest& request) override;
std::unique_ptr<ResultBase> postprocess(InferenceResult& infResult) override;
protected:
void changeInputSize(std::shared_ptr<ov::Model>& model, int coeff);
void prepareInputsOutputs(std::shared_ptr<ov::Model>& model) override;
};
class SuperResolutionChannelJoint : public SuperResolutionModel {
public:
using SuperResolutionModel::SuperResolutionModel;
std::shared_ptr<InternalModelData> preprocess(const InputData& inputData, ov::InferRequest& request) override;
std::unique_ptr<ResultBase> postprocess(InferenceResult& infResult) override;
void prepareInputsOutputs(std::shared_ptr<ov::Model>& model) override;
void setBatch(std::shared_ptr<ov::Model>& model) override;
};