Unverified 提交 276b6745 authored 作者: Glenn Jocher's avatar Glenn Jocher 提交者: GitHub

Fix SKU-110K HUB: `OSError` (#5106)

上级 48b00dbc
...@@ -943,12 +943,22 @@ def dataset_stats(path='coco128.yaml', autodownload=False, verbose=False, profil ...@@ -943,12 +943,22 @@ def dataset_stats(path='coco128.yaml', autodownload=False, verbose=False, profil
return False, None, path return False, None, path
def hub_ops(f, max_dim=1920): def hub_ops(f, max_dim=1920):
# HUB ops for 1 image 'f' # HUB ops for 1 image 'f': resize and save at reduced quality in /dataset-hub for web/app viewing
im = Image.open(f) f_new = im_dir / Path(f).name # dataset-hub image filename
r = max_dim / max(im.height, im.width) # ratio try: # use PIL
if r < 1.0: # image too large im = Image.open(f)
im = im.resize((int(im.width * r), int(im.height * r))) r = max_dim / max(im.height, im.width) # ratio
im.save(im_dir / Path(f).name, quality=75) # save if r < 1.0: # image too large
im = im.resize((int(im.width * r), int(im.height * r)))
im.save(f_new, quality=75) # save
except Exception as e: # use OpenCV
print(f'WARNING: HUB ops PIL failure {f}: {e}')
im = cv2.imread(f)
im_height, im_width = im.shape[:2]
r = max_dim / max(im_height, im_width) # ratio
if r < 1.0: # image too large
im = cv2.resize(im, (int(im_width * r), int(im_height * r)), interpolation=cv2.INTER_LINEAR)
cv2.imwrite(str(f_new), im)
zipped, data_dir, yaml_path = unzip(Path(path)) zipped, data_dir, yaml_path = unzip(Path(path))
with open(check_yaml(yaml_path), errors='ignore') as f: with open(check_yaml(yaml_path), errors='ignore') as f:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论