Skip to content

Commit 451b9b9

Browse files
committed
update old models
1 parent b32e8d4 commit 451b9b9

File tree

8 files changed

+46
-26
lines changed

8 files changed

+46
-26
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ class HpeAssociativeEmbedding : public ImageModel {
6565
int targetSize;
6666
float confidenceThreshold;
6767
float delta;
68-
RESIZE_MODE resizeMode;
6968

7069
std::string embeddingsTensorName;
7170
std::string heatmapsTensorName;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ class StyleTransferModel : public ImageModel {
3636
/// @param layout - model input layout
3737
StyleTransferModel(const std::string& modelFileName, const std::string& layout = "");
3838

39-
std::shared_ptr<InternalModelData> preprocess(const InputData& inputData, ov::InferRequest& request) override;
4039
std::unique_ptr<ResultBase> postprocess(InferenceResult& infResult) override;
4140

4241
protected:

demos/common/cpp/models/src/hpe_model_associative_embedding.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ HpeAssociativeEmbedding::HpeAssociativeEmbedding(const std::string& modelFileNam
5353
aspectRatio(aspectRatio),
5454
targetSize(targetSize),
5555
confidenceThreshold(confidenceThreshold),
56-
delta(delta),
57-
resizeMode(resizeMode) {}
56+
delta(delta) {
57+
resizeMode = resizeMode;
58+
interpolationMode = CUBIC;
59+
}
5860

5961
void HpeAssociativeEmbedding::prepareInputsOutputs(std::shared_ptr<ov::Model>& model) {
6062
// --------------------------- Configure input & output -------------------------------------------------
@@ -136,7 +138,7 @@ std::shared_ptr<InternalModelData> HpeAssociativeEmbedding::preprocess(const Inp
136138
ov::InferRequest& request) {
137139
auto& image = inputData.asRef<ImageInputData>().inputImage;
138140
cv::Rect roi;
139-
auto paddedImage = resizeImageExt(image, inputLayerSize.width, inputLayerSize.height, resizeMode, true, &roi);
141+
auto paddedImage = resizeImageExt(image, inputLayerSize.width, inputLayerSize.height, resizeMode, interpolationMode, &roi);
140142
if (inputLayerSize.height - stride >= roi.height || inputLayerSize.width - stride >= roi.width) {
141143
slog::warn << "\tChosen model aspect ratio doesn't match image aspect ratio" << slog::endl;
142144
}

demos/common/cpp/models/src/hpe_model_openpose.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ HPEOpenPose::HPEOpenPose(const std::string& modelFileName,
5050
: ImageModel(modelFileName, false, layout),
5151
aspectRatio(aspectRatio),
5252
targetSize(targetSize),
53-
confidenceThreshold(confidenceThreshold) {}
53+
confidenceThreshold(confidenceThreshold) {
54+
resizeMode = RESIZE_KEEP_ASPECT;
55+
interpolationMode = CUBIC;
56+
}
5457

5558
void HPEOpenPose::prepareInputsOutputs(std::shared_ptr<ov::Model>& model) {
5659
// --------------------------- Configure input & output -------------------------------------------------
@@ -139,7 +142,7 @@ std::shared_ptr<InternalModelData> HPEOpenPose::preprocess(const InputData& inpu
139142
auto& image = inputData.asRef<ImageInputData>().inputImage;
140143
cv::Rect roi;
141144
auto paddedImage =
142-
resizeImageExt(image, inputLayerSize.width, inputLayerSize.height, RESIZE_KEEP_ASPECT, true, &roi);
145+
resizeImageExt(image, inputLayerSize.width, inputLayerSize.height, resizeMode, interpolationMode, &roi);
143146
if (inputLayerSize.width < roi.width)
144147
throw std::runtime_error("The image aspect ratio doesn't fit current model shape");
145148

demos/common/cpp/models/src/style_transfer_model.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,6 @@ void StyleTransferModel::prepareInputsOutputs(std::shared_ptr<ov::Model>& model)
8181
model = ppp.build();
8282
}
8383

84-
std::shared_ptr<InternalModelData> StyleTransferModel::preprocess(const InputData& inputData,
85-
ov::InferRequest& request) {
86-
auto imgData = inputData.asRef<ImageInputData>();
87-
auto& img = imgData.inputImage;
88-
89-
cv::Mat resizedImage;
90-
resizedImage = resizeImageExt(img, netInputWidth, netInputHeight);
91-
request.set_input_tensor(wrapMat2Tensor(resizedImage));
92-
return std::make_shared<InternalImageModelData>(img.cols, img.rows);
93-
}
94-
9584
std::unique_ptr<ResultBase> StyleTransferModel::postprocess(InferenceResult& infResult) {
9685
ImageResult* result = new ImageResult;
9786
*static_cast<ResultBase*>(result) = static_cast<ResultBase&>(infResult);

demos/common/cpp/utils/include/utils/image_utils.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
// Copyright (C) 2021 Intel Corporation
2+
// Copyright (C) 2021-2022 Intel Corporation
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -24,4 +24,12 @@ enum RESIZE_MODE {
2424
RESIZE_KEEP_ASPECT_LETTERBOX
2525
};
2626

27-
cv::Mat resizeImageExt(const cv::Mat& mat, int width, int height, RESIZE_MODE resizeMode = RESIZE_FILL, bool hqResize = false, cv::Rect* roi = nullptr);
27+
enum INTERPOLATION_MODE {
28+
NEAREST,
29+
LINEAR,
30+
CUBIC,
31+
AREA
32+
};
33+
34+
cv::Mat resizeImageExt(const cv::Mat& mat, int width, int height, RESIZE_MODE resizeMode = RESIZE_FILL,
35+
INTERPOLATION_MODE interpolationMode = LINEAR, cv::Rect* roi = nullptr);

demos/common/cpp/utils/include/utils/nms.hpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
// Copyright (C) 2021 Intel Corporation
2+
// Copyright (C) 2021-2022 Intel Corporation
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -20,6 +20,26 @@
2020
#include <vector>
2121

2222

23+
struct Anchor {
24+
float left;
25+
float top;
26+
float right;
27+
float bottom;
28+
29+
float getWidth() const {
30+
return (right - left) + 1.0f;
31+
}
32+
float getHeight() const {
33+
return (bottom - top) + 1.0f;
34+
}
35+
float getXCenter() const {
36+
return left + (getWidth() - 1.0f) / 2.0f;
37+
}
38+
float getYCenter() const {
39+
return top + (getHeight() - 1.0f) / 2.0f;
40+
}
41+
};
42+
2343
template <typename Anchor>
2444
std::vector<int> nms(const std::vector<Anchor>& boxes, const std::vector<float>& scores,
2545
const float thresh, bool includeBoundaries=false) {

demos/common/cpp/utils/src/image_utils.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
// Copyright (C) 2021 Intel Corporation
2+
// Copyright (C) 2021-2022 Intel Corporation
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -16,18 +16,18 @@
1616

1717
#include "utils/image_utils.h"
1818

19-
cv::Mat resizeImageExt(const cv::Mat& mat, int width, int height, RESIZE_MODE resizeMode, bool hqResize, cv::Rect* roi) {
19+
cv::Mat resizeImageExt(const cv::Mat& mat, int width, int height, RESIZE_MODE resizeMode,
20+
INTERPOLATION_MODE interpolationMode, cv::Rect* roi) {
2021
if (width == mat.cols && height == mat.rows) {
2122
return mat;
2223
}
2324

2425
cv::Mat dst;
25-
int interpMode = hqResize ? cv::INTER_CUBIC : cv::INTER_LINEAR;
2626

2727
switch (resizeMode) {
2828
case RESIZE_FILL:
2929
{
30-
cv::resize(mat, dst, cv::Size(width, height), interpMode);
30+
cv::resize(mat, dst, cv::Size(width, height), interpolationMode);
3131
if (roi) {
3232
*roi = cv::Rect(0, 0, width, height);
3333
}
@@ -38,7 +38,7 @@ cv::Mat resizeImageExt(const cv::Mat& mat, int width, int height, RESIZE_MODE re
3838
{
3939
double scale = std::min(static_cast<double>(width) / mat.cols, static_cast<double>(height) / mat.rows);
4040
cv::Mat resizedImage;
41-
cv::resize(mat, resizedImage, cv::Size(0, 0), scale, scale, interpMode);
41+
cv::resize(mat, resizedImage, cv::Size(0, 0), scale, scale, interpolationMode);
4242

4343
int dx = resizeMode == RESIZE_KEEP_ASPECT ? 0 : (width - resizedImage.cols) / 2;
4444
int dy = resizeMode == RESIZE_KEEP_ASPECT ? 0 : (height - resizedImage.rows) / 2;

0 commit comments

Comments
 (0)