add train and test sets + take off comments
Browse files
NLVR2.py
CHANGED
|
@@ -39,17 +39,15 @@ _LICENSE = "CC BY 4.0"
|
|
| 39 |
|
| 40 |
_URL_BASE = "https://raw.githubusercontent.com/lil-lab/nlvr/master/nlvr2/data/"
|
| 41 |
_SPLITS = {
|
| 42 |
-
|
| 43 |
"validation": "dev.json",
|
| 44 |
-
|
| 45 |
-
# "test2": "test2.json",
|
| 46 |
}
|
| 47 |
_JZ_IMG_FOLDER_PATH = f"{os.environ['cnw_ALL_CCFRSCRATCH']}/local_datasets/nlvr2/"
|
| 48 |
_IMG_SPLITS = {
|
| 49 |
-
|
| 50 |
"validation": "dev_nlvr2.tar.gz",
|
| 51 |
-
|
| 52 |
-
# "test2": "test2_nlvr2.tar.gz",
|
| 53 |
}
|
| 54 |
|
| 55 |
|
|
@@ -80,58 +78,52 @@ class NLVR2Dataset(datasets.GeneratorBasedBuilder):
|
|
| 80 |
def _split_generators(self, dl_manager):
|
| 81 |
urls = {
|
| 82 |
"Default": {
|
| 83 |
-
|
| 84 |
"validation": os.path.join(_URL_BASE, _SPLITS["validation"]),
|
| 85 |
-
|
| 86 |
-
# "test2": os.path.join(_URL_BASE, _SPLITS["test2"]),
|
| 87 |
},
|
| 88 |
}
|
| 89 |
files_path = dl_manager.download_and_extract(urls)
|
| 90 |
|
| 91 |
images_files = {
|
| 92 |
-
|
| 93 |
"validation": os.path.join(_JZ_IMG_FOLDER_PATH, _IMG_SPLITS["validation"]),
|
| 94 |
-
|
| 95 |
-
# "test2": os.path.join(_JZ_IMG_FOLDER_PATH, _IMG_SPLITS["test2"]),
|
| 96 |
}
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
print(f"img_path2:{validation_img_path}")
|
| 101 |
-
print(f"{os.path.exists(os.path.join(validation_img_path,'dev-946-1-img0.png'))}")
|
| 102 |
-
# test1_img_path = os.path.join(dl_manager.extract(images_files["test1"]), "test1_nlvr2")
|
| 103 |
return [
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
datasets.SplitGenerator(
|
| 109 |
name=datasets.Split.VALIDATION,
|
| 110 |
-
gen_kwargs={"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
),
|
| 112 |
-
# datasets.SplitGenerator(
|
| 113 |
-
# name=datasets.Split.TEST,
|
| 114 |
-
# gen_kwargs={"files_paths": [files_path[self.config.name]["test1"], files_path[self.config.name]["test2"]], "images_path": test1_img_path, "split_name": "test1"},
|
| 115 |
-
# ),
|
| 116 |
]
|
| 117 |
|
| 118 |
-
def _generate_examples(self,
|
| 119 |
idx = 0
|
| 120 |
-
for
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
yield idx, record
|
|
|
|
| 39 |
|
| 40 |
_URL_BASE = "https://raw.githubusercontent.com/lil-lab/nlvr/master/nlvr2/data/"
|
| 41 |
_SPLITS = {
|
| 42 |
+
"train": "train.json",
|
| 43 |
"validation": "dev.json",
|
| 44 |
+
"test1": "test1.json",
|
|
|
|
| 45 |
}
|
| 46 |
_JZ_IMG_FOLDER_PATH = f"{os.environ['cnw_ALL_CCFRSCRATCH']}/local_datasets/nlvr2/"
|
| 47 |
_IMG_SPLITS = {
|
| 48 |
+
"train": "train_nlvr2.tar.gz",
|
| 49 |
"validation": "dev_nlvr2.tar.gz",
|
| 50 |
+
"test1": "test1_nlvr2.tar.gz",
|
|
|
|
| 51 |
}
|
| 52 |
|
| 53 |
|
|
|
|
| 78 |
def _split_generators(self, dl_manager):
|
| 79 |
urls = {
|
| 80 |
"Default": {
|
| 81 |
+
"train": os.path.join(_URL_BASE, _SPLITS["train"]),
|
| 82 |
"validation": os.path.join(_URL_BASE, _SPLITS["validation"]),
|
| 83 |
+
"test1": os.path.join(_URL_BASE, _SPLITS["test1"]),
|
|
|
|
| 84 |
},
|
| 85 |
}
|
| 86 |
files_path = dl_manager.download_and_extract(urls)
|
| 87 |
|
| 88 |
images_files = {
|
| 89 |
+
"train": os.path.join(_JZ_IMG_FOLDER_PATH, _IMG_SPLITS["train"]),
|
| 90 |
"validation": os.path.join(_JZ_IMG_FOLDER_PATH, _IMG_SPLITS["validation"]),
|
| 91 |
+
"test1": os.path.join(_JZ_IMG_FOLDER_PATH, _IMG_SPLITS["test1"]),
|
|
|
|
| 92 |
}
|
| 93 |
+
train_img_path = os.path.join(dl_manager.extract(images_files["train"]), "train_nlvr2")
|
| 94 |
+
validation_img_path = os.path.join(dl_manager.extract(images_files["validation"]), "dev_nlvr2")
|
| 95 |
+
test1_img_path = os.path.join(dl_manager.extract(images_files["test1"]), "test1_nlvr2")
|
|
|
|
|
|
|
|
|
|
| 96 |
return [
|
| 97 |
+
datasets.SplitGenerator(
|
| 98 |
+
name=datasets.Split.TRAIN,
|
| 99 |
+
gen_kwargs={"files_path": files_path[self.config.name]["train"], "images_path": train_img_path, "split_name": "train"},
|
| 100 |
+
),
|
| 101 |
datasets.SplitGenerator(
|
| 102 |
name=datasets.Split.VALIDATION,
|
| 103 |
+
gen_kwargs={"files_path": files_path[self.config.name]["validation"], "images_path": validation_img_path, "split_name": "dev"},
|
| 104 |
+
),
|
| 105 |
+
datasets.SplitGenerator(
|
| 106 |
+
name=datasets.Split.TEST,
|
| 107 |
+
gen_kwargs={"files_path": files_path[self.config.name]["test1"], "images_path": test1_img_path, "split_name": "test1"},
|
| 108 |
),
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
]
|
| 110 |
|
| 111 |
+
def _generate_examples(self, files_path, images_path, split_name):
|
| 112 |
idx = 0
|
| 113 |
+
for line in open(files_path).readlines():
|
| 114 |
+
ex = json.loads(line)
|
| 115 |
+
common_img_identifier = ex["identifier"].split("-")
|
| 116 |
+
left_img_identifier = f"{split_name}-{common_img_identifier[1]}-{common_img_identifier[2]}-img0.png"
|
| 117 |
+
right_img_identifier = f"{split_name}-{common_img_identifier[1]}-{common_img_identifier[2]}-img1.png"
|
| 118 |
+
left_image_path = str(os.path.join(images_path, left_img_identifier))
|
| 119 |
+
right_image_path = str(os.path.join(images_path, right_img_identifier))
|
| 120 |
+
# if os.path.exists(left_image_path) and os.path.exists(right_image_path):
|
| 121 |
+
record = {
|
| 122 |
+
"identifier": ex["identifier"],
|
| 123 |
+
"sentence": ex["sentence"],
|
| 124 |
+
"left_image": left_image_path,
|
| 125 |
+
"right_image": right_image_path,
|
| 126 |
+
"label": ex["label"],
|
| 127 |
+
}
|
| 128 |
+
idx += 1
|
| 129 |
+
yield idx, record
|
|
|