axiong commited on
Commit
5458f75
·
1 Parent(s): 3df56fd
Files changed (2) hide show
  1. create_shard.py +0 -8
  2. imagenet-r.py +15 -14
create_shard.py DELETED
@@ -1,8 +0,0 @@
1
- '''
2
- 把 imagenet-r.tar 改写成多个 tar shard
3
- '''
4
-
5
- import tarfile
6
-
7
-
8
- num_shard = 10
 
 
 
 
 
 
 
 
 
imagenet-r.py CHANGED
@@ -17,10 +17,12 @@ _CITATION = """\
17
  """
18
 
19
  _DESCRIPTION = """\
20
- 之后放
 
 
21
  """
22
 
23
- _HOMEPAGE = "之后搞"
24
 
25
  _URLs = {
26
  "imagenet-r": "./imagenet-r.tar",
@@ -42,18 +44,14 @@ class ImageNet_R_Config(datasets.BuilderConfig):
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
 
@@ -64,7 +62,7 @@ class ImageNet_R(datasets.GeneratorBasedBuilder):
64
  BUILDER_CONFIGS = [
65
  ImageNet_R_Config(
66
  name="test",
67
- description="test set.",
68
  ),
69
  ]
70
 
@@ -74,7 +72,7 @@ class ImageNet_R(datasets.GeneratorBasedBuilder):
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
  }
@@ -115,16 +113,19 @@ class ImageNet_R(datasets.GeneratorBasedBuilder):
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
  }
 
 
17
  """
18
 
19
  _DESCRIPTION = """\
20
+ ImageNet-R(endition) contains art, cartoons, deviantart, graffiti, embroidery, graphics, origami, paintings, patterns, plastic objects, plush objects, sculptures, sketches, tattoos, toys, and video game renditions of ImageNet classes.
21
+
22
+ ImageNet-R has renditions of 200 ImageNet classes resulting in 30,000 images.
23
  """
24
 
25
+ _HOMEPAGE = "https://github.com/hendrycks/imagenet-r/"
26
 
27
  _URLs = {
28
  "imagenet-r": "./imagenet-r.tar",
 
44
 
45
 
46
  def list_subfolders_and_files(root_dir):
47
+ # all images paths
48
+ all_paths = []
49
 
50
  for root, dirs, files in os.walk(root_dir):
 
 
 
 
51
  for file in files:
52
  file_path = os.path.join(root, file)
53
  all_paths.append(file_path)
54
+ # end for
 
55
  return all_paths
56
 
57
 
 
62
  BUILDER_CONFIGS = [
63
  ImageNet_R_Config(
64
  name="test",
65
+ description="test-set of ImageNet-R",
66
  ),
67
  ]
68
 
 
72
  description=_DESCRIPTION,
73
  features=datasets.Features(
74
  {
75
+ "image": datasets.Image(),
76
  "wnid": datasets.Value("string"),
77
  "class_name": datasets.Value("string"),
78
  }
 
113
 
114
  image_paths = list_subfolders_and_files(filepath)
115
 
 
116
  for _id, image_path in enumerate(image_paths):
117
  if self.config.name == "test":
118
+ # img_style = image_path.split('/')[-1].split('_')[0] # [art]_0.jpg
119
  wnid = image_path.split('/')[-2]
120
  class_name = wordnet[wnid]
121
 
122
  yield _id, {
123
+ "image": {
124
+ "path": image_path,
125
+ "bytes": open(image_path, "rb").read(),
126
+ },
127
  # "label": imagenet_r_wnids.index(wnid),
128
  "wnid": wnid,
129
  "class_name": class_name,
130
  }
131
+