Created
September 10, 2022 06:59
-
-
Save HenryLoenwind/b4de693093a31d1d6a05826a8ff47145 to your computer and use it in GitHub Desktop.
Command iterator for SD
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
=for doc | |
Script to generate expand a list of commands with placeholders. | |
Output is written to "gentmp.cmd". Directly calling the commands from this script doesn't work with SD. | |
=cut | |
use strict; | |
use warnings; | |
# put your independent commands into this list: | |
our @inputs = (); | |
=for doc | |
I usually only have one command to iterate over, but below there's an example of me re-running a whole list of seeds for different prompts. | |
The prompts can take placeholders that are then expanded: | |
* [1,2,3] - a simple comma-separated list. This gets simple expanded into the contained elements. | |
** [1,2,3,%] - the special element "%" gets expanded into the empty string. | |
** [1,2,3,<c:/images/nu*s/good/4*.png>,</home/user/my pictures/*.png>] - an element in <> is taken as a path specifier. The script will find all matching files and iterate over them. | |
** [1,2,3,42..87] - You can give ranges of integers with the ".." operator (or even letters, see the perldoc for "..") | |
** [1,2,3,0.45..0.61:0.025] - You can also give the step size for numbers. This would yield your 0.45, 0.475, 0.5, 0.525, 0.55. 0.575, 0.6. See how I phad to set the end value slightly above what I wanted because of computer math's precision. | |
=cut | |
# push @inputs, q{python optimizedSD/optimized_txt2img.py --ddim_steps 15 --n_iter 10 --H 768 --W 512 --n_samples 10 --seed 0 --prompt "photograph of a goddess standing in an X position with widely spread legs in front of a neutral background. Her eyes are closed and her face shows a benevolent smile. ..."}; | |
# push @inputs, q{python optimizedSD/optimized_img2img.py --ddim_steps 50 --n_iter 3 --H 768 --W 512 --n_samples 3 --prompt "by [Fabian Perez,Daniel Ridgway Knight,Arthur Hughes,Edward Robert Hughes,Jules Bastien-Lepage,Thomas Benjamin Kennington, Arthur Wardle,Josephine Wall,Dorina Costras,Henri-Edmond Cross,Richard S. Johnson,Andrew Atroshenko,Anne Stokes,Patrice Murciano,Eric Wallis,Donato Giancola,Marco Mazzoni,Craig Davison,Joseph Lorusso,Karol Bak], a goddess with golden skin in front of a neutral background. ..." --init-img "outputs\nice_goddess\seed_83_00004_ddim_50_str_0.6 copy 2.png" --strength [0.525..0.61:0.025]}; | |
# push @inputs, q{python optimizedSD/optimized_txt2img.py --ddim_steps 15 --n_iter 10 --H 768 --W 512 --n_samples 10 --seed 0 --prompt "by [Fabian Perez,Daniel Ridgway Knight,Arthur Hughes,Edward Robert Hughes,Jules Bastien-Lepage,Thomas Benjamin Kennington, Arthur Wardle,Josephine Wall,Dorina Costras,Henri-Edmond Cross,Richard S. Johnson,Andrew Atroshenko,Anne Stokes,Patrice Murciano,Eric Wallis,Donato Giancola,Marco Mazzoni,Craig Davison,Joseph Lorusso,Karol Bak], droneshot of a mediterrean house with an inner courtyard, middle-eastern, clay-brick, wood door, siesta, no people, noon, hot day, heat ripples, cloths line with women's underwear, empty, ancient, [with a dragon overhead,%]"}; | |
our $prompt = q{, a posing Mexican attractive woman with dragon wings, breasts covered in dragon scales, crotch covered in dragon scales, human body, posing in front of a white wall. highly ...}; | |
#our $command = q{python optimizedSD/optimized_txt2img.py --ddim_steps 500 --n_iter 1 --H 768 --W 512 --n_samples 1 --prompt}; | |
#push @inputs, $command.q{ "Andrew Atroshenko}.$prompt.q{" --seed [117920,114922,117923,117926,117936,117947,117976,117977,117978,117981,118000,118001]}; | |
#push @inputs, $command.q{ "Anne Stokes}.$prompt.q{" --seed [269168,269186,269204,269206,269207,269229,269234,269235,269250,269251,269252,269255]}; | |
#push @inputs, $command.q{ "Arthur Hughes}.$prompt.q{" --seed [482201,482208,482209,482260,482261,482271,482276,482282,482290,482297]}; | |
#push @inputs, $command.q{ "Arthur Wardle}.$prompt.q{" --seed [510962,511009,511017]}; | |
#push @inputs, $command.q{ "Craig Davison}.$prompt.q{" --seed [619035,619040,619050,619055,619070,619073,619078,619080,619089,6190963,619100,619112,619113,619163]}; | |
#push @inputs, $command.q{ "Daniel Ridgway Knight}.$prompt.q{" --seed [171281,171287,171306,171314,171323,171326,171327,171331,171333,171348]}; | |
#push @inputs, $command.q{ "Donato Giancola}.$prompt.q{" --seed [327653,327657,327665,327668,327671,327674,327690,327692,327693,327699,327701,327708,327727]}; | |
#push @inputs, $command.q{ "Dorina Costras}.$prompt.q{" --seed [486059,486061,486115]}; | |
#push @inputs, $command.q{ "Edward Robert Hughes}.$prompt.q{" --seed [483827,483847,483859]}; | |
#push @inputs, $command.q{ "Eric Wallis}.$prompt.q{" --seed [645466,645478,645479,645485,645497,645498,645506,645511,645513,645531,645538,645545]}; | |
#push @inputs, $command.q{ "Fabian Perez}.$prompt.q{" --seed [9017,9030,9083,9106]}; | |
#push @inputs, $command.q{ "Joseph Lorusso}.$prompt.q{" --seed [534078,534079,534080,534106,534116,534141,534142,534149,534155,534163,534169]}; | |
#push @inputs, $command.q{ "Josephine Wall}.$prompt.q{" --seed [167387,167394,167398,167399,167401,167411,167412]}; | |
#push @inputs, $command.q{ "Jules Bastien-Lepage}.$prompt.q{" --seed [375396,375402,375454]}; | |
#push @inputs, $command.q{ "Karol Bak}.$prompt.q{" --seed [307523,307525,307527,307553,307562,307566,307571,307589,307604,307607,307608]}; | |
#push @inputs, $command.q{ "Marco Mazzoni}.$prompt.q{" --seed [554626,554630,554632,554634,554647,554662,554674,554714,554724]}; | |
#push @inputs, $command.q{ "Patrice Murciano}.$prompt.q{" --seed [287350,287353,287355,287362,287392,287394,287396,287398,287421,287425]}; | |
#push @inputs, $command.q{ "Richard S. Johnson}.$prompt.q{" --seed [59495,59516,59517,59527,59559,59566]}; | |
#push @inputs, $command.q{ "Thomas Benjamin Kennington}.$prompt.q{" --seed [404898]}; | |
push @inputs, q{python optimizedSD/optimized_img2img.py --ddim_steps [15,50] --n_iter 5 --H 768 --W 512 --n_samples 2 --strength [0.45,0.5,0.55] --init-img [<outputs/txt2img-samples/dragonlady3/*.png>] --prompt "[Fabian Perez,Daniel Ridgway Knight,Arthur Hughes,Edward Robert Hughes,Jules Bastien-Lepage,Thomas Benjamin Kennington, Arthur Wardle,Josephine Wall,Dorina Costras,Henri-Edmond Cross,Richard S. Johnson,Andrew Atroshenko,Anne Stokes,Patrice Murciano,Eric Wallis,Donato Giancola,Marco Mazzoni,Craig Davison,Joseph Lorusso,Karol Bak]}.$prompt.q{"}; | |
### | |
our $count = 0; | |
sub process { | |
my $x = shift; | |
my @result = (); | |
if ($x =~ m/^(.*?)\[(.*?)\](.*)$/) { | |
my ($pre, $e, $post) = ($1, $2, $3); | |
for my $value (expand($e)) { | |
push @result, process($pre . $value . $post); | |
} | |
} else { | |
push @result, 'title Task '.(++$count).'/###'; # change "title" to "echo" on Linux/MacOS | |
push @result, $x; | |
} | |
return @result; | |
} | |
sub expand { | |
my $x = shift; | |
my @result = (); | |
while (length($x)) { | |
if ($x =~ s/^\s*([0-9.]+)\s*\.\.\s*([0-9.]+)\s*:\s*([0-9.]+)\s*(,|$)//) { | |
my ($from, $to, $step) = ($1, $2, $3); | |
while ($from <= $to) { | |
push @result, $from; | |
$from += $step; | |
} | |
} elsif ($x =~ s/^\s*(\d+)\s*\.\.\s*(\d+)\s*(,|$)//) { | |
my ($from, $to) = ($1, $2); | |
push @result, $_ for $from .. $to; | |
} elsif ($x =~ s/^\s*\%\s*(,|$)//) { | |
push @result, ''; | |
} elsif ($x =~ s/^\s*<([^<>]+)>\s*(,|$)//) { | |
push @result, glob($1); | |
} elsif ($x =~ s/^\s*([^,]+?)\s*(,|$)//) { | |
push @result, $1; | |
} else { | |
die $x; | |
} | |
} | |
return @result; | |
} | |
sub repl { | |
my $x = shift; | |
$x =~ s/###/$count/; | |
return $x; | |
} | |
our @all = (); | |
push @all, process($_) for @inputs; | |
print "Running ".$count." tasks...\n"; | |
sleep 5 if $count > 5; | |
open F, '>', 'gentmp.cmd'; # change ".cmd" to ".sh" on Linux/MacOS | |
print F join("\n", map(repl($_), @all)); | |
print F "\ntitle Done.\n"; | |
close F; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment