Avoid loading of reader if it doesn't exist (#758)
* Avoid loading of reader if it doesn't exist * Updated error messages
This commit is contained in:
parent
c7d130efbe
commit
a705f0c358
@ -102,14 +102,28 @@ void registerReaders() {
|
|||||||
static std::mutex readerMutex;
|
static std::mutex readerMutex;
|
||||||
std::lock_guard<std::mutex> lock(readerMutex);
|
std::lock_guard<std::mutex> lock(readerMutex);
|
||||||
if (initialized) return;
|
if (initialized) return;
|
||||||
|
|
||||||
// TODO: Read readers info from XML
|
// TODO: Read readers info from XML
|
||||||
#ifdef ONNX_IMPORT_ENABLE
|
auto create_if_exists = [] (const std::string name, const std::string library_name) {
|
||||||
auto onnxReader = std::make_shared<Reader>("ONNX", std::string("inference_engine_onnx_reader") + std::string(IE_BUILD_POSTFIX));
|
FileUtils::FilePath libraryName = FileUtils::toFilePath(library_name);
|
||||||
readers.emplace("onnx", onnxReader);
|
FileUtils::FilePath readersLibraryPath = FileUtils::makeSharedLibraryName(getInferenceEngineLibraryPath(), libraryName);
|
||||||
readers.emplace("prototxt", onnxReader);
|
|
||||||
#endif
|
if (!FileUtils::fileExist(readersLibraryPath))
|
||||||
auto irReader = std::make_shared<Reader>("IR", std::string("inference_engine_ir_reader") + std::string(IE_BUILD_POSTFIX));
|
return std::shared_ptr<Reader>();
|
||||||
readers.emplace("xml", irReader);
|
return std::make_shared<Reader>(name, library_name);
|
||||||
|
};
|
||||||
|
|
||||||
|
// try to load ONNX reader if library exists
|
||||||
|
auto onnxReader = create_if_exists("ONNX", std::string("inference_engine_onnx_reader") + std::string(IE_BUILD_POSTFIX));
|
||||||
|
if (onnxReader) {
|
||||||
|
readers.emplace("onnx", onnxReader);
|
||||||
|
readers.emplace("prototxt", onnxReader);
|
||||||
|
}
|
||||||
|
|
||||||
|
// try to load IR reader if library exists
|
||||||
|
auto irReader = create_if_exists("IR", std::string("inference_engine_ir_reader") + std::string(IE_BUILD_POSTFIX));
|
||||||
|
if (irReader)
|
||||||
|
readers.emplace("xml", irReader);
|
||||||
initialized = true;
|
initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,7 +185,8 @@ CNNNetwork details::ReadNetwork(const std::string& modelPath, const std::string&
|
|||||||
return reader->read(modelStream, exts);
|
return reader->read(modelStream, exts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
THROW_IE_EXCEPTION << "Unknown model format! Cannot read the model: " << modelPath;
|
THROW_IE_EXCEPTION << "Unknown model format! Cannot find reader for model format: " << fileExt << " and read the model: " << modelPath <<
|
||||||
|
". Please check that reader library exists in your PATH.";
|
||||||
}
|
}
|
||||||
|
|
||||||
CNNNetwork details::ReadNetwork(const std::string& model, const Blob::CPtr& weights, const std::vector<IExtensionPtr>& exts) {
|
CNNNetwork details::ReadNetwork(const std::string& model, const Blob::CPtr& weights, const std::vector<IExtensionPtr>& exts) {
|
||||||
@ -189,7 +204,7 @@ CNNNetwork details::ReadNetwork(const std::string& model, const Blob::CPtr& weig
|
|||||||
return reader->read(modelStream, exts);
|
return reader->read(modelStream, exts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
THROW_IE_EXCEPTION << "Unknown model format! Cannot read the model from string!";
|
THROW_IE_EXCEPTION << "Unknown model format! Cannot find reader for the model and read it. Please check that reader library exists in your PATH.";
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace InferenceEngine
|
} // namespace InferenceEngine
|
||||||
|
Loading…
Reference in New Issue
Block a user