MCPcopy
hub / github.com/kohya-ss/sd-scripts / process_batch

Function process_batch

gen_img.py:2373–2711  ·  view source on GitHub ↗
(batch: List[BatchData], highres_fix, highres_1st=False)

Source from the content-addressed store, hash-verified

2371
2372 # バッチ処理の関数
2373 def process_batch(batch: List[BatchData], highres_fix, highres_1st=False):
2374 batch_size = len(batch)
2375
2376 # highres_fixの処理
2377 if highres_fix and not highres_1st:
2378 # 1st stageのバッチを作成して呼び出す:サイズを小さくして呼び出す
2379 is_1st_latent = upscaler.support_latents() if upscaler else args.highres_fix_latents_upscaling
2380
2381 logger.info("process 1st stage")
2382 batch_1st = []
2383 for _, base, ext in batch:
2384
2385 def scale_and_round(x):
2386 if x is None:
2387 return None
2388 return int(x * args.highres_fix_scale + 0.5)
2389
2390 width_1st = scale_and_round(ext.width)
2391 height_1st = scale_and_round(ext.height)
2392 width_1st = width_1st - width_1st % 32
2393 height_1st = height_1st - height_1st % 32
2394
2395 original_width_1st = scale_and_round(ext.original_width)
2396 original_height_1st = scale_and_round(ext.original_height)
2397 original_width_negative_1st = scale_and_round(ext.original_width_negative)
2398 original_height_negative_1st = scale_and_round(ext.original_height_negative)
2399 crop_left_1st = scale_and_round(ext.crop_left)
2400 crop_top_1st = scale_and_round(ext.crop_top)
2401
2402 strength_1st = ext.strength if args.highres_fix_strength is None else args.highres_fix_strength
2403
2404 ext_1st = BatchDataExt(
2405 width_1st,
2406 height_1st,
2407 original_width_1st,
2408 original_height_1st,
2409 original_width_negative_1st,
2410 original_height_negative_1st,
2411 crop_left_1st,
2412 crop_top_1st,
2413 args.highres_fix_steps,
2414 ext.scale,
2415 ext.negative_scale,
2416 strength_1st,
2417 ext.network_muls,
2418 ext.num_sub_prompts,
2419 )
2420 batch_1st.append(BatchData(is_1st_latent, base, ext_1st))
2421
2422 pipe.set_enable_control_net(True) # 1st stageではControlNetを有効にする
2423 images_1st = process_batch(batch_1st, True, True)
2424
2425 # 2nd stageのバッチを作成して以下処理する
2426 logger.info("process 2nd stage")
2427 width_2nd, height_2nd = batch[0].ext.width, batch[0].ext.height
2428
2429 if upscaler:
2430 # upscalerを使って画像を拡大する

Callers 1

mainFunction · 0.70

Calls 15

pyramid_noise_likeFunction · 0.90
support_latentsMethod · 0.80
upscaleMethod · 0.80
toMethod · 0.80
interpolateMethod · 0.80
scale_and_roundFunction · 0.70
BatchDataExtClass · 0.70
BatchDataClass · 0.70
BatchDataBaseClass · 0.70
randnMethod · 0.45
reset_sampler_noisesMethod · 0.45

Tested by

no test coverage detected