OCR plattformübergreifendes Engineering von Onnxruntime-GPU-C++-Code

OCR plattformübergreifendes Engineering von Onnxruntime-GPU-C++-Code

Im Internet gibt es nur wenige Codes zum Ausführen des OCR-Modells in der GPU-Umgebung durch onnxruntime. Nach der Überprüfung wird es beim Initialisieren des Modells tatsächlich so geschrieben.

void DbNet::setNumThread(int numOfThread) {
    numThread = numOfThread;
    //===session options===
    // Sets the number of threads used to parallelize the execution within nodes
    // A value of 0 means ORT will pick a default
    //sessionOptions.SetIntraOpNumThreads(numThread);
    //set OMP_NUM_THREADS=16

    // Sets the number of threads used to parallelize the execution of the graph (across nodes)
    // If sequential execution is enabled this value is ignored
    // A value of 0 means ORT will pick a default
    sessionOptions.SetInterOpNumThreads(numThread);

    // Sets graph optimization level
    // ORT_DISABLE_ALL -> To disable all optimizations
    // ORT_ENABLE_BASIC -> To enable basic optimizations (Such as redundant node removals)
    // ORT_ENABLE_EXTENDED -> To enable extended optimizations (Includes level 1 + more complex optimizations like node fusions)
    // ORT_ENABLE_ALL -> To Enable All possible opitmizations
    sessionOptions.SetGraphOptimizationLevel(GraphOptimizationLevel::ORT_ENABLE_EXTENDED);
}

void DbNet::initModel(const std::string &pathStr) {
#ifdef _WIN32
    std::wstring dbPath = strToWstr(pathStr);
    session = new Ort::Session(env, dbPath.c_str(), sessionOptions);
#else
    OrtSessionOptionsAppendExecutionProvider_CUDA(sessionOptions, 0);
    session = new Ort::Session(env, pathStr.c_str(), sessionOptions);
#endif
    getInputName(session, inputName);
    getOutputName(session, outputName);
}
OrtSessionOptionsAppendExecutionProvider_CUDA(sessionOptions, 0);

Diese Codezeile dient dazu, das Modell auf GPU0 auszuführen

  sessionOptions.SetInterOpNumThreads(numThread);

Diese Codezeile dient zum Festlegen der Anzahl der Operationsthreads

Wenn crnn erkannt wird, wird Batch als Vorhersagemethode verwendet

Fügen Sie hier eine Bildbeschreibung ein

Alle Codeprojektdateien können in meinem Profil heruntergeladen werden

Supongo que te gusta

Origin blog.csdn.net/weixin_42280271/article/details/119007195
Recomendado
Clasificación