Commit
·
dc25053
1
Parent(s):
b641d79
Create miap.py
Browse files
miap.py
ADDED
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
# Copyright 2022 the HuggingFace Datasets Authors.
|
3 |
+
#
|
4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5 |
+
# you may not use this file except in compliance with the License.
|
6 |
+
# You may obtain a copy of the License at
|
7 |
+
#
|
8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9 |
+
#
|
10 |
+
# Unless required by applicable law or agreed to in writing, software
|
11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 |
+
# See the License for the specific language governing permissions and
|
14 |
+
# limitations under the License.
|
15 |
+
|
16 |
+
import os
|
17 |
+
import pandas as pd
|
18 |
+
import datasets
|
19 |
+
import json
|
20 |
+
from huggingface_hub import hf_hub_url
|
21 |
+
|
22 |
+
_INPUT_CSV = "open_images_extended_miap_boxes_test_labeled.csv"
|
23 |
+
_INPUT_IMAGES = "images_miap"
|
24 |
+
_REPO_ID = "nlphuji/open_images_dataset_v7"
|
25 |
+
_IMAGE_EXTENSION = 'jpg'
|
26 |
+
|
27 |
+
class Dataset(datasets.GeneratorBasedBuilder):
|
28 |
+
VERSION = datasets.Version("1.1.0")
|
29 |
+
BUILDER_CONFIGS = [
|
30 |
+
datasets.BuilderConfig(name="TEST", version=VERSION, description="test"),
|
31 |
+
]
|
32 |
+
|
33 |
+
def _info(self):
|
34 |
+
return datasets.DatasetInfo(
|
35 |
+
features=datasets.Features(
|
36 |
+
{
|
37 |
+
"ImageID": datasets.Value('string'),
|
38 |
+
"LabelName": datasets.Value('string'),
|
39 |
+
"Confidence": datasets.Value('float32'),
|
40 |
+
"XMin": datasets.Value('float32'),
|
41 |
+
"XMax": datasets.Value('float32'),
|
42 |
+
"YMin": datasets.Value('float32'),
|
43 |
+
"YMax": datasets.Value('float32'),
|
44 |
+
"IsOccluded": datasets.Value('int64'),
|
45 |
+
"IsTruncated": datasets.Value('int64'),
|
46 |
+
"IsGroupOf": datasets.Value('int64'),
|
47 |
+
"IsDepictionOf": datasets.Value('int64'),
|
48 |
+
"IsInsideOf": datasets.Value('int64'),
|
49 |
+
"GenderPresentation": datasets.Value('string'),
|
50 |
+
"AgePresentation": datasets.Value('string'),
|
51 |
+
"label": datasets.Value('string')
|
52 |
+
}
|
53 |
+
),
|
54 |
+
task_templates=[],
|
55 |
+
)
|
56 |
+
|
57 |
+
def _split_generators(self, dl_manager):
|
58 |
+
"""Returns SplitGenerators."""
|
59 |
+
|
60 |
+
repo_id = _REPO_ID
|
61 |
+
data_dir = dl_manager.download_and_extract({
|
62 |
+
"examples_csv": hf_hub_url(repo_id=repo_id, repo_type='dataset', filename=_INPUT_CSV),
|
63 |
+
"images_dir": hf_hub_url(repo_id=repo_id, repo_type='dataset', filename=f"{_INPUT_IMAGES}.zip")
|
64 |
+
})
|
65 |
+
|
66 |
+
return [datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs=data_dir)]
|
67 |
+
|
68 |
+
|
69 |
+
def _generate_examples(self, examples_csv, images_dir):
|
70 |
+
"""Yields examples."""
|
71 |
+
df = pd.read_csv(examples_csv)
|
72 |
+
|
73 |
+
for r_idx, r in df.iterrows():
|
74 |
+
r_dict = r.to_dict()
|
75 |
+
image_path = os.path.join(images_dir, _INPUT_IMAGES, f"{r_dict['ImageID']}.{_IMAGE_EXTENSION}")
|
76 |
+
r_dict['image'] = image_path
|
77 |
+
yield r_idx, r_dict
|