@@ -66,7 +66,7 @@ def __getattr__(self, item):
66
66
67
67
def core_generation_funnel (outpath , inputimages , inputdepthmaps , inputnames , inp , ops = None ):
68
68
if len (inputimages ) == 0 or inputimages [0 ] is None :
69
- return [], '' , ''
69
+ return
70
70
if inputdepthmaps is None or len (inputdepthmaps ) == 0 :
71
71
inputdepthmaps : list [Image ] = [None for _ in range (len (inputimages ))]
72
72
inputdepthmaps_complete = all ([x is not None for x in inputdepthmaps ])
@@ -103,12 +103,7 @@ def core_generation_funnel(outpath, inputimages, inputdepthmaps, inputnames, inp
103
103
device = torch .device ("cpu" )
104
104
print ("device: %s" % device )
105
105
106
- generated_images = [{} for _ in range (len (inputimages ))]
107
- """Images that will be returned.
108
- Every array element corresponds to particular input image.
109
- Dictionary keys are types of images that were derived from the input image."""
110
- # TODO: ???
111
- meshsimple_fi = None
106
+ # TODO: This should not be here
112
107
inpaint_imgs = []
113
108
inpaint_depths = []
114
109
@@ -192,14 +187,14 @@ def core_generation_funnel(outpath, inputimages, inputdepthmaps, inputnames, inp
192
187
background_removed_array [:, :, 2 ] == 0 ) & (background_removed_array [:, :, 3 ] <= 0.2 )
193
188
img_output [bg_mask ] = 0 # far value
194
189
195
- generated_images [ count ][ 'background_removed' ] = background_removed_image
190
+ yield count , 'background_removed' , background_removed_image
196
191
197
192
if inp [go .SAVE_BACKGROUND_REMOVAL_MASKS ]:
198
193
bg_array = (1 - bg_mask .astype ('int8' )) * 255
199
194
mask_array = np .stack ((bg_array , bg_array , bg_array , bg_array ), axis = 2 )
200
195
mask_image = Image .fromarray (mask_array .astype (np .uint8 ))
201
196
202
- generated_images [ count ][ 'foreground_mask' ] = mask_image
197
+ yield count , 'foreground_mask' , mask_image
203
198
204
199
# A weird quirk: if user tries to save depthmap, whereas input depthmap is used,
205
200
# depthmap will be outputed, even if output_depth_combine is used.
@@ -211,9 +206,9 @@ def core_generation_funnel(outpath, inputimages, inputdepthmaps, inputnames, inp
211
206
img_concat = Image .fromarray (np .concatenate (
212
207
(inputimages [count ], convert_i16_to_rgb (img_depth , inputimages [count ])),
213
208
axis = axis ))
214
- generated_images [ count ][ 'concat_depth' ] = img_concat
209
+ yield count , 'concat_depth' , img_concat
215
210
else :
216
- generated_images [ count ][ 'depth' ] = Image .fromarray (img_depth )
211
+ yield count , 'depth' , Image .fromarray (img_depth )
217
212
218
213
if inp [go .GEN_STEREO ]:
219
214
print ("Generating stereoscopic images.." )
@@ -222,21 +217,22 @@ def core_generation_funnel(outpath, inputimages, inputdepthmaps, inputnames, inp
222
217
inp [go .STEREO_DIVERGENCE ], inp [go .STEREO_SEPARATION ],
223
218
inp [go .STEREO_MODES ], inp [go .STEREO_BALANCE ], inp [go .STEREO_FILL_ALGO ])
224
219
for c in range (0 , len (stereoimages )):
225
- generated_images [ count ][ inp [go .STEREO_MODES ][c ]] = stereoimages [c ]
220
+ yield count , inp [go .STEREO_MODES ][c ], stereoimages [c ]
226
221
227
222
if inp [go .GEN_NORMALMAP ]:
228
- generated_images [ count ][ ' normalmap' ] = create_normalmap (
223
+ normalmap = create_normalmap (
229
224
img_output ,
230
225
inp [go .NORMALMAP_PRE_BLUR_KERNEL ] if inp [go .NORMALMAP_PRE_BLUR ] else None ,
231
226
inp [go .NORMALMAP_SOBEL_KERNEL ] if inp [go .NORMALMAP_SOBEL ] else None ,
232
227
inp [go .NORMALMAP_POST_BLUR_KERNEL ] if inp [go .NORMALMAP_POST_BLUR ] else None ,
233
228
inp [go .NORMALMAP_INVERT ]
234
229
)
230
+ yield count , 'normalmap' , normalmap
235
231
236
232
if inp [go .GEN_HEATMAP ]:
237
233
from dzoedepth .utils .misc import colorize
238
234
heatmap = Image .fromarray (colorize (img_output , cmap = 'inferno' ))
239
- generated_images [ count ][ 'heatmap' ] = heatmap
235
+ yield count , 'heatmap' , heatmap
240
236
241
237
# gen mesh
242
238
if inp [go .GEN_SIMPLE_MESH ]:
@@ -268,17 +264,25 @@ def core_generation_funnel(outpath, inputimages, inputdepthmaps, inputnames, inp
268
264
mesh = create_mesh (inputimages [count ], depthi , keep_edges = not inp [go .SIMPLE_MESH_OCCLUDE ],
269
265
spherical = (inp [go .SIMPLE_MESH_SPHERICAL ]))
270
266
mesh .export (meshsimple_fi )
267
+ yield count , 'simple_mesh' , meshsimple_fi
271
268
272
269
print ("Computing output(s) done." )
273
270
except RuntimeError as e :
274
271
# TODO: display in UI
275
272
if 'out of memory' in str (e ):
276
- suggestion = "ERROR: out of memory, could not generate depthmap!\n Please try a different model"
277
- if device != torch .device ("cpu" ):
278
- suggestion += ", or try using the CPU"
273
+ suggestion = "ERROR: out of GPU memory, could not generate depthmap! " \
274
+ "Here are some suggestions to work around this issue:\n "
279
275
if inp [go .BOOST ]:
280
- suggestion += ", or disable BOOST"
281
- print (f"{ suggestion } ." )
276
+ suggestion += " * Disable BOOST (generation will be faster, but the depthmap will be less detailed)\n "
277
+ if backbone .USED_BACKBONE == backbone .BackboneType .WEBUI :
278
+ suggestion += " * Run DepthMap in the standalone mode - without launching the SD WebUI\n "
279
+ if device != torch .device ("cpu" ):
280
+ suggestion += " * Select CPU as the processing device (this will be slower)\n "
281
+ if inp [go .MODEL_TYPE ] != 6 :
282
+ suggestion += " * Use a different model (this could reduce quality)\n "
283
+ if not inp [go .BOOST ]:
284
+ suggestion += " * Reduce net size (this could reduce quality)\n "
285
+ print (f"{ suggestion } " )
282
286
else :
283
287
raise e
284
288
finally :
@@ -301,12 +305,12 @@ def core_generation_funnel(outpath, inputimages, inputdepthmaps, inputnames, inp
301
305
mesh_fi = run_3dphoto (device , inpaint_imgs , inpaint_depths , inputnames , outpath ,
302
306
inp [go .GEN_INPAINTED_MESH_DEMOS ],
303
307
1 , "mp4" )
308
+ yield 0 , 'inpainted_mesh' , mesh_fi
304
309
except Exception as e :
305
310
print (f'{ str (e )} , some issue with generating inpainted mesh' )
306
311
307
312
backbone .reload_sd_model ()
308
313
print ("All done.\n " )
309
- return generated_images , mesh_fi , meshsimple_fi
310
314
311
315
312
316
def get_uniquefn (outpath , basename , ext ):
0 commit comments