Download utils/prepare_data.py from pythn/DIAS: direct link, hf CLI and curl.
- Browser
- Download file 968 Bytes
-
https://huggingface.co/datasets/pythn/DIAS/resolve/refs%2Fpr%2F1/utils/prepare_data.py
- Command line
-
hf download hf://datasets/pythn/DIAS@refs/pr/1/utils/prepare_data.py
-
curl -L -o prepare_data.py https://huggingface.co/datasets/pythn/DIAS/resolve/refs%2Fpr%2F1/utils/prepare_data.py
968 Bytes
| import os | |
| import re | |
| # Define your directories | |
| image_dir = '/home/abdelrahman.elsayed/DIAS/images' | |
| mask_dir = '/home/abdelrahman.elsayed/DIAS/masks' | |
| # Rename images | |
| for filename in os.listdir(image_dir): | |
| if filename.endswith('.png') or filename.endswith('.jpg'): | |
| print(filename) | |
| test_name = filename.split("-") | |
| print(test_name) | |
| match = re.match(r'image_s(\d+)_i(\d+)\.png', filename) | |
| if match: | |
| new_name = f's{match.group(1)}.png' | |
| os.rename(os.path.join(image_dir, filename), os.path.join(image_dir, new_name)) | |
| # print(new_name) | |
| # Rename masks | |
| for filename in os.listdir(mask_dir): | |
| if filename.endswith('.png'): | |
| match = re.match(r'label_s(\d+)\.png', filename) | |
| print(filename) | |
| if match: | |
| new_name = f's{match.group(1)}_mask.png' | |
| os.rename(os.path.join(mask_dir, filename), os.path.join(mask_dir, new_name)) | |
| print(new_name) | |