diff --git a/easyocr/detection.py b/easyocr/detection.py index e2964b71b45..6e378bde59d 100644 --- a/easyocr/detection.py +++ b/easyocr/detection.py @@ -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) diff --git a/easyocr/easyocr.py b/easyocr/easyocr.py index c08fe0388dd..e00104bc4c7 100644 --- a/easyocr/easyocr.py +++ b/easyocr/easyocr.py @@ -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 @@ -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: diff --git a/easyocr/recognition.py b/easyocr/recognition.py index 530ef9517e2..cf4eaef21da 100644 --- a/easyocr/recognition.py +++ b/easyocr/recognition.py @@ -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:] diff --git a/easyocr/utils.py b/easyocr/utils.py index 987baf2c9a6..9d38deed9fd 100644 --- a/easyocr/utils.py +++ b/easyocr/utils.py @@ -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 @@ -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