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

Improved tiled upscale #128

Merged
merged 2 commits into from
Feb 2, 2024
Merged

Improved tiled upscale #128

merged 2 commits into from
Feb 2, 2024

Conversation

monstruosoft
Copy link
Contributor

OK, I guess the changes in this PR require some explanation. First of all, the simplest way to upscale an image is by using the upscale argument and specifying a file at the CLI, for example:

$ python src/app.py --inference_steps 1 --lcm_model_id stabilityai/sd-turbo --use_offline_model -t -f '/home/monstruosoft/fastsdcpu/results/f834fc7f-f613-42b1-aa54-42d0cefb21d3-1.png' --upscale

Now you can also achieve the same result by passing a JSON file argument, like this:

$ python src/app.py --inference_steps 1 --lcm_model_id stabilityai/sd-turbo --use_offline_model -t --upscale --custom_settings upscale.json

The JSON file has the following format:

{
  "source_file": "/home/monstruosoft/fastsdcpu/results/f834fc7f-f613-42b1-aa54-42d0cefb21d3-1.png",
  "target_file": null,
  "target_format": "jpg",
  "tile_size": 256,
  "tile_overlap": 16,
  "scale_factor": 2.0,
  "strength": 0.3,
  "tiles": []
}

An empty tiles array indicates the code to perform the default tiled upscale; however, that is not always enough to obtain a good result, particularly faces might require some extra generation to improve the output, so you can specify custom tile settings in the JSON file, for example:

{
  "source_file": "/home/monstruosoft/fastsdcpu/results/f834fc7f-f613-42b1-aa54-42d0cefb21d3-1.png",
  "target_file": "/home/monstruosoft/fastsdcpu/results/FastSD-1706709089.jpg",
  "target_format": "jpg",
  "tile_size": 256,
  "tile_overlap": 16,
  "scale_factor": 2.0,
  "strength": 0.3,
  "tiles": [{
    "x": 288,
    "y": 62,
    "w": 125,
    "h": 109,
    "scale_factor": 4.0,
    "mask_box": null,
    "prompt": null
  }]
}

This will generate a new tile from the specified region of the source image and paste it on the target image (usually a previously upscaled version of the same source file).

What each option does might seem complicated at first and, if needed, I may post an explanation including images to demonstrate their meaning and how each option affects the output.

Note that, at the moment, the JSON file requires manual editing but the idea is that eventually the settings might get generated dynamically from within the GUI versions of FastSD CPU.

Improve CLI tiled upscale using Image variations
Tiled upscale now supports alternative tile creation using
prompt-based img2img; this might help improve output on tiles that
require it
@rupeshs
Copy link
Owner

rupeshs commented Feb 2, 2024

@monstruosoft Thanks

@rupeshs rupeshs merged commit f7b083a into rupeshs:main Feb 2, 2024
@rupeshs
Copy link
Owner

rupeshs commented Feb 2, 2024

@monstruosoft It is not working with OpenVINO.

image

@monstruosoft
Copy link
Contributor Author

Might be due to the arbitrary sizes used for image generation, OpenVINO must have more strict checks for output resolution. Will take a look at it.

@rupeshs
Copy link
Owner

rupeshs commented Feb 3, 2024

@monstruosoft Openvino supports image size multiple of 64, I adjusted tile_overlap=32 and reshape=True, works but output resolution is 1024x1152 (Openvino upscale is slow because of this compiling)

        current_tile = context.generate_text_to_image(
            settings=config,
            device=DEVICE,
            reshape=True,
        )[0]

@rupeshs
Copy link
Owner

rupeshs commented Feb 3, 2024

@monstruosoft I just added OpenVINO upscale support and EDSR , more details #127

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