Back to Paddleocr

PaddleOCR Model Inference Parameter Explanation

docs/version2.x/ppocr/blog/inference_args.en.md

3.5.09.8 KB
Original Source

PaddleOCR Model Inference Parameter Explanation

When using PaddleOCR for model inference, you can customize the modification parameters to modify the model, data, preprocessing, postprocessing, etc. (parameter file: utility.py),The detailed parameter explanation is as follows:

  • Global parameters
parameterstypedefaultimplication
image_dirstrNone, must be specified explicitlyImage or folder path
page_numint0Valid when the input type is pdf file, specify to predict the previous page_num pages, all pages are predicted by default
vis_font_pathstr"./doc/fonts/simfang.ttf"font path for visualization
drop_scorefloat0.5Results with a recognition score less than this value will be discarded and will not be returned as results
use_pdservingboolFalseWhether to use Paddle Serving for prediction
warmupboolFalseWhether to enable warmup, this method can be used when statistical prediction time
draw_img_save_dirstr"./inference_results"The saving folder of the system's tandem prediction OCR results
save_crop_resboolFalseWhether to save the recognized text image for OCR
crop_res_save_dirstr"./output"Save the text image path recognized by OCR
use_mpboolFalseWhether to enable multi-process prediction
total_process_numint6The number of processes, which takes effect when use_mp is True
process_idint0The id number of the current process, no need to modify it yourself
benchmarkboolFalseWhether to enable benchmark, and make statistics on prediction speed, memory usage, etc.
save_log_pathstr"./log_output/"Folder where log results are saved when benchmark is enabled
show_logboolTrueWhether to show the log information in the inference
use_onnxboolFalseWhether to enable onnx prediction
  • Prediction engine related parameters
parameterstypedefaultimplication
use_gpuboolTrueWhether to use GPU for prediction
ir_optimboolTrueWhether to analyze and optimize the calculation graph. The prediction process can be accelerated when ir_optim is enabled
use_tensorrtboolFalseWhether to enable tensorrt
min_subgraph_sizeint15The minimum subgraph size in tensorrt. When the size of the subgraph is greater than this value, it will try to use the trt engine to calculate the subgraph.
precisionstrfp32The precision of prediction, supports fp32, fp16, int8
enable_mkldnnboolTrueWhether to enable mkldnn
cpu_threadsint10When mkldnn is enabled, the number of threads predicted by the cpu
  • Text detection model related parameters
parameterstypedefaultimplication
det_algorithmstr"DB"Text detection algorithm name, currently supports DB, EAST, SAST, PSE, DB++, FCE
det_model_dirstrxxDetection inference model paths
det_limit_side_lenint960image side length limit
det_limit_typestr"max"The side length limit type, currently supports minand max. min means to ensure that the shortest side of the image is not less than det_limit_side_len, max means to ensure that the longest side of the image is not greater than det_limit_side_len

The relevant parameters of the DB algorithm are as follows

parameterstypedefaultimplication
det_db_threshfloat0.3In the probability map output by DB, only pixels with a score greater than this threshold will be considered as text pixels
det_db_box_threshfloat0.6Within the detection box, when the average score of all pixels is greater than the threshold, the result will be considered as a text area
det_db_unclip_ratiofloat1.5The expansion factor of the Vatti clipping algorithm, which is used to expand the text area
max_batch_sizeint10max batch size
use_dilationboolFalseWhether to inflate the segmentation results to obtain better detection results
det_db_score_modestr"fast"DB detection result score calculation method, supports fast and slow, fast calculates the average score according to all pixels within the bounding rectangle of the polygon, slow calculates the average score according to all pixels within the original polygon, The calculation speed is relatively slower, but more accurate.

The relevant parameters of the EAST algorithm are as follows

parameterstypedefaultimplication
det_east_score_threshfloat0.8Threshold for score map in EAST postprocess
det_east_cover_threshfloat0.1Average score threshold for text boxes in EAST postprocess
det_east_nms_threshfloat0.2Threshold of nms in EAST postprocess

The relevant parameters of the SAST algorithm are as follows

parameterstypedefaultimplication
det_sast_score_threshfloat0.5Score thresholds in SAST postprocess
det_sast_nms_threshfloat0.5Thresholding of nms in SAST postprocess
det_box_typestr'quad'Whether polygon detection, curved text scene (such as Total-Text) is set to 'poly'

The relevant parameters of the PSE algorithm are as follows

parameterstypedefaultimplication
det_pse_threshfloat0.0Threshold for binarizing the output image
det_pse_box_threshfloat0.85Threshold for filtering boxes, below this threshold is discarded
det_pse_min_areafloat16The minimum area of the box, below this threshold is discarded
det_box_typestr"quad"The type of the returned box, quad: four point coordinates, poly: all point coordinates of the curved text
det_pse_scaleint1The ratio of the input image relative to the post-processed image, such as an image of 640*640, the network output is 160*160, and when the scale is 2, the shape of the post-processed image is 320*320. Increasing this value can speed up the post-processing speed, but it will bring about a decrease in accuracy
  • Text recognition model related parameters
parameterstypedefaultimplication
rec_algorithmstr"CRNN"Text recognition algorithm name, currently supports CRNN, SRN, RARE, NETR, SAR, ViTSTR, ABINet, VisionLAN, SPIN, RobustScanner, SVTR, SVTR_LCNet
rec_model_dirstrNone, it is required if using the recognition modelrecognition inference model paths
rec_image_shapestr"3,48,320" ]Image size at the time of recognition
rec_batch_numint6batch size
max_text_lengthint25The maximum length of the recognition result, valid in SRN
rec_char_dict_pathstr"./ppocr/utils/ppocr_keys_v1.txt"character dictionary file
use_space_charboolTrueWhether to include spaces, if True, the space character will be added at the end of the character dictionary
  • End-to-end text detection and recognition model related parameters
parameterstypedefaultimplication
e2e_algorithmstr"PGNet"End-to-end algorithm name, currently supports PGNet
e2e_model_dirstrNone, it is required if using the end-to-end modelend-to-end model inference model path
e2e_limit_side_lenint768End-to-end input image side length limit
e2e_limit_typestr"max"End-to-end side length limit type, currently supports min and max. min means to ensure that the shortest side of the image is not less than e2e_limit_side_len, max means to ensure that the longest side of the image is not greater than e2e_limit_side_len
e2e_pgnet_score_threshfloat0.5End-to-end score threshold, results below this threshold are discarded
e2e_char_dict_pathstr"./ppocr/utils/ic15_dict.txt"Recognition dictionary file path
e2e_pgnet_valid_setstr"totaltext"The name of the validation set, currently supports totaltext, partvgg, the post-processing methods corresponding to different data sets are different, and it can be consistent with the training process
e2e_pgnet_modestr"fast"PGNet's detection result score calculation method, supports fast and slow, fast calculates the average score according to all pixels within the bounding rectangle of the polygon, slow calculates the average score according to all pixels within the original polygon, The calculation speed is relatively slower, but more accurate.
  • Angle classifier model related parameters
parameterstypedefaultimplication
use_angle_clsboolFalsewhether to use an angle classifier
cls_model_dirstrNone, if you need to use, you must specify the path explicitlyangle classifier inference model path
cls_image_shapestr"3,48,192"prediction shape
label_listlist['0', '180']The angle value corresponding to the class id
cls_batch_numint6batch size
cls_threshfloat0.9Prediction threshold, when the model prediction result is 180 degrees, and the score is greater than the threshold, the final prediction result is considered to be 180 degrees and needs to be flipped
  • OCR image preprocessing parameters
parameterstypedefaultimplication
invertboolFalsewhether to invert image before processing
binarizeboolFalsewhether to threshold binarize image before processing
alphacolortuple"255,255,255"Replacement color for the alpha channel, if the latter is present; R,G,B integers