Upload Corrosion.py
Browse files- Corrosion.py +67 -0
Corrosion.py
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import copy
|
| 2 |
+
import json
|
| 3 |
+
import os
|
| 4 |
+
import pandas as pd
|
| 5 |
+
from glob import glob
|
| 6 |
+
import datasets
|
| 7 |
+
from datasets import load_dataset
|
| 8 |
+
|
| 9 |
+
_CITATION = """\
|
| 10 |
+
|
| 11 |
+
"""
|
| 12 |
+
_DESCRIPTION = """\
|
| 13 |
+
|
| 14 |
+
"""
|
| 15 |
+
|
| 16 |
+
_SPLITS = ["train", "test"]
|
| 17 |
+
|
| 18 |
+
#Your zip url
|
| 19 |
+
_URL = "https://huggingface.co/datasets/Dodon/Corrosion/blob/main/original-20231018T064149Z-001.zip"
|
| 20 |
+
|
| 21 |
+
class CorrisonData(datasets.GeneratorBasedBuilder):
|
| 22 |
+
|
| 23 |
+
def _info(self):
|
| 24 |
+
features = datasets.Features(
|
| 25 |
+
{
|
| 26 |
+
"imgname": datasets.Value("string"),
|
| 27 |
+
"image": datasets.Image(),
|
| 28 |
+
"label": datasets.Value("int64")
|
| 29 |
+
}
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
return datasets.DatasetInfo(
|
| 33 |
+
description=_DESCRIPTION,
|
| 34 |
+
features=features,
|
| 35 |
+
supervised_keys=None,
|
| 36 |
+
license=_LICENSE,
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
def _split_generators(self, dl_manager):
|
| 40 |
+
downloaded_file = dl_manager.download_and_extract(_URL) + "/original"
|
| 41 |
+
|
| 42 |
+
return [
|
| 43 |
+
datasets.SplitGenerator(
|
| 44 |
+
name=datasets.Split.TRAIN,
|
| 45 |
+
gen_kwargs={
|
| 46 |
+
"label_path": downloaded_file + "/Train/json",
|
| 47 |
+
"images_path": downloaded_file + "/Train/images",
|
| 48 |
+
},
|
| 49 |
+
),
|
| 50 |
+
datasets.SplitGenerator(
|
| 51 |
+
name=datasets.Split.TEST,
|
| 52 |
+
gen_kwargs={
|
| 53 |
+
"label_path": downloaded_file + "/Test/json",
|
| 54 |
+
"images_path": downloaded_file + "/Test/images",
|
| 55 |
+
},
|
| 56 |
+
),
|
| 57 |
+
]
|
| 58 |
+
|
| 59 |
+
def _generate_examples(self, label_path:str, images_path: str):
|
| 60 |
+
idx = 0
|
| 61 |
+
for json_path in glob(os.path.join(label_path, '/*.json')):
|
| 62 |
+
fname = os.path.basename(json_path).split('.')[0]
|
| 63 |
+
|
| 64 |
+
with open(json_path) as f:
|
| 65 |
+
data = json.load(f)
|
| 66 |
+
|
| 67 |
+
yield {"imgname": fname, "image": s.path.join(images_path,fname+'.jpeg'), "label": np.max([int(a['label'][:1]) for a in data['shapes']])}
|