@@ -62,7 +62,7 @@ def reload_sd_model():
6262def core_generation_funnel (outpath , inputimages , inputdepthmaps , inputnames , inp ):
6363 if len (inputimages ) == 0 or inputimages [0 ] is None :
6464 return [], '' , ''
65- if len (inputdepthmaps ) == 0 :
65+ if inputdepthmaps is None or len (inputdepthmaps ) == 0 :
6666 inputdepthmaps : list [Image ] = [None for _ in range (len (inputimages ))]
6767 inputdepthmaps_complete = all ([x is not None for x in inputdepthmaps ])
6868
@@ -78,8 +78,8 @@ def core_generation_funnel(outpath, inputimages, inputdepthmaps, inputnames, inp
7878 gen_mesh = inp ["gen_mesh" ]
7979 gen_normal = inp ["gen_normal" ] if "gen_normal" in inp else False
8080 gen_stereo = inp ["gen_stereo" ]
81- inpaint = inp ["inpaint" ]
82- inpaint_vids = inp ["inpaint_vids" ]
81+ inpaint = inp ["inpaint" ] if "inpaint" in inp else False
82+ inpaint_vids = inp ["inpaint_vids" ] if "inpaint_vids" in inp else False
8383 invert_depth = inp ["invert_depth" ]
8484 match_size = inp ["match_size" ]
8585 mesh_occlude = inp ["mesh_occlude" ]
@@ -165,7 +165,9 @@ def core_generation_funnel(outpath, inputimages, inputdepthmaps, inputnames, inp
165165 else :
166166 # override net size (size may be different for different images)
167167 if match_size :
168- net_width , net_height = inputimages [count ].width , inputimages [count ].height
168+ # Round up to a multiple of 32 to avoid potential issues
169+ net_width = (inputimages [count ].width + 31 ) // 32 * 32
170+ net_height = (inputimages [count ].height + 31 ) // 32 * 32
169171 raw_prediction , raw_prediction_invert = \
170172 model_holder .get_raw_prediction (inputimages [count ], net_width , net_height )
171173
@@ -304,14 +306,14 @@ def core_generation_funnel(outpath, inputimages, inputdepthmaps, inputnames, inp
304306 else :
305307 raise e
306308 finally :
307- if not (hasattr (opts , 'depthmap_script_keepmodels' ) and opts .depthmap_script_keepmodels ):
309+ if hasattr (opts , 'depthmap_script_keepmodels' ) and opts .depthmap_script_keepmodels :
310+ model_holder .offload () # Swap to CPU memory
311+ else :
308312 if 'model' in locals ():
309313 del model
310314 if 'pix2pixmodel' in locals ():
311315 del pix2pix_model
312316 model_holder .unload_models ()
313- else :
314- model_holder .swap_to_cpu_memory ()
315317
316318 gc .collect ()
317319 devices .torch_gc ()
0 commit comments