vrptest2 / vrptest2.py
SKYWF's picture
fix
a6f5da9
raw
history blame
No virus
3.04 kB
# Builder script
# coding=utf-8
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# GNU GENERAL PUBLIC LICENSE
# Version 3, 29 June 2007
#
# Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
# Everyone is permitted to copy and distribute verbatim copies
# of this license document, but changing it is not allowed.
"""VRP2 dataset"""
import copy
import json
import os
import pandas as pd
import datasets
from datasets import load_dataset
_CITATION = """\
@article{vp2r2022jjk,
title={xxxxx},
author={test1},
journal={arXiv preprint arXiv:2203.10981},
year={2022}
}
"""
_DESCRIPTION = """\
yhello
"""
_LICENSE = "GNU General Public License v3.0"
_SPLITS = ["test"]
_URL = "https://huggingface.co/datasets/mujif/vrptest2/resolve/main/data/IQ" # todo
class ChartQA(datasets.GeneratorBasedBuilder):
def _info(self):
features = datasets.Features(
{
"imgname": datasets.Value("string"),
"image": datasets.Image(),
"question": datasets.Value("string"),
"gt_answer": datasets.Value("string"),
}
)
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=features,
supervised_keys=None,
license=_LICENSE,
)
def _split_generators(self, dl_manager):
# downloaded_file = dl_manager.download_and_extract(_URL) + "/ChartQA Dataset"
downloaded_file = dl_manager.download_and_extract(_URL)
return [
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={
"images_path": downloaded_file + "/test",
"img_anno_path": downloaded_file + "/test/result.jsonl",
},
),
]
def _generate_examples(self, img_anno_path:str ,images_path: str):
idx = 0
with open(img_anno_path, "r", encoding="utf-8") as f:
data = json.load(f)
#returns the examples in the raw in json file
for item in data:
item = copy.deepcopy(item)
item["image"] = os.path.join(images_path,item["file_name"])
item["question"] = item["question"]
item["gt_answer"] = item["gt_answer"]
yield idx, item
idx += 1