Error when creating more than one split
Hello,
My loading script food_vision_199_classes.py
works when loading images for the training dataset, however, when I try to use multiple splits, it fails.
I'm running the testing code:
datasets-cli test food_vision_199_classes.py --save_info --all_configs
- Datasets version: 2.7.1
- Python version: 3.8.13
I've narrowed the error down to how many splits I return in the _split_generators()
method.
For example, only returning one datasets.SplitGenerator()
works:
def _split_generators(self, dl_manager):
"""
This function returns the logic to split the dataset into different splits as well as labels.
"""
annotations_csv = dl_manager.download("annotations_with_links.csv")
print(annotations_csv)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"annotations": annotations_csv,
"split": "train"
}
),
##### Commented out TEST split #####
# datasets.SplitGenerator(
# name=datasets.Split.TEST,
# gen_kwargs={
# "annotations": annotations_csv,
# "split": "test"
# }
# )
]
But when I try two splits, it doesn't work:
def _split_generators(self, dl_manager):
"""
This function returns the logic to split the dataset into different splits as well as labels.
"""
annotations_csv = dl_manager.download("annotations_with_links.csv")
print(annotations_csv)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"annotations": annotations_csv,
"split": "train"
}
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={
"annotations": annotations_csv,
"split": "test"
}
)
]
I get the following error (after running datasets-cli test food_vision_199_classes.py --save_info --all_configs
):
Datasets version: 2.7.1
Verbosity level: 10
Testing builder 'default' (1/1)
Downloading and preparing dataset food_vision_199_classes/default to /home/daniel/.cache/huggingface/datasets/food_vision_199_classes/default/0.0.0/95cc7959e7881588f10aab90899c14edc40197b884aef48406145b08756412df...
annotations_with_links.csv
name: None
Traceback (most recent call last):
File "/home/daniel/code/pytorch/env/bin/datasets-cli", line 8, in <module>
sys.exit(main())
File "/home/daniel/code/pytorch/env/lib/python3.8/site-packages/datasets/commands/datasets_cli.py", line 39, in main
service.run()
File "/home/daniel/code/pytorch/env/lib/python3.8/site-packages/datasets/commands/test.py", line 141, in run
builder.download_and_prepare(
File "/home/daniel/code/pytorch/env/lib/python3.8/site-packages/datasets/builder.py", line 822, in download_and_prepare
self._download_and_prepare(
File "/home/daniel/code/pytorch/env/lib/python3.8/site-packages/datasets/builder.py", line 1555, in _download_and_prepare
super()._download_and_prepare(
File "/home/daniel/code/pytorch/env/lib/python3.8/site-packages/datasets/builder.py", line 913, in _download_and_prepare
self._prepare_split(split_generator, **prepare_split_kwargs)
File "/home/daniel/code/pytorch/env/lib/python3.8/site-packages/datasets/builder.py", line 1356, in _prepare_split
split_info = self.info.splits[split_generator.name]
File "/home/daniel/code/pytorch/env/lib/python3.8/site-packages/datasets/splits.py", line 525, in __getitem__
instructions = make_file_instructions(
File "/home/daniel/code/pytorch/env/lib/python3.8/site-packages/datasets/arrow_reader.py", line 111, in make_file_instructions
name2filenames = {
File "/home/daniel/code/pytorch/env/lib/python3.8/site-packages/datasets/arrow_reader.py", line 112, in <dictcomp>
info.name: filenames_for_dataset_split(
File "/home/daniel/code/pytorch/env/lib/python3.8/site-packages/datasets/naming.py", line 78, in filenames_for_dataset_split
prefix = filename_prefix_for_split(dataset_name, split)
File "/home/daniel/code/pytorch/env/lib/python3.8/site-packages/datasets/naming.py", line 57, in filename_prefix_for_split
if os.path.basename(name) != name:
File "/home/daniel/code/pytorch/env/lib/python3.8/posixpath.py", line 143, in basename
p = os.fspath(p)
TypeError: expected str, bytes or os.PathLike object, not NoneType
See the full code for food_vision_199_classes.py
here:
https://huggingface.co./datasets/mrdbourke/food_vision_199_classes/blob/main/food_vision_199_classes.py
Any help would be greatly appreciated!
Hi
@mrdbourke
! Your dataset doesn't pass checks for the information about splits that is specified in README.md
: it contains only train
split but now you also have test
. This seems to be a bug actually.
To avoid this, you can remove these lines from your README.md
:
splits:
- name: train
num_bytes: 2973286
num_examples: 19747
Also, you can use ImageFolder the data structure you have: https://huggingface.co./docs/datasets/v2.7.1/en/image_dataset#imagefolder. That way you don't need to write any scripts. For your case, you don't even need .csv metadata files as you only have labels :)
We have opened an issue to fix this: https://github.com/huggingface/datasets/issues/5315