Skip to content

Commit

Permalink
Merge pull request kohya-ss#129 from p1atdev/main
Browse files Browse the repository at this point in the history
Add support for .jpeg images in glob
  • Loading branch information
kohya-ss authored Jan 31, 2023
2 parents 9abbee0 + 86f4e20 commit 8c3a52e
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion finetune/make_captions.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def main(args):
os.chdir('finetune')

print(f"load images from {args.train_data_dir}")
image_paths = glob.glob(os.path.join(args.train_data_dir, "*.jpg")) + \
image_paths = glob.glob(os.path.join(args.train_data_dir, "*.jpg")) + glob.glob(os.path.join(args.train_data_dir, "*.jpeg")) + \
glob.glob(os.path.join(args.train_data_dir, "*.png")) + glob.glob(os.path.join(args.train_data_dir, "*.webp"))
print(f"found {len(image_paths)} images.")

Expand Down
5 changes: 3 additions & 2 deletions finetune/merge_captions_to_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


def main(args):
image_paths = glob.glob(os.path.join(args.train_data_dir, "*.jpg")) + \
image_paths = glob.glob(os.path.join(args.train_data_dir, "*.jpg")) + glob.glob(os.path.join(args.train_data_dir, "*.jpeg")) + \
glob.glob(os.path.join(args.train_data_dir, "*.png")) + glob.glob(os.path.join(args.train_data_dir, "*.webp"))
print(f"found {len(image_paths)} images.")

Expand All @@ -30,7 +30,8 @@ def main(args):
for image_path in tqdm(image_paths):
caption_path = os.path.splitext(image_path)[0] + args.caption_extension
with open(caption_path, "rt", encoding='utf-8') as f:
caption = f.readlines()[0].strip()
lines = f.readlines()
caption = lines[0].strip() if len(lines) > 0 else ""

image_key = image_path if args.full_path else os.path.splitext(os.path.basename(image_path))[0]
if image_key not in metadata:
Expand Down
3 changes: 2 additions & 1 deletion finetune/merge_dd_tags_to_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@


def main(args):

image_paths = None
train_data_dir_path = Path(args.train_data_dir)
if args.recursive:
image_paths = list(train_data_dir_path.rglob('*.jpg')) + \
list(train_data_dir_path.rglob('*.jpeg')) + \
list(train_data_dir_path.rglob('*.png')) + \
list(train_data_dir_path.rglob('*.webp'))
else:
image_paths = list(train_data_dir_path.glob('*.jpg')) + \
list(train_data_dir_path.glob('*.jpeg')) + \
list(train_data_dir_path.glob('*.png')) + \
list(train_data_dir_path.glob('*.webp'))

Expand Down
2 changes: 1 addition & 1 deletion finetune/prepare_buckets_latents.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def get_latents(vae, images, weight_dtype):


def main(args):
image_paths = glob.glob(os.path.join(args.train_data_dir, "*.jpg")) + \
image_paths = glob.glob(os.path.join(args.train_data_dir, "*.jpg")) + glob.glob(os.path.join(args.train_data_dir, "*.jpeg")) + \
glob.glob(os.path.join(args.train_data_dir, "*.png")) + glob.glob(os.path.join(args.train_data_dir, "*.webp"))
print(f"found {len(image_paths)} images.")

Expand Down
1 change: 1 addition & 0 deletions finetune/tag_images_by_wd14_tagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def main(args):

# 画像を読み込む
image_paths = glob.glob(os.path.join(args.train_data_dir, "*.jpg")) + \
glob.glob(os.path.join(args.train_data_dir, "*.jpeg")) + \
glob.glob(os.path.join(args.train_data_dir, "*.png")) + \
glob.glob(os.path.join(args.train_data_dir, "*.webp")) + \
glob.glob(os.path.join(args.train_data_dir, "*.bmp"))
Expand Down

0 comments on commit 8c3a52e

Please sign in to comment.