yonatanbitton commited on
Commit
daa2f84
1 Parent(s): a597d45

Update flickr_1k_test_image_text_retrieval.py

Browse files
flickr_1k_test_image_text_retrieval.py CHANGED
@@ -19,6 +19,10 @@ import datasets
19
  import json
20
  from huggingface_hub import hf_hub_url
21
 
 
 
 
 
22
  class Dataset(datasets.GeneratorBasedBuilder):
23
  VERSION = datasets.Version("1.1.0")
24
  BUILDER_CONFIGS = [
@@ -49,10 +53,10 @@ class Dataset(datasets.GeneratorBasedBuilder):
49
  "Please set use_auth_token=True or use_auth_token='<TOKEN>' to download this dataset"
50
  )
51
 
52
- repo_id = 'yonatanbitton/flickr_1k_test_image_text_retrieval'
53
  data_dir = dl_manager.download_and_extract({
54
- "examples_csv": hf_hub_url(repo_id=repo_id, repo_type='dataset', filename="test_1k_flickr.csv"),
55
- "images_dir": hf_hub_url(repo_id=repo_id, repo_type='dataset', filename="images_flickr_1k_test.zip")
56
  })
57
 
58
  return [datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs=data_dir)]
@@ -61,8 +65,11 @@ class Dataset(datasets.GeneratorBasedBuilder):
61
  def _generate_examples(self, examples_csv, images_dir):
62
  """Yields examples."""
63
  df = pd.read_csv(examples_csv)
 
 
 
64
  for r_idx, r in df.iterrows():
65
  r_dict = r.to_dict()
66
- image_path = os.path.join(images_dir, "images_flickr_1k_test", r_dict['filename'])
67
  r_dict['image'] = image_path
68
  yield r_idx, r_dict
 
19
  import json
20
  from huggingface_hub import hf_hub_url
21
 
22
+ _INPUT_CSV = "test_1k_flickr.csv"
23
+ _INPUT_IMAGES = "images_flickr_1k_test"
24
+ _REPO_ID = "yonatanbitton/flickr_1k_test_image_text_retrieval"
25
+
26
  class Dataset(datasets.GeneratorBasedBuilder):
27
  VERSION = datasets.Version("1.1.0")
28
  BUILDER_CONFIGS = [
 
53
  "Please set use_auth_token=True or use_auth_token='<TOKEN>' to download this dataset"
54
  )
55
 
56
+ repo_id = _REPO_ID
57
  data_dir = dl_manager.download_and_extract({
58
+ "examples_csv": hf_hub_url(repo_id=repo_id, repo_type='dataset', filename=_INPUT_CSV),
59
+ "images_dir": hf_hub_url(repo_id=repo_id, repo_type='dataset', filename=f"{_INPUT_IMAGES}.zip")
60
  })
61
 
62
  return [datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs=data_dir)]
 
65
  def _generate_examples(self, examples_csv, images_dir):
66
  """Yields examples."""
67
  df = pd.read_csv(examples_csv)
68
+ for c in ['sentids', 'sentences']:
69
+ df[c] = df[c].apply(json.loads)
70
+
71
  for r_idx, r in df.iterrows():
72
  r_dict = r.to_dict()
73
+ image_path = os.path.join(images_dir, _INPUT_IMAGES, r_dict['filename'])
74
  r_dict['image'] = image_path
75
  yield r_idx, r_dict