ONNX/cpp/src/onnx_run.cpp
/**
 * @brief inference on onnx
 * 
 * @param image opencv image
 * @param output output float data
 */
@brief inference on onnx

@param image opencv image
@param output output float data
@brief inference on onnx @param image opencv image @param output output float data
void ONNXModel::forward(const cv::Mat& image, vector<float>& output) {
    this->inputTensors.clear();
    this->outputTensors.clear();
    output.resize(this->outputElements[0]);
    Ort::MemoryInfo memoryInfo = Ort::MemoryInfo::CreateCpu(OrtAllocatorType::OrtArenaAllocator, OrtMemType::OrtMemTypeDefault);
    this->inputTensors.push_back(Ort::Value::CreateTensor<float>(memoryInfo, (float*)image.data, this->inputElements[0], 
                                                                 this->inputShapes[0].data(), this->inputShapes[0].size()));
    this->outputTensors.push_back(Ort::Value::CreateTensor<float>(memoryInfo, output.data(), this->outputElements[0], 
                                                                  this->outputShapes[0].data(), this->outputShapes[0].size()));
    this->session.Run(Ort::RunOptions{nullptr}, 
                      this->inputNames.data(), this->inputTensors.data(), 1, 
                      this->outputNames.data(), this->outputTensors.data(), 1);
}
void ONNXModel :: forward ( const cv :: Mat & image , vector < float > & output ) { this -> inputTensors . clear ( ) ; this -> outputTensors . clear ( ) ; output . resize ( this -> outputElements [ 0 ] ) ; Ort :: MemoryInfo memoryInfo = Ort :: MemoryInfo :: CreateCpu ( OrtAllocatorType :: OrtArenaAllocator , OrtMemType :: OrtMemTypeDefault ) ; this -> inputTensors . push_back ( Ort :: Value :: CreateTensor < float > ( memoryInfo , ( float * ) image . data , this -> inputElements [ 0 ] , this -> inputShapes [ 0 ] . data ( ) , this -> inputShapes [ 0 ] . size ( ) ) ) ; this -> outputTensors . push_back ( Ort :: Value :: CreateTensor < float > ( memoryInfo , output . data ( ) , this -> outputElements [ 0 ] , this -> outputShapes [ 0 ] . data ( ) , this -> outputShapes [ 0 ] . size ( ) ) ) ; this -> session . Run ( Ort :: RunOptions { nullptr } , this -> inputNames . data ( ) , this -> inputTensors . data ( ) , 1 , this -> outputNames . data ( ) , this -> outputTensors . data ( ) , 1 ) ; }
@brief inference on onnx
@brief inference on onnx
// copy data to onnx tensor // run session