Datasets:
ebowwa
commited on
Commit
·
1ec6854
1
Parent(s):
c4150ab
Add COCO dataset loading script for proper HuggingFace viewer support
Browse files- dataset_infos.json +44 -0
- usd_side_coco_annotations.py +129 -0
dataset_infos.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"default": {
|
| 3 |
+
"description": "USD Side Detection Dataset - COCO format object detection annotations for US Dollar currency with Front/Back classification",
|
| 4 |
+
"citation": "",
|
| 5 |
+
"homepage": "https://huggingface.co/datasets/ebowwa/usd-side-coco-annotations",
|
| 6 |
+
"license": "MIT",
|
| 7 |
+
"features": {
|
| 8 |
+
"image_id": {"dtype": "int32", "_type": "Value"},
|
| 9 |
+
"image": {"_type": "Image"},
|
| 10 |
+
"width": {"dtype": "int32", "_type": "Value"},
|
| 11 |
+
"height": {"dtype": "int32", "_type": "Value"},
|
| 12 |
+
"objects": {
|
| 13 |
+
"feature": {
|
| 14 |
+
"id": {"dtype": "int64", "_type": "Value"},
|
| 15 |
+
"area": {"dtype": "float64", "_type": "Value"},
|
| 16 |
+
"bbox": {"feature": {"dtype": "float64", "_type": "Value"}, "_type": "Sequence"},
|
| 17 |
+
"category": {"names": [
|
| 18 |
+
"USD-Dollar-cash-counting--c-TiEZ",
|
| 19 |
+
"100USD-Back", "100USD-Front",
|
| 20 |
+
"10USD", "10USD-Back", "10USD-Front",
|
| 21 |
+
"1USD", "1USD-Back", "1USD-Front",
|
| 22 |
+
"20USD-Back", "20USD-Front",
|
| 23 |
+
"50USD-Back", "50USD-Front",
|
| 24 |
+
"5USD-Back", "5USD-Front",
|
| 25 |
+
"Counterfeit 100 USD Back", "Counterfeit 100 USD Front",
|
| 26 |
+
"Counterfeit 10USD", "Counterfeit 10USD Front", "Counterfeit 10USD Back",
|
| 27 |
+
"Counterfeit 1USD Front", "Counterfeit 1USD Back",
|
| 28 |
+
"Counterfeit 20USD Front", "Counterfeit 20USD Back",
|
| 29 |
+
"Counterfeit 50USD", "Counterfeit 50USD Front", "Counterfeit 50USD Back",
|
| 30 |
+
"Counterfeit 5USD", "Counterfeit 5USD Front", "Counterfeit 5USD Back"
|
| 31 |
+
], "_type": "ClassLabel"}
|
| 32 |
+
},
|
| 33 |
+
"_type": "Sequence"
|
| 34 |
+
}
|
| 35 |
+
},
|
| 36 |
+
"splits": {
|
| 37 |
+
"train": {"name": "train", "num_bytes": 2800000000, "num_examples": 2671},
|
| 38 |
+
"validation": {"name": "validation", "num_bytes": 600000000, "num_examples": 597},
|
| 39 |
+
"test": {"name": "test", "num_bytes": 350000000, "num_examples": 350}
|
| 40 |
+
},
|
| 41 |
+
"download_size": 3750000000,
|
| 42 |
+
"dataset_size": 3750000000
|
| 43 |
+
}
|
| 44 |
+
}
|
usd_side_coco_annotations.py
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""USD Side Detection Dataset - COCO format object detection."""
|
| 2 |
+
|
| 3 |
+
import json
|
| 4 |
+
import os
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
import datasets
|
| 8 |
+
from datasets import DatasetBuilder, DownloadManager, SplitGenerator
|
| 9 |
+
from datasets.features import ClassLabel, Features, Image, Sequence, Value
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
_DESCRIPTION = """
|
| 13 |
+
USD Side Detection Dataset with Front/Back classification.
|
| 14 |
+
|
| 15 |
+
A COCO-format dataset for detecting US Dollar currency and classifying
|
| 16 |
+
whether the front or back side is visible.
|
| 17 |
+
|
| 18 |
+
- 3,618 images (all with annotations)
|
| 19 |
+
- 3,746 annotations
|
| 20 |
+
- 24 classes (12 regular + 12 counterfeit USD)
|
| 21 |
+
- 100% Front/Back classified
|
| 22 |
+
"""
|
| 23 |
+
|
| 24 |
+
_HOMEPAGE = "https://huggingface.co/datasets/ebowwa/usd-side-coco-annotations"
|
| 25 |
+
|
| 26 |
+
_LICENSE = "MIT"
|
| 27 |
+
|
| 28 |
+
_CATEGORIES = [
|
| 29 |
+
"100USD-Back", "100USD-Front",
|
| 30 |
+
"10USD-Back", "10USD-Front",
|
| 31 |
+
"1USD-Back", "1USD-Front",
|
| 32 |
+
"20USD-Back", "20USD-Front",
|
| 33 |
+
"50USD-Back", "50USD-Front",
|
| 34 |
+
"5USD-Back", "5USD-Front",
|
| 35 |
+
"Counterfeit 100 USD Back", "Counterfeit 100 USD Front",
|
| 36 |
+
"Counterfeit 10USD Back", "Counterfeit 10USD Front",
|
| 37 |
+
"Counterfeit 1USD Back", "Counterfeit 1USD Front",
|
| 38 |
+
"Counterfeit 20USD Back", "Counterfeit 20USD Front",
|
| 39 |
+
"Counterfeit 50USD Back", "Counterfeit 50USD Front",
|
| 40 |
+
"Counterfeit 5USD Back", "Counterfeit 5USD Front",
|
| 41 |
+
]
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
class UsdSideCocoAnnotations(DatasetBuilder):
|
| 45 |
+
"""USD Side Detection Dataset."""
|
| 46 |
+
|
| 47 |
+
VERSION = datasets.Version("1.0.0")
|
| 48 |
+
|
| 49 |
+
def _info(self):
|
| 50 |
+
return datasets.DatasetInfo(
|
| 51 |
+
description=_DESCRIPTION,
|
| 52 |
+
features=Features({
|
| 53 |
+
"image_id": Value("int32"),
|
| 54 |
+
"image": Image(),
|
| 55 |
+
"width": Value("int32"),
|
| 56 |
+
"height": Value("int32"),
|
| 57 |
+
"objects": Sequence({
|
| 58 |
+
"id": Value("int64"),
|
| 59 |
+
"area": Value("float64"),
|
| 60 |
+
"bbox": Sequence(Value("float64"), length=4),
|
| 61 |
+
"category": ClassLabel(names=_CATEGORIES),
|
| 62 |
+
}),
|
| 63 |
+
}),
|
| 64 |
+
homepage=_HOMEPAGE,
|
| 65 |
+
license=_LICENSE,
|
| 66 |
+
)
|
| 67 |
+
|
| 68 |
+
def _split_generators(self, dl_manager: DownloadManager):
|
| 69 |
+
data_dir = dl_manager.download_and_extract(
|
| 70 |
+
"https://huggingface.co/datasets/ebowwa/usd-side-coco-annotations/resolve/main/"
|
| 71 |
+
) if dl_manager else Path(".")
|
| 72 |
+
|
| 73 |
+
return [
|
| 74 |
+
SplitGenerator(
|
| 75 |
+
name=datasets.Split.TRAIN,
|
| 76 |
+
gen_kwargs={"split_dir": os.path.join(data_dir, "train")},
|
| 77 |
+
),
|
| 78 |
+
SplitGenerator(
|
| 79 |
+
name=datasets.Split.VALIDATION,
|
| 80 |
+
gen_kwargs={"split_dir": os.path.join(data_dir, "valid")},
|
| 81 |
+
),
|
| 82 |
+
SplitGenerator(
|
| 83 |
+
name=datasets.Split.TEST,
|
| 84 |
+
gen_kwargs={"split_dir": os.path.join(data_dir, "test")},
|
| 85 |
+
),
|
| 86 |
+
]
|
| 87 |
+
|
| 88 |
+
def _generate_examples(self, split_dir):
|
| 89 |
+
ann_file = os.path.join(split_dir, "_annotations.coco.json")
|
| 90 |
+
|
| 91 |
+
with open(ann_file) as f:
|
| 92 |
+
coco = json.load(f)
|
| 93 |
+
|
| 94 |
+
# Build category mapping
|
| 95 |
+
cat_id_to_name = {c["id"]: c["name"] for c in coco["categories"]}
|
| 96 |
+
cat_name_to_idx = {name: idx for idx, name in enumerate(_CATEGORIES)}
|
| 97 |
+
|
| 98 |
+
# Group annotations by image_id
|
| 99 |
+
img_to_anns = {}
|
| 100 |
+
for ann in coco["annotations"]:
|
| 101 |
+
img_id = ann["image_id"]
|
| 102 |
+
if img_id not in img_to_anns:
|
| 103 |
+
img_to_anns[img_id] = []
|
| 104 |
+
img_to_anns[img_id].append(ann)
|
| 105 |
+
|
| 106 |
+
# Generate examples
|
| 107 |
+
for img in coco["images"]:
|
| 108 |
+
img_id = img["id"]
|
| 109 |
+
img_path = os.path.join(split_dir, img["file_name"])
|
| 110 |
+
|
| 111 |
+
anns = img_to_anns.get(img_id, [])
|
| 112 |
+
objects = []
|
| 113 |
+
for ann in anns:
|
| 114 |
+
cat_name = cat_id_to_name.get(ann["category_id"])
|
| 115 |
+
if cat_name in cat_name_to_idx:
|
| 116 |
+
objects.append({
|
| 117 |
+
"id": ann["id"],
|
| 118 |
+
"area": ann["area"],
|
| 119 |
+
"bbox": ann["bbox"],
|
| 120 |
+
"category": cat_name_to_idx[cat_name],
|
| 121 |
+
})
|
| 122 |
+
|
| 123 |
+
yield img_id, {
|
| 124 |
+
"image_id": img_id,
|
| 125 |
+
"image": img_path,
|
| 126 |
+
"width": img["width"],
|
| 127 |
+
"height": img["height"],
|
| 128 |
+
"objects": objects,
|
| 129 |
+
}
|