Switched to exception handling

This commit is contained in:
alg-wiki
2022-10-11 17:32:46 +09:00
parent 907a88b2d0
commit b2368a3bce
3 changed files with 18 additions and 18 deletions

View File

@@ -22,7 +22,6 @@ class PersonalizedBase(Dataset):
self.width = width
self.height = height
self.flip = transforms.RandomHorizontalFlip(p=flip_p)
self.extns = [".jpg",".jpeg",".png",".webp",".bmp"]
self.dataset = []
@@ -33,12 +32,13 @@ class PersonalizedBase(Dataset):
assert data_root, 'dataset directory not specified'
self.image_paths = [os.path.join(data_root, file_path) for file_path in os.listdir(data_root) if os.path.splitext(file_path.casefold())[1] in self.extns]
self.image_paths = [os.path.join(data_root, file_path) for file_path in os.listdir(data_root)]
print("Preparing dataset...")
for path in tqdm.tqdm(self.image_paths):
image = Image.open(path)
image = image.convert('RGB')
image = image.resize((self.width, self.height), PIL.Image.BICUBIC)
try:
image = Image.open(path).convert('RGB').resize((self.width, self.height), PIL.Image.BICUBIC)
except Exception:
continue
filename = os.path.basename(path)
filename_tokens = os.path.splitext(filename)[0]