skytnt commited on
Commit
f73854b
1 Parent(s): 34a03de

Update anime-segmentation.py

Browse files
Files changed (1) hide show
  1. anime-segmentation.py +5 -7
anime-segmentation.py CHANGED
@@ -1,13 +1,13 @@
1
  import os
2
  import datasets
3
- import PIL
4
- from datasets import DownloadManager, DatasetInfo, load_dataset
5
 
6
  _DESCRIPTION = """\
7
  A segmentation dataset for anime character
8
  """
9
  _HOMEPAGE = "https://huggingface.co/datasets/skytnt/anime-segmentation"
10
  _URL_BASE = "https://huggingface.co/datasets/skytnt/anime-segmentation/resolve/main/data/"
 
11
 
12
 
13
  class AnimeSegmentationConfig(datasets.BuilderConfig):
@@ -61,16 +61,14 @@ class AnimeSegmentation(datasets.GeneratorBasedBuilder):
61
  for path in dirs:
62
  all_fnames = {os.path.relpath(os.path.join(root, fname), start=path)
63
  for root, _dirs, files in os.walk(path) for fname in files}
64
- image_fnames = sorted(fname for fname in all_fnames
65
- if os.path.splitext(fname)[1].lower() in PIL.Image.EXTENSION)
66
  for image_fname in image_fnames:
67
  yield image_fname, {"image": os.path.join(path, image_fname)}
68
  else:
69
- path = dirs[0]
70
  all_fnames = {os.path.relpath(os.path.join(root, fname), start=path)
71
  for root, _dirs, files in os.walk(path) for fname in files}
72
- image_fnames = sorted(fname for fname in all_fnames if fname.startswith(
73
- "imgs") and os.path.splitext(fname)[1].lower() in PIL.Image.EXTENSION)
74
  for image_fname in image_fnames:
75
  yield image_fname, {"image": os.path.join(path, image_fname),
76
  "mask": os.path.join(path, image_fname.replace("imgs", "masks"))}
1
  import os
2
  import datasets
3
+ from datasets import DownloadManager, DatasetInfo
 
4
 
5
  _DESCRIPTION = """\
6
  A segmentation dataset for anime character
7
  """
8
  _HOMEPAGE = "https://huggingface.co/datasets/skytnt/anime-segmentation"
9
  _URL_BASE = "https://huggingface.co/datasets/skytnt/anime-segmentation/resolve/main/data/"
10
+ _EXTENSION = [".png", ".jpg"]
11
 
12
 
13
  class AnimeSegmentationConfig(datasets.BuilderConfig):
61
  for path in dirs:
62
  all_fnames = {os.path.relpath(os.path.join(root, fname), start=path)
63
  for root, _dirs, files in os.walk(path) for fname in files}
64
+ image_fnames = sorted(fname for fname in all_fnames if os.path.splitext(fname)[1].lower() in _EXTENSION)
 
65
  for image_fname in image_fnames:
66
  yield image_fname, {"image": os.path.join(path, image_fname)}
67
  else:
68
+ path = os.path.join(dirs[0], "imgs")
69
  all_fnames = {os.path.relpath(os.path.join(root, fname), start=path)
70
  for root, _dirs, files in os.walk(path) for fname in files}
71
+ image_fnames = sorted(fname for fname in all_fnames if os.path.splitext(fname)[1].lower() in _EXTENSION)
 
72
  for image_fname in image_fnames:
73
  yield image_fname, {"image": os.path.join(path, image_fname),
74
  "mask": os.path.join(path, image_fname.replace("imgs", "masks"))}