echarlaix HF staff commited on
Commit
f748c12
1 Parent(s): afd8d44

Fix evaluation set image features url

Browse files
Files changed (1) hide show
  1. gqa-lxmert.py +11 -13
gqa-lxmert.py CHANGED
@@ -44,21 +44,19 @@ seeking to address key shortcomings of previous visual question answering (VQA)
44
 
45
  _URLS = {
46
  "train": "https://nlp.cs.unc.edu/data/lxmert_data/gqa/train.json",
47
- "train_feat": "https://nlp.cs.unc.edu/data/lxmert_data/vg_gqa_imgfeat/vg_gqa_obj36.zip",
48
  "dev": "https://nlp.cs.unc.edu/data/lxmert_data/gqa/valid.json",
49
- "dev_feat": "https://nlp.cs.unc.edu/data/lxmert_data/vg_gqa_imgfeat/gqa_testdev_obj36.zip",
50
  "ans2label": "https://raw.githubusercontent.com/airsplay/lxmert/master/data/gqa/trainval_ans2label.json",
51
  }
52
 
53
- _TRAIN_IMG_PATH = "vg_gqa_imgfeat/vg_gqa_obj36.tsv"
54
- _DEV_IMG_PATH = "vg_gqa_imgfeat/gqa_testdev_obj36.tsv"
55
 
56
  FIELDNAMES = [
57
  "img_id", "img_h", "img_w", "objects_id", "objects_conf", "attrs_id", "attrs_conf", "num_boxes", "boxes", "features"
58
  ]
59
 
60
- SHAPE_FEATURES = (36, 2048)
61
- SHAPE_BOXES = (36, 4)
62
 
63
 
64
  class GqaLxmert(datasets.GeneratorBasedBuilder):
@@ -75,8 +73,8 @@ class GqaLxmert(datasets.GeneratorBasedBuilder):
75
  "question": datasets.Value("string"),
76
  "question_id": datasets.Value("int32"),
77
  "image_id": datasets.Value("string"),
78
- "features": datasets.Array2D(SHAPE_FEATURES, dtype="float32"),
79
- "boxes": datasets.Array2D(SHAPE_BOXES, dtype="float32"),
80
  "label": datasets.Value("int32"),
81
  }
82
  )
@@ -91,15 +89,16 @@ class GqaLxmert(datasets.GeneratorBasedBuilder):
91
  """Returns SplitGenerators."""
92
  dl_dir = dl_manager.download_and_extract(_URLS)
93
  self.ans2label = json.load(open(dl_dir["ans2label"]))
 
94
 
95
  return [
96
  datasets.SplitGenerator(
97
  name=datasets.Split.TRAIN,
98
- gen_kwargs={"filepath": dl_dir["train"], "imgfeat": os.path.join(dl_dir["train_feat"], _TRAIN_IMG_PATH)},
99
  ),
100
  datasets.SplitGenerator(
101
  name=datasets.Split.VALIDATION,
102
- gen_kwargs={"filepath": dl_dir["dev"], "imgfeat": os.path.join(dl_dir["dev_feat"], _DEV_IMG_PATH)},
103
  ),
104
  ]
105
 
@@ -126,13 +125,12 @@ class GqaLxmert(datasets.GeneratorBasedBuilder):
126
  id2features[item["img_id"]] = features
127
  return id2features
128
 
129
- def _generate_examples(self, filepath, imgfeat):
130
  """ Yields examples as (key, example) tuples."""
131
- id2features = self._load_features(imgfeat)
132
  with open(filepath, encoding="utf-8") as f:
133
  gqa = json.load(f)
134
  for id_, d in enumerate(gqa):
135
- img_features = id2features[d["img_id"]]
136
  label = self.ans2label[next(iter(d["label"]))]
137
  yield id_, {
138
  "question": d["sent"],
 
44
 
45
  _URLS = {
46
  "train": "https://nlp.cs.unc.edu/data/lxmert_data/gqa/train.json",
 
47
  "dev": "https://nlp.cs.unc.edu/data/lxmert_data/gqa/valid.json",
48
+ "feat": "https://nlp.cs.unc.edu/data/lxmert_data/vg_gqa_imgfeat/vg_gqa_obj36.zip",
49
  "ans2label": "https://raw.githubusercontent.com/airsplay/lxmert/master/data/gqa/trainval_ans2label.json",
50
  }
51
 
52
+ _FEAT_PATH = "vg_gqa_imgfeat/vg_gqa_obj36.tsv"
 
53
 
54
  FIELDNAMES = [
55
  "img_id", "img_h", "img_w", "objects_id", "objects_conf", "attrs_id", "attrs_conf", "num_boxes", "boxes", "features"
56
  ]
57
 
58
+ _SHAPE_FEATURES = (36, 2048)
59
+ _SHAPE_BOXES = (36, 4)
60
 
61
 
62
  class GqaLxmert(datasets.GeneratorBasedBuilder):
 
73
  "question": datasets.Value("string"),
74
  "question_id": datasets.Value("int32"),
75
  "image_id": datasets.Value("string"),
76
+ "features": datasets.Array2D(_SHAPE_FEATURES, dtype="float32"),
77
+ "boxes": datasets.Array2D(_SHAPE_BOXES, dtype="float32"),
78
  "label": datasets.Value("int32"),
79
  }
80
  )
 
89
  """Returns SplitGenerators."""
90
  dl_dir = dl_manager.download_and_extract(_URLS)
91
  self.ans2label = json.load(open(dl_dir["ans2label"]))
92
+ self.id2features = self._load_features(os.path.join(dl_dir["feat"], _FEAT_PATH))
93
 
94
  return [
95
  datasets.SplitGenerator(
96
  name=datasets.Split.TRAIN,
97
+ gen_kwargs={"filepath": dl_dir["train"]},
98
  ),
99
  datasets.SplitGenerator(
100
  name=datasets.Split.VALIDATION,
101
+ gen_kwargs={"filepath": dl_dir["dev"]},
102
  ),
103
  ]
104
 
 
125
  id2features[item["img_id"]] = features
126
  return id2features
127
 
128
+ def _generate_examples(self, filepath):
129
  """ Yields examples as (key, example) tuples."""
 
130
  with open(filepath, encoding="utf-8") as f:
131
  gqa = json.load(f)
132
  for id_, d in enumerate(gqa):
133
+ img_features = self.id2features[d["img_id"]]
134
  label = self.ans2label[next(iter(d["label"]))]
135
  yield id_, {
136
  "question": d["sent"],