Upload test_11_07_7.py with huggingface_hub
Browse files- test_11_07_7.py +96 -0
test_11_07_7.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import datasets
|
| 3 |
+
import urllib.request
|
| 4 |
+
import csv
|
| 5 |
+
|
| 6 |
+
_CITATION = """\
|
| 7 |
+
@InProceedings{huggingface:dataset,
|
| 8 |
+
title = {diffusion train set},
|
| 9 |
+
}
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
_DESCRIPTION = """\
|
| 13 |
+
This is a dataset that image data and caption txt
|
| 14 |
+
"""
|
| 15 |
+
_HOMEPAGE = ""
|
| 16 |
+
|
| 17 |
+
_LICENSE = ""
|
| 18 |
+
|
| 19 |
+
_VERSION = "0.0.1"
|
| 20 |
+
|
| 21 |
+
_URL = "data/"
|
| 22 |
+
|
| 23 |
+
_URLS = {
|
| 24 |
+
"train": _URL + 'train_dataset.csv',
|
| 25 |
+
"reg": _URL + 'reg_dataset.csv',
|
| 26 |
+
"test": _URL + 'test_dataset.csv',
|
| 27 |
+
}
|
| 28 |
+
task_list = [
|
| 29 |
+
"train",
|
| 30 |
+
"reg",
|
| 31 |
+
"test",
|
| 32 |
+
]
|
| 33 |
+
|
| 34 |
+
class TaskConfig(datasets.BuilderConfig):
|
| 35 |
+
def __init__(self, **kwargs):
|
| 36 |
+
super().__init__(version=datasets.Version("1.0.0"), **kwargs)
|
| 37 |
+
|
| 38 |
+
class ImgDataset(datasets.GeneratorBasedBuilder):
|
| 39 |
+
BUILDER_CONFIGS = [
|
| 40 |
+
TaskConfig(
|
| 41 |
+
name=task_name,
|
| 42 |
+
)
|
| 43 |
+
for task_name in task_list
|
| 44 |
+
]
|
| 45 |
+
|
| 46 |
+
def _info(self):
|
| 47 |
+
features = datasets.Features(
|
| 48 |
+
{
|
| 49 |
+
"folder_name" : datasets.Value("string"),
|
| 50 |
+
"Class_name": datasets.Value("string"),
|
| 51 |
+
"file_name": datasets.Value("string"),
|
| 52 |
+
"file_id": datasets.Value("string")
|
| 53 |
+
|
| 54 |
+
}
|
| 55 |
+
)
|
| 56 |
+
return datasets.DatasetInfo(
|
| 57 |
+
description=_DESCRIPTION,
|
| 58 |
+
features=features,
|
| 59 |
+
supervised_keys=None,
|
| 60 |
+
version=_VERSION,
|
| 61 |
+
citation=_CITATION,
|
| 62 |
+
)
|
| 63 |
+
|
| 64 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager):
|
| 65 |
+
URL = {self.config.name: _URLS[self.config.name]}
|
| 66 |
+
|
| 67 |
+
downloaded_files = dl_manager.download_and_extract(_URLS)
|
| 68 |
+
task_name = self.config.name
|
| 69 |
+
|
| 70 |
+
return [
|
| 71 |
+
datasets.SplitGenerator(datasets.Split.TRAIN, {
|
| 72 |
+
"filepath": downloaded_files[task_name]
|
| 73 |
+
}),
|
| 74 |
+
]
|
| 75 |
+
def _generate_examples(self, filepath):
|
| 76 |
+
"""This function returns the examples in the raw (text) form."""
|
| 77 |
+
with open(filepath, encoding="utf-8") as f:
|
| 78 |
+
data = csv.DictReader(f)
|
| 79 |
+
key = 0
|
| 80 |
+
for row in data:
|
| 81 |
+
yield key, {
|
| 82 |
+
"folder_name" : row['folder_name'],
|
| 83 |
+
"Class_name": row['Class_name'],
|
| 84 |
+
"file_name": row['file_name'],
|
| 85 |
+
"file_id": row['file_id']
|
| 86 |
+
}
|
| 87 |
+
folder_name = row['folder_name']
|
| 88 |
+
class_name =row['Class_name']
|
| 89 |
+
file_name = row['file_name']
|
| 90 |
+
url =row['file_id']
|
| 91 |
+
path = os.path.join('./',folder_name,class_name,file_name)
|
| 92 |
+
folder = os.path.join('./',folder_name,class_name)
|
| 93 |
+
if not os.path.isdir(folder):
|
| 94 |
+
os.makedirs(folder)
|
| 95 |
+
urllib.request.urlretrieve(url, path)
|
| 96 |
+
key += 1
|