| import os |
| import json |
| import argparse |
|
|
|
|
| def main(): |
| parser = argparse.ArgumentParser( |
| description="Generate metadata.jsonl for DayRainDrop dataset" |
| ) |
| parser.add_argument( |
| "--root_dir", default="DayRainDrop_Train", help="Root directory of the dataset" |
| ) |
| parser.add_argument( |
| "--blur_dir_name", default="Blur", help="Name of the blur directory" |
| ) |
| parser.add_argument( |
| "--clear_dir_name", default="Clear", help="Name of the clear directory" |
| ) |
| parser.add_argument( |
| "--drop_dir_name", default="Drop", help="Name of the drop directory" |
| ) |
| parser.add_argument( |
| "--output_path", |
| default="output/metadata.jsonl", |
| help="Output path for metadata.jsonl", |
| ) |
|
|
| args = parser.parse_args() |
|
|
| root_dir = args.root_dir |
| blur_dir = os.path.join(root_dir, args.blur_dir_name) |
| clear_dir = os.path.join(root_dir, args.clear_dir_name) |
| drop_dir = os.path.join(root_dir, args.drop_dir_name) |
| output_path = args.output_path |
|
|
| |
| os.makedirs(os.path.dirname(output_path), exist_ok=True) |
|
|
| |
| output_dir = os.path.dirname(os.path.abspath(output_path)) |
|
|
| with open(output_path, "w") as f: |
| |
| for subdir in sorted(os.listdir(drop_dir)): |
| blur_sub = os.path.join(blur_dir, subdir) |
| clear_sub = os.path.join(clear_dir, subdir) |
| drop_sub = os.path.join(drop_dir, subdir) |
|
|
| if not os.path.isdir(drop_sub): |
| continue |
|
|
| |
| drop_files = sorted( |
| [f for f in os.listdir(drop_sub) if f.lower().endswith(".png")] |
| ) |
|
|
| |
| for fname in drop_files: |
| drop_path = os.path.join(drop_sub, fname) |
| blur_path = ( |
| os.path.join(blur_sub, fname) |
| if os.path.exists(os.path.join(blur_sub, fname)) |
| else None |
| ) |
| clear_path = ( |
| os.path.join(clear_sub, fname) |
| if os.path.exists(os.path.join(clear_sub, fname)) |
| else None |
| ) |
|
|
| |
| rel_drop = os.path.relpath(drop_path, output_dir) |
| rel_blur = os.path.relpath(blur_path, output_dir) if blur_path else None |
| rel_clear = ( |
| os.path.relpath(clear_path, output_dir) if clear_path else None |
| ) |
|
|
| entry = {} |
| if rel_drop: |
| entry["drop_file_name"] = rel_drop |
| else: |
| entry["drop_file_name"] = None |
| if rel_blur: |
| entry["blur_file_name"] = rel_blur |
| else: |
| entry["blur_file_name"] = None |
| if rel_clear: |
| entry["clear_file_name"] = rel_clear |
| else: |
| entry["clear_file_name"] = None |
| f.write(json.dumps(entry) + "\n") |
|
|
|
|
| if __name__ == "__main__": |
| main() |
|
|