9
9
import json
10
10
11
11
from .custom_logging import setup_logging
12
- from datetime import datetime
13
12
14
13
# Set up logging
15
14
log = setup_logging ()
@@ -699,7 +698,7 @@ def run_cmd_advanced_training(**kwargs):
699
698
if "additional_parameters" in kwargs :
700
699
run_cmd += f' { kwargs ["additional_parameters" ]} '
701
700
702
- if "block_lr" in kwargs :
701
+ if "block_lr" in kwargs and kwargs [ "block_lr" ] != "" :
703
702
run_cmd += f' --block_lr="{ kwargs ["block_lr" ]} "'
704
703
705
704
if kwargs .get ("bucket_no_upscale" ):
@@ -1143,12 +1142,12 @@ def run_cmd_advanced_training(**kwargs):
1143
1142
1144
1143
def verify_image_folder_pattern (folder_path ):
1145
1144
false_response = True # temporarily set to true to prevent stopping training in case of false positive
1146
- true_response = True
1147
1145
1146
+ log .info (f"Verifying image folder pattern of { folder_path } ..." )
1148
1147
# Check if the folder exists
1149
1148
if not os .path .isdir (folder_path ):
1150
1149
log .error (
1151
- f"The provided path '{ folder_path } ' is not a valid folder. Please follow the folder structure documentation found at docs\image_folder_structure.md ..."
1150
+ f"...the provided path '{ folder_path } ' is not a valid folder. Please follow the folder structure documentation found at docs\image_folder_structure.md ..."
1152
1151
)
1153
1152
return false_response
1154
1153
@@ -1176,22 +1175,22 @@ def verify_image_folder_pattern(folder_path):
1176
1175
non_matching_subfolders = set (subfolders ) - set (matching_subfolders )
1177
1176
if non_matching_subfolders :
1178
1177
log .error (
1179
- f"The following folders do not match the required pattern <number>_<text>: { ', ' .join (non_matching_subfolders )} "
1178
+ f"...the following folders do not match the required pattern <number>_<text>: { ', ' .join (non_matching_subfolders )} "
1180
1179
)
1181
1180
log .error (
1182
- f"Please follow the folder structure documentation found at docs\image_folder_structure.md ..."
1181
+ f"...please follow the folder structure documentation found at docs\image_folder_structure.md ..."
1183
1182
)
1184
1183
return false_response
1185
1184
1186
1185
# Check if no sub-folders exist
1187
1186
if not matching_subfolders :
1188
1187
log .error (
1189
- f"No image folders found in { folder_path } . Please follow the folder structure documentation found at docs\image_folder_structure.md ..."
1188
+ f"...no image folders found in { folder_path } . Please follow the folder structure documentation found at docs\image_folder_structure.md ..."
1190
1189
)
1191
1190
return false_response
1192
1191
1193
- log .info (f"Valid image folder names found in: { folder_path } " )
1194
- return true_response
1192
+ log .info (f"...valid " )
1193
+ return True
1195
1194
1196
1195
1197
1196
def SaveConfigFile (
@@ -1231,7 +1230,9 @@ def save_to_file(content):
1231
1230
def check_duplicate_filenames (
1232
1231
folder_path , image_extension = [".gif" , ".png" , ".jpg" , ".jpeg" , ".webp" ]
1233
1232
):
1234
- log .info ("Checking for duplicate image filenames in training data directory..." )
1233
+ duplicate = False
1234
+
1235
+ log .info (f"Checking for duplicate image filenames in training data directory { folder_path } ..." )
1235
1236
for root , dirs , files in os .walk (folder_path ):
1236
1237
filenames = {}
1237
1238
for file in files :
@@ -1241,15 +1242,138 @@ def check_duplicate_filenames(
1241
1242
if filename in filenames :
1242
1243
existing_path = filenames [filename ]
1243
1244
if existing_path != full_path :
1244
- print (
1245
- f"Warning: Same filename '{ filename } ' with different image extension found. This will cause training issues. Rename one of the file."
1245
+ log . warning (
1246
+ f"...same filename '{ filename } ' with different image extension found. This will cause training issues. Rename one of the file."
1246
1247
)
1247
- print (f"Existing file: { existing_path } " )
1248
- print (f"Current file: { full_path } " )
1248
+ log .warning (f" Existing file: { existing_path } " )
1249
+ log .warning (f" Current file: { full_path } " )
1250
+ duplicate = True
1249
1251
else :
1250
1252
filenames [filename ] = full_path
1253
+ if not duplicate :
1254
+ log .info ("...valid" )
1251
1255
1252
1256
1257
+ def validate_paths (headless :bool = False , ** kwargs ):
1258
+ from .class_source_model import default_models
1259
+
1260
+ pretrained_model_name_or_path = kwargs .get ("pretrained_model_name_or_path" )
1261
+ train_data_dir = kwargs .get ("train_data_dir" )
1262
+ reg_data_dir = kwargs .get ("reg_data_dir" )
1263
+ output_dir = kwargs .get ("output_dir" )
1264
+ logging_dir = kwargs .get ("logging_dir" )
1265
+ lora_network_weights = kwargs .get ("lora_network_weights" )
1266
+ finetune_image_folder = kwargs .get ("finetune_image_folder" )
1267
+ resume = kwargs .get ("resume" )
1268
+ vae = kwargs .get ("vae" )
1269
+
1270
+ if pretrained_model_name_or_path is not None :
1271
+ log .info (f"Validating model file or folder path { pretrained_model_name_or_path } existence..." )
1272
+
1273
+ # Check if it matches the Hugging Face model pattern
1274
+ if re .match (r'^[\w-]+\/[\w-]+$' , pretrained_model_name_or_path ):
1275
+ log .info ("...huggingface.co model, skipping validation" )
1276
+ elif pretrained_model_name_or_path not in default_models :
1277
+ # If not one of the default models, check if it's a valid local path
1278
+ if not os .path .exists (pretrained_model_name_or_path ):
1279
+ log .error (f"...source model path '{ pretrained_model_name_or_path } ' is missing or does not exist" )
1280
+ return False
1281
+ else :
1282
+ log .info ("...valid" )
1283
+ else :
1284
+ log .info ("...valid" )
1285
+
1286
+ # Check if train_data_dir is valid
1287
+ if train_data_dir != None :
1288
+ log .info (f"Validating training data folder path { train_data_dir } existence..." )
1289
+ if not train_data_dir or not os .path .exists (train_data_dir ):
1290
+ log .error (f"Image folder path '{ train_data_dir } ' is missing or does not exist" )
1291
+ return False
1292
+ else :
1293
+ log .info ("...valid" )
1294
+
1295
+ # Check if there are files with the same filename but different image extension... warn the user if it is the case.
1296
+ check_duplicate_filenames (train_data_dir )
1297
+
1298
+ if not verify_image_folder_pattern (folder_path = train_data_dir ):
1299
+ return False
1300
+
1301
+ if finetune_image_folder != None :
1302
+ log .info (f"Validating finetuning image folder path { finetune_image_folder } existence..." )
1303
+ if not finetune_image_folder or not os .path .exists (finetune_image_folder ):
1304
+ log .error (f"Image folder path '{ finetune_image_folder } ' is missing or does not exist" )
1305
+ return False
1306
+ else :
1307
+ log .info ("...valid" )
1308
+
1309
+ if reg_data_dir != None :
1310
+ if reg_data_dir != "" :
1311
+ log .info (f"Validating regularisation data folder path { reg_data_dir } existence..." )
1312
+ if not os .path .exists (reg_data_dir ):
1313
+ log .error ("...regularisation folder does not exist" )
1314
+ return False
1315
+
1316
+ if not verify_image_folder_pattern (folder_path = reg_data_dir ):
1317
+ return False
1318
+ log .info ("...valid" )
1319
+ else :
1320
+ log .info ("Regularisation folder not specified, skipping validation" )
1321
+
1322
+ if output_dir != None :
1323
+ log .info (f"Validating output folder path { output_dir } existence..." )
1324
+ if output_dir == "" or not os .path .exists (output_dir ):
1325
+ log .error ("...output folder path is missing or invalid" )
1326
+ return False
1327
+ else :
1328
+ log .info ("...valid" )
1329
+
1330
+ if logging_dir != None :
1331
+ if logging_dir != "" :
1332
+ log .info (f"Validating logging folder path { logging_dir } existence..." )
1333
+ if not os .path .exists (logging_dir ):
1334
+ log .error ("...logging folder path is missing or invalid" )
1335
+ return False
1336
+ else :
1337
+ log .info ("...valid" )
1338
+ else :
1339
+ log .info ("Logging folder not specified, skipping validation" )
1340
+
1341
+ if lora_network_weights != None :
1342
+ if lora_network_weights != "" :
1343
+ log .info (f"Validating LoRA Network Weight file path { lora_network_weights } existence..." )
1344
+ if not os .path .exists (lora_network_weights ):
1345
+ log .error ("...path is invalid" )
1346
+ return False
1347
+ else :
1348
+ log .info ("...valid" )
1349
+ else :
1350
+ log .info ("LoRA Network Weight file not specified, skipping validation" )
1351
+
1352
+ if resume != None :
1353
+ if resume != "" :
1354
+ log .info (f"Validating model resume file path { resume } existence..." )
1355
+ if not os .path .exists (resume ):
1356
+ log .error ("...path is invalid" )
1357
+ return False
1358
+ else :
1359
+ log .info ("...valid" )
1360
+ else :
1361
+ log .info ("Model resume file not specified, skipping validation" )
1362
+
1363
+ if vae != None :
1364
+ if vae != "" :
1365
+ log .info (f"Validating VAE file path { vae } existence..." )
1366
+ if not os .path .exists (vae ):
1367
+ log .error ("...vae path is invalid" )
1368
+ return False
1369
+ else :
1370
+ log .info ("...valid" )
1371
+ else :
1372
+ log .info ("VAE file not specified, skipping validation" )
1373
+
1374
+
1375
+ return True
1376
+
1253
1377
def is_file_writable (file_path ):
1254
1378
if not os .path .exists (file_path ):
1255
1379
# print(f"File '{file_path}' does not exist.")
0 commit comments