From 4eac6715446d9b183509f7921379bd82fb00fbfa Mon Sep 17 00:00:00 2001 From: Victor Hall Date: Tue, 17 Jan 2023 16:34:00 -0500 Subject: [PATCH] make preloader throw if file is corrupt --- ldm/data/data_loader.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ldm/data/data_loader.py b/ldm/data/data_loader.py index c11b413..72257da 100644 --- a/ldm/data/data_loader.py +++ b/ldm/data/data_loader.py @@ -69,7 +69,14 @@ class DataLoaderMultiAspect(): #if debug_level > 1: print(f" * DLMA file: {pathname} with caption: {caption}") - image = Image.open(pathname) + try: + image = Image.open(pathname).convert('RGB') + except Exception as e: + print(f"File corrupt. Cannot continue. Error opening image: {self.pathname}") + print(e) + print(f"You should remove this image or try to correct it by resaving it.") + exit() + width, height = image.size image_aspect = width / height