| 19 | } |
| 20 | |
| 21 | void Segmentation::_startONNXSession(const std::string sessionName, const std::string modelFilePath, bool useCUDA, size_t numThreads){ |
| 22 | Ort::SessionOptions sessionOptions; |
| 23 | sessionOptions.SetIntraOpNumThreads(numThreads); |
| 24 | // Sets graph optimization level |
| 25 | // Available levels are |
| 26 | // ORT_DISABLE_ALL -> To disable all optimizations |
| 27 | // ORT_ENABLE_BASIC -> To enable basic optimizations (Such as redundant node |
| 28 | // removals) ORT_ENABLE_EXTENDED -> To enable extended optimizations |
| 29 | // (Includes level 1 + more complex optimizations like node fusions) |
| 30 | // ORT_ENABLE_ALL -> To Enable All possible optimizations |
| 31 | sessionOptions.SetGraphOptimizationLevel(GraphOptimizationLevel::ORT_ENABLE_EXTENDED); |
| 32 | if (useCUDA){ |
| 33 | // Using CUDA backend |
| 34 | // https://github.com/microsoft/onnxruntime/blob/v1.8.2/include/onnxruntime/core/session/onnxruntime_cxx_api.h#L329 |
| 35 | OrtCUDAProviderOptions cuda_options{0}; |
| 36 | sessionOptions.AppendExecutionProvider_CUDA(cuda_options); |
| 37 | } |
| 38 | |
| 39 | auto env = boost::make_shared<Ort::Env>(ORT_LOGGING_LEVEL_ERROR, sessionName.c_str()); |
| 40 | _env = boost::move(env); |
| 41 | |
| 42 | auto session = boost::make_shared<Ort::Session>(*_env, modelFilePath.c_str(), sessionOptions); |
| 43 | _session = boost::move(session); |
| 44 | |
| 45 | auto memInfo = boost::make_shared<Ort::MemoryInfo>(Ort::MemoryInfo::CreateCpu( |
| 46 | OrtAllocatorType::OrtArenaAllocator, OrtMemType::OrtMemTypeDefault)); |
| 47 | _memoryInfo = boost::move(memInfo); |
| 48 | |
| 49 | // Ort::AllocatorWithDefaultOptions allocator; |
| 50 | // INPUT |
| 51 | const char* inputName = _session->GetInputName(0, _allocator); |
| 52 | std::cout << "[Segmentation] Input Name: " << inputName << std::endl; |
| 53 | |
| 54 | Ort::TypeInfo inputTypeInfo = _session->GetInputTypeInfo(0); |
| 55 | auto inputTensorInfo = inputTypeInfo.GetTensorTypeAndShapeInfo(); |
| 56 | _inputDims = inputTensorInfo.GetShape(); |
| 57 | // _inputDims = {1, 64, 2048, 2}; |
| 58 | std::cout << "[Segmentation] Input Dimensions: "; printVector(_inputDims); |
| 59 | |
| 60 | // OUTPUT |
| 61 | const char* outputName = _session->GetOutputName(0, _allocator); |
| 62 | std::cout << "[Segmentation] Output Name: " << outputName << std::endl; |
| 63 | |
| 64 | Ort::TypeInfo outputTypeInfo = _session->GetOutputTypeInfo(0); |
| 65 | auto outputTensorInfo = outputTypeInfo.GetTensorTypeAndShapeInfo(); |
| 66 | // ONNXTensorElementDataType outputType = outputTensorInfo.GetElementType(); |
| 67 | |
| 68 | _outputDims = outputTensorInfo.GetShape(); |
| 69 | // _outputDims = {1, 64, 2048, 2}; |
| 70 | std::cout << "[Segmentation] Output Dimensions: "; printVector(_outputDims); |
| 71 | |
| 72 | // _inputTensorSize = _img_w * _img_h * _img_d; |
| 73 | // _outputTensorSize = _img_w * _img_h * _img_d; |
| 74 | _inputTensorSize = vectorProduct(_inputDims); |
| 75 | _outputTensorSize = vectorProduct(_outputDims); |
| 76 | _inputNames = {inputName}; |
| 77 | _outputNames = {outputName}; |
| 78 | } |
nothing calls this directly
no test coverage detected