Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Commit

Permalink
added .csv image loading utils
Browse files Browse the repository at this point in the history
  • Loading branch information
williamFalcon committed Feb 14, 2021
1 parent f154943 commit 2b213fb
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions flash/vision/classification/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import pandas as pd
import torch
from PIL import Image
from PIL import Image, UnidentifiedImageError
from pytorch_lightning.utilities.exceptions import MisconfigurationException
from torchvision import transforms as T
from torchvision.datasets import VisionDataset
Expand Down Expand Up @@ -241,9 +241,13 @@ def before_collate(self, samples: Any) -> Any:
if isinstance(samples, (list, tuple)) and all(isinstance(p, str) for p in samples):
outputs = []
for sample in samples:
output = self._loader(sample)
transform = self._valid_transform if self._use_valid_transform else self._train_transform
outputs.append(transform(output))
try:
output = self._loader(sample)
transform = self._valid_transform if self._use_valid_transform else self._train_transform
outputs.append(transform(output))
except UnidentifiedImageError as e:
print(f'Skipping: could not read file {sample}')

return outputs
raise MisconfigurationException("The samples should either be a tensor or a list of paths.")

Expand Down

0 comments on commit 2b213fb

Please sign in to comment.