[update]add dataset.tar.gz to speed up download
Browse files- cppe-5.py +64 -47
- cppe_5_backup.py +118 -0
- data/dataset.tar.gz +0 -0
cppe-5.py
CHANGED
|
@@ -1,20 +1,26 @@
|
|
| 1 |
-
|
| 2 |
-
#
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
import json
|
| 5 |
import os
|
| 6 |
-
from pathlib import Path
|
| 7 |
|
| 8 |
import datasets
|
| 9 |
-
from PIL import Image
|
| 10 |
|
| 11 |
-
# _URL = "https://drive.google.com/uc?id=1MGnaAfbckUmigGUvihz7uiHGC6rBIbvr"
|
| 12 |
-
|
| 13 |
-
_HOMEPAGE = "https://sites.google.com/view/cppe5"
|
| 14 |
-
|
| 15 |
-
_LICENSE = "Unknown"
|
| 16 |
-
|
| 17 |
-
_CATEGORIES = ["Coverall", "Face_Shield", "Gloves", "Goggles", "Mask"]
|
| 18 |
|
| 19 |
_CITATION = """\
|
| 20 |
@misc{dagli2021cppe5,
|
|
@@ -33,6 +39,15 @@ to allow the study of subordinate categorization of medical personal protective
|
|
| 33 |
which is not possible with other popular data sets that focus on broad level categories.
|
| 34 |
"""
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
class CPPE5(datasets.GeneratorBasedBuilder):
|
| 38 |
"""CPPE - 5 dataset."""
|
|
@@ -47,12 +62,12 @@ class CPPE5(datasets.GeneratorBasedBuilder):
|
|
| 47 |
"width": datasets.Value("int32"),
|
| 48 |
"height": datasets.Value("int32"),
|
| 49 |
"objects": datasets.Sequence(
|
| 50 |
-
|
| 51 |
"id": datasets.Value("int64"),
|
| 52 |
"area": datasets.Value("int64"),
|
| 53 |
"bbox": datasets.Sequence(datasets.Value("float32"), length=4),
|
| 54 |
"category": datasets.ClassLabel(names=_CATEGORIES),
|
| 55 |
-
}
|
| 56 |
),
|
| 57 |
}
|
| 58 |
)
|
|
@@ -65,54 +80,56 @@ class CPPE5(datasets.GeneratorBasedBuilder):
|
|
| 65 |
)
|
| 66 |
|
| 67 |
def _split_generators(self, dl_manager):
|
| 68 |
-
|
| 69 |
-
train_json = dl_manager.download("data/annotations/train.jsonl")
|
| 70 |
-
test_json = dl_manager.download("data/annotations/test.jsonl")
|
| 71 |
-
|
| 72 |
return [
|
| 73 |
datasets.SplitGenerator(
|
| 74 |
name=datasets.Split.TRAIN,
|
| 75 |
gen_kwargs={
|
| 76 |
-
"
|
| 77 |
-
"
|
| 78 |
},
|
| 79 |
),
|
| 80 |
datasets.SplitGenerator(
|
| 81 |
name=datasets.Split.TEST,
|
| 82 |
gen_kwargs={
|
| 83 |
-
"
|
| 84 |
-
"
|
| 85 |
},
|
| 86 |
),
|
| 87 |
]
|
| 88 |
|
| 89 |
-
def _generate_examples(self,
|
| 90 |
-
|
| 91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
|
|
|
| 93 |
idx = 0
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
yield idx, {
|
| 107 |
-
"image_id":
|
| 108 |
-
"image": {"path":
|
| 109 |
-
|
| 110 |
-
"
|
| 111 |
-
"
|
| 112 |
-
"objects": sample["objects"],
|
| 113 |
}
|
| 114 |
idx += 1
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
if __name__ == '__main__':
|
| 118 |
-
pass
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
# Copyright 2021 The HuggingFace Datasets Authors and the current dataset script contributor.
|
| 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 |
+
"""CPPE-5 dataset."""
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
import collections
|
| 19 |
import json
|
| 20 |
import os
|
|
|
|
| 21 |
|
| 22 |
import datasets
|
|
|
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
_CITATION = """\
|
| 26 |
@misc{dagli2021cppe5,
|
|
|
|
| 39 |
which is not possible with other popular data sets that focus on broad level categories.
|
| 40 |
"""
|
| 41 |
|
| 42 |
+
_HOMEPAGE = "https://sites.google.com/view/cppe5"
|
| 43 |
+
|
| 44 |
+
_LICENSE = "Unknown"
|
| 45 |
+
|
| 46 |
+
# _URL = "https://drive.google.com/uc?id=1MGnaAfbckUmigGUvihz7uiHGC6rBIbvr"
|
| 47 |
+
_URL = "data/dataset.tar.gz"
|
| 48 |
+
|
| 49 |
+
_CATEGORIES = ["Coverall", "Face_Shield", "Gloves", "Goggles", "Mask"]
|
| 50 |
+
|
| 51 |
|
| 52 |
class CPPE5(datasets.GeneratorBasedBuilder):
|
| 53 |
"""CPPE - 5 dataset."""
|
|
|
|
| 62 |
"width": datasets.Value("int32"),
|
| 63 |
"height": datasets.Value("int32"),
|
| 64 |
"objects": datasets.Sequence(
|
| 65 |
+
{
|
| 66 |
"id": datasets.Value("int64"),
|
| 67 |
"area": datasets.Value("int64"),
|
| 68 |
"bbox": datasets.Sequence(datasets.Value("float32"), length=4),
|
| 69 |
"category": datasets.ClassLabel(names=_CATEGORIES),
|
| 70 |
+
}
|
| 71 |
),
|
| 72 |
}
|
| 73 |
)
|
|
|
|
| 80 |
)
|
| 81 |
|
| 82 |
def _split_generators(self, dl_manager):
|
| 83 |
+
archive = dl_manager.download(_URL)
|
|
|
|
|
|
|
|
|
|
| 84 |
return [
|
| 85 |
datasets.SplitGenerator(
|
| 86 |
name=datasets.Split.TRAIN,
|
| 87 |
gen_kwargs={
|
| 88 |
+
"annotation_file_path": "annotations/train.json",
|
| 89 |
+
"files": dl_manager.iter_archive(archive),
|
| 90 |
},
|
| 91 |
),
|
| 92 |
datasets.SplitGenerator(
|
| 93 |
name=datasets.Split.TEST,
|
| 94 |
gen_kwargs={
|
| 95 |
+
"annotation_file_path": "annotations/test.json",
|
| 96 |
+
"files": dl_manager.iter_archive(archive),
|
| 97 |
},
|
| 98 |
),
|
| 99 |
]
|
| 100 |
|
| 101 |
+
def _generate_examples(self, annotation_file_path, files):
|
| 102 |
+
def process_annot(annot, category_id_to_category):
|
| 103 |
+
return {
|
| 104 |
+
"id": annot["id"],
|
| 105 |
+
"area": annot["area"],
|
| 106 |
+
"bbox": annot["bbox"],
|
| 107 |
+
"category": category_id_to_category[annot["category_id"]],
|
| 108 |
+
}
|
| 109 |
|
| 110 |
+
image_id_to_image = {}
|
| 111 |
idx = 0
|
| 112 |
+
# This loop relies on the ordering of the files in the archive:
|
| 113 |
+
# Annotation files come first, then the images.
|
| 114 |
+
for path, f in files:
|
| 115 |
+
file_name = os.path.basename(path)
|
| 116 |
+
if path == annotation_file_path:
|
| 117 |
+
annotations = json.load(f)
|
| 118 |
+
category_id_to_category = {category["id"]: category["name"] for category in annotations["categories"]}
|
| 119 |
+
image_id_to_annotations = collections.defaultdict(list)
|
| 120 |
+
for annot in annotations["annotations"]:
|
| 121 |
+
image_id_to_annotations[annot["image_id"]].append(annot)
|
| 122 |
+
image_id_to_image = {annot["file_name"]: annot for annot in annotations["images"]}
|
| 123 |
+
elif file_name in image_id_to_image:
|
| 124 |
+
image = image_id_to_image[file_name]
|
| 125 |
+
objects = [
|
| 126 |
+
process_annot(annot, category_id_to_category) for annot in image_id_to_annotations[image["id"]]
|
| 127 |
+
]
|
| 128 |
yield idx, {
|
| 129 |
+
"image_id": image["id"],
|
| 130 |
+
"image": {"path": path, "bytes": f.read()},
|
| 131 |
+
"width": image["width"],
|
| 132 |
+
"height": image["height"],
|
| 133 |
+
"objects": objects,
|
|
|
|
| 134 |
}
|
| 135 |
idx += 1
|
|
|
|
|
|
|
|
|
|
|
|
cppe_5_backup.py
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
from glob import glob
|
| 4 |
+
import json
|
| 5 |
+
import os
|
| 6 |
+
from pathlib import Path
|
| 7 |
+
|
| 8 |
+
import datasets
|
| 9 |
+
from PIL import Image
|
| 10 |
+
|
| 11 |
+
# _URL = "https://drive.google.com/uc?id=1MGnaAfbckUmigGUvihz7uiHGC6rBIbvr"
|
| 12 |
+
|
| 13 |
+
_HOMEPAGE = "https://sites.google.com/view/cppe5"
|
| 14 |
+
|
| 15 |
+
_LICENSE = "Unknown"
|
| 16 |
+
|
| 17 |
+
_CATEGORIES = ["Coverall", "Face_Shield", "Gloves", "Goggles", "Mask"]
|
| 18 |
+
|
| 19 |
+
_CITATION = """\
|
| 20 |
+
@misc{dagli2021cppe5,
|
| 21 |
+
title={CPPE-5: Medical Personal Protective Equipment Dataset},
|
| 22 |
+
author={Rishit Dagli and Ali Mustufa Shaikh},
|
| 23 |
+
year={2021},
|
| 24 |
+
eprint={2112.09569},
|
| 25 |
+
archivePrefix={arXiv},
|
| 26 |
+
primaryClass={cs.CV}
|
| 27 |
+
}
|
| 28 |
+
"""
|
| 29 |
+
|
| 30 |
+
_DESCRIPTION = """\
|
| 31 |
+
CPPE - 5 (Medical Personal Protective Equipment) is a new challenging dataset with the goal
|
| 32 |
+
to allow the study of subordinate categorization of medical personal protective equipments,
|
| 33 |
+
which is not possible with other popular data sets that focus on broad level categories.
|
| 34 |
+
"""
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
class CPPE5(datasets.GeneratorBasedBuilder):
|
| 38 |
+
"""CPPE - 5 dataset."""
|
| 39 |
+
|
| 40 |
+
VERSION = datasets.Version("1.0.0")
|
| 41 |
+
|
| 42 |
+
def _info(self):
|
| 43 |
+
features = datasets.Features(
|
| 44 |
+
{
|
| 45 |
+
"image_id": datasets.Value("int64"),
|
| 46 |
+
"image": datasets.Image(),
|
| 47 |
+
"width": datasets.Value("int32"),
|
| 48 |
+
"height": datasets.Value("int32"),
|
| 49 |
+
"objects": datasets.Sequence(
|
| 50 |
+
feature=datasets.Features({
|
| 51 |
+
"id": datasets.Value("int64"),
|
| 52 |
+
"area": datasets.Value("int64"),
|
| 53 |
+
"bbox": datasets.Sequence(datasets.Value("float32"), length=4),
|
| 54 |
+
"category": datasets.ClassLabel(names=_CATEGORIES),
|
| 55 |
+
})
|
| 56 |
+
),
|
| 57 |
+
}
|
| 58 |
+
)
|
| 59 |
+
return datasets.DatasetInfo(
|
| 60 |
+
description=_DESCRIPTION,
|
| 61 |
+
features=features,
|
| 62 |
+
homepage=_HOMEPAGE,
|
| 63 |
+
license=_LICENSE,
|
| 64 |
+
citation=_CITATION,
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
def _split_generators(self, dl_manager):
|
| 68 |
+
"""Returns SplitGenerators."""
|
| 69 |
+
train_json = dl_manager.download("data/annotations/train.jsonl")
|
| 70 |
+
test_json = dl_manager.download("data/annotations/test.jsonl")
|
| 71 |
+
|
| 72 |
+
return [
|
| 73 |
+
datasets.SplitGenerator(
|
| 74 |
+
name=datasets.Split.TRAIN,
|
| 75 |
+
gen_kwargs={
|
| 76 |
+
"archive_path": train_json,
|
| 77 |
+
"dl_manager": dl_manager,
|
| 78 |
+
},
|
| 79 |
+
),
|
| 80 |
+
datasets.SplitGenerator(
|
| 81 |
+
name=datasets.Split.TEST,
|
| 82 |
+
gen_kwargs={
|
| 83 |
+
"archive_path": test_json,
|
| 84 |
+
"dl_manager": dl_manager,
|
| 85 |
+
},
|
| 86 |
+
),
|
| 87 |
+
]
|
| 88 |
+
|
| 89 |
+
def _generate_examples(self, archive_path, dl_manager):
|
| 90 |
+
"""Yields examples."""
|
| 91 |
+
archive_path = Path(archive_path)
|
| 92 |
+
|
| 93 |
+
idx = 0
|
| 94 |
+
|
| 95 |
+
with open(archive_path, "r", encoding="utf-8") as f:
|
| 96 |
+
for row in f:
|
| 97 |
+
sample = json.loads(row)
|
| 98 |
+
|
| 99 |
+
file_path = sample["image"]
|
| 100 |
+
file_path = dl_manager.download(file_path)
|
| 101 |
+
|
| 102 |
+
with open(file_path, "rb") as image_f:
|
| 103 |
+
image_bytes = image_f.read()
|
| 104 |
+
# image = Image.open(image_f)
|
| 105 |
+
|
| 106 |
+
yield idx, {
|
| 107 |
+
"image_id": sample["image_id"],
|
| 108 |
+
"image": {"path": file_path, "bytes": image_bytes},
|
| 109 |
+
# "image": image,
|
| 110 |
+
"width": sample["width"],
|
| 111 |
+
"height": sample["height"],
|
| 112 |
+
"objects": sample["objects"],
|
| 113 |
+
}
|
| 114 |
+
idx += 1
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
if __name__ == '__main__':
|
| 118 |
+
pass
|
data/dataset.tar.gz
ADDED
|
File without changes
|