mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
Merge branch 'yunsaki-main' into main
This commit is contained in:
commit
3b2569ebdd
14
README.md
14
README.md
@ -185,7 +185,13 @@ innovative packaging for a squid's dinner -S137038382
|
|||||||
Then pass this file's name to dream.py when you invoke it:
|
Then pass this file's name to dream.py when you invoke it:
|
||||||
|
|
||||||
~~~~
|
~~~~
|
||||||
(ldm) ~/stable-diffusion$ python3 scripts/dream.py --from_file="path/to/prompts.txt"
|
(ldm) ~/stable-diffusion$ python3 scripts/dream.py --from_file "path/to/prompts.txt"
|
||||||
|
~~~~
|
||||||
|
|
||||||
|
You may read a series of prompts from standard input by providing a filename of "-":
|
||||||
|
|
||||||
|
~~~~
|
||||||
|
(ldm) ~/stable-diffusion$ echo "a beautiful day" | python3 scripts/dream.py --from_file -
|
||||||
~~~~
|
~~~~
|
||||||
|
|
||||||
## Shortcut for reusing seeds from the previous command
|
## Shortcut for reusing seeds from the previous command
|
||||||
@ -298,6 +304,10 @@ repository and associated paper for details and limitations.
|
|||||||
|
|
||||||
## Changes
|
## Changes
|
||||||
|
|
||||||
|
* v1.12 (28 August 2022)
|
||||||
|
* Improved file handling, including ability to read prompts from standard input.
|
||||||
|
(kudos to [Yunsaki](https://github.com/yunsaki)
|
||||||
|
|
||||||
* v1.11 (26 August 2022)
|
* v1.11 (26 August 2022)
|
||||||
* NEW FEATURE: Support upscaling and face enhancement using the GFPGAN module. (kudos to [Oceanswave](https://github.com/Oceanswave)
|
* NEW FEATURE: Support upscaling and face enhancement using the GFPGAN module. (kudos to [Oceanswave](https://github.com/Oceanswave)
|
||||||
* You now can specify a seed of -1 to use the previous image's seed, -2 to use the seed for the image generated before that, etc.
|
* You now can specify a seed of -1 to use the previous image's seed, -2 to use the seed for the image generated before that, etc.
|
||||||
@ -601,7 +611,7 @@ to send me an email if you use and like the script.
|
|||||||
[Peter Kowalczyk](https://github.com/slix), [Henry Harrison](https://github.com/hwharrison),
|
[Peter Kowalczyk](https://github.com/slix), [Henry Harrison](https://github.com/hwharrison),
|
||||||
[xraxra](https://github.com/xraxra), [bmaltais](https://github.com/bmaltais), [Sean McLellan](https://github.com/Oceanswave),
|
[xraxra](https://github.com/xraxra), [bmaltais](https://github.com/bmaltais), [Sean McLellan](https://github.com/Oceanswave),
|
||||||
[nicolai256](https://github.com/nicolai256), [Benjamin Warner](https://github.com/warner-benjamin),
|
[nicolai256](https://github.com/nicolai256), [Benjamin Warner](https://github.com/warner-benjamin),
|
||||||
[tildebyte](https://github.com/tildebyte),
|
[tildebyte](https://github.com/tildebyte),[yunsaki](https://github.com/yunsaki)
|
||||||
and [Tesseract Cat](https://github.com/TesseractCat)
|
and [Tesseract Cat](https://github.com/TesseractCat)
|
||||||
|
|
||||||
|
|
||||||
|
@ -554,13 +554,15 @@ class T2I:
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
print(
|
print(
|
||||||
'Using half precision math. Call with --full_precision to use slower but more accurate full precision.'
|
'Using half precision math. Call with --full_precision to use more accurate but VRAM-intensive full precision.'
|
||||||
)
|
)
|
||||||
model.half()
|
model.half()
|
||||||
return model
|
return model
|
||||||
|
|
||||||
def _load_img(self, path):
|
def _load_img(self, path):
|
||||||
image = Image.open(path).convert('RGB')
|
with Image.open(path) as img:
|
||||||
|
image = img.convert("RGB")
|
||||||
|
|
||||||
w, h = image.size
|
w, h = image.size
|
||||||
print(f'loaded input image of size ({w}, {h}) from {path}')
|
print(f'loaded input image of size ({w}, {h}) from {path}')
|
||||||
w, h = map(
|
w, h = map(
|
||||||
|
@ -61,13 +61,19 @@ def main():
|
|||||||
# gets rid of annoying messages about random seed
|
# gets rid of annoying messages about random seed
|
||||||
logging.getLogger('pytorch_lightning').setLevel(logging.ERROR)
|
logging.getLogger('pytorch_lightning').setLevel(logging.ERROR)
|
||||||
|
|
||||||
|
# load the infile as a list of lines
|
||||||
infile = None
|
infile = None
|
||||||
try:
|
if opt.infile:
|
||||||
if opt.infile is not None:
|
try:
|
||||||
infile = open(opt.infile, 'r')
|
if os.path.isfile(opt.infile):
|
||||||
except FileNotFoundError as e:
|
infile = open(opt.infile,'r')
|
||||||
print(e)
|
elif opt.infile=='-': # stdin
|
||||||
exit(-1)
|
infile = sys.stdin
|
||||||
|
else:
|
||||||
|
raise FileNotFoundError(f'{opt.infile} not found.')
|
||||||
|
except (FileNotFoundError,IOError) as e:
|
||||||
|
print(f'{e}. Aborting.')
|
||||||
|
sys.exit(-1)
|
||||||
|
|
||||||
# preload the model
|
# preload the model
|
||||||
t2i.load_model()
|
t2i.load_model()
|
||||||
@ -107,34 +113,31 @@ def main():
|
|||||||
print('Error loading GFPGAN:', file=sys.stderr)
|
print('Error loading GFPGAN:', file=sys.stderr)
|
||||||
print(traceback.format_exc(), file=sys.stderr)
|
print(traceback.format_exc(), file=sys.stderr)
|
||||||
|
|
||||||
print(
|
if not infile:
|
||||||
"\n* Initialization done! Awaiting your command (-h for help, 'q' to quit, 'cd' to change output dir, 'pwd' to print output dir)..."
|
print(
|
||||||
)
|
"\n* Initialization done! Awaiting your command (-h for help, 'q' to quit, 'cd' to change output dir, 'pwd' to print output dir)..."
|
||||||
|
)
|
||||||
|
|
||||||
log_path = os.path.join(opt.outdir, 'dream_log.txt')
|
log_path = os.path.join(opt.outdir, 'dream_log.txt')
|
||||||
with open(log_path, 'a') as log:
|
cmd_parser = create_cmd_parser()
|
||||||
cmd_parser = create_cmd_parser()
|
main_loop(t2i, opt.outdir, cmd_parser, log_path, infile)
|
||||||
main_loop(t2i, opt.outdir, cmd_parser, log, infile)
|
|
||||||
log.close()
|
|
||||||
if infile:
|
|
||||||
infile.close()
|
|
||||||
|
|
||||||
|
|
||||||
def main_loop(t2i, outdir, parser, log, infile):
|
def main_loop(t2i, outdir, parser, log_path, infile):
|
||||||
"""prompt/read/execute loop"""
|
"""prompt/read/execute loop"""
|
||||||
done = False
|
done = False
|
||||||
last_seeds = []
|
last_seeds = []
|
||||||
|
|
||||||
while not done:
|
while not done:
|
||||||
try:
|
try:
|
||||||
command = infile.readline() if infile else input('dream> ')
|
command = get_next_command(infile)
|
||||||
except EOFError:
|
except EOFError:
|
||||||
done = True
|
done = True
|
||||||
break
|
break
|
||||||
|
|
||||||
if infile and len(command) == 0:
|
# skip empty lines
|
||||||
done = True
|
if not command.strip():
|
||||||
break
|
continue
|
||||||
|
|
||||||
if command.startswith(('#', '//')):
|
if command.startswith(('#', '//')):
|
||||||
continue
|
continue
|
||||||
@ -149,9 +152,6 @@ def main_loop(t2i, outdir, parser, log, infile):
|
|||||||
print(str(e))
|
print(str(e))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if len(elements) == 0:
|
|
||||||
continue
|
|
||||||
|
|
||||||
if elements[0] == 'q':
|
if elements[0] == 'q':
|
||||||
done = True
|
done = True
|
||||||
break
|
break
|
||||||
@ -236,11 +236,22 @@ def main_loop(t2i, outdir, parser, log, infile):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
print('Outputs:')
|
print('Outputs:')
|
||||||
write_log_message(t2i, normalized_prompt, results, log)
|
write_log_message(t2i, normalized_prompt, results, log_path)
|
||||||
|
|
||||||
print('goodbye!')
|
print('goodbye!')
|
||||||
|
|
||||||
|
def get_next_command(infile=None) -> 'command string':
|
||||||
|
if infile is None:
|
||||||
|
command = input("dream> ")
|
||||||
|
else:
|
||||||
|
command = infile.readline()
|
||||||
|
if not command:
|
||||||
|
raise EOFError
|
||||||
|
else:
|
||||||
|
command = command.strip()
|
||||||
|
print(f'#{command}')
|
||||||
|
return command
|
||||||
|
|
||||||
def load_gfpgan_bg_upsampler(bg_upsampler, bg_tile=400):
|
def load_gfpgan_bg_upsampler(bg_upsampler, bg_tile=400):
|
||||||
import torch
|
import torch
|
||||||
|
|
||||||
@ -306,19 +317,14 @@ def load_gfpgan_bg_upsampler(bg_upsampler, bg_tile=400):
|
|||||||
# return variants
|
# return variants
|
||||||
|
|
||||||
|
|
||||||
def write_log_message(t2i, prompt, results, logfile):
|
### the t2i variable doesn't seem to be necessary here. maybe remove it?
|
||||||
|
def write_log_message(t2i, prompt, results, log_path):
|
||||||
"""logs the name of the output image, its prompt and seed to the terminal, log file, and a Dream text chunk in the PNG metadata"""
|
"""logs the name of the output image, its prompt and seed to the terminal, log file, and a Dream text chunk in the PNG metadata"""
|
||||||
last_seed = None
|
log_lines = [f"{r[0]}: {prompt} -S{r[1]}\n" for r in results]
|
||||||
img_num = 1
|
print(*log_lines, sep="")
|
||||||
seenit = {}
|
|
||||||
|
|
||||||
for r in results:
|
with open(log_path, "a") as file:
|
||||||
seed = r[1]
|
file.writelines(log_lines)
|
||||||
log_message = f'{r[0]}: {prompt} -S{seed}'
|
|
||||||
|
|
||||||
print(log_message)
|
|
||||||
logfile.write(log_message + '\n')
|
|
||||||
logfile.flush()
|
|
||||||
|
|
||||||
|
|
||||||
def create_argv_parser():
|
def create_argv_parser():
|
||||||
|
Loading…
Reference in New Issue
Block a user