未验证 提交 66461c33 编写于 作者: I itasli 提交者: GitHub

Cherrypicking GH-10251 & GH-10181 to PaddleOCR:dygraph (#10710)

* fix undefined save_model_dir when using wandb (#10251)

* fix undefined save_model_dir when using wand

* Update program.py

* Fix fitz camelCase deprecation and .PDF not being recognized as pdf file (#10181)

* Fix fitz camelCase deprecation and .PDF not being recognized as pdf file

* refactor get_image_file_list function
上级 1046c239
...@@ -62,7 +62,6 @@ def get_image_file_list(img_file): ...@@ -62,7 +62,6 @@ def get_image_file_list(img_file):
if img_file is None or not os.path.exists(img_file): if img_file is None or not os.path.exists(img_file):
raise Exception("not found any img file in {}".format(img_file)) raise Exception("not found any img file in {}".format(img_file))
img_end = {'jpg', 'bmp', 'png', 'jpeg', 'rgb', 'tif', 'tiff', 'gif', 'pdf'}
if os.path.isfile(img_file) and _check_image_file(img_file): if os.path.isfile(img_file) and _check_image_file(img_file):
imgs_lists.append(img_file) imgs_lists.append(img_file)
elif os.path.isdir(img_file): elif os.path.isdir(img_file):
...@@ -96,7 +95,7 @@ def alpha_to_color(img, alpha_color=(255, 255, 255)): ...@@ -96,7 +95,7 @@ def alpha_to_color(img, alpha_color=(255, 255, 255)):
return img return img
def check_and_read(img_path): def check_and_read(img_path):
if os.path.basename(img_path)[-3:] in ['gif', 'GIF']: if os.path.basename(img_path)[-3:].lower() == 'gif':
gif = cv2.VideoCapture(img_path) gif = cv2.VideoCapture(img_path)
ret, frame = gif.read() ret, frame = gif.read()
if not ret: if not ret:
...@@ -107,19 +106,19 @@ def check_and_read(img_path): ...@@ -107,19 +106,19 @@ def check_and_read(img_path):
frame = cv2.cvtColor(frame, cv2.COLOR_GRAY2RGB) frame = cv2.cvtColor(frame, cv2.COLOR_GRAY2RGB)
imgvalue = frame[:, :, ::-1] imgvalue = frame[:, :, ::-1]
return imgvalue, True, False return imgvalue, True, False
elif os.path.basename(img_path)[-3:] in ['pdf']: elif os.path.basename(img_path)[-3:].lower() == 'pdf':
import fitz import fitz
from PIL import Image from PIL import Image
imgs = [] imgs = []
with fitz.open(img_path) as pdf: with fitz.open(img_path) as pdf:
for pg in range(0, pdf.pageCount): for pg in range(0, pdf.page_count):
page = pdf[pg] page = pdf[pg]
mat = fitz.Matrix(2, 2) mat = fitz.Matrix(2, 2)
pm = page.getPixmap(matrix=mat, alpha=False) pm = page.get_pixmap(matrix=mat, alpha=False)
# if width or height > 2000 pixels, don't enlarge the image # if width or height > 2000 pixels, don't enlarge the image
if pm.width > 2000 or pm.height > 2000: if pm.width > 2000 or pm.height > 2000:
pm = page.getPixmap(matrix=fitz.Matrix(1, 1), alpha=False) pm = page.get_pixmap(matrix=fitz.Matrix(1, 1), alpha=False)
img = Image.frombytes("RGB", [pm.width, pm.height], pm.samples) img = Image.frombytes("RGB", [pm.width, pm.height], pm.samples)
img = cv2.cvtColor(np.array(img), cv2.COLOR_RGB2BGR) img = cv2.cvtColor(np.array(img), cv2.COLOR_RGB2BGR)
......
...@@ -697,7 +697,7 @@ def preprocess(is_train=False): ...@@ -697,7 +697,7 @@ def preprocess(is_train=False):
wandb_params = config['wandb'] wandb_params = config['wandb']
else: else:
wandb_params = dict() wandb_params = dict()
wandb_params.update({'save_dir': save_model_dir}) wandb_params.update({'save_dir': save_dir})
log_writer = WandbLogger(**wandb_params, config=config) log_writer = WandbLogger(**wandb_params, config=config)
loggers.append(log_writer) loggers.append(log_writer)
else: else:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册