Skip to content

Commit 053b6ef

Browse files
committed
feat: enhance DeforumArgs and DeforumAnimArgs with new parameters and update initialization logic
1 parent d8f095b commit 053b6ef

File tree

4 files changed

+54
-32
lines changed

4 files changed

+54
-32
lines changed

deforum_sd/Dockerfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ RUN mkdir -p $WORKDIR
3333
WORKDIR $WORKDIR
3434

3535
# setup deforum environment
36-
RUN git clone --branch patch-1 https://github.com/devxpy/deforum-stable-diffusion.git
37-
RUN echo '' > deforum-stable-diffusion/src/k_diffusion/__init__.py
36+
RUN git clone https://github.com/deforum/deforum-stable-diffusion.git
3837

3938
# app dependencies
4039
RUN apt-get update && apt-get install -y --no-install-recommends \

deforum_sd/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def deforum(pipeline: PipelineInfo, inputs: deforum_script.DeforumAnimArgs):
1717
# init args
1818
args = deforum_script.DeforumArgs(batch_name=str(uuid.uuid1()))
1919
args.seed = pipeline.seed
20+
args.__dict__.update(inputs.args)
2021
if pipeline.scheduler:
2122
args.sampler = pipeline.scheduler
2223
anim_args = deforum_script.DeforumAnimArgs()

deforum_sd/deforum_script.py

Lines changed: 49 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import subprocess
55
import sys
66
import time
7-
from base64 import b64encode
87
from typing import Any
98
import gooey_gpu
109

@@ -33,6 +32,7 @@
3332
)
3433
from helpers.model_load import load_model, get_model_output_paths
3534
from helpers.aesthetics import load_aesthetics_model
35+
from helpers.prompts import Prompts
3636

3737

3838
# @markdown **Path Setup**
@@ -89,16 +89,20 @@ class DeforumAnimArgs(BaseModel):
8989
noise_schedule = "0: (0.02)" # @param {type:"string"}
9090
strength_schedule = "0: (0.65)" # @param {type:"string"}
9191
contrast_schedule = "0: (1.0)" # @param {type:"string"}
92-
hybrid_video_comp_alpha_schedule = "0:(1)" # @param {type:"string"}
93-
hybrid_video_comp_mask_blend_alpha_schedule = "0:(0.5)" # @param {type:"string"}
94-
hybrid_video_comp_mask_contrast_schedule = "0:(1)" # @param {type:"string"}
95-
hybrid_video_comp_mask_auto_contrast_cutoff_high_schedule = (
92+
hybrid_comp_alpha_schedule = "0:(1)" # @param {type:"string"}
93+
hybrid_comp_mask_blend_alpha_schedule = "0:(0.5)" # @param {type:"string"}
94+
hybrid_comp_mask_contrast_schedule = "0:(1)" # @param {type:"string"}
95+
hybrid_comp_mask_auto_contrast_cutoff_high_schedule = (
9696
"0:(100)" # @param {type:"string"}
9797
)
98-
hybrid_video_comp_mask_auto_contrast_cutoff_low_schedule = (
98+
hybrid_comp_mask_auto_contrast_cutoff_low_schedule = (
9999
"0:(0)" # @param {type:"string"}
100100
)
101101

102+
# @markdown ####**Sampler Scheduling:**
103+
enable_schedule_samplers = False # @param {type:"boolean"}
104+
sampler_schedule = "0:('euler'),10:('dpm2'),20:('dpm2_ancestral'),30:('heun'),40:('euler'),50:('euler_ancestral'),60:('dpm_fast'),70:('dpm_adaptive'),80:('dpmpp_2s_a'),90:('dpmpp_2m')" # @param {type:"string"}
105+
102106
# @markdown ####**Unsharp mask (anti-blur) Parameters:**
103107
kernel_schedule = "0: (5)" # @param {type:"string"}
104108
sigma_schedule = "0: (1.0)" # @param {type:"string"}
@@ -108,6 +112,7 @@ class DeforumAnimArgs(BaseModel):
108112
# @markdown ####**Coherence:**
109113
color_coherence = "Match Frame 0 LAB" # @param ['None', 'Match Frame 0 HSV', 'Match Frame 0 LAB', 'Match Frame 0 RGB', 'Video Input'] {type:'string'}
110114
color_coherence_video_every_N_frames = 1 # @param {type:"integer"}
115+
color_force_grayscale = False # @param {type:"boolean"}
111116
diffusion_cadence = "1" # @param ['1','2','3','4','5','6','7','8'] {type:'string'}
112117

113118
# @markdown ####**3D Depth Warping:**
@@ -130,25 +135,26 @@ class DeforumAnimArgs(BaseModel):
130135
video_mask_path = "/content/video_in.mp4" # @param {type:"string"}
131136

132137
# @markdown ####**Hybrid Video for 2D/3D Animation Mode:**
133-
hybrid_video_generate_inputframes = False # @param {type:"boolean"}
134-
hybrid_video_use_first_frame_as_init_image = True # @param {type:"boolean"}
135-
hybrid_video_motion = (
136-
"None" # @param ['None','Optical Flow','Perspective','Affine']
138+
hybrid_generate_inputframes = False # @param {type:"boolean"}
139+
hybrid_use_first_frame_as_init_image = True # @param {type:"boolean"}
140+
hybrid_motion = "None" # @param ['None','Optical Flow','Perspective','Affine']
141+
hybrid_motion_use_prev_img = False # @param {type:"boolean"}
142+
hybrid_flow_method = (
143+
"DIS Medium" # @param ['DenseRLOF','DIS Medium','Farneback','SF']
137144
)
138-
hybrid_video_flow_method = "Farneback" # @param ['Farneback','DenseRLOF','SF']
139-
hybrid_video_composite = False # @param {type:"boolean"}
140-
hybrid_video_comp_mask_type = (
145+
hybrid_composite = False # @param {type:"boolean"}
146+
hybrid_comp_mask_type = (
141147
"None" # @param ['None', 'Depth', 'Video Depth', 'Blend', 'Difference']
142148
)
143-
hybrid_video_comp_mask_inverse = False # @param {type:"boolean"}
144-
hybrid_video_comp_mask_equalize = "None" # @param ['None','Before','After','Both']
145-
hybrid_video_comp_mask_auto_contrast = False # @param {type:"boolean"}
146-
hybrid_video_comp_save_extra_frames = False # @param {type:"boolean"}
147-
hybrid_video_use_video_as_mse_image = False # @param {type:"boolean"}
149+
hybrid_comp_mask_inverse = False # @param {type:"boolean"}
150+
hybrid_comp_mask_equalize = "None" # @param ['None','Before','After','Both']
151+
hybrid_comp_mask_auto_contrast = False # @param {type:"boolean"}
152+
hybrid_comp_save_extra_frames = False # @param {type:"boolean"}
153+
hybrid_use_video_as_mse_image = False # @param {type:"boolean"}
148154

149155
# @markdown ####**Interpolation:**
150156
interpolate_key_frames = False # @param {type:"boolean"}
151-
interpolate_x_frames = 4 # @param {type:"number"}
157+
interpolate_x_frames = 20 # @param {type:"number"}
152158

153159
# @markdown ####**Resume Animation:**
154160
resume_from_timestring = False # @param {type:"boolean"}
@@ -157,6 +163,9 @@ class DeforumAnimArgs(BaseModel):
157163
prompts = []
158164

159165
animation_prompts = {}
166+
neg_animation_prompts = {}
167+
168+
args = {}
160169

161170

162171
# @markdown **Load Settings**
@@ -195,7 +204,8 @@ class DeforumArgs:
195204

196205
# @markdown **Batch Settings**
197206
n_batch = 1 # @param
198-
# batch_name = "StableFun" # @param {type:"string"}
207+
n_samples = 1 # @param
208+
batch_name = "StableFun" # @param {type:"string"}
199209
filename_format = "{timestring}_{index}_{prompt}.png" # @param ["{timestring}_{index}_{seed}.png","{timestring}_{index}_{prompt}.png"]
200210
seed_behavior = "iter" # @param ["iter","fixed","random","ladder","alternate"]
201211
seed_iter_N = 1 # @param {type:'integer'}
@@ -204,11 +214,13 @@ class DeforumArgs:
204214

205215
# @markdown **Init Settings**
206216
use_init = False # @param {type:"boolean"}
207-
strength = 0.1 # @param {type:"number"}
217+
strength = 0.65 # @param {type:"number"}
208218
strength_0_no_init = (
209219
True # Set the strength to 0 automatically when no init image is used
210220
)
211221
init_image = "https://cdn.pixabay.com/photo/2022/07/30/13/10/green-longhorn-beetle-7353749_1280.jpg" # @param {type:"string"}
222+
add_init_noise = False # @param {type:"boolean"}
223+
init_noise = 0.01 # @param
212224
# Whiter areas of the mask are areas that change more
213225
use_mask = False # @param {type:"boolean"}
214226
use_alpha_as_mask = False # use the alpha channel of the init image as the mask
@@ -262,12 +274,15 @@ class DeforumArgs:
262274
# @markdown **Speed vs VRAM Settings**
263275
cond_uncond_sync = True # @param {type:"boolean"}
264276

265-
n_samples = 1 # doesnt do anything
266277
precision = "autocast"
267278
C = 4
268279
f = 8
269280

270281
prompt = ""
282+
cond_prompt = ""
283+
cond_prompts = ""
284+
uncond_prompt = ""
285+
uncond_prompts = ""
271286
timestring = ""
272287
init_latent = None
273288
init_sample = None
@@ -310,7 +325,7 @@ def run(root: Root, args: DeforumArgs, anim_args: DeforumAnimArgs):
310325
if not args.use_init:
311326
args.init_image = None
312327
if args.sampler == "plms" and (args.use_init or anim_args.animation_mode != "None"):
313-
print(f"Init images aren't supported with PLMS yet, switching to KLMS")
328+
print("Init images aren't supported with PLMS yet, switching to KLMS")
314329
args.sampler = "klms"
315330
if args.sampler != "ddim":
316331
args.ddim_eta = 0
@@ -324,15 +339,20 @@ def run(root: Root, args: DeforumArgs, anim_args: DeforumAnimArgs):
324339
gc.collect()
325340
torch.cuda.empty_cache()
326341

342+
# get prompts
343+
cond, uncond = Prompts(
344+
prompt=anim_args.animation_prompts, neg_prompt=anim_args.neg_animation_prompts
345+
).as_dict()
346+
327347
# dispatch to appropriate renderer
328348
if anim_args.animation_mode == "2D" or anim_args.animation_mode == "3D":
329-
render_animation(args, anim_args, anim_args.animation_prompts, root)
349+
render_animation(root, anim_args, args, cond, uncond)
330350
elif anim_args.animation_mode == "Video Input":
331-
render_input_video(args, anim_args, anim_args.animation_prompts, root)
351+
render_input_video(root, anim_args, args, cond, uncond)
332352
elif anim_args.animation_mode == "Interpolation":
333-
render_interpolation(args, anim_args, anim_args.animation_prompts, root)
353+
render_interpolation(root, anim_args, args, cond, uncond)
334354
else:
335-
render_image_batch(args, anim_args.prompts, root)
355+
render_image_batch(root, anim_args, args, cond, uncond)
336356

337357

338358
def create_video(args: DeforumArgs, anim_args: DeforumAnimArgs):
@@ -344,10 +364,10 @@ def create_video(args: DeforumArgs, anim_args: DeforumAnimArgs):
344364
# mp4_path = "/content/drive/MyDrive/AI/StableDiffusion/2023-01/StableFun/20230101212135.mp4" # @param {type:"string"}
345365
render_steps = False # @param {type: 'boolean'}
346366
path_name_modifier = "x0_pred" # @param ["x0_pred","x"]
347-
make_gif = False
367+
# make_gif = False # Currently unused
348368
bitdepth_extension = "exr" if args.bit_depth_output == 32 else "png"
349369

350-
if skip_video_for_run_all == True:
370+
if skip_video_for_run_all:
351371
print(
352372
"Skipping video creation, uncheck skip_video_for_run_all if you want to run it"
353373
)

deforum_sd/requirements.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ torchvision==0.14.1+cu116
1212
torchaudio==0.13.1+cu116
1313

1414
## xformers
15+
--extra-index-url https://pypi.python.org/simple/
1516
xformers==0.0.16
16-
triton==2.0.0.dev20221202
17+
triton==2.0.0
1718

1819
## huggingface diffusers
1920
diffusers ~= 0.15.0
@@ -46,3 +47,4 @@ torchsde ~= 0.2.5
4647
open-clip-torch ~= 2.10.1
4748
numpngw ~= 0.1.2
4849
ipython ~= 8.9.0
50+
clean-fid ~= 0.1.35

0 commit comments

Comments
 (0)