Datasets:
SushantGautam
commited on
Commit
•
12d36f8
1
Parent(s):
5caf550
Upload folder using huggingface_hub
Browse files- HuggingFaceDataset-Binary.py +124 -0
- metadata.csv +0 -0
HuggingFaceDataset-Binary.py
ADDED
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright 2024 The HuggingFace Datasets Authors and the current dataset script contributor.
|
2 |
+
#
|
3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
+
# you may not use this file except in compliance with the License.
|
5 |
+
# You may obtain a copy of the License at
|
6 |
+
#
|
7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
#
|
9 |
+
# Unless required by applicable law or agreed to in writing, software
|
10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
+
# See the License for the specific language governing permissions and
|
13 |
+
# limitations under the License.
|
14 |
+
|
15 |
+
import json
|
16 |
+
import os
|
17 |
+
import csv
|
18 |
+
from PIL import Image
|
19 |
+
import pandas as pd
|
20 |
+
|
21 |
+
import datasets
|
22 |
+
|
23 |
+
|
24 |
+
_CITATION = """\
|
25 |
+
@inproceedings{gautam2024kvasirvqa,
|
26 |
+
title={Kvasir-VQA: A Text-Image Pair GI Tract Dataset},
|
27 |
+
author={Gautam, Sushant and Storås, Andrea and Midoglu, Cise and Hicks, Steven A. and Thambawita, Vajira and Halvorsen, Pål and Riegler, Michael A.},
|
28 |
+
booktitle={Proceedings of the First International Workshop on Vision-Language Models for Biomedical Applications (VLM4Bio '24)},
|
29 |
+
year={2024},
|
30 |
+
location={Melbourne, VIC, Australia},
|
31 |
+
publisher={ACM},
|
32 |
+
doi={10.1145/3689096.3689458}
|
33 |
+
}
|
34 |
+
"""
|
35 |
+
|
36 |
+
_DESCRIPTION = """\
|
37 |
+
The Kvasir-VQA dataset is an extended dataset derived from the HyperKvasir and Kvasir-Instrument datasets, augmented with question-and-answer annotations. This dataset is designed to facilitate advanced machine learning tasks in gastrointestinal (GI) diagnostics, including image captioning, Visual Question Answering (VQA), and text-based generation of synthetic medical images.
|
38 |
+
"""
|
39 |
+
|
40 |
+
_HOMEPAGE = "https://datasets.simula.no/kvasir-vqa/"
|
41 |
+
|
42 |
+
_LICENSE = "cc-by-nc-4.0"
|
43 |
+
|
44 |
+
|
45 |
+
class KvasirVQADataset(datasets.GeneratorBasedBuilder):
|
46 |
+
"""Kvasir-VQA: A Text-Image Pair GI Tract Dataset"""
|
47 |
+
|
48 |
+
VERSION = datasets.Version("1.0.0")
|
49 |
+
|
50 |
+
BUILDER_CONFIGS = [
|
51 |
+
datasets.BuilderConfig(
|
52 |
+
name="kvasir_vqa", version=VERSION, description="Kvasir-VQA dataset containing text-image pairs with question-and-answer annotations"),
|
53 |
+
]
|
54 |
+
|
55 |
+
DEFAULT_CONFIG_NAME = "kvasir_vqa"
|
56 |
+
|
57 |
+
def _info(self):
|
58 |
+
features = datasets.Features(
|
59 |
+
{
|
60 |
+
"image": datasets.Image(),
|
61 |
+
"source": datasets.Value("string"),
|
62 |
+
"question": datasets.Value("string"),
|
63 |
+
"answer": datasets.Value("string"),
|
64 |
+
"img_id": datasets.Value("string"),
|
65 |
+
}
|
66 |
+
)
|
67 |
+
return datasets.DatasetInfo(
|
68 |
+
description=_DESCRIPTION,
|
69 |
+
features=features,
|
70 |
+
homepage=_HOMEPAGE,
|
71 |
+
license=_LICENSE,
|
72 |
+
citation=_CITATION,
|
73 |
+
)
|
74 |
+
|
75 |
+
def _split_generators(self, dl_manager):
|
76 |
+
data_dir = "."
|
77 |
+
return [
|
78 |
+
datasets.SplitGenerator(
|
79 |
+
name="raw_annotations",
|
80 |
+
gen_kwargs={
|
81 |
+
"metadata_file": os.path.join(data_dir, "metadata.csv"),
|
82 |
+
"image_dir": data_dir,
|
83 |
+
},
|
84 |
+
)
|
85 |
+
]
|
86 |
+
|
87 |
+
def _generate_examples(self, metadata_file, image_dir):
|
88 |
+
image_cache = {}
|
89 |
+
df = pd.read_csv(metadata_file, encoding='utf-8')
|
90 |
+
# shuffled_df = df.sample(frac=1, random_state=42).reset_index(drop=True)
|
91 |
+
shuffled_df = df
|
92 |
+
for idx, row in shuffled_df.iterrows():
|
93 |
+
image_file = row["file_name"]
|
94 |
+
image_path = os.path.join(image_dir, image_file)
|
95 |
+
|
96 |
+
if image_file not in image_cache:
|
97 |
+
if os.path.exists(image_path):
|
98 |
+
with open(image_path, "rb") as img_file:
|
99 |
+
image_cache[image_file] = img_file.read()
|
100 |
+
else:
|
101 |
+
continue # Skip if the image file does not exist
|
102 |
+
|
103 |
+
yield idx, {
|
104 |
+
"image": image_cache[image_file],
|
105 |
+
"source": row["source"],
|
106 |
+
"question": row["question"],
|
107 |
+
"answer": row["answer"],
|
108 |
+
"img_id": image_file.replace(".jpg", "").replace("images/", ""),
|
109 |
+
}
|
110 |
+
|
111 |
+
# RUN: datasets-cli test HuggingFaceDataset-Binary.py --save_info --all_configs
|
112 |
+
|
113 |
+
## upload to huggingface, it will save as arrow
|
114 |
+
|
115 |
+
# huggingface-cli upload SimulaMet-HOST/xxKvasir-VQA . . --repo-type dataset xxx
|
116 |
+
|
117 |
+
## then convert the arrow to parqueet
|
118 |
+
|
119 |
+
# datasets-cli convert_to_parquet SimulaMet-HOST/xxKvasir-VQA
|
120 |
+
|
121 |
+
|
122 |
+
# The file names were weird. I had to rename them to make it more readable.
|
123 |
+
# cloned the repo to local and pushed again to huggingface
|
124 |
+
|
metadata.csv
CHANGED
The diff for this file is too large to render.
See raw diff
|
|