Merge branch 'dev' into sd3

This commit is contained in:
kohya-ss
2024-08-13 21:00:44 +09:00
3 changed files with 16 additions and 12 deletions

View File

@@ -2638,16 +2638,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)