-
Notifications
You must be signed in to change notification settings - Fork 15
/
stablezero123.py
195 lines (164 loc) · 6.55 KB
/
stablezero123.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
import torch
import requests
from PIL import Image
from diffusers import DiffusionPipeline, EulerAncestralDiscreteScheduler, ControlNetModel
import numpy as np
#tiles = [im[x:x+M,y:y+N] for x in range(0,im.shape[0],M) for y in range(0,im.shape[1],N)]
class ImageSplit:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"images": ("IMAGE", ),
"columns": ("INT", {
"default": 2,
"min": 1, #Minimum value
"max": 100, #Maximum value
"step": 1, #Slider's step
"display": "number"
}),
"lines": ("INT", {
"default": 3,
"min": 1, #Minimum value
"max": 100, #Maximum value
"step": 1, #Slider's step
"display": "number"
}),
},
}
RETURN_TYPES = ("IMAGE",)
FUNCTION = "execute"
CATEGORY = "tests"
def execute(self, images, columns, lines):
image=images[0]
i = 255. * image.cpu().numpy()
pil_image = Image.fromarray(np.clip(i, 0, 255).astype(np.uint8))
imgwidth = pil_image.size[0]
imgheight = pil_image.size[1]
M=int(imgwidth/columns)
N=int(imgheight/lines)
tiles=[]
for i in range(0, imgheight-imgheight%N, N):
for j in range(0, imgwidth-imgwidth%M, M):
box = (j, i, j+M, i+N)
tiles.append(pil_image.crop(box))
t_tiles=[]
for tile in tiles:
t_tile = tile.convert("RGB")
t_tile = np.array(t_tile).astype(np.float32) / 255.0
t_tile = torch.from_numpy(t_tile)[None,]
t_tiles.append(t_tile)
s=t_tiles[0]
for i in range(1,len(t_tiles)):
s = torch.cat((s, t_tiles[i]), dim=0)
return (s,)
class Stablezero123:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"images": ("IMAGE", ),
"ckpt_name": ("STRING", {
"multiline": False,
"default": "sudo-ai/zero123plus-v1.1"
}),
"pipeline_name": ("STRING", {
"multiline": False,
"default": "sudo-ai/zero123plus-pipeline"
}),
"inference_steps": ("INT", {
"default": 75,
"min": 1, #Minimum value
"max": 100, #Maximum value
"step": 1, #Slider's step
"display": "number"
}),
},
}
RETURN_TYPES = ("IMAGE",)
FUNCTION = "execute"
CATEGORY = "tests"
def execute(self, images, ckpt_name, pipeline_name, inference_steps):
pipeline = DiffusionPipeline.from_pretrained(ckpt_name, custom_pipeline=pipeline_name, torch_dtype=torch.float16)
pipeline.scheduler = EulerAncestralDiscreteScheduler.from_config(
pipeline.scheduler.config, timestep_spacing='trailing')
pipeline.to('cuda:0')
image=images[0]
i = 255. * image.cpu().numpy()
cond = Image.fromarray(np.clip(i, 0, 255).astype(np.uint8))
##cond = Image.open(requests.get("https://d.skis.ltd/nrp/sample-data/lysol.png", stream=True).raw)
## Converter para formato img
image = pipeline(cond, num_inference_steps=inference_steps).images[0]
image = image.convert("RGB")
image = np.array(image).astype(np.float32) / 255.0
image = torch.from_numpy(image)[None,]
return (image,)
class Stablezero123WithDepth:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"images": ("IMAGE", ),
"depth_images": ("IMAGE", ),
"ckpt_name": ("STRING", {
"multiline": False,
"default": "sudo-ai/zero123plus-v1.1"
}),
"control_model_name": ("STRING", {
"multiline": False,
"default": "sudo-ai/controlnet-zp11-depth-v1"
}),
"pipeline_name": ("STRING", {
"multiline": False,
"default": "sudo-ai/zero123plus-pipeline"
}),
"inference_steps": ("INT", {
"default": 75,
"min": 1, #Minimum value
"max": 100, #Maximum value
"step": 1, #Slider's step
"display": "number"
}),
},
}
RETURN_TYPES = ("IMAGE",)
FUNCTION = "execute"
CATEGORY = "tests"
def execute(self, images, depth_images, ckpt_name, control_model_name, pipeline_name, inference_steps):
pipeline = DiffusionPipeline.from_pretrained(ckpt_name, custom_pipeline=pipeline_name, torch_dtype=torch.float16)
pipeline.add_controlnet(ControlNetModel.from_pretrained(control_model_name, torch_dtype=torch.float16), conditioning_scale=0.75)
pipeline.scheduler = EulerAncestralDiscreteScheduler.from_config(
pipeline.scheduler.config, timestep_spacing='trailing')
pipeline.to('cuda:0')
image=images[0]
i = 255. * image.cpu().numpy()
cond = Image.fromarray(np.clip(i, 0, 255).astype(np.uint8))
depth=depth_images[0]
ii = 255. * depth.cpu().numpy()
depth = Image.fromarray(np.clip(ii, 0, 255).astype(np.uint8))
##cond = Image.open(requests.get("https://d.skis.ltd/nrp/sample-data/lysol.png", stream=True).raw)
## Converter para formato img
image = pipeline(cond, depth_image=depth, num_inference_steps=inference_steps).images[0]
image = image.convert("RGB")
image = np.array(image).astype(np.float32) / 255.0
image = torch.from_numpy(image)[None,]
return (image,)
# A dictionary that contains all nodes you want to export with their names
# NOTE: names should be globally unique
NODE_CLASS_MAPPINGS = {
#"Stablezero123WithDepth" : Stablezero123WithDepth,
"Stablezero123": Stablezero123,
"SDZero ImageSplit" : ImageSplit
}
# A dictionary that contains the friendly/humanly readable titles for the nodes
NODE_DISPLAY_NAME_MAPPINGS = {
#"Stablezero123WithDepth": "Stablezero123WithDepth",
"Stablezero123": "Stablezero123",
"SDZero ImageSplit" : "SDZero ImageSplit"
}