Datasets:
Tasks:
Image-to-Image
Languages:
English
Size:
1M<n<10M
Tags:
image-restoration
super-resolution
image-denoising
image-deblurring
low-light-enhancement
dehazing
License:
Update dataset.py
Browse files- dataset.py +26 -14
dataset.py
CHANGED
|
@@ -1,17 +1,18 @@
|
|
| 1 |
import os
|
|
|
|
| 2 |
from datasets import DatasetInfo, GeneratorBasedBuilder, Features, Image, ClassLabel, Split
|
| 3 |
from huggingface_hub import hf_hub_download
|
| 4 |
|
| 5 |
class UIR25MReference(GeneratorBasedBuilder):
|
| 6 |
-
"""UIR-2.5M Reference Dataset Loader"""
|
| 7 |
|
| 8 |
VERSION = "1.0.0"
|
| 9 |
|
| 10 |
-
# Directory
|
| 11 |
PRETRAINED_DIR = os.path.expanduser("./pretrained_models")
|
| 12 |
os.makedirs(PRETRAINED_DIR, exist_ok=True)
|
| 13 |
|
| 14 |
-
#
|
| 15 |
PRETRAINED_MODELS = [
|
| 16 |
"nafnet_maskdcpt_12d.pth",
|
| 17 |
"nafnet_maskdcpt_5d.pth",
|
|
@@ -20,7 +21,6 @@ class UIR25MReference(GeneratorBasedBuilder):
|
|
| 20 |
"restormer_maskdcpt_5d.pth",
|
| 21 |
"swinir_maskdcpt_5d.pth"
|
| 22 |
]
|
| 23 |
-
|
| 24 |
PRETRAINED_REPO = "Jiakui/MaskDCPT"
|
| 25 |
|
| 26 |
def download_pretrained_models(self):
|
|
@@ -63,8 +63,8 @@ class UIR25MReference(GeneratorBasedBuilder):
|
|
| 63 |
|
| 64 |
def _split_generators(self, dl_manager):
|
| 65 |
"""
|
| 66 |
-
|
| 67 |
-
Expects directories named
|
| 68 |
"""
|
| 69 |
data_dir = dl_manager.download_and_extract("https://github.com/MILab-PKU/MaskDCPT.git")
|
| 70 |
splits = []
|
|
@@ -80,18 +80,30 @@ class UIR25MReference(GeneratorBasedBuilder):
|
|
| 80 |
return splits
|
| 81 |
|
| 82 |
def _generate_examples(self, images_dir):
|
| 83 |
-
"""Yield examples
|
| 84 |
low_dir = os.path.join(images_dir, "low_quality")
|
| 85 |
high_dir = os.path.join(images_dir, "high_quality")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
|
|
|
|
|
|
|
|
|
| 93 |
yield idx, {
|
| 94 |
"low_quality": low_path,
|
| 95 |
"high_quality": high_path,
|
| 96 |
"degradation_type": degradation_type
|
| 97 |
-
}
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
+
import json
|
| 3 |
from datasets import DatasetInfo, GeneratorBasedBuilder, Features, Image, ClassLabel, Split
|
| 4 |
from huggingface_hub import hf_hub_download
|
| 5 |
|
| 6 |
class UIR25MReference(GeneratorBasedBuilder):
|
| 7 |
+
"""UIR-2.5M Reference Dataset Loader with metadata mapping"""
|
| 8 |
|
| 9 |
VERSION = "1.0.0"
|
| 10 |
|
| 11 |
+
# Directory for pretrained models
|
| 12 |
PRETRAINED_DIR = os.path.expanduser("./pretrained_models")
|
| 13 |
os.makedirs(PRETRAINED_DIR, exist_ok=True)
|
| 14 |
|
| 15 |
+
# Pretrained models info
|
| 16 |
PRETRAINED_MODELS = [
|
| 17 |
"nafnet_maskdcpt_12d.pth",
|
| 18 |
"nafnet_maskdcpt_5d.pth",
|
|
|
|
| 21 |
"restormer_maskdcpt_5d.pth",
|
| 22 |
"swinir_maskdcpt_5d.pth"
|
| 23 |
]
|
|
|
|
| 24 |
PRETRAINED_REPO = "Jiakui/MaskDCPT"
|
| 25 |
|
| 26 |
def download_pretrained_models(self):
|
|
|
|
| 63 |
|
| 64 |
def _split_generators(self, dl_manager):
|
| 65 |
"""
|
| 66 |
+
Automatic split detection:
|
| 67 |
+
Expects directories named train/test/validation
|
| 68 |
"""
|
| 69 |
data_dir = dl_manager.download_and_extract("https://github.com/MILab-PKU/MaskDCPT.git")
|
| 70 |
splits = []
|
|
|
|
| 80 |
return splits
|
| 81 |
|
| 82 |
def _generate_examples(self, images_dir):
|
| 83 |
+
"""Yield examples using metadata JSON mapping"""
|
| 84 |
low_dir = os.path.join(images_dir, "low_quality")
|
| 85 |
high_dir = os.path.join(images_dir, "high_quality")
|
| 86 |
+
metadata_file = os.path.join(images_dir, "metadata.json")
|
| 87 |
+
|
| 88 |
+
if not os.path.exists(metadata_file):
|
| 89 |
+
raise FileNotFoundError(f"Metadata file not found: {metadata_file}")
|
| 90 |
+
|
| 91 |
+
with open(metadata_file, "r") as f:
|
| 92 |
+
metadata = json.load(f)
|
| 93 |
|
| 94 |
+
for idx, sample in enumerate(metadata):
|
| 95 |
+
low_fname = sample["low_quality"]
|
| 96 |
+
high_fname = sample["high_quality"]
|
| 97 |
+
degradation_type = sample["degradation_type"]
|
| 98 |
+
|
| 99 |
+
low_path = os.path.join(low_dir, low_fname)
|
| 100 |
+
high_path = os.path.join(high_dir, high_fname)
|
| 101 |
+
|
| 102 |
+
if os.path.exists(low_path) and os.path.exists(high_path):
|
| 103 |
yield idx, {
|
| 104 |
"low_quality": low_path,
|
| 105 |
"high_quality": high_path,
|
| 106 |
"degradation_type": degradation_type
|
| 107 |
+
}
|
| 108 |
+
else:
|
| 109 |
+
print(f"Skipping missing files: {low_fname} or {high_fname}")
|