Skip to content

Commit e2810d9

Browse files
committed
Fix val split overlap, fix logic miss for training on split
1 parent 507cee7 commit e2810d9

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

library/train_util.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,16 +175,17 @@ def split_train_val(
175175
paths, sizes = zip(*dataset)
176176
paths = list(paths)
177177
sizes = list(sizes)
178+
178179
# Split the dataset between training and validation
180+
val_count = round(len(paths) * validation_split)
181+
split_index = len(paths) - val_count
182+
179183
if is_training_dataset:
180184
# Training dataset we split to the first part
181-
split = math.ceil(len(paths) * (1 - validation_split))
182-
return paths[0:split], sizes[0:split]
185+
return paths[:split_index], sizes[:split_index]
183186
else:
184187
# Validation dataset we split to the second part
185-
split = len(paths) - round(len(paths) * validation_split)
186-
return paths[split:], sizes[split:]
187-
188+
return paths[split_index:], sizes[split_index:]
188189

189190
class ImageInfo:
190191
def __init__(self, image_key: str, num_repeats: int, caption: str, is_reg: bool, is_val: bool, absolute_path: str) -> None:
@@ -2125,6 +2126,11 @@ def load_dreambooth_dir(subset: DreamBoothSubset):
21252126
img_paths, sizes, self.is_training_dataset, self.validation_split, self.validation_seed
21262127
)
21272128
subset.is_val = True
2129+
elif not subset.is_val:
2130+
img_paths, sizes = split_train_val(
2131+
img_paths, sizes, self.is_training_dataset, self.validation_split, self.validation_seed
2132+
)
2133+
21282134

21292135
logger.info(f"found directory {subset.image_dir} contains {len(img_paths)} image files")
21302136

0 commit comments

Comments
 (0)