lemonaddie
commited on
Commit
•
463b37d
1
Parent(s):
0c69724
Update app2.py
Browse files
app2.py
CHANGED
@@ -31,7 +31,7 @@ import sys
|
|
31 |
sys.path.append("../")
|
32 |
from models.depth_normal_pipeline_clip import DepthNormalEstimationPipeline
|
33 |
#from models.depth_normal_pipeline_clip_cfg import DepthNormalEstimationPipeline
|
34 |
-
|
35 |
from utils.seed_all import seed_all
|
36 |
import matplotlib.pyplot as plt
|
37 |
from utils.de_normalized import align_scale_shift
|
@@ -56,13 +56,20 @@ image_encoder = CLIPVisionModelWithProjection.from_pretrained(sd_image_variation
|
|
56 |
feature_extractor = CLIPImageProcessor.from_pretrained(sd_image_variations_diffusers_path, subfolder="feature_extractor")
|
57 |
|
58 |
unet = UNet2DConditionModel.from_pretrained('./wocfg/unet_ema')
|
59 |
-
|
60 |
|
61 |
pipe = DepthNormalEstimationPipeline(vae=vae,
|
62 |
image_encoder=image_encoder,
|
63 |
feature_extractor=feature_extractor,
|
64 |
unet=unet,
|
65 |
scheduler=scheduler)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
|
67 |
try:
|
68 |
import xformers
|
@@ -78,20 +85,34 @@ def depth_normal(img,
|
|
78 |
denoising_steps,
|
79 |
ensemble_size,
|
80 |
processing_res,
|
81 |
-
|
82 |
domain):
|
83 |
|
84 |
#img = img.resize((processing_res, processing_res), Image.Resampling.LANCZOS)
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
|
96 |
depth_colored = pipe_out.depth_colored
|
97 |
normal_colored = pipe_out.normal_colored
|
@@ -152,13 +173,13 @@ def run_demo():
|
|
152 |
label="Data Type (Must Select One matches your image)",
|
153 |
value="indoor",
|
154 |
)
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
denoising_steps = gr.Slider(
|
163 |
label="Number of denoising steps (More stepes, better quality)",
|
164 |
minimum=1,
|
@@ -195,7 +216,7 @@ def run_demo():
|
|
195 |
inputs=[input_image, denoising_steps,
|
196 |
ensemble_size,
|
197 |
processing_res,
|
198 |
-
|
199 |
domain],
|
200 |
outputs=[depth, normal]
|
201 |
)
|
|
|
31 |
sys.path.append("../")
|
32 |
from models.depth_normal_pipeline_clip import DepthNormalEstimationPipeline
|
33 |
#from models.depth_normal_pipeline_clip_cfg import DepthNormalEstimationPipeline
|
34 |
+
from models.depth_normal_pipeline_clip_cfg_1 import DepthNormalEstimationPipeline as DepthNormalEstimationPipelineCFG
|
35 |
from utils.seed_all import seed_all
|
36 |
import matplotlib.pyplot as plt
|
37 |
from utils.de_normalized import align_scale_shift
|
|
|
56 |
feature_extractor = CLIPImageProcessor.from_pretrained(sd_image_variations_diffusers_path, subfolder="feature_extractor")
|
57 |
|
58 |
unet = UNet2DConditionModel.from_pretrained('./wocfg/unet_ema')
|
59 |
+
unet_cfg = UNet2DConditionModel.from_pretrained('./cfg/unet_ema')
|
60 |
|
61 |
pipe = DepthNormalEstimationPipeline(vae=vae,
|
62 |
image_encoder=image_encoder,
|
63 |
feature_extractor=feature_extractor,
|
64 |
unet=unet,
|
65 |
scheduler=scheduler)
|
66 |
+
|
67 |
+
pipe_cfg = DepthNormalEstimationPipelineCFG(vae=vae,
|
68 |
+
image_encoder=image_encoder,
|
69 |
+
feature_extractor=feature_extractor,
|
70 |
+
unet=unet_cfg,
|
71 |
+
scheduler=scheduler)
|
72 |
+
|
73 |
|
74 |
try:
|
75 |
import xformers
|
|
|
85 |
denoising_steps,
|
86 |
ensemble_size,
|
87 |
processing_res,
|
88 |
+
guidance_scale,
|
89 |
domain):
|
90 |
|
91 |
#img = img.resize((processing_res, processing_res), Image.Resampling.LANCZOS)
|
92 |
+
|
93 |
+
if guidance_scale > 0:
|
94 |
+
pipe_out = pipe_cfg(
|
95 |
+
img,
|
96 |
+
denoising_steps=denoising_steps,
|
97 |
+
ensemble_size=ensemble_size,
|
98 |
+
processing_res=processing_res,
|
99 |
+
batch_size=0,
|
100 |
+
guidance_scale=guidance_scale,
|
101 |
+
domain=domain,
|
102 |
+
show_progress_bar=True,
|
103 |
+
)
|
104 |
+
|
105 |
+
else:
|
106 |
+
pipe_out = pipe(
|
107 |
+
img,
|
108 |
+
denoising_steps=denoising_steps,
|
109 |
+
ensemble_size=ensemble_size,
|
110 |
+
processing_res=processing_res,
|
111 |
+
batch_size=0,
|
112 |
+
#guidance_scale=guidance_scale,
|
113 |
+
domain=domain,
|
114 |
+
show_progress_bar=True,
|
115 |
+
)
|
116 |
|
117 |
depth_colored = pipe_out.depth_colored
|
118 |
normal_colored = pipe_out.normal_colored
|
|
|
173 |
label="Data Type (Must Select One matches your image)",
|
174 |
value="indoor",
|
175 |
)
|
176 |
+
guidance_scale = gr.Slider(
|
177 |
+
label="Classifier Free Guidance Scale, 0 for without guidance",
|
178 |
+
minimum=0,
|
179 |
+
maximum=5,
|
180 |
+
step=1,
|
181 |
+
value=0,
|
182 |
+
)
|
183 |
denoising_steps = gr.Slider(
|
184 |
label="Number of denoising steps (More stepes, better quality)",
|
185 |
minimum=1,
|
|
|
216 |
inputs=[input_image, denoising_steps,
|
217 |
ensemble_size,
|
218 |
processing_res,
|
219 |
+
guidance_scale,
|
220 |
domain],
|
221 |
outputs=[depth, normal]
|
222 |
)
|