OCRNet output parser not working

Please provide complete information as applicable to your setup.

• Hardware Platform (Jetson / GPU) : A2000
• DeepStream Version:6.3
• JetPack Version (valid for Jetson only)
• TensorRT Version:8.6.1
• NVIDIA GPU Driver Version (valid for GPU only) :525
• Issue Type( questions, new requirements, bugs): OCRNet output parser not working
• How to reproduce the issue ? (This is for bugs. Including which sample app is using, the configuration files content, the command line used and other details for reproducing)
• Requirement details( This is for new requirement. Including the module name-for which plugin or for which sample application, the function description):

I have written a output parser for OCRNet which is integrated in Deepstream reference app as sgie2. The model seems to infer fine. But the output parser is not working.

Code:

bool NvDsInferParseCustomOCRNet(const vector &outputLayersInfo,
const NvDsInferNetworkInfo &networkInfo,
vector &attrList,
string &attrString) {
// Initialize variables
std::cout << “Hello World from parser” << std::endl;
float *outputProbBuffer = nullptr;
int *outputIdBuffer = nullptr;
int seqLen = 0;
vector dict_table; // Using vector instead of deque
bool dict_ready = false;

// Load dictionary if not loaded already
if (!dict_ready) {
    ifstream fdict("/home/sigmind/dict.txt");
    if (!fdict.is_open()) {
        cout << "Failed to open dictionary file." << endl;
        return false;
    }
    string line;
    while (getline(fdict, line)) {
        dict_table.push_back(line);
        std::cout<<"line from parser:"<<line<<std::endl;
    }
    dict_ready = true;
    fdict.close();
}

// Retrieve output buffers
for (const auto &layerInfo : outputLayersInfo) {
    if (!layerInfo.isInput) {
        if (layerInfo.dataType == 0) {
            outputProbBuffer = static_cast<float *>(layerInfo.buffer);
        } else if (layerInfo.dataType == 3) {
            std::cout<<"Output Buffer:"<<std::endl;
            outputIdBuffer = static_cast<int *>(layerInfo.buffer);
        }
    }
}


// Calculate sequence length
seqLen = networkInfo.width / 4;

// Parse output buffers and assemble recognized text
attrString = "";
for (int seqId = 0; seqId < seqLen; seqId++) {
    int currData = outputIdBuffer[seqId];
    if (currData < static_cast<int>(dict_table.size())) { // Cast dict_table.size() to int
        attrString += dict_table[currData];
    }
}

// Add OCR attribute to attribute list
NvDsInferAttribute ocrAttr;
ocrAttr.attributeIndex = 0;
ocrAttr.attributeValue = 1;
ocrAttr.attributeConfidence = 1.0;
ocrAttr.attributeLabel = strdup(attrString.c_str()); // Use strdup directly 
std::cout<<"OCR text:"<<attrString.c_str()<<std::endl;
attrList.push_back(ocrAttr);

return true;

}

}// extern “C” `

OCRNet is trained to recognize Bangla texts.

Output: উকখগডইইডইইইইইইইডইইইইইইইইইইঅঅঅঅঅঅঅঅঅঅঅঅঅঅঅঅঅঅঅঅঅঅঅঅ

Model config:

[property]
gpu-id=0

labelfile-path=/home/sigmind/dict.txt

model-engine-file=/home/sigmind/TensorRT-8.6.1.6.Linux.x86_64-gnu.cuda-12.0/TensorRT-8.6.1.6/bin/best_accu_ocrnet.fp16.engine

tlt-model-key=nvidia_tao

batch-size=4

0=FP32, 1=INT8, 2=FP16 mode

network-mode=2
num-detected-classes=3
gie-unique-id=5
uff-input-blob-name=input

#0=Detection 1=Classifier 2=Segmentation
network-type=1
parse-classifier-func-name=NvDsInferParseCustomOCRNet
custom-lib-path=/home/sigmind/nvidia_ocr_application/tao_app/nv-tao-app/deepstream_tao_apps/apps/tao_others/deepstream-nvocdr-app/nvinfer_custom_lpr_parser/libnvdsinfer_custom_impl_lpr.so
process_mode=2
operate-on-gie-id=4
net-scale-factor=0.00392156862745098
#net-scale-factor=1.0
#0=RGB 1=BGR 2=GRAY
model-color-format=2

classifier-threshold=0.51

[class-attrs-all]
#threshold=0.999

Are you using the TAO OCRNet model( Optical Character Recognition | NVIDIA NGC)?

Yes. I have used TAO toolkit to train the model.

Please refer to NVIDIA-AI-IOT/NVIDIA-Optical-Character-Detection-and-Recognition-Solution: This repository provides optical character detection and recognition solution optimized on Nvidia devices. (github.com) and deepstream_tao_apps/apps/tao_others/deepstream-nvocdr-app at master · NVIDIA-AI-IOT/deepstream_tao_apps (github.com)

There is no update from you for a period, assuming this is not an issue anymore. Hence we are closing this topic. If need further support, please open a new one. Thanks

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.