diff --git a/deploy/python/predict_system.py b/deploy/python/predict_system.py index 44ff8a2e14d8cd181f2c59e28efb6e110b3b48f4..c029636b1c2823bb37ade0555cbb4815beae22ef 100644 --- a/deploy/python/predict_system.py +++ b/deploy/python/predict_system.py @@ -31,7 +31,14 @@ class SystemPredictor(object): self.config = config self.rec_predictor = RecPredictor(config) - self.det_predictor = DetPredictor(config) + + if not config["Global"]["det_inference_model_dir"]: + logger.info( + f"find 'Global.det_inference_model_dir' empty({config['Global']['det_inference_model_dir']}), so det_predictor is disabled" + ) + self.det_predictor = None + else: + self.det_predictor = DetPredictor(config) assert 'IndexProcess' in config.keys(), "Index config not found ... " self.return_k = self.config['IndexProcess']['return_k'] @@ -92,7 +99,10 @@ class SystemPredictor(object): def predict(self, img): output = [] # st1: get all detection results - results = self.det_predictor.predict(img) + if self.det_predictor: + results = self.det_predictor.predict(img) + else: + results = [] # st2: add the whole image for recognition to improve recall results = self.append_self(results, img.shape) diff --git a/docs/en/PPShiTu/PPShiTuV2_introduction.md b/docs/en/PPShiTu/PPShiTuV2_introduction.md index bae44aea1aa4b3ebaa3f35408786d94ee91dc9d8..2ad62acdb4ca7bab7e187b1a968f45259c8ebd62 100644 --- a/docs/en/PPShiTu/PPShiTuV2_introduction.md +++ b/docs/en/PPShiTu/PPShiTuV2_introduction.md @@ -198,6 +198,21 @@ The final output is as follows. [{'bbox': [437, 71, 660, 728], 'rec_docs': '元气森林', 'rec_scores': 0.7740249}, {'bbox': [221, 72, 449, 701], 'rec_docs': '元气森林', 'rec_scores': 0.6950992}, {'bbox': [794, 104, 979, 652], 'rec_docs': '元气森林', 'rec_scores': 0.6305153}] ``` +The recognition process supports flexible configuration. Users can choose not to use the object detection model, but directly input a single whole image into the feature extraction model, and calculate the feature vector for subsequent retrieval, thereby reducing the time-consuming of the overall recognition process. It can be achieved by the script below +```shell +# Use the following command to use the GPU for whole-image prediction +python3.7 python/predict_system.py -c configs/inference_general.yaml -o Global.det_inference_model_dir=None + +# Use the following command to use the CPU for whole-image prediction +python3.7 python/predict_system.py -c configs/inference_general.yaml -o Global.use_gpu=False -o Global.det_inference_model_dir=None +``` + +The final output is as follows +```log +INFO: find 'Global.det_inference_model_dir' empty(), so det_predictor is disabled +[{'bbox': [0, 0, 1200, 802], 'rec_docs': '元气森林', 'rec_scores': 0.5696486}] +``` + #### 4.3.2 multi images prediction If you want to predict the images in the folder, you can directly modify the `Global.infer_imgs` field in the configuration file, or you can modify the corresponding configuration through the following -o parameter. diff --git a/docs/zh_CN/quick_start/quick_start_recognition.md b/docs/zh_CN/quick_start/quick_start_recognition.md index a8a8c4fd281db700f121aa4c0cb4bac7cd2671b2..b8912daad820ec77b5ea558b33302734d295ea75 100644 --- a/docs/zh_CN/quick_start/quick_start_recognition.md +++ b/docs/zh_CN/quick_start/quick_start_recognition.md @@ -223,6 +223,20 @@ python3.7 python/predict_system.py -c configs/inference_general.yaml -o Global.u ![](../../images/recognition/drink_data_demo/output/100.jpeg) +识别流程支持灵活配置,用户可以选择不使用主体检测模型,而直接将单幅整图输入到特征提取模型,计算特征向量供后续检索使用,从而减少整体识别流程的耗时。可以按照以下命令直接进行整图识别 +```shell +# 使用下面的命令使用 GPU 进行整图预测 +python3.7 python/predict_system.py -c configs/inference_general.yaml -o Global.det_inference_model_dir=None + +# 使用下面的命令使用 CPU 进行整图预测 +python3.7 python/predict_system.py -c configs/inference_general.yaml -o Global.use_gpu=False -o Global.det_inference_model_dir=None +``` + +最终输出结果如下 +```log +INFO: find 'Global.det_inference_model_dir' empty(), so det_predictor is disabled +[{'bbox': [0, 0, 1200, 802], 'rec_docs': '元气森林', 'rec_scores': 0.5696486}] +```