@@ -1048,6 +1048,10 @@ def run_generate(depthmap_mode,
1048
1048
clipthreshold_far ,
1049
1049
clipthreshold_near ,
1050
1050
inpaint ,
1051
+ background_removal_model ,
1052
+ background_removal ,
1053
+ pre_depth_background_removal ,
1054
+ save_background_removal_masks ,
1051
1055
vid_format ,
1052
1056
vid_ssaa
1053
1057
):
@@ -1091,8 +1095,15 @@ def run_generate(depthmap_mode,
1091
1095
else :
1092
1096
outpath = opts .outdir_samples or opts .outdir_extras_samples
1093
1097
1098
+ background_removed_images = []
1099
+ if background_removal :
1100
+ if pre_depth_background_removal :
1101
+ imageArr = batched_background_removal (imageArr , background_removal_model )
1102
+ background_removed_images = imageArr
1103
+ else :
1104
+ background_removed_images = batched_background_removal (imageArr , background_removal_model )
1094
1105
1095
- outputs , mesh_fi = run_depthmap (None , outpath , imageArr , imageNameArr , compute_device , model_type , net_width , net_height , match_size , invert_depth , boost , save_depth , show_depth , show_heat , combine_output , combine_output_axis , gen_stereo , gen_anaglyph , stereo_divergence , stereo_fill , stereo_balance , clipdepth , clipthreshold_far , clipthreshold_near , inpaint , fnExt , vid_ssaa )
1106
+ outputs , mesh_fi = run_depthmap (None , outpath , imageArr , imageNameArr , compute_device , model_type , net_width , net_height , match_size , invert_depth , boost , save_depth , show_depth , show_heat , combine_output , combine_output_axis , gen_stereo , gen_anaglyph , stereo_divergence , stereo_fill , stereo_balance , clipdepth , clipthreshold_far , clipthreshold_near , inpaint , fnExt , vid_ssaa , background_removal , background_removed_images , save_background_removal_masks )
1096
1107
1097
1108
return outputs , mesh_fi , plaintext_to_html ('info' ), ''
1098
1109
@@ -1157,6 +1168,14 @@ def on_ui_tabs():
1157
1168
with gr .Row ():
1158
1169
inpaint = gr .Checkbox (label = "Generate 3D inpainted mesh and demo videos. (Sloooow)" ,value = False )
1159
1170
1171
+ with gr .Group ():
1172
+ with gr .Row ():
1173
+ background_removal_model = gr .Dropdown (label = "Model" , choices = ['u2net' ,'u2netp' ,'u2net_human_seg' , 'silueta' ], value = 'u2net' , type = "value" , elem_id = "model_type" )
1174
+ with gr .Row ():
1175
+ background_removal = gr .Checkbox (label = "remove background" ,value = False )
1176
+ save_background_removal_masks = gr .Checkbox (label = "save the foreground masks" ,value = False )
1177
+ pre_depth_background_removal = gr .Checkbox (label = "pre-depth background removal" ,value = False )
1178
+
1160
1179
with gr .Box ():
1161
1180
gr .HTML ("Information, comment and share @ <a href='https://github.com/thygate/stable-diffusion-webui-depthmap-script'>https://github.com/thygate/stable-diffusion-webui-depthmap-script</a>" )
1162
1181
@@ -1231,6 +1250,10 @@ def on_ui_tabs():
1231
1250
clipthreshold_far ,
1232
1251
clipthreshold_near ,
1233
1252
inpaint ,
1253
+ background_removal_model ,
1254
+ background_removal ,
1255
+ pre_depth_background_removal ,
1256
+ save_background_removal_masks ,
1234
1257
vid_format ,
1235
1258
vid_ssaa
1236
1259
],
0 commit comments