Create mini_car_bikes_detection.py
Browse files- mini_car_bikes_detection.py +70 -0
mini_car_bikes_detection.py
ADDED
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from PIL import Image
|
2 |
+
import numpy as np
|
3 |
+
|
4 |
+
import json
|
5 |
+
import os
|
6 |
+
|
7 |
+
import datasets
|
8 |
+
|
9 |
+
|
10 |
+
_DESCRIPTION = """
|
11 |
+
"""
|
12 |
+
|
13 |
+
_HOMEPAGE = ""
|
14 |
+
|
15 |
+
_LICENSE = ""
|
16 |
+
|
17 |
+
_URL = "https://huggingface.co/datasets/alexrods/mini_car_bikes_detection/resolve/main"
|
18 |
+
|
19 |
+
_URLS = {
|
20 |
+
"train_images": f"{_URL}/data/train.zip",
|
21 |
+
"test_images": f"{_URL}/data/test.zip",
|
22 |
+
}
|
23 |
+
|
24 |
+
_CATEGORIES = ['Car', 'bike']
|
25 |
+
|
26 |
+
|
27 |
+
class MiniCarBikesDetection(datasets.GeneratorBasedBuilder):
|
28 |
+
|
29 |
+
VERSION = datasets.Version("1.0.0")
|
30 |
+
|
31 |
+
def _info(self):
|
32 |
+
features = datasets.Features(
|
33 |
+
{
|
34 |
+
"image": datasets.Image(),
|
35 |
+
"image_name": datasets.Value("string"),
|
36 |
+
}
|
37 |
+
)
|
38 |
+
|
39 |
+
return datasets.DatasetInfo(
|
40 |
+
description=_DESCRIPTION,
|
41 |
+
features=features,
|
42 |
+
homepage=_HOMEPAGE,
|
43 |
+
license=_LICENSE,
|
44 |
+
)
|
45 |
+
|
46 |
+
|
47 |
+
def _split_generators(self, dl_manager):
|
48 |
+
data_files = dl_manager.download(_URLS)
|
49 |
+
return [
|
50 |
+
datasets.SplitGenerator(
|
51 |
+
name=datasets.Split.TRAIN,
|
52 |
+
gen_kwargs={
|
53 |
+
"image_files": dl_manager.iter_archive(data_files["train_images"]),
|
54 |
+
"split": "train"
|
55 |
+
},
|
56 |
+
),
|
57 |
+
datasets.SplitGenerator(
|
58 |
+
name=datasets.Split.TEST,
|
59 |
+
gen_kwargs={
|
60 |
+
"image_files": dl_manager.iter_archive(data_files["test_images"]),
|
61 |
+
"split": "test"
|
62 |
+
},
|
63 |
+
),
|
64 |
+
]
|
65 |
+
|
66 |
+
def _generate_examples(self, image_files, split):
|
67 |
+
for image_file in image_files:
|
68 |
+
yield np.array(Image.open(image_file[1])), image_file[0].split("/")[1]
|
69 |
+
|
70 |
+
|