Skip to content

Commit 423e6c2

Browse files
committed
support metadata json+.npz caching (no prepare)
1 parent 9fc2740 commit 423e6c2

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

library/train_util.py

+17-9
Original file line numberDiff line numberDiff line change
@@ -1200,19 +1200,27 @@ def __init__(
12001200
tags_list = []
12011201
for image_key, img_md in metadata.items():
12021202
# path情報を作る
1203+
abs_path = None
1204+
1205+
# まず画像を優先して探す
12031206
if os.path.exists(image_key):
12041207
abs_path = image_key
1205-
elif os.path.exists(os.path.splitext(image_key)[0] + ".npz"):
1206-
abs_path = os.path.splitext(image_key)[0] + ".npz"
12071208
else:
1208-
npz_path = os.path.join(subset.image_dir, image_key + ".npz")
1209-
if os.path.exists(npz_path):
1210-
abs_path = npz_path
1209+
# わりといい加減だがいい方法が思いつかん
1210+
paths = glob_images(subset.image_dir, image_key)
1211+
if len(paths) > 0:
1212+
abs_path = paths[0]
1213+
1214+
# なければnpzを探す
1215+
if abs_path is None:
1216+
if os.path.exists(os.path.splitext(image_key)[0] + ".npz"):
1217+
abs_path = os.path.splitext(image_key)[0] + ".npz"
12111218
else:
1212-
# わりといい加減だがいい方法が思いつかん
1213-
abs_path = glob_images(subset.image_dir, image_key)
1214-
assert len(abs_path) >= 1, f"no image / 画像がありません: {image_key}"
1215-
abs_path = abs_path[0]
1219+
npz_path = os.path.join(subset.image_dir, image_key + ".npz")
1220+
if os.path.exists(npz_path):
1221+
abs_path = npz_path
1222+
1223+
assert abs_path is not None, f"no image / 画像がありません: {image_key}"
12161224

12171225
caption = img_md.get("caption")
12181226
tags = img_md.get("tags")

0 commit comments

Comments
 (0)