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

Commit

Permalink
Fixes wrong label in FilePathDataset (#94)
Browse files Browse the repository at this point in the history
* Fixes #93

Instead of labels, file names were used for making label-to-class map.

* Fix label mapping in FilePathDataset __getitem__

* Cleanup label to class mapping code.
  • Loading branch information
ibraheemmmoosa authored Feb 9, 2021
1 parent b83fac1 commit c79e403
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions flash/vision/classification/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def __init__(
self.transform = transform
self.loader = loader
if self.has_labels:
self.label_to_class_mapping = {v: k for k, v in enumerate(list(sorted(list(set(self.fnames)))))}
self.label_to_class_mapping = dict(map(reversed, enumerate(sorted(set(self.labels)))))

@property
def has_labels(self) -> bool:
Expand All @@ -70,7 +70,8 @@ def __getitem__(self, index: int) -> Tuple[Any, Optional[int]]:
img = self.loader(filename)
label = None
if self.has_labels:
label = self.label_to_class_mapping[filename]
label = self.labels[index]
label = self.label_to_class_mapping[label]
return img, label


Expand Down

0 comments on commit c79e403

Please sign in to comment.