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

add option to CLI and pngwriter that allows user to set PNG compression level #1127

Merged
merged 1 commit into from
Oct 18, 2022

Conversation

lstein
Copy link
Collaborator

@lstein lstein commented Oct 16, 2022

Problem

When running img2img repeatedly on the same image, the PNG compression/decompression artefacts add up.

Solution

This PR adds a new feature that enables the user to change the level of PNG compression used, including turning it off completely.

Details

  • In CLI: the new argument is --png_compression <0..9> (-z<0..9>)
    -- this can be applied either on the command line, or at the invoke> prompt
  • In API, pass new argument compress_level to PngWriter.save_image_and_prompt_to_png()

Compression ranges from 0 (no compression) to 9 (maximum compression). Default value is 6 (as specified by Pillow package).

This addresses an issue first raised in #652.

…on level

- In CLI: the argument is --png_compression <0..9> (-z<0..9>)
- In API, pass `compress_level` to PngWriter.save_image_and_prompt_to_png()

Compression ranges from 0 (no compression) to 9 (maximum compression).
Default value is 6 (as specified by Pillow package).

This addresses an issue first raised in #652.
@tildebyte
Copy link
Contributor

Will this be "sticky", like setting the sample scheduler from the CLI?

@lstein
Copy link
Collaborator Author

lstein commented Oct 17, 2022

Will this be "sticky", like setting the sample scheduler from the CLI?

It isn't currently. The value specified on the command line is the default level of compression. Individual invoke> commands can change it, but just for that one command.

I learned belatedly that PNG compression isn't lossy like JPG, and so this won't fix the problem we observe with loss of fidelity across multiple img2img passes. This seems to be an artefact of the diffusion process itself.

@tildebyte
Copy link
Contributor

The value specified on the command line is the default level of compression. Individual invoke> commands can change it, but just for that one command

This is what I meant by "sticky" :D

@lstein
Copy link
Collaborator Author

lstein commented Oct 17, 2022 via email

@lstein lstein merged commit 0cf11ce into development Oct 18, 2022
@lstein lstein deleted the adjust-png-compression branch October 18, 2022 02:27
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.

2 participants