Batch hires fix?
#14846
Replies: 2 comments 17 replies
-
This can be automated with the API. import requests
import base64
import glob
import os
url = "http://127.0.0.1:7860"
# Find files
files = glob.glob('input/*.png')
os.makedirs("output", exist_ok=True)
for file in files:
# Get PNG Info
with open(file, "rb") as f:
img = base64.b64encode(f.read()).decode('utf-8')
response = requests.post(url=f'{url}/sdapi/v1/png-info', json={"image": img})
params = response.json()["parameters"]
# Generate image
payload = {
"prompt": params["Prompt"],
"negative_prompt": params["Negative prompt"],
"styles": params.get("Styles array", []),
"seed": params["Seed"],
"steps": params["Steps"],
"cfg_scale": params["CFG scale"],
"sampler_name": params["Sampler"],
"width": params["Size-1"],
"height": params["Size-2"],
"enable_hr": True,
"hr_scale": 2.0, # Upscale by
"hr_upscaler": "Latent", # Upscaler
"hr_second_pass_steps": 0, # Hires steps
"denoising_strength": 0.7, # Denoising strength
}
response = requests.post(url=f'{url}/sdapi/v1/txt2img', json=payload)
r = response.json()
# Save image
with open(os.path.join("output", os.path.basename(file)), 'wb') as f:
f.write(base64.b64decode(r['images'][0])) Takes PNGs from |
Beta Was this translation helpful? Give feedback.
13 replies
-
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
The Extras tab in the UI has an option for batch upscaling, but the upscaling that it does here is substantially different from what happens with a hires fix in the txt2img tab. I believe the difference is that it doesn't do any denoising, but someone may correct me if there are other differences.
In my opinion, the upscaled images generated this way are not as good as images generated via hires fix. As a result, I tend to load an image into the png info tab, send it to the txt2img tab with the proper seed, enable hires fix, and regenerate it entirely. If I want to do this to many images, it's time consuming.
I'd like to know if there's a way to do a hires fix on an image after it has been generated. Especially in batch. This seems like an option that could be added to the batch upscaling under Extras.
I'm hoping that I've completely missed something and someone can tell me that there's already an extension for this, but I haven't found one.
Beta Was this translation helpful? Give feedback.
All reactions