Download utils/prepare_data.py from pythn/DB: direct link, hf CLI and curl.
- Browser
- Download file 1.15 kB
-
https://huggingface.co/datasets/pythn/DB/resolve/main/utils/prepare_data.py
- Command line
-
hf download hf://datasets/pythn/DB/utils/prepare_data.py
-
curl -L -o prepare_data.py https://huggingface.co/datasets/pythn/DB/resolve/main/utils/prepare_data.py
1.15 kB
| import os | |
| def append_mask_to_labels(directory): | |
| # Loop through all files in the directory | |
| for filename in os.listdir(directory): | |
| # Get the full path of the current file | |
| file_path = os.path.join(directory, filename) | |
| # Ensure it's a file (not a subdirectory) | |
| if os.path.isfile(file_path): | |
| # Split the filename and its extension | |
| file_name, file_extension = os.path.splitext(filename) | |
| file_list = file_name.split("_") | |
| # print(file_list[0]) | |
| # Create the new filename by appending "_mask" | |
| new_filename = f"{file_list[0]}_mask{file_extension}" | |
| # Get the full path for the new filename | |
| new_file_path = os.path.join(directory, new_filename) | |
| # Rename the file | |
| os.rename(file_path, new_file_path) | |
| print(f"Renamed: {filename} -> {new_filename}") | |
| if __name__ == "__main__": | |
| # Replace with the path to your labels directory | |
| labels_directory = "/home/abdelrahman.elsayed/DB/masks" | |
| # Call the function to append "_mask" to each label | |
| append_mask_to_labels(labels_directory) | |