yonatanbitton commited on
Commit
f9fca7f
1 Parent(s): ef2db1d

Update winogavil.py

Browse files
Files changed (1) hide show
  1. winogavil.py +6 -6
winogavil.py CHANGED
@@ -52,6 +52,7 @@ class Winogavil(datasets.GeneratorBasedBuilder):
52
  BUILDER_CONFIGS = [
53
  datasets.BuilderConfig(name="TEST", version=VERSION, description="winogavil dataset"),
54
  ]
 
55
 
56
  def _info(self):
57
  img = datasets.Image()
@@ -92,12 +93,14 @@ class Winogavil(datasets.GeneratorBasedBuilder):
92
  # It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
93
  # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
94
  data_dir = dl_manager.download_and_extract({
95
- "examples_csv": hf_hub_url("datasets/nlphuji/winogavil", filename="winogavil_dataset.csv")})
 
 
96
 
97
  return [datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs=data_dir)]
98
 
99
  # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
100
- def _generate_examples(self, examples_csv):
101
  # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
102
 
103
  df = pd.read_csv(examples_csv)
@@ -109,11 +112,8 @@ class Winogavil(datasets.GeneratorBasedBuilder):
109
  for r_idx, r in df.iterrows():
110
  r_dict = r.to_dict()
111
  r_dict['candidates'] = json.loads(r_dict['candidates'])
112
- candidates_images = [get_img_url(x) for x in r['candidates']]
113
  r_dict['candidates_images'] = candidates_images
114
  r_dict['associations'] = json.loads(r_dict['associations'])
115
  key = r['ID']
116
  yield key, r_dict
117
-
118
- def get_img_url(image_name):
119
- return 'https://winogavil.s3.eu-west-1.amazonaws.com/{}'.format(image_name + ".jpg")
 
52
  BUILDER_CONFIGS = [
53
  datasets.BuilderConfig(name="TEST", version=VERSION, description="winogavil dataset"),
54
  ]
55
+ IMAGE_EXTENSION = ".jpg"
56
 
57
  def _info(self):
58
  img = datasets.Image()
 
93
  # It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
94
  # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
95
  data_dir = dl_manager.download_and_extract({
96
+ "examples_csv": hf_hub_url("datasets/nlphuji/winogavil", filename="winogavil_dataset.csv"),
97
+ "images_dir": hf_hub_url("datasets/facebook/winoground", filename="winogavil_images.zip")
98
+ })
99
 
100
  return [datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs=data_dir)]
101
 
102
  # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
103
+ def _generate_examples(self, examples_csv, images_dir):
104
  # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
105
 
106
  df = pd.read_csv(examples_csv)
 
112
  for r_idx, r in df.iterrows():
113
  r_dict = r.to_dict()
114
  r_dict['candidates'] = json.loads(r_dict['candidates'])
115
+ candidates_images = [os.path.join(images_dir, f"{x}.{self.IMAGE_EXTENSION}") for x in r['candidates']]
116
  r_dict['candidates_images'] = candidates_images
117
  r_dict['associations'] = json.loads(r_dict['associations'])
118
  key = r['ID']
119
  yield key, r_dict