oneflow icon indicating copy to clipboard operation
oneflow copied to clipboard

[Documention Issue]: Example of how to SD upscale an image?

Open mnpenner opened this issue 2 years ago • 0 comments

Brief Description

Is there an example of how to upscale an image using oneflow/onediff?

I found this article which has helped me get started generating images with OneFlow, but I'm trying to figure out how to upscale an image now.

Is there a OneFlow equivalent to StableDiffusionUpscalePipeline like shown here? Similar to how there's a OneFlowStableDiffusionPipeline? I can't seem to find one.

Basically, I want to do this:

prompt = self.headers.get('SD-Prompt', "highres")
content_length = int(self.headers.get('Content-Length', 0))
raw_body = self.rfile.read(content_length)
low_res_img = Image.open(io.BytesIO(raw_body)).convert("RGB")
low_res_img = low_res_img.resize((low_res_img.width*4,low_res_img.height*4))
upscaled_image = upscale_pipe(prompt=prompt, image=low_res_img).images[0]
now = datetime.datetime.now().strftime("%Y%m%d_%H%M%S_%f")[:-3]
filename = f"{now}-upscaled.png"
upscaled_image.save(os.path.join(OUTPUT_DIR, filename))
print(f"Saved {filename}")
return self._send_json(filename)

But I need an upscale_pipe. The one from diffusers,

upscale_pipe = StableDiffusionUpscalePipeline.from_pretrained(
    "stabilityai/stable-diffusion-x4-upscaler", revision="fp16", torch_dtype=torch.float16
)

Doesn't seem to work, I get this error.

Alternatives

No response

mnpenner avatar Apr 30 '23 19:04 mnpenner