Skip to content
Draft
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion easyocr/detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def get_detector(trained_model, device='cpu', quantize=True, cudnn_benchmark=Fal
net = CRAFT()

if device == 'cpu':
net.load_state_dict(copyStateDict(torch.load(trained_model, map_location=device, weights_only=False)))
net.load_state_dict(copyStateDict(torch.load(trained_model, map_location=device)))
if quantize:
try:
torch.quantization.quantize_dynamic(net, dtype=torch.qint8, inplace=True)
Expand Down
6 changes: 3 additions & 3 deletions easyocr/easyocr.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
make_rotated_img_list, set_result_with_confidence,\
reformat_input_batched, merge_to_free
from .config import *
from bidi import get_display
from bidi.algorithm import get_display
import numpy as np
import cv2
import torch
Expand Down Expand Up @@ -72,8 +72,8 @@ def __init__(self, lang_list, gpu=True, model_storage_directory=None,
elif gpu is True:
if torch.cuda.is_available():
self.device = 'cuda'
elif torch.backends.mps.is_available():
self.device = 'mps'
#elif torch.backends.mps.is_available():
#self.device = 'mps'
else:
self.device = 'cpu'
if verbose:
Expand Down
2 changes: 1 addition & 1 deletion easyocr/recognition.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def get_recognizer(recog_network, network_params, character,\
model = model_pkg.Model(num_class=num_class, **network_params)

if device == 'cpu':
state_dict = torch.load(model_path, map_location=device, weights_only=False)
state_dict = torch.load(model_path, map_location=device)
new_state_dict = OrderedDict()
for key, value in state_dict.items():
new_key = key[7:]
Expand Down
8 changes: 6 additions & 2 deletions easyocr/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
import math
import cv2
from PIL import Image, JpegImagePlugin
try:
from PIL import get_display
except ImportError:
get_display = None
from scipy import ndimage
import hashlib
import sys, os
Expand Down Expand Up @@ -571,9 +575,9 @@ def compute_ratio_and_resize(img,width,height,model_height):
ratio = width/height
if ratio<1.0:
ratio = calculate_ratio(width,height)
img = cv2.resize(img,(model_height,int(model_height*ratio)), interpolation=Image.Resampling.LANCZOS)
img = cv2.resize(img,(model_height,int(model_height*ratio)), interpolation=Image.LANCZOS)
else:
img = cv2.resize(img,(int(model_height*ratio),model_height),interpolation=Image.Resampling.LANCZOS)
img = cv2.resize(img,(int(model_height*ratio),model_height),interpolation=Image.LANCZOS)
return img,ratio


Expand Down