Пример #1
0
 def __init__(self):
     use_pdserving = False
     use_zero_copy_run = False
     rec_image_shape = "3, 32, 320"
     rec_char_type = "ch"
     rec_batch_num = 6
     rec_algorithm = "CRNN"
     max_text_length = 25
     rec_char_dict_path = "./src/ai/ocr_paddle/ppocr/ppocr_keys_v1.txt"
     use_space_char = True
     if use_pdserving is False:
         self.predictor, self.input_tensor, self.output_tensors =\
             utility.create_predictor( mode="rec")
         self.use_zero_copy_run = use_zero_copy_run
     self.rec_image_shape = [int(v) for v in rec_image_shape.split(",")]
     self.character_type = rec_char_type
     self.rec_batch_num = rec_batch_num
     self.rec_algorithm = rec_algorithm
     self.text_len = max_text_length
     char_ops_params = {
         "character_type": rec_char_type,
         "character_dict_path": rec_char_dict_path,
         "use_space_char": use_space_char,
         "max_text_length": max_text_length
     }
     if self.rec_algorithm in ["CRNN", "Rosetta", "STAR-Net"]:
         char_ops_params['loss_type'] = 'ctc'
         self.loss_type = 'ctc'
     elif self.rec_algorithm == "RARE":
         char_ops_params['loss_type'] = 'attention'
         self.loss_type = 'attention'
     elif self.rec_algorithm == "SRN":
         char_ops_params['loss_type'] = 'srn'
         self.loss_type = 'srn'
     self.char_ops = CharacterOps(char_ops_params)
Пример #2
0
 def __init__(self, args):
     self.predictor, self.input_tensor, self.output_tensors =\
         utility.create_predictor(args, mode="rec")
     image_shape = [int(v) for v in args.rec_image_shape.split(",")]
     self.rec_image_shape = image_shape
     char_ops_params = {}
     char_ops_params["character_type"] = args.rec_char_type
     char_ops_params["character_dict_path"] = args.rec_char_dict_path
     char_ops_params['loss_type'] = 'ctc'
     self.char_ops = CharacterOps(char_ops_params)
Пример #3
0
 def __init__(self):
     max_side_len = config.det_max_side_len
     self.det_algorithm = config.det_algorithm
     preprocess_params = {'max_side_len': max_side_len}
     postprocess_params = {}
     self.preprocess_op = db_preprocess.DBProcessTest(preprocess_params)
     postprocess_params["thresh"] = config.det_db_thresh
     postprocess_params["box_thresh"] = config.det_db_box_thresh
     postprocess_params["max_candidates"] = 1000
     postprocess_params["unclip_ratio"] = config.det_db_unclip_ratio
     self.postprocess_op = db_postprocess.DBPostProcess(postprocess_params)
     self.predictor, self.input_tensor, self.output_tensors =\
         utility.create_predictor(mode="detect")
Пример #4
0
def get_text_detector(
    det_model_dir="./paddle_detector/inference/ch_ppocr_mobile_v2.0_det_infer",
    cls_model_dir="./paddle_detector/inference/ch_ppocr_mobile_v2.0_cls_infer",
):
    args = TextDetectorConfig()
    args.det_model_dir = det_model_dir
    args.cls_model_dir = cls_model_dir
    args.use_angle_cls = True
    args.use_gpu = False
    text_detector = TextDetector(args)

    # Patch detector to prevent memory leak
    predictor, input_tensor, output_tensors = create_predictor(
        args, "det", logger)
    text_detector.predictor = predictor
    text_detector.input_tensor = input_tensor
    text_detector.output_tensors = output_tensors
    return text_detector
Пример #5
0
 def __init__(self):
     self.predictor, self.input_tensor, self.output_tensors =\
         utility.create_predictor(mode="rec")
     image_shape = [int(v) for v in config.rec_image_shape.split(",")]
     self.rec_image_shape = image_shape
     self.character_type = config.rec_char_type
     self.rec_batch_num = config.rec_batch_num
     self.rec_algorithm = config.rec_algorithm
     char_ops_params = {}
     char_ops_params["character_type"] = config.rec_char_type
     char_ops_params["character_dict_path"] = config.rec_char_dict_path
     if self.rec_algorithm != "RARE":
         char_ops_params['loss_type'] = 'ctc'
         self.loss_type = 'ctc'
     else:
         char_ops_params['loss_type'] = 'attention'
         self.loss_type = 'attention'
     self.char_ops = character.CharacterOps(char_ops_params)
Пример #6
0
 def __init__(self, args):
     self.predictor, self.input_tensor, self.output_tensors =\
         utility.create_predictor(args, mode="rec")
     self.rec_image_shape = [
         int(v) for v in args.rec_image_shape.split(",")
     ]
     self.character_type = args.rec_char_type
     self.rec_batch_num = args.rec_batch_num
     self.rec_algorithm = args.rec_algorithm
     char_ops_params = {
         "character_type": args.rec_char_type,
         "character_dict_path": args.rec_char_dict_path,
         "use_space_char": args.use_space_char
     }
     if self.rec_algorithm != "RARE":
         char_ops_params['loss_type'] = 'ctc'
         self.loss_type = 'ctc'
     else:
         char_ops_params['loss_type'] = 'attention'
         self.loss_type = 'attention'
     self.char_ops = CharacterOps(char_ops_params)
Пример #7
0
    def __init__(self, args):
        max_side_len = args.det_max_side_len
        self.det_algorithm = args.det_algorithm
        preprocess_params = {'max_side_len': max_side_len}
        postprocess_params = {}
        if self.det_algorithm == "DB":
            self.preprocess_op = DBProcessTest(preprocess_params)
            postprocess_params["thresh"] = args.det_db_thresh
            postprocess_params["box_thresh"] = args.det_db_box_thresh
            postprocess_params["max_candidates"] = 1000
            self.postprocess_op = DBPostProcess(postprocess_params)
        elif self.det_algorithm == "EAST":
            self.preprocess_op = EASTProcessTest(preprocess_params)
            postprocess_params["score_thresh"] = args.det_east_score_thresh
            postprocess_params["cover_thresh"] = args.det_east_cover_thresh
            postprocess_params["nms_thresh"] = args.det_east_nms_thresh
            self.postprocess_op = EASTPostPocess(postprocess_params)
        else:
            logger.info("unknown det_algorithm:{}".format(self.det_algorithm))
            sys.exit(0)

        self.predictor, self.input_tensor, self.output_tensors =\
            utility.create_predictor(args, mode="det")