Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
stash
  • Loading branch information
sivanov-work committed Nov 30, 2023
commit 3128d4f0e346bb3429db994d062fb5038d5f41e6
11 changes: 11 additions & 0 deletions demos/common/cpp/models/src/classification_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,27 @@ ClassificationModel::ClassificationModel(const std::string& modelFileName,

std::unique_ptr<ResultBase> ClassificationModel::postprocess(InferenceResult& infResult) {
const ov::Tensor& indicesTensor = infResult.outputsData.find(outputsNames[0])->second;
const void* indicesTensorBuffer = reinterpret_cast<const void*>(indicesTensor.data());
std::cout << "-S- indices tensor data: " << indicesTensorBuffer << ", size: " << indicesTensor.get_size() << std::endl;
const int* indicesPtr = indicesTensor.data<int>();
for (int i = 0; i < indicesTensor.get_size(); i++){
std::cout << "-S- index[" << i << "]: " << indicesPtr[i] <<std::endl;
}
const ov::Tensor& scoresTensor = infResult.outputsData.find(outputsNames[1])->second;
const float* scoresPtr = scoresTensor.data<float>();
const void* scoresTensorBuffer = reinterpret_cast<const void*>(scoresTensor.data());
std::cout << "-S- scores tensor data: " << scoresTensorBuffer << ", size: " << scoresTensor.get_size() <<std::endl;
for (int i = 0; i < scoresTensor.get_size(); i++){
std::cout << "-S- score[" << i << "]: " << scoresPtr[i] <<std::endl;
}

ClassificationResult* result = new ClassificationResult(infResult.frameId, infResult.metaData);
auto retVal = std::unique_ptr<ResultBase>(result);

result->topLabels.reserve(scoresTensor.get_size());
for (size_t i = 0; i < scoresTensor.get_size(); ++i) {
int ind = indicesPtr[i];
std::cout << "-S- index???[" << i << "]: " << ind << ", labels size: " << labels.size() <<std::endl;
if (ind < 0 || ind >= static_cast<int>(labels.size())) {
throw std::runtime_error(std::string("Invalid index: ") + std::to_string(ind) + " for the class label is found during postprocessing, label size: " + std::to_string(labels.size()));
}
Expand Down
6 changes: 4 additions & 2 deletions demos/common/cpp/models/src/image_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ std::shared_ptr<InternalModelData> ImageModel::preprocess(std::vector<std::share
const size_t width = tensorShape[ov::layout::width_idx(layout)];
const size_t height = tensorShape[ov::layout::height_idx(layout)];
const size_t channels = tensorShape[ov::layout::channels_idx(layout)];

std::cout << "ImageModel::preprocess: batch: " << batch << ", width: " << width << ", height: " << height << ", channels: " << channels << std::endl;
char* memoryBlob = nullptr;
size_t image_index = 0;
bool isMatFloat = false;
Expand Down Expand Up @@ -75,6 +75,7 @@ std::shared_ptr<InternalModelData> ImageModel::preprocess(std::vector<std::share
img = resizeImageExt(img, width, height, resizeMode, interpolationMode);
}
size_t sizeInBytes = img.total() * img.elemSize();
std::cout << "image size in bytes: " << sizeInBytes << std::endl;
if (!memoryBlob) {
memoryBlob = new char[sizeInBytes * batch]; // intended memory leak
}
Expand All @@ -84,9 +85,10 @@ std::shared_ptr<InternalModelData> ImageModel::preprocess(std::vector<std::share
image_index++;
}

std::cout << "isMatFloat: " << isMatFloat << std::endl;
auto precision = isMatFloat ? ov::element::f32 : ov::element::u8;
auto batched_tensor = ov::Tensor(precision, ov::Shape{ batch, height, width, channels }, memoryBlob);
request.set_tensor(inputsNames[0],batched_tensor);
request.set_tensor(inputsNames[0], batched_tensor);
return std::make_shared<InternalImageModelData>(origImg_cols, origImg_rows);
}

Expand Down
1 change: 1 addition & 0 deletions demos/common/cpp/pipelines/src/async_pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ int64_t AsyncPipeline::submitData(std::vector<std::shared_ptr<InputData>>::itera

for (const auto& outName : model->getOutputsNames()) {
auto tensor = request.get_tensor(outName);
std::cout << "-S- output tensorName: " << outName << ", tensor ptr: " << reinterpret_cast<void*>(tensor.data()) << ", size: " << tensor.get_size() << std::endl;
result.outputsData.emplace(outName, tensor);
}

Expand Down