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

OSError: cannot write mode I;16 as JPEG #15

Closed
Tobe2d opened this issue Nov 6, 2022 · 4 comments
Closed

OSError: cannot write mode I;16 as JPEG #15

Tobe2d opened this issue Nov 6, 2022 · 4 comments

Comments

@Tobe2d
Copy link

Tobe2d commented Nov 6, 2022

When I test it with its default settings it work showing side by side results.
the moment I untick "Combine into one image" it does not work.
Basicaly it work with showing combined results Vertical and Horizontal however it does not work making depth only.

below is the log:

(INFO) Result 0:
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00,  9.04it/s]
Total progress: 2it [00:34, 17.28s/it]
DepthMap v0.1.4
device: cuda
Loading midas model weights ..
./models/midas/dpt_large-midas-2f21e586.pt
Computing depthmap(s) ..
Error completing request
Arguments: (0, '', '', 'None', 'None', <PIL.Image.Image image mode=RGB size=512x512 at 0x278540D7880>, {'image': <PIL.Image.Image image mode=RGBA size=512x512 at 0x278540D7790>, 'mask': <PIL.PngImagePlugin.PngImageFile image mode=RGBA size=512x512 at 0x278540D79A0>}, None, None, 0, 20, 0, 4, 1, False, False, 1, 1, 7, 0, -1.0, -1.0, 0, 0, 0, False, 512, 512, 0, False, 32, 0, '', '', 9, 0.9, 5, '0.0001', False, 'None', '', 0.1, False, '<span style="margin-left:13px;" class="text-gray-500 text-[0.855rem] mb-2 block dark:text-gray-200 relative z-40">Unprompted</span>', False, '<div id="unprompted"><div id="ad" class=" gr-box border-solid border border-gray-200" style="border-radius:0 0 8px 8px"><a href="https://payhip.com/b/hdgNR" target="_blank"><img src="https://i.ibb.co/1MSpHL4/Fantasy-Card-Template2.png" style="float: left;width: 150px;margin-bottom:10px;"></a><h1 style="font-size: 20px;letter-spacing:0.015em;margin-top:10px;">NEW! <strong>Premium Fantasy Card Template</strong> is now available.</h1><p style="margin:1em 0;">Generate a wide variety of creatures and characters in the style of a fantasy card game. Perfect for heroes, animals, monsters, and even crazy hybrids.</p><a href="https://payhip.com/b/hdgNR" target=_blank><button class="gr-button gr-button-lg gr-button-secondary" title="View premium assets for Unprompted">Learn More ➜</button></a><hr style="margin:1em 0;clear:both;"><p style="max-width:80%"><em>Purchases help fund the continued development of Unprompted. Thank you for your support!</em> ❤</p></div><a id="toggle-ad" href="#" style="float:right;display: inline;position:absolute;right:20px;bottom:20px;">Show Ad</a></div>', 4.0, 1, 1, 0, 0, 0.0, 4.0, 0.1, 0.1, 1, True, False, False, 0, False, '', 1, False, 0, 1, False, False, False, '<p style="margin-bottom:0.75em">Render these video formats:</p>', '<p style="margin-bottom:0.75em">Animation Parameters</p>', '<p style="margin-bottom:0.75em">Prompt Template, applied to each keyframe below</p>', '<p style="margin-bottom:0.75em">Keyframe Format: <br>Time (s) | Desnoise | Zoom (/s) | X Shift (pix/s) | Y shift (pix/s) | Positive Prompts | Negative Prompts | Seed</p>', '10.0', '15', False, False, True, '1.0', '', '', '', 0.4, '0', '0', False, False, 0.1, 0.5, '<p style="margin-bottom:0.75em">Render these video formats:</p>', '<p style="margin-bottom:0.75em">Animation Parameters</p>', '<p style="margin-bottom:0.75em">Initial Parameters</p>', '<p style="margin-bottom:0.75em">Prompt Template, applied to each keyframe below</p>', '<p style="margin-bottom:0.75em">Props</p>', '<p style="margin-bottom:0.75em">Supported Keyframes:<br>time_s | prompt | positive_prompts | negative_prompts<br>time_s | transform | zoom | x_shift | y_shift | rotation<br>time_s | seed | new_seed_int<br>time_s | denoise | denoise_value<br>time_s | prop | prop_filename | x_pos | y_pos | scale | rotation<br>time_s | set_text | textblock_name | text_prompt | x | y | w | h | fore_color | back_color | font_name<br>time_s | clear_text | textblock_name<br>time_s | prop | prop_name | prop_filename | x pos | y pos | scale | rotation<br>time_s | set_stamp | stamp_name | stamp_filename | x pos | y pos | scale | rotation<br>time_s | clear_stamp | stamp_name<br>time_s | col_set<br>time_s | col_clear<br>time_s | model | Original1-4model, microworld_PublicPrompts, sd-v1-4, sd-v1-4-full-ema, sd-v1-5-inpainting, trinart2_step115000, v1-5-pruned, v1-5-pruned-emaonly, wd-v1-2-full-ema, wd-v1-3-full</p>', '10.0', '15', False, False, True, '1.0', '', '', '', 0.4, '0', '0', '0', False, False, 0.1, 0.5, '', True, False, '', '', 0, 384, 0, True, True, False, 0, '\n            <h3><strong>Combinations</strong></h3>\n            Choose a number of terms from a list, in this case we choose two artists\n            <code>{2$$artist1|artist2|artist3}</code>\n            If $$ is not provided, then 1$$ is assumed.\n            <br>\n            A range can be provided:\n            <code>{1-3$$artist1|artist2|artist3}</code>\n            In this case, a random number of artists between 1 and 3 is chosen.\n            <br/><br/>\n\n            <h3><strong>Wildcards</strong></h3>\n            <p>Available wildcards</p>\n            <ul>\n        <li>__adjective__</li><li>__artist__</li><li>__genre__</li><li>__site__</li><li>__style__</li></ul>\n            <br/>\n            <code>WILDCARD_DIR: scripts/wildcards</code><br/>\n            <small>You can add more wildcards by creating a text file with one term per line and name is mywildcards.txt. Place it in scripts/wildcards. <code>__mywildcards__</code> will then become available.</small>\n        ', None, '', 'outputs', 1550, False, False, '<ul>\n<li><code>CFG Scale</code> should be 2 or lower.</li>\n</ul>\n', True, True, '', '', True, 50, True, 1, 0, False, 256, 0, 1, 0, 0.25, 4, 1, '<p style="margin-bottom:0.75em">Recommended settings: Sampling Steps: 80-100, Sampler: Euler a, Denoising strength: 0.8</p>', 128, 8, ['left', 'right', 'up', 'down'], 1, 0.05, 128, 4, 0, ['left', 'right', 'up', 'down'], '', 1, True, 100, False, False, False, '', 2, '<p style="margin-bottom:0.75em">Will upscale the image to twice the dimensions; use width and height sliders to set tile size</p>', 64, 0, False, 4.0, '', 10.0, False, False, True, 30.0, True, False, False, 10.0, True, 30.0, True, '', '', 100, 0, 0, True, '<div class="gr-block gr-box relative w-full overflow-hidden border-solid border border-gray-200 gr-panel"><p>If you like my work, please consider showing your support on <strong><a href="https://patreon.com/thereforegames" target="_blank">Patreon</a></strong>. Thank you! &#10084;</p></div>', 'Illustration', 'svg', True, True, False, 0.5, True, 16, True, 16, '', 24, 24, 0, 10, '00:00:00', '00:00:00', False, '', 1, 10, True, 1, False, 1, 0, 0, False, 1, '', 0, '', True, False, False, '<p style="font-weight:bold;margin-bottom:0.75em">Deforum v0.5-webui-beta</p>', '<p>This script is deprecated. Please use the full Deforum extension instead.<br>\nUpdate instructions:</p>', '<p>github.com/deforum-art/deforum-for-automatic1111-webui/blob/automatic1111-webui/README.md</p>', '<p>discord.gg/deforum</p>', '<div id="dynamic-prompting">\n    <h3><strong>Combinations</strong></h3>\n\n    Choose a number of terms from a list, in this case we choose two artists: \n    <code class="codeblock">{{2$artist1|artist2|artist3}}</code>\n\n    If $ is not provided, then 1$ is assumed.\n\n    A range can be provided:\n    <code class="codeblock">{{1-3$artist1|artist2|artist3}}</code>\n\n    In this case, a random number of artists between 1 and 3 is chosen.\n\n    <br/><br/>\n\n    <h3><strong>Wildcards</strong></h3>\n    \n\n    <br/>\n    If the groups wont drop down click <strong onclick="check_collapsibles()" style="cursor: pointer">here</strong> to fix the issue.\n\n    <br/><br/>\n\n    <code class="codeblock">WILDCARD_DIR: D:\\stable-diffusion-webui\\extensions\\sd-dynamic-prompts\\wildcards</code><br/>\n    <small onload="check_collapsibles()">You can add more wildcards by creating a text file with one term per line and name is mywildcards.txt. Place it in D:\\stable-diffusion-webui\\extensions\\sd-dynamic-prompts\\wildcards. <code class="codeblock">__&#60;folder&#62;/mywildcards__</code> will then become available.</small>\n</div>\n\n', False, 1, False, False, 1.0, 2.0, 'a painting in', 'style', 'picture frame, portrait photo', None) {}
Traceback (most recent call last):
  File "D:\\stable-diffusion-webui\venv\lib\site-packages\PIL\JpegImagePlugin.py", line 630, in _save
    rawmode = RAWMODE[im.mode]
KeyError: 'I;16'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "D:\stable-diffusion-webui\modules\ui.py", line 185, in f
    res = list(func(*args, **kwargs))
  File "D:\stable-diffusion-webui\webui.py", line 54, in f
    res = func(*args, **kwargs)
  File "D:\stable-diffusion-webui\modules\img2img.py", line 137, in img2img
    processed = modules.scripts.scripts_img2img.run(p, *args)
  File "D:\stable-diffusion-webui\modules\scripts.py", line 296, in run
    processed = script.run(p, *script_args)
  File "D:\stable-diffusion-webui\scripts\depthmap.py", line 227, in run
    images.save_image(Image.fromarray(img_output), p.outpath_samples, "", processed.seed, p.prompt, opts.samples_format, info=info, p=p, suffix="_depth")
  File "D:\stable-diffusion-webui\modules\images.py", line 520, in save_image
    image.save(fullfn, quality=opts.jpeg_quality)
  File "D:\stable-diffusion-webui\venv\lib\site-packages\PIL\Image.py", line 2320, in save
    save_handler(self, fp, filename)
  File "D:\stable-diffusion-webui\venv\lib\site-packages\PIL\JpegImagePlugin.py", line 632, in _save
    raise OSError(f"cannot write mode {im.mode} as JPEG") from e
OSError: cannot write mode I;16 as JPEG

@thygate
Copy link
Owner

thygate commented Nov 6, 2022

OSError: cannot write mode I;16 as JPEG

You're getting this error because it's trying to save a 16 bit single channel image as JPEG, which is not supported.

Do you have any specific settings forcing it to save in JPEG instead of the default PNG ?

@Tobe2d
Copy link
Author

Tobe2d commented Nov 6, 2022

Ohh snap... I was saving as jpg... once I change it to png it worked like a charm!

Thanks for pointing this out.

@Tobe2d Tobe2d closed this as completed Nov 6, 2022
@thygate
Copy link
Owner

thygate commented Nov 6, 2022

Well i would like it to gracefully handle this option too, so i will be looking for a way to fix this..
Probably force it to save in PNG, ...

For now, you can indeed work around it by always saving as png in settings.

@thygate thygate reopened this Nov 6, 2022
@thygate
Copy link
Owner

thygate commented Nov 6, 2022

I've fixed the error in version v0.1.5, saving as JPEG when not combing now works.

Saving as any format other than PNG will now always save an 8 bit, 3 channel RGB image.
Only when saving the (not combined) depthmap as PNG, a 16 bit single channel image is saved.

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

No branches or pull requests

2 participants