chore: restructure new evalset
Browse files- scripts/restructure.py +54 -0
scripts/restructure.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import shutil
|
| 3 |
+
|
| 4 |
+
def move_real_images(source_dir, dest_dir):
|
| 5 |
+
|
| 6 |
+
if not os.path.exists(dest_dir):
|
| 7 |
+
os.makedirs(dest_dir)
|
| 8 |
+
|
| 9 |
+
# Walk through the source directory
|
| 10 |
+
for root, dirs, files in os.walk(source_dir):
|
| 11 |
+
if 'real' in dirs:
|
| 12 |
+
# Construct the full path to the `real` directory
|
| 13 |
+
real_dir = os.path.join(root, 'real')
|
| 14 |
+
model_folder_name = os.path.basename(root)
|
| 15 |
+
dest_model_dir = os.path.join(dest_dir, model_folder_name)
|
| 16 |
+
|
| 17 |
+
if not os.path.exists(dest_model_dir):
|
| 18 |
+
os.makedirs(dest_model_dir)
|
| 19 |
+
|
| 20 |
+
for file in os.listdir(real_dir):
|
| 21 |
+
source_file = os.path.join(real_dir, file)
|
| 22 |
+
dest_file = os.path.join(dest_model_dir, file)
|
| 23 |
+
|
| 24 |
+
shutil.move(source_file, dest_file)
|
| 25 |
+
|
| 26 |
+
print(f"Moved: {source_file} to {dest_file}")
|
| 27 |
+
|
| 28 |
+
def move_generated_images(source_dir):
|
| 29 |
+
# Walk through the source directory
|
| 30 |
+
for root, dirs, files in os.walk(source_dir):
|
| 31 |
+
# Check if the current directory is a `generated` directory
|
| 32 |
+
if 'generated' in dirs:
|
| 33 |
+
# Construct the full path to the `generated` directory
|
| 34 |
+
generated_dir = os.path.join(root, 'generated')
|
| 35 |
+
|
| 36 |
+
# Move all files from the `generated` directory to the parent directory
|
| 37 |
+
for file in os.listdir(generated_dir):
|
| 38 |
+
source_file = os.path.join(generated_dir, file)
|
| 39 |
+
dest_file = os.path.join(root, file)
|
| 40 |
+
|
| 41 |
+
# Move the file
|
| 42 |
+
shutil.move(source_file, dest_file)
|
| 43 |
+
|
| 44 |
+
print(f"Moved: {source_file} to {dest_file}")
|
| 45 |
+
|
| 46 |
+
def main():
|
| 47 |
+
source_dir = 'resampledSet'
|
| 48 |
+
real_dest_dir = 'real'
|
| 49 |
+
|
| 50 |
+
move_real_images(source_dir, real_dest_dir)
|
| 51 |
+
move_generated_images(source_dir)
|
| 52 |
+
|
| 53 |
+
if __name__ == "__main__":
|
| 54 |
+
main()
|