提交 6cf954e1 编写于 作者: H HydrogenSulfate

add flexible configuration for disable det model

上级 3faa1b80
......@@ -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)
......
......@@ -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.
......
......@@ -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}]
```
<a name="基于文件夹的批量识别"></a>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册