| 42 | |
| 43 | |
| 44 | class StructureSystem(object): |
| 45 | def __init__(self, args): |
| 46 | self.mode = args.mode |
| 47 | self.recovery = args.recovery |
| 48 | |
| 49 | self.image_orientation_predictor = None |
| 50 | if args.image_orientation: |
| 51 | import paddleclas |
| 52 | |
| 53 | self.image_orientation_predictor = paddleclas.PaddleClas( |
| 54 | model_name="text_image_orientation" |
| 55 | ) |
| 56 | |
| 57 | if self.mode == "structure": |
| 58 | if not args.show_log: |
| 59 | logger.setLevel(logging.INFO) |
| 60 | if args.layout == False and args.ocr == True: |
| 61 | args.ocr = False |
| 62 | logger.warning( |
| 63 | "When args.layout is false, args.ocr is automatically set to false" |
| 64 | ) |
| 65 | # init model |
| 66 | self.layout_predictor = None |
| 67 | self.text_system = None |
| 68 | self.table_system = None |
| 69 | self.formula_system = None |
| 70 | if args.layout: |
| 71 | self.layout_predictor = LayoutPredictor(args) |
| 72 | if args.ocr: |
| 73 | self.text_system = TextSystem(args) |
| 74 | if args.table: |
| 75 | if self.text_system is not None: |
| 76 | self.table_system = TableSystem( |
| 77 | args, |
| 78 | self.text_system.text_detector, |
| 79 | self.text_system.text_recognizer, |
| 80 | ) |
| 81 | else: |
| 82 | self.table_system = TableSystem(args) |
| 83 | if args.formula: |
| 84 | args_formula = deepcopy(args) |
| 85 | args_formula.rec_algorithm = args.formula_algorithm |
| 86 | args_formula.rec_model_dir = args.formula_model_dir |
| 87 | args_formula.rec_char_dict_path = args.formula_char_dict_path |
| 88 | args_formula.rec_batch_num = args.formula_batch_num |
| 89 | self.formula_system = TextRecognizer(args_formula) |
| 90 | |
| 91 | elif self.mode == "kie": |
| 92 | from ppstructure.kie.predict_kie_token_ser_re import SerRePredictor |
| 93 | |
| 94 | self.kie_predictor = SerRePredictor(args) |
| 95 | |
| 96 | self.return_word_box = args.return_word_box |
| 97 | |
| 98 | def __call__(self, img, return_ocr_result_in_table=False, img_idx=0): |
| 99 | time_dict = { |
| 100 | "image_orientation": 0, |
| 101 | "layout": 0, |
no outgoing calls
no test coverage detected
searching dependent graphs…