问题:在编写OpenVINO推理程序时,遇到报错:没有与这些操作数匹配的“<<”运算符,如下图所示。

原因:<<运算符不支持 std::map<std::string, Version>类型
std::map<std::string, Version> GetVersions(const std::string& deviceName) const;
解决方式:编写<< 运算符重载代码,如下所示:
#include<string>
#include<inference_engine.hpp>
#include<ngraph/ngraph.hpp>
using namespace InferenceEngine;
inline std::ostream& operator<<(std::ostream& os, const InferenceEngine::Version& version) {
os << "\t" << version.description << " version ......... ";
os << IE_VERSION_MAJOR << "." << IE_VERSION_MINOR << "." << IE_VERSION_PATCH;
os << "\n\tBuild ........... ";
os << version.buildNumber;
return os;
}
inline std::ostream& operator<<(std::ostream& os, const InferenceEngine::Version* version) {
if (nullptr != version) {
os << std::endl << *version;
}
return os;
}
inline std::ostream& operator<<(std::ostream& os, const std::map<std::string, InferenceEngine::Version>& versions) {
for (auto&& version : versions) {
os << "\t" << version.first << std::endl;
os << version.second << std::endl;
}
return os;
}
int main(void) {
Core ie;
std::cout << ie.GetVersions("CPU") << std::endl;
return 0;
}

网友评论