@@ -1435,6 +1435,7 @@ class BatchDataBase(NamedTuple):
1435
1435
clip_prompt : str
1436
1436
guide_image : Any
1437
1437
raw_prompt : str
1438
+ file_name : Optional [str ]
1438
1439
1439
1440
1440
1441
class BatchDataExt (NamedTuple ):
@@ -2316,7 +2317,7 @@ def scale_and_round(x):
2316
2317
# このバッチの情報を取り出す
2317
2318
(
2318
2319
return_latents ,
2319
- (step_first , _ , _ , _ , init_image , mask_image , _ , guide_image , _ ),
2320
+ (step_first , _ , _ , _ , init_image , mask_image , _ , guide_image , _ , _ ),
2320
2321
(
2321
2322
width ,
2322
2323
height ,
@@ -2339,6 +2340,7 @@ def scale_and_round(x):
2339
2340
prompts = []
2340
2341
negative_prompts = []
2341
2342
raw_prompts = []
2343
+ filenames = []
2342
2344
start_code = torch .zeros ((batch_size , * noise_shape ), device = device , dtype = dtype )
2343
2345
noises = [
2344
2346
torch .zeros ((batch_size , * noise_shape ), device = device , dtype = dtype )
@@ -2371,14 +2373,15 @@ def scale_and_round(x):
2371
2373
all_guide_images_are_same = True
2372
2374
for i , (
2373
2375
_ ,
2374
- (_ , prompt , negative_prompt , seed , init_image , mask_image , clip_prompt , guide_image , raw_prompt ),
2376
+ (_ , prompt , negative_prompt , seed , init_image , mask_image , clip_prompt , guide_image , raw_prompt , filename ),
2375
2377
_ ,
2376
2378
) in enumerate (batch ):
2377
2379
prompts .append (prompt )
2378
2380
negative_prompts .append (negative_prompt )
2379
2381
seeds .append (seed )
2380
2382
clip_prompts .append (clip_prompt )
2381
2383
raw_prompts .append (raw_prompt )
2384
+ filenames .append (filename )
2382
2385
2383
2386
if init_image is not None :
2384
2387
init_images .append (init_image )
@@ -2478,8 +2481,8 @@ def scale_and_round(x):
2478
2481
# save image
2479
2482
highres_prefix = ("0" if highres_1st else "1" ) if highres_fix else ""
2480
2483
ts_str = time .strftime ("%Y%m%d%H%M%S" , time .localtime ())
2481
- for i , (image , prompt , negative_prompts , seed , clip_prompt , raw_prompt ) in enumerate (
2482
- zip (images , prompts , negative_prompts , seeds , clip_prompts , raw_prompts )
2484
+ for i , (image , prompt , negative_prompts , seed , clip_prompt , raw_prompt , filename ) in enumerate (
2485
+ zip (images , prompts , negative_prompts , seeds , clip_prompts , raw_prompts , filenames )
2483
2486
):
2484
2487
if highres_fix :
2485
2488
seed -= 1 # record original seed
@@ -2505,17 +2508,23 @@ def scale_and_round(x):
2505
2508
metadata .add_text ("crop-top" , str (crop_top ))
2506
2509
metadata .add_text ("crop-left" , str (crop_left ))
2507
2510
2508
- if args .use_original_file_name and init_images is not None :
2509
- if type (init_images ) is list :
2510
- fln = os .path .splitext (os .path .basename (init_images [i % len (init_images )].filename ))[0 ] + ".png"
2511
- else :
2512
- fln = os .path .splitext (os .path .basename (init_images .filename ))[0 ] + ".png"
2513
- elif args .sequential_file_name :
2514
- fln = f"im_{ highres_prefix } { step_first + i + 1 :06d} .png"
2511
+ if filename is not None :
2512
+ fln = filename
2515
2513
else :
2516
- fln = f"im_{ ts_str } _{ highres_prefix } { i :03d} _{ seed } .png"
2514
+ if args .use_original_file_name and init_images is not None :
2515
+ if type (init_images ) is list :
2516
+ fln = os .path .splitext (os .path .basename (init_images [i % len (init_images )].filename ))[0 ] + ".png"
2517
+ else :
2518
+ fln = os .path .splitext (os .path .basename (init_images .filename ))[0 ] + ".png"
2519
+ elif args .sequential_file_name :
2520
+ fln = f"im_{ highres_prefix } { step_first + i + 1 :06d} .png"
2521
+ else :
2522
+ fln = f"im_{ ts_str } _{ highres_prefix } { i :03d} _{ seed } .png"
2517
2523
2518
- image .save (os .path .join (args .outdir , fln ), pnginfo = metadata )
2524
+ if fln .endswith (".webp" ):
2525
+ image .save (os .path .join (args .outdir , fln ), pnginfo = metadata , quality = 100 ) # lossy
2526
+ else :
2527
+ image .save (os .path .join (args .outdir , fln ), pnginfo = metadata )
2519
2528
2520
2529
if not args .no_preview and not highres_1st and args .interactive :
2521
2530
try :
@@ -2562,6 +2571,7 @@ def scale_and_round(x):
2562
2571
# repeat prompt
2563
2572
for pi in range (args .images_per_prompt if len (raw_prompts ) == 1 else len (raw_prompts )):
2564
2573
raw_prompt = raw_prompts [pi ] if len (raw_prompts ) > 1 else raw_prompts [0 ]
2574
+ filename = None
2565
2575
2566
2576
if pi == 0 or len (raw_prompts ) > 1 :
2567
2577
# parse prompt: if prompt is not changed, skip parsing
@@ -2783,6 +2793,12 @@ def scale_and_round(x):
2783
2793
logger .info (f"gradual latent unsharp params: { gl_unsharp_params } " )
2784
2794
continue
2785
2795
2796
+ m = re .match (r"f (.+)" , parg , re .IGNORECASE )
2797
+ if m : # filename
2798
+ filename = m .group (1 )
2799
+ logger .info (f"filename: { filename } " )
2800
+ continue
2801
+
2786
2802
except ValueError as ex :
2787
2803
logger .error (f"Exception in parsing / 解析エラー: { parg } " )
2788
2804
logger .error (f"{ ex } " )
@@ -2873,7 +2889,16 @@ def scale_and_round(x):
2873
2889
b1 = BatchData (
2874
2890
False ,
2875
2891
BatchDataBase (
2876
- global_step , prompt , negative_prompt , seed , init_image , mask_image , clip_prompt , guide_image , raw_prompt
2892
+ global_step ,
2893
+ prompt ,
2894
+ negative_prompt ,
2895
+ seed ,
2896
+ init_image ,
2897
+ mask_image ,
2898
+ clip_prompt ,
2899
+ guide_image ,
2900
+ raw_prompt ,
2901
+ filename ,
2877
2902
),
2878
2903
BatchDataExt (
2879
2904
width ,
@@ -2916,7 +2941,7 @@ def setup_parser() -> argparse.ArgumentParser:
2916
2941
parser = argparse .ArgumentParser ()
2917
2942
2918
2943
add_logging_arguments (parser )
2919
-
2944
+
2920
2945
parser .add_argument (
2921
2946
"--sdxl" , action = "store_true" , help = "load Stable Diffusion XL model / Stable Diffusion XLのモデルを読み込む"
2922
2947
)
0 commit comments