简体   繁体   English

我正在尝试使用 easyocr 对单个 GPU 进行推理。 我试过运行以下代码:

[英]I am trying to run inference on a single GPU with easyocr. I have tried running below codes:

def EasyOcrTextbatch(self):
   batchsize=16
   reader = easyocr.Reader(['en'],cudnn_benchmark=True)
   # reader = easyocr.Reader(['en'],gpu=False)
   # dummy = np.zeros([8,512,384,3], dtype=np.uint8)
   # paragraph=reader.readtext_batched(dummy)
   paragraph=reader.readtext_batched(self.imglist,batch_size=batchsize)
   #paragraph = reader.readtext(self.imglist, batch_size=batchsize, paragraph=True, 
   detail=0)
   del reader
   gc.collect()
   torch.cuda.empty_cache()
   return paragraph

The above code does not speed up and to my surprise running it sequentially was faster.Below code is faster than the above one.上面的代码并没有加速,令我惊讶的是顺序运行它更快。下面的代码比上面的代码快。

def EasyOcrTextSequence(self,):

    reader = easyocr.Reader(['en'])
    #reader = easyocr.Reader(['en'],cudnn_benchmark=False)
    # dummy = np.zeros([32, 256, 256, 1], dtype=np.uint8)
    k=[cv2.cvtColor(cv2.imread(i), cv2.COLOR_BGR2GRAY) for i in self.imglist]
    self.arr = np.array(k)
    j=[reader.readtext(i,paragraph=True,detail=0,batch_size=16) for i in self.arr]
    del reader
    return j

The average time for single images comes at.34 seconds and I want to reduce it a lot.Things I have tried:单个图像的平均时间为 34 秒,我想减少很多。我尝试过的事情:

  1. Passing batch size while calling as shown in above code.调用时传递批量大小,如上面的代码所示。
  2. Tried passing Workers=1 and to my surprise the time taken doubles approx.尝试通过 Workers=1,令我惊讶的是,所花费的时间大约翻了一番。 using workers.使用工人。
  3. Have tried passing it sequentially and this is the fastest.已尝试按顺序传递它,这是最快的。
  4. I have even tried vstacking 3 images into one and still no luck.我什至尝试将 3 张图像堆叠为一张,但仍然没有运气。
  5. Size of my images are (512,384)我的图像大小为 (512,384)

Please help me out if you have any suggestion for using easyocr in inference so that the latency should be lowest (Need to process as many images possible within a second).Also I am open for trying different open-source ocr,my only constraint is it should be very fast with good accuracy.如果您对在推理中使用 easyocr 有任何建议,请帮助我,以便延迟应该最低(需要在一秒钟内处理尽可能多的图像)。我也愿意尝试不同的开源 ocr,我唯一的限制是它应该非常快且准确度很高。

I am really stuck at this point.Please help.我真的被困在这一点上。请帮忙。 在此处输入图像描述

List comprehensions are normally a good performance increaser.列表推导通常是一个很好的性能提升器。 They can implemented like this他们可以这样实现

def EasyOcrTextSequence(self,):
   reader = easyocr.Reader(['en'])
   images = (cv2.imread(img) for img in self.imglist)
   images_grayscaled = (cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) for img in images)
   self.arr = np.array(images_grayscaled)
   return (reader.readtext(i,paragraph=True,detail=0,batch_size=16) for i in self.arr)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我正在尝试使用 jinja 模板从数据库中显示即将上映的节目。 代码如下所示 - I am trying to display upcoming shows from a database using jinja template . The codes are seen below 我正在尝试在gpu上使用keras运行autoencoder_layers.py,但出现此错误 - I am trying to run autoencoder_layers.py using keras on gpu but i get this error 我的Python代码无法运行,我不确定为什么,我尝试将内核从3.6更改为3.0 - My Python code will not run and I am not sure why, I have tried changing the kernel from 3.6 to 3.0 我正在尝试使用 subprocess 函数在 linux 终端中运行某个工具。 我有在终端但在程序中运行它的完整语法? - I am trying to use subprocess function to run a certain tool in linux terminal. I have the complete syntax for running it in terminal but in program? 我尝试在 mac os 终端中运行我的 python 程序,但在我成功安装 Beautifulsoup4 后不断收到以下反馈 - I tried running my python program in a mac os terminal but keep getting the feedback below after I have successfully installed Beautifulsoup4 我正在尝试运行一个从 GitHub 克隆的程序,并按照他们告诉的每一步进行操作,但是我在 CMD 中运行它时遇到了这个问题 - I am trying to run a program which I have cloned from GitHub and followed every step that they told but I am having this problem running it in CMD 我一直在尝试将一组值 qcut 到 4 个 bin 中。 我收到以下错误? 如何解决这个问题我是 Python 的初学者 - I have been trying to qcut an array of values into 4 bins. I am getting the error below? How to solve this I am a beginner in Python [Python]我在以下代码的嵌套 if 语句中遇到缩进问题 - [Python]I have an indent problem in nested if statements at the below codes 我正在尝试使用硒访问网站上的密码框。 我尝试过find_element_by_xpath但没有运气 - I am trying to access the password box on a website using selenium. I have tried find_element_by_xpath but with no luck 我正在尝试将genre_ids 列中的数字更改为实际名称。 我尝试了以下但没有成功 - I am trying to change the numbers in the genre_ids column to the actual names. I have tried the following with no success
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM