簡體   English   中英

使用多處理並行運行多個tesseract實例不返回任何結果

[英]running multiple tesseract instances in parallel using multiprocessing not returning any results

我正在編寫一個 python 腳本,其中我使用 multiproccesing 庫並行啟動多個 tesseract 實例。 當我使用多次調用 tesseract 但按順序使用循環時,它可以工作。但是,當我嘗試並行代碼時,一切看起來都很好,但我沒有得到任何結果(我等了 10 分鍾)。

在我的代碼中,我嘗試將多個 pdf 頁面從原始多頁 PDF 中拆分后進行 Ocrize。

這是我的代碼:

def processPage(i):



    nameJPG="converted-"+str(i)+".jpg"
    nameHocr="converted-"+str(i)
    p=subprocess.check_call(["tesseract",nameJPG,nameHocr,"-l","eng","hocr"])
    print "tesseract did the job for the ",str(i+1),"page" 

pool1=Pool(4)
    pool1.map(processPage, range(len(pdf.pages)))

您的代碼正在啟動一個Pool並在完成工作之前退出。 您需要調用closejoin

pool1=Pool(4)
pool1.map(processPage, range(len(pdf.pages)))
pool1.close()
pool1.join()

或者,您可以等待其結果。

pool1=Pool(4)
print pool1.map(processPage, range(len(pdf.pages)))

據我所知,如果您有四核並且同時運行 4 個進程,那么 pytesseract 將不允許多個進程,而 tesseract 將被阻塞,並且如果您需要為公司使用它並且您不想去,那么您將擁有高 CPU 使用率和其他東西使用 google vision api,您必須設置多個服務器並進行套接字編程以從不同的服務器請求文本,以便並行進程的數量少於您的服務器同時運行不同進程的能力,例如四核,它應該是 2 或 3或者其他明智的做法,您可以使用 google vision api 他們有很多服務器,並且輸出也非常好在 tesseract 中禁用多處理也將有所幫助它可以通過在環境中設置 OMP_THREAD_LIMIT=1 來完成。 但是你不能在同一個服務器上為 tesseract 運行多個進程

https://github.com/tesseract-ocr/tesseract/issues/898#issuecomment-315202167

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM