From 5021e71ae3c1a593e07a3e7f38e1815fe4e86d86 Mon Sep 17 00:00:00 2001 From: Felix B Date: Tue, 19 Apr 2022 19:20:08 +0200 Subject: [PATCH 1/2] Included an optional cut schedule generator Optional generator for more flexible cut_overview and cut_innercut schedules: Min/Max control the respective minimum and maximum values of cut_overview and cut_innercut Delay values delay the scaling of cut_overview and cut_innercut for the first x normalized steps Bias values values allow to shift the middle point of the respective cut_curve --- disco.py | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 75 insertions(+), 4 deletions(-) diff --git a/disco.py b/disco.py index 9dd35984..125399b2 100644 --- a/disco.py +++ b/disco.py @@ -2305,19 +2305,90 @@ def split_prompts(prompts): rand_mag = 0.05 - #@markdown --- - -#@markdown ####**Cutn Scheduling:** -#@markdown Format: `[40]*400+[20]*600` = 40 cuts for the first 400 /1000 steps, then 20 for the last 600/1000 +#@markdown --- +#@markdown ####**Cutn Schedule Generator:** +# Cutn schedule generator +#@markdown Min/Max control the respective minimum and maximum values of cut_overview and cut_innercut +#@markdown Delay values delay the scaling of cut_overview and cut_innercut for the first x normalized steps +#@markdown Bias values values allow to shift the middle point of the respective cut_curve + +use_schedule_gen = True #@param{type: 'boolean'} +def cutnschedule(cut_overview_max, cut_innercut_max, cut_overview_min, cut_overview_delay, cut_innercut_delay, overview_end_bias, inner_start_bias): + # Overview + overview_truemid = int(cut_overview_max * 0.5) + overview_end_bias = 1000 - overview_end_bias + cut_overview = np.linspace(cut_overview_max, cut_overview_max, (cut_overview_delay), dtype='int').tolist() + cut_overview += np.linspace(cut_overview_max+1, overview_truemid, (1000-cut_overview_delay-overview_end_bias)+1, dtype='int').tolist() + del cut_overview[cut_overview_delay] + cut_overview += np.linspace(cut_overview[-1], cut_overview_min, overview_end_bias+1, dtype='int').tolist()[1:] + # Inner + inner_truemid = int(cut_innercut_max * 0.5) + cut_innercut = np.linspace(cut_innercut_max+1, inner_truemid, 1000-cut_innercut_delay-inner_start_bias+1, dtype='int').tolist() + del cut_innercut[0] + cut_innercut += np.linspace(cut_innercut[-1], cut_innercut_min, inner_start_bias+1, dtype='int').tolist()[1:] + cut_innercut += np.linspace(cut_innercut_min, cut_innercut_min, (cut_innercut_delay), dtype='int').tolist() + cut_innercut.reverse() + return (cut_overview, cut_innercut) + + +cut_overview_max = 14 #@param{type: 'number'} +cut_overview_min = 4 #@param{type: 'number'} +cut_innercut_max = 14 #@param{type: 'number'} +cut_innercut_min = 2 #@param{type: 'number'} +cut_overview_delay = 75 #@param{type: 'number'} +cut_innercut_delay = 50 #@param{type: 'number'} +overview_end_bias = 400 #@param{type: 'number'} +inner_start_bias = 400 #@param{type: 'number'} + + +#@markdown ####**Manual Cutn Scheduling:** +#@markdown Format: `[4]*400+[12]*600` = 4 cuts for the first 400 /1000 steps, then 12 for the last 600/1000 #@markdown cut_overview and cut_innercut are cumulative for total cutn on any given step. Overview cuts see the entire image and are good for early structure, innercuts are your standard cutn. +#@markdown ####**Manual Cutn Scheduling:** +#@markdown Format: `[4]*400+[12]*600` = 4 cuts for the first 400 /1000 steps, then 12 for the last 600/1000 +#@markdown cut_overview and cut_innercut are cumulative for total cutn on any given step. Overview cuts see the entire image and are good for early structure, innercuts are your standard cutn. cut_overview = "[12]*400+[4]*600" #@param {type: 'string'} cut_innercut ="[4]*400+[12]*600"#@param {type: 'string'} cut_ic_pow = 1#@param {type: 'number'} cut_icgray_p = "[0.2]*400+[0]*600"#@param {type: 'string'} + +if use_schedule_gen == True: + cut_overview, cut_innercut = cutnschedule(cut_overview_max=cut_overview_max, cut_innercut_max=cut_innercut_max, cut_overview_min=cut_overview_min, cut_overview_delay=cut_overview_delay, cut_innercut_delay=cut_innercut_delay, overview_end_bias = overview_end_bias, inner_start_bias = inner_start_bias) + +print(f'Cut_overview: {cut_overview}') +print(f'Cut:Innercut: {cut_innercut}') + +%matplotlib inline +import matplotlib.patches as mpatches +x = np.linspace(0, 1000, 1000, dtype='int') +fig, ax = plt.subplots(figsize=(6.5, 3.7)) +overview_plot = ax.plot(x, cut_overview, color='black', label='cut_overview') +innercut_plot = ax.plot(x, cut_innercut, color='red', label='cut_innercut') +black_patch = mpatches.Patch(color='black', label='cut_overview') +red_patch = mpatches.Patch(color='red', label='cut_innercut') +ax.legend(handles=[black_patch,red_patch]) +ax.set_xlabel('Steps') +ax.set_ylabel('Cuts') + + +cut_string = "" +inner_string = "" +for i in range(len(cut_overview)): + if i < len(cut_overview)-1: + cut_string += "["+str(cut_overview[i])+"]*1+" + inner_string += "["+str(cut_innercut[i])+"]*1+" + else: + cut_string += "["+str(cut_overview[i])+"]*1" + inner_string += "["+str(cut_innercut[i])+"]*1" + cut_overview = cut_string + cut_innercut = inner_string + + + # %% # !! {"metadata": { # !! "id": "PromptsTop" From c8e3edff39c403469b17bff4b0b1c2acbcbb693f Mon Sep 17 00:00:00 2001 From: Felix B Date: Sat, 23 Apr 2022 11:58:26 +0100 Subject: [PATCH 2/2] Updated cut_overview and cut_innercut schedule generator Updated cut schedule generator for more flexible cut_overview and cut_innercut schedules: --- disco.py | 128 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 76 insertions(+), 52 deletions(-) diff --git a/disco.py b/disco.py index 125399b2..3c90b090 100644 --- a/disco.py +++ b/disco.py @@ -2307,85 +2307,109 @@ def split_prompts(prompts): #@markdown --- -#@markdown ####**Cutn Schedule Generator:** -# Cutn schedule generator -#@markdown Min/Max control the respective minimum and maximum values of cut_overview and cut_innercut -#@markdown Delay values delay the scaling of cut_overview and cut_innercut for the first x normalized steps -#@markdown Bias values values allow to shift the middle point of the respective cut_curve - -use_schedule_gen = True #@param{type: 'boolean'} -def cutnschedule(cut_overview_max, cut_innercut_max, cut_overview_min, cut_overview_delay, cut_innercut_delay, overview_end_bias, inner_start_bias): + +#@markdown ####**Cutn Schedule Generator** +def cutnschedule(cut_overview_max, cut_innercut_max, cut_overview_min, cut_overview_delay, cut_innercut_delay, overview_bias, inner_bias): + import numpy as np # Overview overview_truemid = int(cut_overview_max * 0.5) - overview_end_bias = 1000 - overview_end_bias - cut_overview = np.linspace(cut_overview_max, cut_overview_max, (cut_overview_delay), dtype='int').tolist() - cut_overview += np.linspace(cut_overview_max+1, overview_truemid, (1000-cut_overview_delay-overview_end_bias)+1, dtype='int').tolist() - del cut_overview[cut_overview_delay] - cut_overview += np.linspace(cut_overview[-1], cut_overview_min, overview_end_bias+1, dtype='int').tolist()[1:] + if overview_bias != 0: + overview_bias = 1000 - overview_bias + cut_overview = np.linspace(cut_overview_max, cut_overview_max, (cut_overview_delay), dtype='int').tolist() + cut_overview += np.linspace(cut_overview_max+1, overview_truemid, (1000-cut_overview_delay-overview_bias)+1, dtype='int').tolist() + del cut_overview[cut_overview_delay] + cut_overview += np.linspace(cut_overview[-1], cut_overview_min, overview_bias+1, dtype='int').tolist()[1:] + else: + cut_overview = np.linspace(cut_overview_max, cut_overview_max, cut_overview_delay, dtype='int').tolist() + cut_overview += np.linspace(cut_overview[-1], cut_overview_min, (1000-cut_overview_delay)+1, dtype='int').tolist() + del cut_overview[cut_overview_delay] # Inner inner_truemid = int(cut_innercut_max * 0.5) - cut_innercut = np.linspace(cut_innercut_max+1, inner_truemid, 1000-cut_innercut_delay-inner_start_bias+1, dtype='int').tolist() - del cut_innercut[0] - cut_innercut += np.linspace(cut_innercut[-1], cut_innercut_min, inner_start_bias+1, dtype='int').tolist()[1:] - cut_innercut += np.linspace(cut_innercut_min, cut_innercut_min, (cut_innercut_delay), dtype='int').tolist() - cut_innercut.reverse() + if inner_bias != 0: + cut_innercut = np.linspace(cut_innercut_max+1, inner_truemid, 1000-cut_innercut_delay-inner_bias+1, dtype='int').tolist() + del cut_innercut[0] + cut_innercut += np.linspace(cut_innercut[-1], cut_innercut_min, inner_bias+1, dtype='int').tolist()[1:] + cut_innercut += np.linspace(cut_innercut_min, cut_innercut_min, cut_innercut_delay, dtype='int').tolist() + else: + cut_innercut = np.linspace(cut_innercut_max+1, cut_innercut_min+1, (1000-cut_innercut_delay)+1, dtype='int').tolist() + cut_innercut += np.linspace(cut_innercut_min, cut_innercut_min, cut_innercut_delay, dtype='int').tolist() + del cut_innercut[0] + cut_innercut.reverse() return (cut_overview, cut_innercut) + + +#@markdown cut_overview_max and cut_innercut_max: Maximum value of cut_overview and cut_innercut + +#@markdown cut_overview_min and cut_innercut_min: Minimum value of cut_overview and cut_innercut -cut_overview_max = 14 #@param{type: 'number'} -cut_overview_min = 4 #@param{type: 'number'} -cut_innercut_max = 14 #@param{type: 'number'} -cut_innercut_min = 2 #@param{type: 'number'} -cut_overview_delay = 75 #@param{type: 'number'} -cut_innercut_delay = 50 #@param{type: 'number'} -overview_end_bias = 400 #@param{type: 'number'} -inner_start_bias = 400 #@param{type: 'number'} +#@markdown cut_overview_delay and cut_innercut_delay: Delay the initial scalings +#@markdown overview_bias and inner_bias: Minimum value of 100. Introduces assymetry to the scaling + +#@markdown use_schedule_gen: Overrides standard Cutn Scheduling if ticked + +cut_overview_max = 12 #@param{type: 'number'} +cut_overview_min = 4 #@param{type: 'number'} +cut_innercut_max = 12 #@param{type: 'number'} +cut_innercut_min = 4 #@param{type: 'number'} +cut_overview_delay = 200 #@param{type: 'number'} +cut_innercut_delay = 200 #@param{type: 'number'} +overview_bias = 0 #@param{type: 'number'} +inner_bias = 0 #@param{type: 'number'} +use_schedule_gen = True #@param{type: 'boolean'} -#@markdown ####**Manual Cutn Scheduling:** -#@markdown Format: `[4]*400+[12]*600` = 4 cuts for the first 400 /1000 steps, then 12 for the last 600/1000 +#@markdown --- +#@markdown ####**Cutn Scheduling** +#@markdown ####**OVERRIDEN BY GENERATOR IF use_schedule_gen is ticked** +#@markdown Format: `[40]*400+[20]*600` = 40 cuts for the first 400 /1000 steps, then 20 for the last 600/1000 #@markdown cut_overview and cut_innercut are cumulative for total cutn on any given step. Overview cuts see the entire image and are good for early structure, innercuts are your standard cutn. -#@markdown ####**Manual Cutn Scheduling:** -#@markdown Format: `[4]*400+[12]*600` = 4 cuts for the first 400 /1000 steps, then 12 for the last 600/1000 -#@markdown cut_overview and cut_innercut are cumulative for total cutn on any given step. Overview cuts see the entire image and are good for early structure, innercuts are your standard cutn. cut_overview = "[12]*400+[4]*600" #@param {type: 'string'} -cut_innercut ="[4]*400+[12]*600"#@param {type: 'string'} +cut_innercut ="[4]*400+[12]*600"#@param {type: 'string'} + +#@markdown --- + +#@markdown ####**cut_ic_pow and cut_icgray_p Scheduling** cut_ic_pow = 1#@param {type: 'number'} cut_icgray_p = "[0.2]*400+[0]*600"#@param {type: 'string'} - if use_schedule_gen == True: - cut_overview, cut_innercut = cutnschedule(cut_overview_max=cut_overview_max, cut_innercut_max=cut_innercut_max, cut_overview_min=cut_overview_min, cut_overview_delay=cut_overview_delay, cut_innercut_delay=cut_innercut_delay, overview_end_bias = overview_end_bias, inner_start_bias = inner_start_bias) + cut_overview_gen, cut_innercut_gen = cutnschedule(cut_overview_max=cut_overview_max, cut_innercut_max=cut_innercut_max, cut_overview_min=cut_overview_min, cut_overview_delay=cut_overview_delay, cut_innercut_delay=cut_innercut_delay, overview_bias = overview_bias, inner_bias = inner_bias) + + # Cleans up the cut_overview schedule + clearup_overview = dict((i, cut_overview_gen.count(i)) for i in cut_overview_gen) + cut_string = '' + for key in clearup_overview: + cut_string += "["+str(key)+"]*"+str(clearup_overview[key])+"+" + cut_string = cut_string[:-1] + + # Cleans up the cut_innercut schedule + clearup_innercut = dict((i, cut_innercut_gen.count(i)) for i in cut_innercut_gen) + inner_string = '' + for key in clearup_innercut: + inner_string += "["+str(key)+"]*"+str(clearup_innercut[key])+"+" + inner_string = inner_string[:-1] + cut_overview = cut_string + cut_innercut = inner_string +print(f'cut_overview: {cut_overview}') +print(f'cut_innercut: {cut_innercut}') -print(f'Cut_overview: {cut_overview}') -print(f'Cut:Innercut: {cut_innercut}') -%matplotlib inline +# Output the cut schedule as a plot +import matplotlib.pyplot as plt import matplotlib.patches as mpatches x = np.linspace(0, 1000, 1000, dtype='int') fig, ax = plt.subplots(figsize=(6.5, 3.7)) -overview_plot = ax.plot(x, cut_overview, color='black', label='cut_overview') -innercut_plot = ax.plot(x, cut_innercut, color='red', label='cut_innercut') +overview_plot = ax.plot(x, cut_overview_gen, color='black', label='cut_overview') +innercut_plot = ax.plot(x, cut_innercut_gen, color='red', label='cut_innercut') black_patch = mpatches.Patch(color='black', label='cut_overview') red_patch = mpatches.Patch(color='red', label='cut_innercut') ax.legend(handles=[black_patch,red_patch]) ax.set_xlabel('Steps') ax.set_ylabel('Cuts') - - -cut_string = "" -inner_string = "" -for i in range(len(cut_overview)): - if i < len(cut_overview)-1: - cut_string += "["+str(cut_overview[i])+"]*1+" - inner_string += "["+str(cut_innercut[i])+"]*1+" - else: - cut_string += "["+str(cut_overview[i])+"]*1" - inner_string += "["+str(cut_innercut[i])+"]*1" - cut_overview = cut_string - cut_innercut = inner_string +plt.show()