Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scheduled eta and clamp_max #131

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions disco.py
Original file line number Diff line number Diff line change
Expand Up @@ -1331,8 +1331,9 @@ def do_run():
del init2

cur_t = None

t_int = 0
def cond_fn(x, t, y=None):
global t_int
with torch.enable_grad():
x_is_NaN = False
x = x.detach().requires_grad_()
Expand Down Expand Up @@ -1392,7 +1393,7 @@ def cond_fn(x, t, y=None):
grad = torch.zeros_like(x)
if args.clamp_grad and x_is_NaN == False:
magnitude = grad.square().mean().sqrt()
return grad * magnitude.clamp(max=args.clamp_max) / magnitude #min=-0.02, min=-clamp_max,
return grad * magnitude.clamp(max=args.clamp_max[1000-t_int] if type(args.clamp_max) is np.ndarray else args.clamp_max ) / magnitude #min=-0.02, min=-clamp_max,
return grad

if args.diffusion_sampling_mode == 'ddim':
Expand Down Expand Up @@ -1429,7 +1430,7 @@ def cond_fn(x, t, y=None):
skip_timesteps=skip_steps,
init_image=init,
randomize_class=randomize_class,
eta=eta,
eta=args.eta[1000-t_int] if type(args.eta) is np.ndarray else args.eta,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

really like this feature, can you provide a screenshot how it looks when this is intergrated?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's the results: https://imgur.com/a/bVGj5Lc

And here's the link to the custom notebook with this feature implemented:
https://colab.research.google.com/drive/173sJy8VmXM8d9mUhjQcnEFr8WckpXIsc?usp=sharing

transformation_fn=symmetry_transformation_fn,
transformation_percent=args.transformation_percent
)
Expand Down Expand Up @@ -2772,9 +2773,9 @@ def warp(frame1, frame2, flo_path, blend=0.5, weights_path=None):
perlin_init = False #@param{type: 'boolean'}
perlin_mode = 'mixed' #@param ['mixed', 'color', 'gray']
set_seed = 'random_seed' #@param{type: 'string'}
eta = 0.8 #@param{type: 'number'}
eta = [0.9, 0.1] #@param
clamp_grad = True #@param{type: 'boolean'}
clamp_max = 0.05 #@param{type: 'number'}
clamp_max = [0.1, 0.04] #@param


### EXTRA ADVANCED SETTINGS:
Expand Down Expand Up @@ -3017,9 +3018,9 @@ def move_files(start_num, end_num, old_folder, new_folder):
'perlin_init': perlin_init,
'perlin_mode': perlin_mode,
'set_seed': set_seed,
'eta': eta,
'eta': np.linspace(eta[0], eta[1], cutn_batches) if type(eta) is list else eta,
'clamp_grad': clamp_grad,
'clamp_max': clamp_max,
'clamp_max': np.linspace(clamp_max[0], clamp_max[1], 1000) if type(clamp_max) is list else clamp_max,
'skip_augs': skip_augs,
'randomize_class': randomize_class,
'clip_denoised': clip_denoised,
Expand Down