Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 30a6da5

Browse files
authored
Merge pull request #2 from persona-id/bjou/fix-memory-leak
fix: resolves memory leak caused by using CRAFT detector with detect() or readtext()
2 parents 6bce479 + 1a4221c commit 30a6da5

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

easyocr/detection.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ def test_net(
5858
with torch.no_grad():
5959
y, feature = net(x)
6060

61+
# remove x and feature from device, whether GPU or CPU
62+
del x, feature
63+
6164
boxes_list, polys_list = [], []
6265
for out in y:
6366
# make score and link map
@@ -82,6 +85,11 @@ def test_net(
8285
boxes_list.append(boxes)
8386
polys_list.append(polys)
8487

88+
# remove y from device, whether GPU or CPU, and check if cuda was used before calling empty_cache() to clean up
89+
del y
90+
if device == 'cuda':
91+
torch.cuda.empty_cache()
92+
8593
return boxes_list, polys_list
8694

8795
def get_detector(trained_model, device='cpu', quantize=True, cudnn_benchmark=False):

0 commit comments

Comments
 (0)