[SD] Add Openpose to Stencil + image size issue fix (#1181)

-- This commit adds openpose model variant to stencil.
-- Fixes image size issue.
-- Also includes fix for the .exe bug introduced by https://github.com/nod-ai/SHARK/pull/1175

Signed-off-by: Abhishek Varma <abhishek@nod-labs.com>
Co-authored-by: Abhishek Varma <abhishek@nod-labs.com>
This commit is contained in:
Abhishek Varma
2023-03-14 23:00:52 +05:30
committed by GitHub
parent 771120b76c
commit e6b925e012
17 changed files with 1112 additions and 13 deletions

View File

@@ -3,7 +3,6 @@ import torch
import time
from PIL import Image
from dataclasses import dataclass
from apps.stable_diffusion.web.ui.utils import get_custom_model_pathfile
from apps.stable_diffusion.src import (
args,
Image2ImagePipeline,
@@ -42,12 +41,22 @@ init_import_mlir = args.import_mlir
# For stencil, the input image can be of any size but we need to ensure that
# it conforms with our model contraints :-
# Both width and height should be > 384 and multiple of 8.
# This utility function performs the transformation on the input image before
# sending it to the stencil pipeline.
# This utility function performs the transformation on the input image while
# also maintaining the aspect ratio before sending it to the stencil pipeline.
def resize_stencil(image: Image.Image):
width, height = image.size
if width < 384 or height < 384:
sys.exit("width and height should at least be 384")
aspect_ratio = width / height
min_size = min(width, height)
if min_size < 384:
n_size = 384
if width == min_size:
width = n_size
height = n_size / aspect_ratio
else:
height = n_size
width = n_size * aspect_ratio
width = int(width)
height = int(height)
n_width = width // 8
n_height = height // 8
n_width *= 8
@@ -79,6 +88,8 @@ def img2img_inf(
save_metadata_to_json: bool,
save_metadata_to_png: bool,
):
from apps.stable_diffusion.web.ui.utils import get_custom_model_pathfile
global img2img_obj
global config_obj
global schedulers

View File

@@ -2,7 +2,6 @@ import torch
import time
from PIL import Image
from dataclasses import dataclass
from apps.stable_diffusion.web.ui.utils import get_custom_model_pathfile
from apps.stable_diffusion.src import (
args,
InpaintPipeline,
@@ -59,6 +58,8 @@ def inpaint_inf(
save_metadata_to_json: bool,
save_metadata_to_png: bool,
):
from apps.stable_diffusion.web.ui.utils import get_custom_model_pathfile
global inpaint_obj
global config_obj
global schedulers

View File

@@ -2,7 +2,6 @@ import torch
import time
from PIL import Image
from dataclasses import dataclass
from apps.stable_diffusion.web.ui.utils import get_custom_model_pathfile
from apps.stable_diffusion.src import (
args,
OutpaintPipeline,
@@ -62,6 +61,8 @@ def outpaint_inf(
save_metadata_to_json: bool,
save_metadata_to_png: bool,
):
from apps.stable_diffusion.web.ui.utils import get_custom_model_pathfile
global outpaint_obj
global config_obj
global schedulers

View File

@@ -1,7 +1,6 @@
import torch
import time
from dataclasses import dataclass
from apps.stable_diffusion.web.ui.utils import get_custom_model_pathfile
from apps.stable_diffusion.src import (
args,
Text2ImagePipeline,
@@ -55,6 +54,8 @@ def txt2img_inf(
save_metadata_to_json: bool,
save_metadata_to_png: bool,
):
from apps.stable_diffusion.web.ui.utils import get_custom_model_pathfile
global txt2img_obj
global config_obj
global schedulers