|
2 | 2 | from PIL import Image
|
3 | 3 | import pandas as pd
|
4 | 4 | import shutil
|
5 |
| -from config import FOLDERS, EXTENSION, W, H |
| 5 | +from config import FOLDERS, EXTENSION, W, H, WEIGHTS |
6 | 6 |
|
7 | 7 |
|
8 | 8 | def get_files_path(folders=FOLDERS):
|
@@ -44,22 +44,58 @@ def get_files_path(folders=FOLDERS):
|
44 | 44 | print(f"{folder} folder cleaned")
|
45 | 45 | os.mkdir(folder)
|
46 | 46 |
|
| 47 | + # Validate weights |
| 48 | + assert ( |
| 49 | + sum(WEIGHTS) == 1 |
| 50 | + ), f"sum of PARTS_DICT's value in config.py should be 1, now is {sum(WEIGHTS)}" |
| 51 | + |
47 | 52 | # Validate image format and size
|
| 53 | + error = 0 |
48 | 54 | for path in files_path:
|
49 |
| - assert ( |
50 |
| - path.split(".")[-1] in EXTENSION |
51 |
| - ), f"{path}'s extension is not {EXTENSION} " |
52 |
| - im = Image.open(path) |
53 |
| - w, h = im.size |
54 |
| - assert w == W, f"{path} width not equal {W}" |
55 |
| - assert h == H, f"{path} height not equal {H}" |
| 55 | + try: |
| 56 | + assert ( |
| 57 | + path.split(".")[-1] in EXTENSION |
| 58 | + ), f"{path}'s extension is not {EXTENSION} " |
| 59 | + im = Image.open(path) |
| 60 | + w, h = im.size |
| 61 | + assert w == W, f"{path} width not equal {W}" |
| 62 | + assert h == H, f"{path} height not equal {H}" |
| 63 | + except Exception as e: |
| 64 | + print(e) |
| 65 | + error += 1 |
| 66 | + if error != 0: |
| 67 | + print(f"{error} images have error, fix and try again") |
| 68 | + exit() |
56 | 69 |
|
57 | 70 | # Validate path name has -
|
58 | 71 | for path in files_path:
|
59 | 72 | assert (
|
60 | 73 | "-" not in path.split("/")[-1]
|
61 | 74 | ), f"{path} is invalid, files should not have '-' symbol"
|
62 | 75 |
|
| 76 | + folder_set = set() |
| 77 | + folder_error = 0 |
| 78 | + # check all parts folders has same order |
| 79 | + for folder in FOLDERS: |
| 80 | + try: |
| 81 | + for root, subfolders, _ in os.walk(folder): |
| 82 | + if root == folder: |
| 83 | + for subfolder in subfolders: |
| 84 | + if subfolder not in folder_set and subfolder.split("_")[ |
| 85 | + 1 |
| 86 | + ] in map(lambda f: f.split("_")[1], folder_set): |
| 87 | + raise Exception( |
| 88 | + f"in '{root}' folder '{subfolder}' is invalid, index of subfolder with same trait should be same." |
| 89 | + ) |
| 90 | + else: |
| 91 | + folder_set.add(subfolder) |
| 92 | + except Exception as e: |
| 93 | + print(e) |
| 94 | + folder_error += 1 |
| 95 | + if folder_error != 0: |
| 96 | + print("Exited, please fix subfolder error and retry") |
| 97 | + exit() |
| 98 | + |
63 | 99 | # export tables
|
64 | 100 | attrs = [os.path.split(path) for path in files_path]
|
65 | 101 | d = {
|
|
0 commit comments