Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions easyocr/detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ def test_net(canvas_size, mag_ratio, net, image, text_threshold, link_threshold,
with torch.no_grad():
y, feature = net(x)

# remove x and feature from device, whether GPU or CPU
del x, feature

boxes_list, polys_list = [], []
for out in y:
# make score and link map
Expand All @@ -68,6 +71,11 @@ def test_net(canvas_size, mag_ratio, net, image, text_threshold, link_threshold,
polys[k] = boxes[k]
boxes_list.append(boxes)
polys_list.append(polys)

# remove y from device, whether GPU or CPU, and check if cuda was used before calling empty_cache() to clean up
del y
if device == 'cuda':
torch.cuda.empty_cache()

return boxes_list, polys_list

Expand Down