Python 有没有办法消除Calamari ocr文本检测引擎中不必要的时间延迟?

Python 有没有办法消除Calamari ocr文本检测引擎中不必要的时间延迟?,python,machine-learning,computer-vision,ocr,lstm,Python,Machine Learning,Computer Vision,Ocr,Lstm,我一直在玩Calamari ocr文本检测引擎。 我注意到,当一个人进行预测时,它会发出很多信息,当它真的做出预测时,它会告诉你,比如说,做出预测花了1秒的时间,我已经花了5秒的时间才能真正做出预测。i、 e.如果我对“预测命令”计时,大约需要5秒,即使模型告诉我模型只需要1秒就可以做出预测 我的调查让我在回购协议中找到了预测发生的地方。然后,我进一步指出,MultiPredictor类对此负责(第92行)。所以我看了这个类的定义,发现它是被定义的。 但我找不到是什么导致了信息和警告的喷涌,导致

我一直在玩Calamari ocr文本检测引擎。 我注意到,当一个人进行预测时,它会发出很多信息,当它真的做出预测时,它会告诉你,比如说,做出预测花了1秒的时间,我已经花了5秒的时间才能真正做出预测。i、 e.如果我对“预测命令”计时,大约需要5秒,即使模型告诉我模型只需要1秒就可以做出预测

我的调查让我在回购协议中找到了预测发生的地方。然后,我进一步指出,
MultiPredictor
类对此负责(第92行)。所以我看了这个类的定义,发现它是被定义的。 但我找不到是什么导致了信息和警告的喷涌,导致了我的延误

下面是我用来进行预测和计时的代码片段:

import subprocess
import time

cmd = ['calamari-predict', '--checkpoint', '/opt/working/base_model/model_Calamari_1.ckpt.json', '--files', '/opt/working/data/*.png']
start_time = time.time()
subprocess.run(cmd)
print(time.time()-start_time)
请注意,我已经按照回购协议的说明安装了calamari软件包以及所需的依赖项

以下是我运行预测时提供的响应:

Found 1 files in the dataset
Checkpoint version 2 is up-to-date.
2020-09-02 14:50:49.243030: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'libcudart.so.10.1'; dlerror: libcudart.so.10.1: cannot open shared object file: No such file or directory
2020-09-02 14:50:49.243090: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
2020-09-02 14:50:50.390703: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'libcuda.so.1'; dlerror: libcuda.so.1: cannot open shared object file: No such file or directory
2020-09-02 14:50:50.390770: W tensorflow/stream_executor/cuda/cuda_driver.cc:312] failed call to cuInit: UNKNOWN ERROR (303)
2020-09-02 14:50:50.390814: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:156] kernel driver does not appear to be running on this host (6d0f92664ca6): /proc/driver/nvidia/version does not exist
2020-09-02 14:50:50.391069: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN)to use the following CPU instructions in performance-critical operations:  AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2020-09-02 14:50:50.396503: I tensorflow/core/platform/profile_utils/cpu_utils.cc:104] CPU Frequency: 1896005000 Hz
2020-09-02 14:50:50.396883: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x55ca0736dbb0 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-09-02 14:50:50.396937: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
Model: "functional_1"
__________________________________________________________________________________________________
Layer (type)                    Output Shape         Param #     Connected to                     
==================================================================================================
input_data (InputLayer)         [(None, None, 48, 1) 0                                            
__________________________________________________________________________________________________
conv2d_0 (Conv2D)               (None, None, 48, 40) 400         input_data[0][0]                 
__________________________________________________________________________________________________
pool2d_1 (MaxPooling2D)         (None, None, 24, 40) 0           conv2d_0[0][0]                   
__________________________________________________________________________________________________
conv2d_1 (Conv2D)               (None, None, 24, 60) 21660       pool2d_1[0][0]                   
__________________________________________________________________________________________________
pool2d_3 (MaxPooling2D)         (None, None, 12, 60) 0           conv2d_1[0][0]                   
__________________________________________________________________________________________________
reshape (Reshape)               (None, None, 720)    0           pool2d_3[0][0]                   
__________________________________________________________________________________________________
bidirectional (Bidirectional)   (None, None, 400)    1473600     reshape[0][0]                    
__________________________________________________________________________________________________
input_sequence_length (InputLay [(None, 1)]          0                                            
__________________________________________________________________________________________________
dropout (Dropout)               (None, None, 400)    0           bidirectional[0][0]              
__________________________________________________________________________________________________
tf_op_layer_FloorDiv (TensorFlo [(None, 1)]          0           input_sequence_length[0][0]      
__________________________________________________________________________________________________
logits (Dense)                  (None, None, 29)     11629       dropout[0][0]                    
__________________________________________________________________________________________________
tf_op_layer_FloorDiv_1 (TensorF [(None, 1)]          0           tf_op_layer_FloorDiv[0][0]       
__________________________________________________________________________________________________
softmax (Softmax)               (None, None, 29)     0           logits[0][0]                     
__________________________________________________________________________________________________
input_data_params (InputLayer)  [(None, 1)]          0                                            
__________________________________________________________________________________________________
tf_op_layer_Cast (TensorFlowOpL [(None, 1)]          0           tf_op_layer_FloorDiv_1[0][0]     
==================================================================================================
Total params: 1,507,289
Trainable params: 1,507,289
Non-trainable params: 0
__________________________________________________________________________________________________
None
Prediction:   0%|                                                                                       | 0/1 [00:00<?, ?it/s]
barcode_0: '‪CLK0SU0M((141707‬'
Prediction: 100%|███████████████████████████████████████████████████████████████████████████████| 1/1 [00:01<00:00,  1.52s/it]
Prediction of 1 models took 1.5640497207641602s
Average sentence confidence: 85.41%
All files written
4.881764888763428
但这仍然是我得到的:

Checkpoint version 2 is up-to-date.
2020-09-02 15:23:00.328806: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'libcudart.so.10.1'; dlerror: libcudart.so.10.1: cannot open shared object file: No such file or directory
2020-09-02 15:23:00.328876: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
2020-09-02 15:23:01.536020: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'libcuda.so.1'; dlerror: libcuda.so.1: cannot open shared object file: No such file or directory
2020-09-02 15:23:01.536096: W tensorflow/stream_executor/cuda/cuda_driver.cc:312] failed call to cuInit: UNKNOWN ERROR (303)
2020-09-02 15:23:01.536122: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:156] kernel driver does not appear to be running on this host (6d0f92664ca6): /proc/driver/nvidia/version does not exist
2020-09-02 15:23:01.536450: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN)to use the following CPU instructions in performance-critical operations:  AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2020-09-02 15:23:01.542147: I tensorflow/core/platform/profile_utils/cpu_utils.cc:104] CPU Frequency: 1896005000 Hz
2020-09-02 15:23:01.542953: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x560df22dbb30 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-09-02 15:23:01.543009: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
Model: "functional_1"
__________________________________________________________________________________________________
Layer (type)                    Output Shape         Param #     Connected to                     
==================================================================================================
input_data (InputLayer)         [(None, None, 48, 1) 0                                            
__________________________________________________________________________________________________
conv2d_0 (Conv2D)               (None, None, 48, 40) 400         input_data[0][0]                 
__________________________________________________________________________________________________
pool2d_1 (MaxPooling2D)         (None, None, 24, 40) 0           conv2d_0[0][0]                   
__________________________________________________________________________________________________
conv2d_1 (Conv2D)               (None, None, 24, 60) 21660       pool2d_1[0][0]                   
__________________________________________________________________________________________________
pool2d_3 (MaxPooling2D)         (None, None, 12, 60) 0           conv2d_1[0][0]                   
__________________________________________________________________________________________________
reshape (Reshape)               (None, None, 720)    0           pool2d_3[0][0]                   
__________________________________________________________________________________________________
bidirectional (Bidirectional)   (None, None, 400)    1473600     reshape[0][0]                    
__________________________________________________________________________________________________
input_sequence_length (InputLay [(None, 1)]          0                                            
__________________________________________________________________________________________________
dropout (Dropout)               (None, None, 400)    0           bidirectional[0][0]              
__________________________________________________________________________________________________
tf_op_layer_FloorDiv (TensorFlo [(None, 1)]          0           input_sequence_length[0][0]      
__________________________________________________________________________________________________
logits (Dense)                  (None, None, 29)     11629       dropout[0][0]                    
__________________________________________________________________________________________________
tf_op_layer_FloorDiv_1 (TensorF [(None, 1)]          0           tf_op_layer_FloorDiv[0][0]       
__________________________________________________________________________________________________
softmax (Softmax)               (None, None, 29)     0           logits[0][0]                     
__________________________________________________________________________________________________
input_data_params (InputLayer)  [(None, 1)]          0                                            
__________________________________________________________________________________________________
tf_op_layer_Cast (TensorFlowOpL [(None, 1)]          0           tf_op_layer_FloorDiv_1[0][0]     
==================================================================================================
Total params: 1,507,289
Trainable params: 1,507,289
Non-trainable params: 0
__________________________________________________________________________________________________
None
Prediction of 1 models took 1.556354284286499s
CLK0SU0M((141707
3.4778225421905518

正如您所见,定时预测时间仍然是声称的预测时间的两倍。

运行子流程意味着必须从头开始加载所有内容(库、python运行时、tensorflow等),您还有所有额外的时间进行预测。也许只是将其用作python库,而不是通过命令行interface@Dr.Snoopy没有。我也尝试过在预测脚本中运行函数,但仍然得到了相同的结果。所有这些警告似乎都是由MultiPredictor类触发的。当我把它拿出来,警告和预测离开时,LLI在你的问题中看不到任何细节,所以我不能真正地评论。@ S.D.SoNoPy你看了我提供的链接吗?我认为你需要考虑的是没有“差异”,你在测量两个不同的东西,一个只是模型预测时间,另一个是导致进行预测的整个代码,包括加载框架、加载数据、模型等。这些时间永远不会匹配,因为所有这些步骤实际上都是进行预测所必需的。你只能把它们减少到最低限度。
Checkpoint version 2 is up-to-date.
2020-09-02 15:23:00.328806: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'libcudart.so.10.1'; dlerror: libcudart.so.10.1: cannot open shared object file: No such file or directory
2020-09-02 15:23:00.328876: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
2020-09-02 15:23:01.536020: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'libcuda.so.1'; dlerror: libcuda.so.1: cannot open shared object file: No such file or directory
2020-09-02 15:23:01.536096: W tensorflow/stream_executor/cuda/cuda_driver.cc:312] failed call to cuInit: UNKNOWN ERROR (303)
2020-09-02 15:23:01.536122: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:156] kernel driver does not appear to be running on this host (6d0f92664ca6): /proc/driver/nvidia/version does not exist
2020-09-02 15:23:01.536450: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN)to use the following CPU instructions in performance-critical operations:  AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2020-09-02 15:23:01.542147: I tensorflow/core/platform/profile_utils/cpu_utils.cc:104] CPU Frequency: 1896005000 Hz
2020-09-02 15:23:01.542953: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x560df22dbb30 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-09-02 15:23:01.543009: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
Model: "functional_1"
__________________________________________________________________________________________________
Layer (type)                    Output Shape         Param #     Connected to                     
==================================================================================================
input_data (InputLayer)         [(None, None, 48, 1) 0                                            
__________________________________________________________________________________________________
conv2d_0 (Conv2D)               (None, None, 48, 40) 400         input_data[0][0]                 
__________________________________________________________________________________________________
pool2d_1 (MaxPooling2D)         (None, None, 24, 40) 0           conv2d_0[0][0]                   
__________________________________________________________________________________________________
conv2d_1 (Conv2D)               (None, None, 24, 60) 21660       pool2d_1[0][0]                   
__________________________________________________________________________________________________
pool2d_3 (MaxPooling2D)         (None, None, 12, 60) 0           conv2d_1[0][0]                   
__________________________________________________________________________________________________
reshape (Reshape)               (None, None, 720)    0           pool2d_3[0][0]                   
__________________________________________________________________________________________________
bidirectional (Bidirectional)   (None, None, 400)    1473600     reshape[0][0]                    
__________________________________________________________________________________________________
input_sequence_length (InputLay [(None, 1)]          0                                            
__________________________________________________________________________________________________
dropout (Dropout)               (None, None, 400)    0           bidirectional[0][0]              
__________________________________________________________________________________________________
tf_op_layer_FloorDiv (TensorFlo [(None, 1)]          0           input_sequence_length[0][0]      
__________________________________________________________________________________________________
logits (Dense)                  (None, None, 29)     11629       dropout[0][0]                    
__________________________________________________________________________________________________
tf_op_layer_FloorDiv_1 (TensorF [(None, 1)]          0           tf_op_layer_FloorDiv[0][0]       
__________________________________________________________________________________________________
softmax (Softmax)               (None, None, 29)     0           logits[0][0]                     
__________________________________________________________________________________________________
input_data_params (InputLayer)  [(None, 1)]          0                                            
__________________________________________________________________________________________________
tf_op_layer_Cast (TensorFlowOpL [(None, 1)]          0           tf_op_layer_FloorDiv_1[0][0]     
==================================================================================================
Total params: 1,507,289
Trainable params: 1,507,289
Non-trainable params: 0
__________________________________________________________________________________________________
None
Prediction of 1 models took 1.556354284286499s
CLK0SU0M((141707
3.4778225421905518