CalfKing commited on
Commit
709e2d4
·
verified ·
1 Parent(s): f96cbb1

Update vtqa2023.py

Browse files
Files changed (1) hide show
  1. vtqa2023.py +30 -11
vtqa2023.py CHANGED
@@ -40,8 +40,10 @@ These questions require multimedia entity alignment, multi-step reasoning and op
40
 
41
  _HOMEPAGE_URL = "https://visual-text-qa.github.io/"
42
 
43
- _LICENSE = "The annotations in this dataset belong to the VTQA Consortium and are licensed under a Creative Commons Attribution NonCommercial NoDerivs 4.0 International License"
44
 
 
 
45
 
46
  _ALL_CONFIGS = sorted(
47
  [
@@ -85,9 +87,6 @@ _BASE_ANSWER_FEATURES = {
85
  }
86
 
87
 
88
- _DATA_URL = "data"
89
-
90
-
91
  class VTQAConfig(datasets.BuilderConfig):
92
  """BuilderConfig for VTQA."""
93
 
@@ -137,7 +136,6 @@ class VTQAConfig(datasets.BuilderConfig):
137
  else _BASE_IMAGE_FEATURES[image_type]
138
  ),
139
  "answers": [baf],
140
- "cws_path": datasets.Value("string"),
141
  }
142
  )
143
  return dataset_features
@@ -172,12 +170,20 @@ class VTQA(datasets.GeneratorBasedBuilder):
172
  lang, image_type = self.config.lang, self.config.image_type
173
 
174
  def _get_url(file_name):
175
- if self.config.local_url is None:
176
- return dl_manager.download_and_extract(
177
- os.path.join(self.config.data_url, f"{file_name}.zip")
178
- )
179
- else:
180
- return os.path.join(self.config.local_url, f"{file_name}")
 
 
 
 
 
 
 
 
181
 
182
  annotation_dir = _get_url("annotations")
183
  image_dir, region_dir, grid_dir = None, None, None
@@ -262,6 +268,19 @@ class VTQA(datasets.GeneratorBasedBuilder):
262
  def _generate_examples(
263
  self, filepath, image_dir=None, region_dir=None, grid_dir=None, labeled=True
264
  ):
 
 
 
 
 
 
 
 
 
 
 
 
 
265
  lang, image_type = self.config.lang, self.config.image_type
266
  use_cws = "cws" if self.config.use_cws else "raw"
267
  """Yields examples as (key, example) tuples."""
 
40
 
41
  _HOMEPAGE_URL = "https://visual-text-qa.github.io/"
42
 
43
+ _LICENSE = "Creative Commons Attribution NonCommercial NoDerivs 4.0 International License"
44
 
45
+ # 修改数据URL
46
+ _DATA_URL = "https://huggingface.co/datasets/CalfKing/vtqa2023/tree/main/data"
47
 
48
  _ALL_CONFIGS = sorted(
49
  [
 
87
  }
88
 
89
 
 
 
 
90
  class VTQAConfig(datasets.BuilderConfig):
91
  """BuilderConfig for VTQA."""
92
 
 
136
  else _BASE_IMAGE_FEATURES[image_type]
137
  ),
138
  "answers": [baf],
 
139
  }
140
  )
141
  return dataset_features
 
170
  lang, image_type = self.config.lang, self.config.image_type
171
 
172
  def _get_url(file_name):
173
+ if self.config.local_url is not None:
174
+ # 检查本地路径是否存在
175
+ local_path = os.path.join(self.config.local_url, f"{file_name}")
176
+ if os.path.exists(local_path):
177
+ return local_path
178
+ else:
179
+ logger.warning(f"Local path {local_path} not found, falling back to download")
180
+
181
+ # 如果local_url未指定或本地文件不存在,则从远程下载
182
+ remote_url = os.path.join(self.config.data_url, f"{file_name}.zip")
183
+ try:
184
+ return dl_manager.download_and_extract(remote_url)
185
+ except Exception as e:
186
+ raise ValueError(f"Failed to download or extract {remote_url}: {str(e)}")
187
 
188
  annotation_dir = _get_url("annotations")
189
  image_dir, region_dir, grid_dir = None, None, None
 
268
  def _generate_examples(
269
  self, filepath, image_dir=None, region_dir=None, grid_dir=None, labeled=True
270
  ):
271
+ # 添加文件存在性检查
272
+ if not os.path.exists(filepath):
273
+ raise ValueError(f"Annotation file not found: {filepath}")
274
+
275
+ if image_dir and not os.path.exists(image_dir):
276
+ raise ValueError(f"Image directory not found: {image_dir}")
277
+
278
+ if region_dir and not os.path.exists(region_dir):
279
+ raise ValueError(f"Region directory not found: {region_dir}")
280
+
281
+ if grid_dir and not os.path.exists(grid_dir):
282
+ raise ValueError(f"Grid directory not found: {grid_dir}")
283
+
284
  lang, image_type = self.config.lang, self.config.image_type
285
  use_cws = "cws" if self.config.use_cws else "raw"
286
  """Yields examples as (key, example) tuples."""