Jiayi-Pan commited on
Commit
b81abb3
1 Parent(s): c07996b

Update Action-Effect.py

Browse files
Files changed (1) hide show
  1. Action-Effect.py +32 -3
Action-Effect.py CHANGED
@@ -1,6 +1,10 @@
1
  import json
2
  from zipfile import ZipFile
3
  import datasets
 
 
 
 
4
 
5
  _CITATION = """\
6
  @inproceedings{gao-etal-2018-action,
@@ -26,6 +30,9 @@ Despite recent advances in knowledge representation, automated reasoning, and ma
26
 
27
  _URL = "https://huggingface.co/datasets/sled-umich/Action-Effect"
28
 
 
 
 
29
 
30
  class Action_Effect(datasets.GeneratorBasedBuilder):
31
  """
@@ -42,6 +49,8 @@ class Action_Effect(datasets.GeneratorBasedBuilder):
42
  "verb noun": datasets.Value("string"),
43
  "effect_sentence_list": datasets.features.Sequence(datasets.Value("string")),
44
  "effect_phrase_list": datasets.features.Sequence(datasets.features.Sequence(datasets.Value("string"))),
 
 
45
  }
46
  ),
47
  homepage=_URL,
@@ -49,18 +58,38 @@ class Action_Effect(datasets.GeneratorBasedBuilder):
49
  )
50
 
51
  def _split_generators(self, dl_manager: datasets.DownloadManager):
 
 
 
52
  return [
53
  datasets.SplitGenerator(
54
- name="ActionEffect",
55
  gen_kwargs={
56
- "action_effect_info_path": self._relative_data_dir() + "/action_effect_info.json",
57
  },
58
  )
59
  ]
60
 
61
- def _generate_examples(self, action_effect_info_path):
62
  with open(action_effect_info_path) as f:
63
  action_effect_info = json.load(f)
 
 
 
 
64
  for idx, this_ae_info in enumerate(action_effect_info):
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  yield idx, this_ae_info
66
 
 
1
  import json
2
  from zipfile import ZipFile
3
  import datasets
4
+ import os
5
+ from PIL import Image
6
+ from numpy import asarray
7
+ import tarfile
8
 
9
  _CITATION = """\
10
  @inproceedings{gao-etal-2018-action,
 
30
 
31
  _URL = "https://huggingface.co/datasets/sled-umich/Action-Effect"
32
 
33
+ JSON_URL = "http://162.212.153.129/action_effect_info.json"
34
+
35
+ IMGS_URL = "action_effect_image_rs.tar.gz"
36
 
37
  class Action_Effect(datasets.GeneratorBasedBuilder):
38
  """
 
49
  "verb noun": datasets.Value("string"),
50
  "effect_sentence_list": datasets.features.Sequence(datasets.Value("string")),
51
  "effect_phrase_list": datasets.features.Sequence(datasets.features.Sequence(datasets.Value("string"))),
52
+ "positvie_image_list": datasets.features.Sequence(datasets.Image()),
53
+ "negative_image_list": datasets.features.Sequence(datasets.Image()),
54
  }
55
  ),
56
  homepage=_URL,
 
58
  )
59
 
60
  def _split_generators(self, dl_manager: datasets.DownloadManager):
61
+ dl_dir = dl_manager.download_and_extract(JSON_URL)
62
+ action_effect_info_path = dl_dir + "/action_effect_info.json"
63
+ img_zip_path = dl_dir + "/action_effect_image_rs.tar.gz"
64
  return [
65
  datasets.SplitGenerator(
66
+ name= "ActionEffect",
67
  gen_kwargs={
68
+ "action_effect_info_path": action_effect_info_path, "img_zip_path": img_zip_path
69
  },
70
  )
71
  ]
72
 
73
+ def _generate_examples(self, action_effect_info_path, img_zip_path):
74
  with open(action_effect_info_path) as f:
75
  action_effect_info = json.load(f)
76
+ img_zip = tarfile.open(img_zip_path)
77
+ img_zip.extractall("./action_effect_image_rs")
78
+ img_root = "./action_effect_image_rs/"
79
+ img_zip.close()
80
  for idx, this_ae_info in enumerate(action_effect_info):
81
+ this_ae_info['positive_image_list'] = []
82
+ this_ae_info['negative_image_list'] = []
83
+ vn = this_ae_info["verb noun"]
84
+ this_image_root_positive = img_root + vn.replace(" ", "+") + "/positive/"
85
+ this_image_root_negative = img_root + vn.replace(" ", "+") + "/positive/"
86
+ for img_name in os.listdir(this_image_root_positive):
87
+ img_pil = Image.open(this_image_root_positive + img_name)
88
+ img_np = asarray(img_pil)
89
+ this_image_root_positive.append(img_np)
90
+ for img_name in os.listdir(this_image_root_negative):
91
+ img_pil = Image.open(this_image_root_negative + img_name)
92
+ img_np = asarray(img_pil)
93
+ this_image_root_negative.append(img_np)
94
  yield idx, this_ae_info
95