vkashko commited on
Commit
4e80975
·
1 Parent(s): cffd940

feat: add load script

Browse files
Files changed (1) hide show
  1. wagons-images-classification.py +76 -0
wagons-images-classification.py ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from xml.etree import ElementTree as ET
2
+
3
+ import datasets
4
+
5
+ _CITATION = """\
6
+ @InProceedings{huggingface:dataset,
7
+ title = {wagons-images-classification},
8
+ author = {TrainingDataPro},
9
+ year = {2023}
10
+ }
11
+ """
12
+
13
+ _DESCRIPTION = """\
14
+ The dataset consists of images depicting **loaded and unloaded** wagons.
15
+ The data are organasied in two folders for loaded and unloaded wagons and assisted with
16
+ .CSV file containing text classification of the images.
17
+ This dataset can be useful for various tasks, such as *image classification, object
18
+ detection and data-driven analyses related to wagon loading and unloading processes.
19
+ The dataset is useful for **rail transport sphere**, it can be utilised for automation
20
+ the identification and classification of the wagons and further optimization of the
21
+ processes in the industry.
22
+ """
23
+
24
+ _NAME = "wagons-images-classification"
25
+
26
+ _HOMEPAGE = f"https://huggingface.co/datasets/TrainingDataPro/{_NAME}"
27
+
28
+ _LICENSE = ""
29
+
30
+ _DATA = f"https://huggingface.co/datasets/TrainingDataPro/{_NAME}/resolve/main/data/"
31
+
32
+ _LABELS = ["loaded", "unloaded"]
33
+
34
+
35
+ class MinersDetection(datasets.GeneratorBasedBuilder):
36
+ def _info(self):
37
+ return datasets.DatasetInfo(
38
+ description=_DESCRIPTION,
39
+ features=datasets.Features(
40
+ {
41
+ "id": datasets.Value("int32"),
42
+ "name": datasets.Value("string"),
43
+ "image": datasets.Image(),
44
+ "label": datasets.ClassLabel(
45
+ num_classes=len(_LABELS),
46
+ names=_LABELS,
47
+ ),
48
+ }
49
+ ),
50
+ supervised_keys=None,
51
+ homepage=_HOMEPAGE,
52
+ citation=_CITATION,
53
+ )
54
+
55
+ def _split_generators(self, dl_manager):
56
+ images = dl_manager.download(f"{_DATA}images.tar.gz")
57
+ images = dl_manager.iter_archive(images)
58
+ return [
59
+ datasets.SplitGenerator(
60
+ name=datasets.Split.TRAIN,
61
+ gen_kwargs={
62
+ "images": images,
63
+ },
64
+ ),
65
+ ]
66
+
67
+ def _generate_examples(self, images):
68
+ for idx, ((image_path, image)) in enumerate(images):
69
+ label = "unloaded" if "unloaded" in image_path else "loaded"
70
+
71
+ yield idx, {
72
+ "id": idx,
73
+ "name": image_path,
74
+ "image": {"path": image_path, "bytes": image.read()},
75
+ "label": label,
76
+ }