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

BUGFIX: Limit filename length for saved images and grid #85

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

TalAter
Copy link

@TalAter TalAter commented Nov 6, 2022

🐛 Bug

scripts/stable_txt2img.py generates the filename of the output images and the grid images from the prompt argument.

If the prompt argument is too long, the script crashes with this error:

Traceback (most recent call last):
  File "scripts/stable_txt2img.py", line 292, in <module>
    main()
  File "scripts/stable_txt2img.py", line 275, in main
    save_image(grid[i, :, :, :], os.path.join(outpath,opt.prompt[:1800]+'_{}.png'.format(i)))
  File "/opt/conda/lib/python3.7/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
    return func(*args, **kwargs)
  File "/opt/conda/lib/python3.7/site-packages/torchvision/utils.py", line 160, in save_image
    im.save(fp, format=format)
  File "/opt/conda/lib/python3.7/site-packages/PIL/Image.py", line 2209, in save
    fp = builtins.open(filename, "w+b")
OSError: [Errno 36] File name too long: 'outputs/txt2img-samples/talAter person riding a unicorn as a digital painting of afrofuturism, from left, Makoto Shinkai, Stanley Artgerm Lau, WLOP, Rossdraws, James Jean, Andrei Riabovitchev, Marc Simonetti, krenz cushart, Sakimichan, D&D trending on ArtStation, digital  person riding a unicorn as a digital painting of tracer from Overwatch, artstation, CGSociety, by artgerm, by rossdraws, anime style_0.png'

🔧 Fix

This fix truncates the filename to something more manageable.

💡 Note

Technically, the OS supports longer filenames than proposed in this PR. However, the longer filenames give JupyterLab indigestion so this PR shortens the filename to 180 chars (plus the suffix).

CleanShot 2022-11-06 at 15 34 55

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant