| 46 | type="cv/structure_system", |
| 47 | ) |
| 48 | class StructureSystem(hub.Module): |
| 49 | def _initialize(self, use_gpu=False, enable_mkldnn=False): |
| 50 | """ |
| 51 | initialize with the necessary elements |
| 52 | """ |
| 53 | cfg = self.merge_configs() |
| 54 | |
| 55 | cfg.use_gpu = use_gpu |
| 56 | if use_gpu: |
| 57 | try: |
| 58 | _places = os.environ["CUDA_VISIBLE_DEVICES"] |
| 59 | int(_places[0]) |
| 60 | print("use gpu: ", use_gpu) |
| 61 | print("CUDA_VISIBLE_DEVICES: ", _places) |
| 62 | cfg.gpu_mem = 8000 |
| 63 | except: |
| 64 | raise RuntimeError( |
| 65 | "Environment Variable CUDA_VISIBLE_DEVICES is not set correctly. If you wanna use gpu, please set CUDA_VISIBLE_DEVICES via export CUDA_VISIBLE_DEVICES=cuda_device_id." |
| 66 | ) |
| 67 | cfg.ir_optim = True |
| 68 | cfg.enable_mkldnn = enable_mkldnn |
| 69 | |
| 70 | self.table_sys = PPStructureSystem(cfg) |
| 71 | |
| 72 | def merge_configs(self): |
| 73 | # default cfg |
| 74 | backup_argv = copy.deepcopy(sys.argv) |
| 75 | sys.argv = sys.argv[:1] |
| 76 | cfg = parse_args() |
| 77 | |
| 78 | update_cfg_map = vars(read_params()) |
| 79 | |
| 80 | for key in update_cfg_map: |
| 81 | cfg.__setattr__(key, update_cfg_map[key]) |
| 82 | |
| 83 | sys.argv = copy.deepcopy(backup_argv) |
| 84 | return cfg |
| 85 | |
| 86 | def read_images(self, paths=[]): |
| 87 | images = [] |
| 88 | for img_path in paths: |
| 89 | assert os.path.isfile(img_path), "The {} isn't a valid file.".format( |
| 90 | img_path |
| 91 | ) |
| 92 | img = cv2.imread(img_path) |
| 93 | if img is None: |
| 94 | logger.info("error in loading image:{}".format(img_path)) |
| 95 | continue |
| 96 | images.append(img) |
| 97 | return images |
| 98 | |
| 99 | def predict(self, images=[], paths=[]): |
| 100 | """ |
| 101 | Get the chinese texts in the predicted images. |
| 102 | Args: |
| 103 | images (list(numpy.ndarray)): images data, shape of each is [H, W, C]. If images not paths |
| 104 | paths (list[str]): The paths of images. If paths not images |
| 105 | Returns: |
no outgoing calls
no test coverage detected
searching dependent graphs…