Skip to content

Commit

Permalink
Iterate dirs instead of using st_size
Browse files Browse the repository at this point in the history
- stat-size is filesystem-specific, therefore it was not sufficient to
check for empty folders on all systems in feed_forward.py
  • Loading branch information
chr5tphr committed Jul 2, 2021
1 parent e3d37a7 commit 1b5cfae
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions share/example/feed_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class AllowEmptyClassImageFolder(ImageFolder):
'''
def find_classes(self, directory):
with os.scandir(directory) as scanit:
class_info = sorted((entry.name, entry.stat().st_size) for entry in scanit if entry.is_dir())
class_to_idx = {class_name: index for index, (class_name, st_size) in enumerate(class_info) if st_size}
class_info = sorted((entry.name, len(list(os.scandir(entry.path)))) for entry in scanit if entry.is_dir())
class_to_idx = {class_name: index for index, (class_name, n_members) in enumerate(class_info) if n_members}
if not class_to_idx:
raise FileNotFoundError(f'No non-empty classes found in \'{directory}\'.')
return list(class_to_idx), class_to_idx
Expand Down

0 comments on commit 1b5cfae

Please sign in to comment.