axiong commited on
Commit
88e9859
1 Parent(s): 421c555

Delete loading script

Browse files
Files changed (1) hide show
  1. imagenet-r.py +0 -130
imagenet-r.py DELETED
@@ -1,130 +0,0 @@
1
- """ImageNet-R Dataset"""
2
-
3
- import os
4
- import datasets
5
- import json
6
-
7
-
8
- logger = datasets.logging.get_logger(__name__)
9
-
10
- _CITATION = """\
11
- @article{hendrycks2020many,
12
- title={The Many Faces of Robustness: A Critical Analysis of Out-of-Distribution Generalization},
13
- author={Dan Hendrycks and Steven Basart and Norman Mu and Saurav Kadavath and Frank Wang and Evan Dorundo and Rahul Desai and Tyler Zhu and Samyak Parajuli and Mike Guo and Dawn Song and Jacob Steinhardt and Justin Gilmer},
14
- journal={arXiv preprint arXiv:2006.16241},
15
- year={2020}
16
- }
17
- """
18
-
19
- _DESCRIPTION = """\
20
- 之后放
21
- """
22
-
23
- _HOMEPAGE = "之后搞"
24
-
25
- _URLs = {
26
- "imagenet-r": "./imagenet-r.tar",
27
- "classes": "./classes.json",
28
- "wordnet": "./wordnet.json",
29
- }
30
-
31
-
32
- class ImageNet_R_Config(datasets.BuilderConfig):
33
- """BuilderConfig for ImageNet-R"""
34
-
35
- def __init__(self, **kwargs):
36
- """
37
- Args:
38
- **kwargs: keyword arguments forwarded to super.
39
- """
40
- super(ImageNet_R_Config, self).__init__(version=datasets.Version("1.0.0", ""), **kwargs)
41
-
42
-
43
-
44
- def list_subfolders_and_files(root_dir):
45
- all_paths = [] # 用于存储所有路径的列表
46
-
47
- for root, dirs, files in os.walk(root_dir):
48
- # 添加当前遍历到的目录路径
49
- # all_paths.append(root)
50
-
51
- # 遍历当前目录下的所有文件,添加文件路径
52
- for file in files:
53
- file_path = os.path.join(root, file)
54
- all_paths.append(file_path)
55
-
56
- # raise RuntimeError( len(all_paths) )
57
- return all_paths
58
-
59
-
60
- class ImageNet_R(datasets.GeneratorBasedBuilder):
61
- """ImageNet-R Dataset"""
62
-
63
- VERSION = datasets.Version("1.0.0")
64
- BUILDER_CONFIGS = [
65
- ImageNet_R_Config(
66
- name="test",
67
- description="test set.",
68
- ),
69
- ]
70
-
71
- def _info(self):
72
- if self.config.name == "test":
73
- return datasets.DatasetInfo(
74
- description=_DESCRIPTION,
75
- features=datasets.Features(
76
- {
77
- "image": datasets.Value("string"),
78
- "wnid": datasets.Value("string"),
79
- "class_name": datasets.Value("string"),
80
- }
81
- ),
82
- supervised_keys=None,
83
- citation=_CITATION,
84
- homepage=_HOMEPAGE,
85
- )
86
-
87
- def _split_generators(self, dl_manager):
88
- """Returns SplitGenerators."""
89
- downloaded_files = dl_manager.download_and_extract(_URLs)
90
-
91
- if self.config.name == "test":
92
- return [
93
- datasets.SplitGenerator(
94
- name = datasets.Split.TEST,
95
- gen_kwargs = {
96
- "filepath": downloaded_files["imagenet-r"],
97
- "classes_path": downloaded_files["classes"],
98
- "wordnet_path": downloaded_files["wordnet"],
99
- }
100
- )
101
- ]
102
-
103
-
104
- def _generate_examples(self, filepath, classes_path, wordnet_path):
105
- """Yields examples."""
106
- logger.info("generating examples from = %s", filepath)
107
-
108
- with open(classes_path, 'r') as f:
109
- classes = json.load(f)
110
- with open(wordnet_path, 'r') as f:
111
- wordnet = json.load(f)
112
-
113
- imagenet_r_wnids = classes['imagenet_r_wnids']
114
- all_wnids = classes['all_wnids']
115
-
116
- image_paths = list_subfolders_and_files(filepath)
117
-
118
- # raise RuntimeError( len(image_paths), image_paths[0], image_paths[-1] )
119
- for _id, image_path in enumerate(image_paths):
120
- if self.config.name == "test":
121
- img_style = image_path.split('/')[-1].split('_')[0] # 这个描述的是图像风格
122
- wnid = image_path.split('/')[-2]
123
- class_name = wordnet[wnid]
124
-
125
- yield _id, {
126
- "image": image_path,
127
- # "label": imagenet_r_wnids.index(wnid),
128
- "wnid": wnid,
129
- "class_name": class_name,
130
- }