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:
- Passing batch size while calling as shown in above code.
- Tried passing Workers=1 and to my surprise the time taken doubles approx. using workers.
- Have tried passing it sequentially and this is the fastest.
- I have even tried vstacking 3 images into one and still no luck.
- Size of my images are (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.