Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/cpp/models/src/classification_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ std::unique_ptr<ResultBase> ClassificationModel::get_hierarchical_predictions(In
bool add_raw_scores) {
ClassificationResult* result = new ClassificationResult(infResult.frameId, infResult.metaData);

const ov::Tensor& logitsTensor = infResult.outputsData.find(outputNames[0])->second;
ov::Tensor& logitsTensor = infResult.outputsData.find(outputNames[0])->second;
float* logitsPtr = logitsTensor.data<float>();

auto raw_scores = ov::Tensor();
Expand Down Expand Up @@ -411,7 +411,7 @@ ov::Tensor ClassificationModel::reorder_saliency_maps(const ov::Tensor& source_m
}

auto reordered_maps = ov::Tensor(source_maps.get_element_type(), source_maps.get_shape());
const std::uint8_t* source_maps_ptr = static_cast<std::uint8_t*>(source_maps.data());
const std::uint8_t* source_maps_ptr = static_cast<const std::uint8_t*>(source_maps.data());
std::uint8_t* reordered_maps_ptr = static_cast<std::uint8_t*>(reordered_maps.data());

size_t shape_offset = (source_maps.get_shape().size() == 4) ? 1 : 0;
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/models/src/detection_model_yolox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ std::unique_ptr<ResultBase> ModelYoloX::postprocess(InferenceResult& infResult)
const auto& scale = infResult.internalModelData->asRef<InternalScaleData>();

// Get output tensor
const ov::Tensor& output = infResult.outputsData[outputNames[0]];
ov::Tensor& output = infResult.outputsData[outputNames[0]];
const auto& outputShape = output.get_shape();
float* outputPtr = output.data<float>();

Expand Down
6 changes: 5 additions & 1 deletion src/cpp/models/src/instance_segmentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ constexpr char saliency_map_name[]{"saliency_map"};
constexpr char feature_vector_name[]{"feature_vector"};
constexpr char labels_name[]{"labels"};
constexpr char boxes_name[]{"boxes"};
constexpr char bboxes_name[]{"bboxes"};
constexpr char masks_name[]{"masks"};

void append_xai_names(const std::vector<ov::Output<ov::Node>>& outputs, std::vector<std::string>& outputNames) {
Expand Down Expand Up @@ -93,6 +94,9 @@ Lbm filterTensors(const std::map<std::string, ov::Tensor>& infResult) {

auto labels_it = infResult.find(labels_name);
auto boxes_it = infResult.find(boxes_name);
if (boxes_it == infResult.end()) {
boxes_it = infResult.find(bboxes_name); // Alternative name for boxes
}
auto masks_it = infResult.find(masks_name);

if (labels_it != infResult.end() && boxes_it != infResult.end() && masks_it != infResult.end()) {
Expand Down Expand Up @@ -308,7 +312,7 @@ std::unique_ptr<ResultBase> MaskRCNNModel::postprocess(InferenceResult& infResul
padTop = (netInputHeight - int(std::round(floatInputImgHeight / invertedScaleY))) / 2;
}
}
const Lbm& lbm = filterTensors(infResult.outputsData);
Lbm lbm = filterTensors(infResult.outputsData);
const int64_t* const labels_tensor_ptr = lbm.labels.data<int64_t>();
const float* const boxes = lbm.boxes.data<float>();
size_t objectSize = lbm.boxes.get_shape().back();
Expand Down
4 changes: 2 additions & 2 deletions src/cpp/models/src/keypoint_detection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,15 +210,15 @@ void KeypointDetectionModel::prepareInputsOutputs(std::shared_ptr<ov::Model>& mo
std::unique_ptr<ResultBase> KeypointDetectionModel::postprocess(InferenceResult& infResult) {
KeypointDetectionResult* result = new KeypointDetectionResult(infResult.frameId, infResult.metaData);

const ov::Tensor& pred_x_tensor = infResult.outputsData.find(outputNames[0])->second;
ov::Tensor& pred_x_tensor = infResult.outputsData.find(outputNames[0])->second;
size_t shape_offset = pred_x_tensor.get_shape().size() == 3 ? 1 : 0;
auto pred_x_mat = cv::Mat(cv::Size(static_cast<int>(pred_x_tensor.get_shape()[shape_offset + 1]),
static_cast<int>(pred_x_tensor.get_shape()[shape_offset])),
CV_32F,
pred_x_tensor.data(),
pred_x_tensor.get_strides()[shape_offset]);

const ov::Tensor& pred_y_tensor = infResult.outputsData.find(outputNames[1])->second;
ov::Tensor& pred_y_tensor = infResult.outputsData.find(outputNames[1])->second;
shape_offset = pred_y_tensor.get_shape().size() == 3 ? 1 : 0;
auto pred_y_mat = cv::Mat(cv::Size(static_cast<int>(pred_y_tensor.get_shape()[shape_offset + 1]),
static_cast<int>(pred_y_tensor.get_shape()[shape_offset])),
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/models/src/segmentation_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ void SegmentationModel::prepareInputsOutputs(std::shared_ptr<ov::Model>& model)
std::unique_ptr<ResultBase> SegmentationModel::postprocess(InferenceResult& infResult) {
const auto& inputImgSize = infResult.internalModelData->asRef<InternalImageModelData>();
const auto& outputName = outputNames[0] == feature_vector_name ? outputNames[1] : outputNames[0];
const auto& outTensor = infResult.outputsData[outputName];
auto& outTensor = infResult.outputsData[outputName];
const ov::Shape& outputShape = outTensor.get_shape();
const ov::Layout& outputLayout = getLayoutFromShape(outputShape);
size_t outChannels =
Expand Down
7 changes: 4 additions & 3 deletions src/cpp/utils/include/utils/ocv_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,17 @@ static inline ov::Tensor wrapMat2Tensor(const cv::Mat& mat) {
}
auto precision = isMatFloat ? ov::element::f32 : ov::element::u8;
struct SharedMatAllocator {
const cv::Mat mat;
cv::Mat mat;
SharedMatAllocator(const cv::Mat& m) : mat(m) {}
void* allocate(size_t bytes, size_t) {
return bytes <= mat.rows * mat.step[0] ? mat.data : nullptr;
}
void deallocate(void*, size_t, size_t) {}
void deallocate(void*, size_t, size_t) noexcept {}
bool is_equal(const SharedMatAllocator& other) const noexcept {
return this == &other;
}
};
return ov::Tensor(precision, ov::Shape{1, height, width, channels}, SharedMatAllocator{mat});
return ov::Tensor(precision, ov::Shape{1, height, width, channels}, ov::Allocator(SharedMatAllocator{mat}));
}

struct IntervalCondition {
Expand Down
6 changes: 4 additions & 2 deletions src/cpp/utils/src/image_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ Output<Node> cropResizeGraph(const ov::Output<ov::Node>& input,
opset10::Constant::create(element::i64, Shape{1}, {1}),
opset10::Constant::create(element::i64, Shape{1}, {h_axis}));
auto then_body_res_1 = std::make_shared<opset10::Result>(then_cropped_frame);
auto then_body = std::make_shared<Model>(NodeVector{then_body_res_1}, ParameterVector{image_t, iw_t, ih_t});
auto then_body =
std::make_shared<Model>(ov::ResultVector{then_body_res_1}, ParameterVector{image_t, iw_t, ih_t});

// else_body
auto image_e = std::make_shared<opset10::Parameter>(element::u8, PartialShape{-1, -1, -1, 3});
Expand All @@ -235,7 +236,8 @@ Output<Node> cropResizeGraph(const ov::Output<ov::Node>& input,
opset10::Constant::create(element::i64, Shape{1}, {1}),
opset10::Constant::create(element::i64, Shape{1}, {w_axis}));
auto else_body_res_1 = std::make_shared<opset10::Result>(else_cropped_frame);
auto else_body = std::make_shared<Model>(NodeVector{else_body_res_1}, ParameterVector{image_e, iw_e, ih_e});
auto else_body =
std::make_shared<Model>(ov::ResultVector{else_body_res_1}, ParameterVector{image_e, iw_e, ih_e});

// if operator
auto condition = std::make_shared<opset10::Greater>(ih, iw);
Expand Down