Skip to content

Commit

Permalink
show file name if error in load_image ref #1385
Browse files Browse the repository at this point in the history
  • Loading branch information
kohya-ss committed Jun 25, 2024
1 parent 9dd1ee4 commit 0b3e4f7
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions library/train_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2434,16 +2434,20 @@ def load_arbitrary_dataset(args, tokenizer) -> MinimalDataset:
return train_dataset_group


def load_image(image_path, alpha=False):
image = Image.open(image_path)
if alpha:
if not image.mode == "RGBA":
image = image.convert("RGBA")
else:
if not image.mode == "RGB":
image = image.convert("RGB")
img = np.array(image, np.uint8)
return img
def load_image(image_path, alpha=False):
try:
with Image.open(image_path) as image:
if alpha:
if not image.mode == "RGBA":
image = image.convert("RGBA")
else:
if not image.mode == "RGB":
image = image.convert("RGB")
img = np.array(image, np.uint8)
return img
except (IOError, OSError) as e:
logger.error(f"Error loading file: {image_path}")
raise e


# 画像を読み込む。戻り値はnumpy.ndarray,(original width, original height),(crop left, crop top, crop right, crop bottom)
Expand Down

0 comments on commit 0b3e4f7

Please sign in to comment.