From 3bc41b54ed9ea562e17734ece8a9523a54a4967d Mon Sep 17 00:00:00 2001 From: Ivan Vikhrev Date: Tue, 27 Jul 2021 18:13:02 +0300 Subject: [PATCH] cpp demos: logging fix (#2642) * replace \n with slog::endl, print statstream only if it isn't empty * fix mistake --- demos/common/cpp/models/src/classification_model.cpp | 2 +- demos/common/cpp/models/src/deblurring_model.cpp | 2 +- .../common/cpp/models/src/hpe_model_associative_embedding.cpp | 2 +- demos/common/cpp/models/src/hpe_model_openpose.cpp | 2 +- demos/smart_classroom_demo/cpp_gapi/main.cpp | 4 +++- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/demos/common/cpp/models/src/classification_model.cpp b/demos/common/cpp/models/src/classification_model.cpp index 24d9ac79a62..27c4384e9f0 100644 --- a/demos/common/cpp/models/src/classification_model.cpp +++ b/demos/common/cpp/models/src/classification_model.cpp @@ -107,7 +107,7 @@ void ClassificationModel::prepareInputsOutputs(InferenceEngine::CNNNetwork& cnnN throw std::runtime_error("The model provides " + std::to_string(outSizeVector[1]) + " classes, but " + std::to_string(nTop) + " labels are requested to be predicted"); if (outSizeVector[1] == labels.size() + 1) { labels.insert(labels.begin(), "other"); - slog::warn << "\tInserted 'other' label as first.\n"; + slog::warn << "\tInserted 'other' label as first." << slog::endl; } else if (outSizeVector[1] != labels.size()) throw std::logic_error("Model's number of classes and parsed labels must match (" + std::to_string(outSizeVector[1]) + " and " + std::to_string(labels.size()) + ')'); diff --git a/demos/common/cpp/models/src/deblurring_model.cpp b/demos/common/cpp/models/src/deblurring_model.cpp index 91bf09d8cf9..f62358c5c08 100644 --- a/demos/common/cpp/models/src/deblurring_model.cpp +++ b/demos/common/cpp/models/src/deblurring_model.cpp @@ -85,7 +85,7 @@ std::shared_ptr DeblurringModel::preprocess(const InputData& cv::copyMakeBorder(image, resizedImage, 0, bottom, 0, right, cv::BORDER_CONSTANT, 0); } else { - slog::warn << "\tChosen model aspect ratio doesn't match image aspect ratio\n"; + slog::warn << "\tChosen model aspect ratio doesn't match image aspect ratio" << slog::endl; cv::resize(image, resizedImage, cv::Size(netInputWidth, netInputHeight)); } Blob::Ptr frameBlob = request->GetBlob(inputsNames[0]); diff --git a/demos/common/cpp/models/src/hpe_model_associative_embedding.cpp b/demos/common/cpp/models/src/hpe_model_associative_embedding.cpp index 1b664c1c2ea..e5514ce83b3 100644 --- a/demos/common/cpp/models/src/hpe_model_associative_embedding.cpp +++ b/demos/common/cpp/models/src/hpe_model_associative_embedding.cpp @@ -106,7 +106,7 @@ std::shared_ptr HpeAssociativeEmbedding::preprocess(const Inp auto paddedImage = resizeImageExt(image, inputLayerSize.width, inputLayerSize.height, resizeMode, true, &roi); if (inputLayerSize.height - stride >= roi.height || inputLayerSize.width - stride >= roi.width) { - slog::warn << "\tChosen model aspect ratio doesn't match image aspect ratio\n"; + slog::warn << "\tChosen model aspect ratio doesn't match image aspect ratio" << slog::endl; } request->SetBlob(inputsNames[0], wrapMat2Blob(paddedImage)); /* IE::Blob::Ptr from wrapMat2Blob() doesn't own data. Save the image to avoid deallocation before inference */ diff --git a/demos/common/cpp/models/src/hpe_model_openpose.cpp b/demos/common/cpp/models/src/hpe_model_openpose.cpp index 92713225de0..85b3217bc72 100644 --- a/demos/common/cpp/models/src/hpe_model_openpose.cpp +++ b/demos/common/cpp/models/src/hpe_model_openpose.cpp @@ -107,7 +107,7 @@ std::shared_ptr HPEOpenPose::preprocess(const InputData& inpu throw std::runtime_error("The image aspect ratio doesn't fit current model shape"); if (inputLayerSize.width - stride >= roi.width) { - slog::warn << "\tChosen model aspect ratio doesn't match image aspect ratio\n"; + slog::warn << "\tChosen model aspect ratio doesn't match image aspect ratio" << slog::endl; } request->SetBlob(inputsNames[0], wrapMat2Blob(paddedImage)); diff --git a/demos/smart_classroom_demo/cpp_gapi/main.cpp b/demos/smart_classroom_demo/cpp_gapi/main.cpp index a9ad0e84e32..4661023ec1a 100644 --- a/demos/smart_classroom_demo/cpp_gapi/main.cpp +++ b/demos/smart_classroom_demo/cpp_gapi/main.cpp @@ -348,7 +348,9 @@ int main(int argc, char* argv[]) { videoWriter << proc; }; /** Console log, if exists **/ - slog::debug << stream_log; + if (!stream_log.empty()) { + slog::debug << stream_log << slog::endl; + } } auto elapsed = std::chrono::high_resolution_clock::now() - started_all; work_time_ms_all += std::chrono::duration_cast(elapsed).count();