Download data/create_csv.py from annghoang/flood-detection: direct link, hf CLI and curl.
- Browser
- Download file 986 Bytes
-
https://huggingface.co/datasets/annghoang/flood-detection/resolve/main/data/create_csv.py
- Command line
-
hf download hf://datasets/annghoang/flood-detection/data/create_csv.py
-
curl -L -o create_csv.py https://huggingface.co/datasets/annghoang/flood-detection/resolve/main/data/create_csv.py
986 Bytes
| import os | |
| import csv | |
| base_dir = r"C:\Users\an\Desktop\dpl302m\2026-sum-dpl-30-xm\testset_images" | |
| flood_dir = os.path.join(base_dir, "flood") | |
| not_flood_dir = os.path.join(base_dir, "not_flood") | |
| output_csv = os.path.join(base_dir, "final_submission.csv") | |
| data = [] | |
| # Process flood directory | |
| if os.path.exists(flood_dir): | |
| for f in os.listdir(flood_dir): | |
| if f.lower().endswith(('.png', '.jpg', '.jpeg')): | |
| file_id = os.path.splitext(f)[0] | |
| data.append((file_id, 1)) | |
| # Process not_flood directory | |
| if os.path.exists(not_flood_dir): | |
| for f in os.listdir(not_flood_dir): | |
| if f.lower().endswith(('.png', '.jpg', '.jpeg')): | |
| file_id = os.path.splitext(f)[0] | |
| data.append((file_id, 0)) | |
| # Write to CSV | |
| with open(output_csv, 'w', newline='') as f: | |
| writer = csv.writer(f) | |
| writer.writerow(['id', 'label']) | |
| for row in data: | |
| writer.writerow(row) | |
| print(f"Successfully saved {len(data)} entries to {output_csv}") | |