SingleZombie
commited on
Commit
·
9fd841c
1
Parent(s):
ff715ca
update app
Browse files- webUI.py → app.py +43 -11
webUI.py → app.py
RENAMED
@@ -35,6 +35,34 @@ from annotator.hed import HEDdetector
|
|
35 |
from annotator.canny import CannyDetector
|
36 |
from annotator.midas import MidasDetector
|
37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
def get_models(config):
|
40 |
# optical flow
|
@@ -45,7 +73,7 @@ def get_models(config):
|
|
45 |
attention_type='swin',
|
46 |
ffn_dim_expansion=4,
|
47 |
num_transformer_layers=6,
|
48 |
-
).to(
|
49 |
|
50 |
checkpoint = torch.load(
|
51 |
config['gmflow_path'], map_location=lambda storage, loc: storage)
|
@@ -56,14 +84,14 @@ def get_models(config):
|
|
56 |
# saliency detection
|
57 |
sod_model = build_model('resnet')
|
58 |
sod_model.load_state_dict(torch.load(config['sod_path']))
|
59 |
-
sod_model.to(
|
60 |
|
61 |
# controlnet
|
62 |
if config['controlnet_type'] not in ['hed', 'depth', 'canny']:
|
63 |
config['controlnet_type'] = 'hed'
|
64 |
controlnet = ControlNetModel.from_pretrained("lllyasviel/sd-controlnet-"+config['controlnet_type'],
|
65 |
torch_dtype=torch.float16)
|
66 |
-
controlnet.to(
|
67 |
if config['controlnet_type'] == 'depth':
|
68 |
detector = MidasDetector()
|
69 |
elif config['controlnet_type'] == 'canny':
|
@@ -77,7 +105,7 @@ def get_models(config):
|
|
77 |
pipe = StableDiffusionPipeline.from_pretrained(
|
78 |
config['sd_path'], vae=vae, torch_dtype=torch.float16)
|
79 |
pipe.scheduler = DDPMScheduler.from_config(pipe.scheduler.config)
|
80 |
-
pipe.to(
|
81 |
pipe.scheduler.set_timesteps(
|
82 |
config['num_inference_steps'], device=pipe._execution_device)
|
83 |
|
@@ -168,14 +196,15 @@ class GlobalState:
|
|
168 |
self.control_type = control_type
|
169 |
self.controlnet = ControlNetModel.from_pretrained("lllyasviel/sd-controlnet-"+control_type,
|
170 |
torch_dtype=torch.float16)
|
171 |
-
self.controlnet.to(
|
172 |
if control_type == 'depth':
|
173 |
self.detector = MidasDetector()
|
174 |
elif control_type == 'canny':
|
175 |
self.detector = CannyDetector()
|
176 |
else:
|
177 |
self.detector = HEDdetector()
|
178 |
-
|
|
|
179 |
for param in self.controlnet.parameters():
|
180 |
param.requires_grad = False
|
181 |
|
@@ -189,10 +218,11 @@ class GlobalState:
|
|
189 |
sd_model, vae=vae, torch_dtype=torch.float16)
|
190 |
self.pipe.scheduler = DDPMScheduler.from_config(
|
191 |
self.pipe.scheduler.config)
|
192 |
-
self.pipe.to(
|
193 |
self.frescoProc = apply_FRESCO_attn(self.pipe)
|
194 |
self.frescoProc.controller.disable_controller()
|
195 |
-
|
|
|
196 |
for param in self.pipe.unet.parameters():
|
197 |
param.requires_grad = False
|
198 |
|
@@ -291,7 +321,7 @@ def process1(input_path, prompt, sd_model, seed, image_resolution, control_stren
|
|
291 |
|
292 |
edges = torch.cat([numpy2tensor(apply_control(img,
|
293 |
global_state.detector, control_type)[:, :, None]) for img in imgs], dim=0)
|
294 |
-
edges = edges.repeat(1, 3, 1, 1).
|
295 |
edges = torch.cat([edges.to(global_state.pipe.unet.dtype)] * 2)
|
296 |
|
297 |
if bg_smooth:
|
@@ -326,7 +356,8 @@ def process1(input_path, prompt, sd_model, seed, image_resolution, control_stren
|
|
326 |
saliency=saliency, optimize_temporal=optimize_temporal)
|
327 |
|
328 |
gc.collect()
|
329 |
-
|
|
|
330 |
|
331 |
# run!
|
332 |
latents = inference(global_state.pipe, global_state.controlnet, global_state.frescoProc,
|
@@ -354,7 +385,8 @@ def process1(input_path, prompt, sd_model, seed, image_resolution, control_stren
|
|
354 |
propagation_mode = batch_ind > 0
|
355 |
if batch_ind == len(sublists):
|
356 |
gc.collect()
|
357 |
-
|
|
|
358 |
break
|
359 |
|
360 |
writer = imageio.get_writer(os.path.join(save_path, 'key.mp4'), fps=fps)
|
|
|
35 |
from annotator.canny import CannyDetector
|
36 |
from annotator.midas import MidasDetector
|
37 |
|
38 |
+
import huggingface_hub
|
39 |
+
|
40 |
+
huggingface_hub.hf_hub_download('SingleZombie/FRESCO',
|
41 |
+
'boxer-punching-towards-camera.mp4',
|
42 |
+
local_dir='data')
|
43 |
+
huggingface_hub.hf_hub_download('SingleZombie/FRESCO',
|
44 |
+
'car-turn.mp4',
|
45 |
+
local_dir='data')
|
46 |
+
huggingface_hub.hf_hub_download('SingleZombie/FRESCO',
|
47 |
+
'dog.mp4',
|
48 |
+
local_dir='data')
|
49 |
+
huggingface_hub.hf_hub_download('SingleZombie/FRESCO',
|
50 |
+
'music.mp4',
|
51 |
+
local_dir='data')
|
52 |
+
|
53 |
+
huggingface_hub.hf_hub_download('PKUWilliamYang/Rerender',
|
54 |
+
'gmflow_sintel-0c07dcb3.pth',
|
55 |
+
local_dir='model')
|
56 |
+
|
57 |
+
huggingface_hub.hf_hub_download('PKUWilliamYang/Rerender',
|
58 |
+
'epoch_resnet.pth',
|
59 |
+
local_dir='model')
|
60 |
+
|
61 |
+
huggingface_hub.hf_hub_download('PKUWilliamYang/Rerender',
|
62 |
+
'ebsynth',
|
63 |
+
local_dir='src/ebsynth/deps/ebsynth/bin')
|
64 |
+
|
65 |
+
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
66 |
|
67 |
def get_models(config):
|
68 |
# optical flow
|
|
|
73 |
attention_type='swin',
|
74 |
ffn_dim_expansion=4,
|
75 |
num_transformer_layers=6,
|
76 |
+
).to(device)
|
77 |
|
78 |
checkpoint = torch.load(
|
79 |
config['gmflow_path'], map_location=lambda storage, loc: storage)
|
|
|
84 |
# saliency detection
|
85 |
sod_model = build_model('resnet')
|
86 |
sod_model.load_state_dict(torch.load(config['sod_path']))
|
87 |
+
sod_model.to(device).eval()
|
88 |
|
89 |
# controlnet
|
90 |
if config['controlnet_type'] not in ['hed', 'depth', 'canny']:
|
91 |
config['controlnet_type'] = 'hed'
|
92 |
controlnet = ControlNetModel.from_pretrained("lllyasviel/sd-controlnet-"+config['controlnet_type'],
|
93 |
torch_dtype=torch.float16)
|
94 |
+
controlnet.to(device)
|
95 |
if config['controlnet_type'] == 'depth':
|
96 |
detector = MidasDetector()
|
97 |
elif config['controlnet_type'] == 'canny':
|
|
|
105 |
pipe = StableDiffusionPipeline.from_pretrained(
|
106 |
config['sd_path'], vae=vae, torch_dtype=torch.float16)
|
107 |
pipe.scheduler = DDPMScheduler.from_config(pipe.scheduler.config)
|
108 |
+
pipe.to(device)
|
109 |
pipe.scheduler.set_timesteps(
|
110 |
config['num_inference_steps'], device=pipe._execution_device)
|
111 |
|
|
|
196 |
self.control_type = control_type
|
197 |
self.controlnet = ControlNetModel.from_pretrained("lllyasviel/sd-controlnet-"+control_type,
|
198 |
torch_dtype=torch.float16)
|
199 |
+
self.controlnet.to(device)
|
200 |
if control_type == 'depth':
|
201 |
self.detector = MidasDetector()
|
202 |
elif control_type == 'canny':
|
203 |
self.detector = CannyDetector()
|
204 |
else:
|
205 |
self.detector = HEDdetector()
|
206 |
+
if device == 'cuda':
|
207 |
+
torch.cuda.empty_cache()
|
208 |
for param in self.controlnet.parameters():
|
209 |
param.requires_grad = False
|
210 |
|
|
|
218 |
sd_model, vae=vae, torch_dtype=torch.float16)
|
219 |
self.pipe.scheduler = DDPMScheduler.from_config(
|
220 |
self.pipe.scheduler.config)
|
221 |
+
self.pipe.to(device)
|
222 |
self.frescoProc = apply_FRESCO_attn(self.pipe)
|
223 |
self.frescoProc.controller.disable_controller()
|
224 |
+
if device == 'cuda':
|
225 |
+
torch.cuda.empty_cache()
|
226 |
for param in self.pipe.unet.parameters():
|
227 |
param.requires_grad = False
|
228 |
|
|
|
321 |
|
322 |
edges = torch.cat([numpy2tensor(apply_control(img,
|
323 |
global_state.detector, control_type)[:, :, None]) for img in imgs], dim=0)
|
324 |
+
edges = edges.repeat(1, 3, 1, 1).to(device) * 0.5 + 0.5
|
325 |
edges = torch.cat([edges.to(global_state.pipe.unet.dtype)] * 2)
|
326 |
|
327 |
if bg_smooth:
|
|
|
356 |
saliency=saliency, optimize_temporal=optimize_temporal)
|
357 |
|
358 |
gc.collect()
|
359 |
+
if device == 'cuda':
|
360 |
+
torch.cuda.empty_cache()
|
361 |
|
362 |
# run!
|
363 |
latents = inference(global_state.pipe, global_state.controlnet, global_state.frescoProc,
|
|
|
385 |
propagation_mode = batch_ind > 0
|
386 |
if batch_ind == len(sublists):
|
387 |
gc.collect()
|
388 |
+
if device == 'cuda':
|
389 |
+
torch.cuda.empty_cache()
|
390 |
break
|
391 |
|
392 |
writer = imageio.get_writer(os.path.join(save_path, 'key.mp4'), fps=fps)
|