Skip to content

Commit 74fd62a

Browse files
authored
Correct use tensor and data pointer (#4005)
Signed-off-by: Raasz, Pawel <[email protected]>
1 parent d919cdf commit 74fd62a

File tree

13 files changed

+35
-25
lines changed

13 files changed

+35
-25
lines changed

demos/common/cpp/models/src/detection_model_centernet.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ std::vector<std::pair<size_t, float>> nms(float* scoresPtr, const ov::Shape& sha
185185
return scores;
186186
}
187187

188-
static std::vector<std::pair<size_t, float>> filterScores(const ov::Tensor& scoresTensor, float threshold) {
188+
static std::vector<std::pair<size_t, float>>
189+
filterScores(ov::Tensor &scoresTensor, float threshold) {
189190
auto shape = scoresTensor.get_shape();
190191
float* scoresPtr = scoresTensor.data<float>();
191192

@@ -259,7 +260,7 @@ void transform(std::vector<ModelCenterNet::BBox>& boxes,
259260

260261
std::unique_ptr<ResultBase> ModelCenterNet::postprocess(InferenceResult& infResult) {
261262
// --------------------------- Filter data and get valid indices ---------------------------------
262-
const auto& heatmapTensor = infResult.outputsData[outputsNames[0]];
263+
auto &heatmapTensor = infResult.outputsData[outputsNames[0]];
263264
const auto& heatmapTensorShape = heatmapTensor.get_shape();
264265
const auto chSize = heatmapTensorShape[2] * heatmapTensorShape[3];
265266
const auto scores = filterScores(heatmapTensor, confidenceThreshold);

demos/common/cpp/models/src/detection_model_ssd.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ ModelSSD::ModelSSD(const std::string& modelFileName,
4242

4343
std::shared_ptr<InternalModelData> ModelSSD::preprocess(const InputData& inputData, ov::InferRequest& request) {
4444
if (inputsNames.size() > 1) {
45-
const auto& imageInfoTensor = request.get_tensor(inputsNames[1]);
45+
auto imageInfoTensor = request.get_tensor(inputsNames[1]);
4646
const auto info = imageInfoTensor.data<float>();
4747
info[0] = static_cast<float>(netInputHeight);
4848
info[1] = static_cast<float>(netInputWidth);

demos/common/cpp/models/src/detection_model_yolox.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ std::unique_ptr<ResultBase> ModelYoloX::postprocess(InferenceResult& infResult)
127127
const auto& scale = infResult.internalModelData->asRef<InternalScaleData>();
128128

129129
// Get output tensor
130-
const ov::Tensor& output = infResult.outputsData[outputsNames[0]];
130+
ov::Tensor &output = infResult.outputsData[outputsNames[0]];
131131
const auto& outputShape = output.get_shape();
132132
float* outputPtr = output.data<float>();
133133

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,19 +153,19 @@ std::shared_ptr<InternalModelData> HpeAssociativeEmbedding::preprocess(const Inp
153153
std::unique_ptr<ResultBase> HpeAssociativeEmbedding::postprocess(InferenceResult& infResult) {
154154
HumanPoseResult* result = new HumanPoseResult(infResult.frameId, infResult.metaData);
155155

156-
const auto& aembds = infResult.outputsData[embeddingsTensorName];
156+
auto &aembds = infResult.outputsData[embeddingsTensorName];
157157
const ov::Shape& aembdsShape = aembds.get_shape();
158158
float* const aembdsMapped = aembds.data<float>();
159159
std::vector<cv::Mat> aembdsMaps = split(aembdsMapped, aembdsShape);
160160

161-
const auto& heats = infResult.outputsData[heatmapsTensorName];
161+
auto &heats = infResult.outputsData[heatmapsTensorName];
162162
const ov::Shape& heatMapsShape = heats.get_shape();
163163
float* const heatMapsMapped = heats.data<float>();
164164
std::vector<cv::Mat> heatMaps = split(heatMapsMapped, heatMapsShape);
165165

166166
std::vector<cv::Mat> nmsHeatMaps = heatMaps;
167167
if (nmsHeatmapsTensorName != heatmapsTensorName) {
168-
const auto& nmsHeats = infResult.outputsData[nmsHeatmapsTensorName];
168+
auto& nmsHeats = infResult.outputsData[nmsHeatmapsTensorName];
169169
const ov::Shape& nmsHeatMapsShape = nmsHeats.get_shape();
170170
float* const nmsHeatMapsMapped = nmsHeats.data<float>();
171171
nmsHeatMaps = split(nmsHeatMapsMapped, nmsHeatMapsShape);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ std::shared_ptr<InternalModelData> HPEOpenPose::preprocess(const InputData& inpu
160160
std::unique_ptr<ResultBase> HPEOpenPose::postprocess(InferenceResult& infResult) {
161161
HumanPoseResult* result = new HumanPoseResult(infResult.frameId, infResult.metaData);
162162

163-
const auto& heatMapsMapped = infResult.outputsData[outputsNames[0]];
164-
const auto& outputMapped = infResult.outputsData[outputsNames[1]];
163+
auto& heatMapsMapped = infResult.outputsData[outputsNames[0]];
164+
auto& outputMapped = infResult.outputsData[outputsNames[1]];
165165

166166
const ov::Shape& outputShape = outputMapped.get_shape();
167167
const ov::Shape& heatMapShape = heatMapsMapped.get_shape();

demos/common/cpp/models/src/segmentation_model.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ void SegmentationModel::prepareInputsOutputs(std::shared_ptr<ov::Model>& model)
116116
std::unique_ptr<ResultBase> SegmentationModel::postprocess(InferenceResult& infResult) {
117117
ImageResult* result = new ImageResult(infResult.frameId, infResult.metaData);
118118
const auto& inputImgSize = infResult.internalModelData->asRef<InternalImageModelData>();
119-
const auto& outTensor = infResult.getFirstOutputTensor();
119+
auto outTensor = infResult.getFirstOutputTensor();
120120

121121
result->resultImage = cv::Mat(outHeight, outWidth, CV_8UC1);
122122

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ const T getMatValue(const cv::Mat& mat, size_t h, size_t w, size_t c) {
3535
* @param tensor - Tensor object which to be filled by an image data.
3636
* @param batchIndex - batch index of an image inside of the blob.
3737
*/
38-
static UNUSED void matToTensor(const cv::Mat& mat, const ov::Tensor& tensor, int batchIndex = 0) {
38+
static UNUSED void matToTensor(const cv::Mat &mat, ov::Tensor &tensor,
39+
int batchIndex = 0) {
3940
ov::Shape tensorShape = tensor.get_shape();
4041
static const ov::Layout layout("NCHW");
4142
const size_t width = tensorShape[ov::layout::width_idx(layout)];
@@ -99,7 +100,7 @@ static UNUSED ov::Tensor wrapMat2Tensor(const cv::Mat& mat) {
99100
return ov::Tensor(precision, ov::Shape{ 1, height, width, channels }, SharedMatAllocator{mat});
100101
}
101102

102-
static inline void resize2tensor(const cv::Mat& mat, const ov::Tensor& tensor) {
103+
static inline void resize2tensor(const cv::Mat &mat, ov::Tensor &tensor) {
103104
static const ov::Layout layout{"NHWC"};
104105
const ov::Shape& shape = tensor.get_shape();
105106
cv::Size size{int(shape[ov::layout::width_idx(layout)]), int(shape[ov::layout::height_idx(layout)])};

demos/interactive_face_detection_demo/cpp/detectors.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,10 @@ void AntispoofingClassifier::enqueue(const cv::Mat& face) {
203203
if (!enabled()) {
204204
return;
205205
}
206-
resize2tensor(face, ov::Tensor{inTensor, {enquedFaces, 0, 0, 0}, {enquedFaces + 1, inShape[1], inShape[2], inShape[3]}});
206+
ov::Tensor t{inTensor,
207+
{enquedFaces, 0, 0, 0},
208+
{enquedFaces + 1, inShape[1], inShape[2], inShape[3]}};
209+
resize2tensor(face, t);
207210
enquedFaces++;
208211
}
209212

@@ -253,7 +256,8 @@ void AgeGenderDetection::enqueue(const cv::Mat &face) {
253256
if (!enabled()) {
254257
return;
255258
}
256-
resize2tensor(face, ov::Tensor{inTensor, {enquedFaces, 0, 0, 0}, {enquedFaces + 1, inShape[1], inShape[2], inShape[3]}});
259+
ov::Tensor t{inTensor, {enquedFaces, 0, 0, 0}, {enquedFaces + 1, inShape[1], inShape[2], inShape[3]}};
260+
resize2tensor(face, t);
257261
enquedFaces++;
258262
}
259263

@@ -309,7 +313,8 @@ void HeadPoseDetection::enqueue(const cv::Mat &face) {
309313
if (!enabled()) {
310314
return;
311315
}
312-
resize2tensor(face, ov::Tensor{inTensor, {enquedFaces, 0, 0, 0}, {enquedFaces + 1, inShape[1], inShape[2], inShape[3]}});
316+
ov::Tensor t{inTensor, {enquedFaces, 0, 0, 0}, {enquedFaces + 1, inShape[1], inShape[2], inShape[3]}};
317+
resize2tensor(face, t);
313318
enquedFaces++;
314319
}
315320

@@ -364,7 +369,8 @@ void EmotionsDetection::enqueue(const cv::Mat &face) {
364369
if (!enabled()) {
365370
return;
366371
}
367-
resize2tensor(face, ov::Tensor{inTensor, {enquedFaces, 0, 0, 0}, {enquedFaces + 1, inShape[1], inShape[2], inShape[3]}});
372+
ov::Tensor t{inTensor, {enquedFaces, 0, 0, 0}, {enquedFaces + 1, inShape[1], inShape[2], inShape[3]}};
373+
resize2tensor(face, t);
368374
enquedFaces++;
369375
}
370376

@@ -381,7 +387,7 @@ std::map<std::string, float> EmotionsDetection::operator[](int idx) {
381387
"to used emotions vector size (" +
382388
std::to_string(emotionsVecSize) + ")");
383389
}
384-
float* emotionsValues = tensor.data<float>();
390+
auto emotionsValues = tensor.data<float>();
385391
auto outputIdxPos = emotionsValues + idx * emotionsVecSize;
386392
std::map<std::string, float> emotions;
387393

@@ -440,7 +446,8 @@ void FacialLandmarksDetection::enqueue(const cv::Mat &face) {
440446
if (!enabled()) {
441447
return;
442448
}
443-
resize2tensor(face, ov::Tensor{inTensor, {enquedFaces, 0, 0, 0}, {enquedFaces + 1, inShape[1], inShape[2], inShape[3]}});
449+
ov::Tensor t{inTensor, {enquedFaces, 0, 0, 0}, {enquedFaces + 1, inShape[1], inShape[2], inShape[3]}};
450+
resize2tensor(face, t);
444451
enquedFaces++;
445452
}
446453

demos/multi_channel_common/cpp/graph.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include "threading.hpp"
1414

1515
namespace {
16-
void framesToTensor(const std::vector<std::shared_ptr<VideoFrame>>& frames, const ov::Tensor& tensor) {
16+
void framesToTensor(const std::vector<std::shared_ptr<VideoFrame>>& frames, ov::Tensor tensor) {
1717
static const ov::Layout layout{"NHWC"};
1818
static const ov::Shape shape = tensor.get_shape();
1919
static const size_t batchSize = shape[ov::layout::batch_idx(layout)];

demos/pedestrian_tracker_demo/cpp/include/cnn.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class BaseModel {
5757
* @param results_fetcher Callback to fetch inference results
5858
*/
5959
void InferBatch(const std::vector<cv::Mat>& frames,
60-
const std::function<void(const ov::Tensor&, size_t)>& results_fetcher) const;
60+
const std::function<void(ov::Tensor, size_t)>& results_fetcher) const;
6161

6262
/** @brief Config */
6363
Config config;

0 commit comments

Comments
 (0)