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
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ static int toDepth(const std::string& prec) {
return CV_16F;
if (prec == "U8")
return CV_8U;
if (prec == "I32")
if (prec == "I32" || prec == "I64")
return CV_32S;
throw std::logic_error("Unsupported precision type: " + prec);
}
Expand Down
24 changes: 18 additions & 6 deletions src/plugins/intel_npu/tools/protopipe/src/utils/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

#include "utils.hpp"

#include <algorithm>
#include <cstdint>
#include <opencv2/gapi/own/assert.hpp>

#include <fstream>

namespace utils {
Expand Down Expand Up @@ -65,12 +66,23 @@ void readFromBinFile(const std::string& filepath, cv::Mat& mat) {
ifs.seekg(0, std::ios::beg);

const auto mat_byte_size = mat.total() * mat.elemSize();
if (file_byte_size != mat_byte_size) {
throw std::logic_error("Failed to read cv::Mat from binary file: " + filepath + ". Mat size: " +
std::to_string(mat_byte_size) + ", File size: " + std::to_string(file_byte_size));
}
// workaround for I64 input type precision
if (mat.type() == CV_32S && file_byte_size == mat_byte_size * 2) {

ifs.read(mat.ptr<char>(), mat_byte_size);
std::vector<int64_t> buffer64;
buffer64.resize(file_byte_size / 8);
ifs.read(reinterpret_cast<char*>(buffer64.data()), file_byte_size);
std::transform(buffer64.begin(), buffer64.end(), mat.ptr<int32_t>(),
[](int64_t val) {return static_cast<int32_t>(val); });
}
else {
if (file_byte_size != mat_byte_size) {
throw std::logic_error("Failed to read cv::Mat from binary file: " + filepath + ". Mat size: " +
std::to_string(mat_byte_size) + ", File size: " + std::to_string(file_byte_size));
}
ifs.read(mat.ptr<char>(), mat_byte_size);
}
ifs.close();
}

void writeToBinFile(const std::string& filepath, const cv::Mat& mat) {
Expand Down
Loading