-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy path__init__.py
141 lines (110 loc) · 4.26 KB
/
__init__.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
import sys
from os import path
sys.path.insert(0, path.dirname(__file__))
from .ldsrlib.LDSR import LDSR
from folder_paths import get_filename_list, get_full_path
from comfy.model_management import get_torch_device
from comfy.utils import ProgressBar
import torch
class LDSRModelLoader:
@classmethod
def INPUT_TYPES(s):
model_list = get_filename_list("upscale_models")
candidates = [name for name in model_list if 'last.ckpt' in name]
if len(candidates) > 0:
default_path = candidates[0]
else:
default_path = 'last.ckpt'
return {
"required": {
"model": (model_list, {'default': default_path}),
}
}
RETURN_TYPES = ("UPSCALE_MODEL",)
FUNCTION = "load"
CATEGORY = "Flowty LDSR"
def load(self, model):
model_path = get_full_path("upscale_models", model)
model = LDSR.load_model_from_path(model_path)
model['model'].cpu()
return (model, )
class LDSRUpscale:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"upscale_model": ("UPSCALE_MODEL",),
"images": ("IMAGE",),
"steps": (["25", "50", "100", "250", "500", "1000"], {"default": "100"}),
"pre_downscale": (['None', '1/2', '1/4'], {"default": "None"}),
"post_downscale": (['None', 'Original Size', '1/2', '1/4'], {"default": "None"}),
"downsample_method": (['Nearest', 'Lanczos'], {"default": "Lanczos"}),
}
}
RETURN_TYPES = ("IMAGE",)
RETURN_NAMES = ("images",)
FUNCTION = "upscale"
CATEGORY = "Flowty LDSR"
def upscale(self, upscale_model, images, steps, pre_downscale="None", post_downscale="None", downsample_method="Lanczos"):
pbar = ProgressBar(int(steps))
p = {"prev": 0}
def prog(i):
i = i + 1
if i < p["prev"]:
p["prev"] = 0
pbar.update(i - p["prev"])
p["prev"] = i
ldsr = LDSR(model=upscale_model, on_progress=prog)
outputs = []
for image in images:
outputs.append(ldsr.superResolution(image, int(steps), pre_downscale, post_downscale, downsample_method))
return (torch.stack(outputs),)
class LDSRUpscaler:
@classmethod
def INPUT_TYPES(s):
model_list = get_filename_list("upscale_models")
candidates = [name for name in model_list if 'last.ckpt' in name]
if len(candidates) > 0:
default_path = candidates[0]
else:
default_path = 'last.ckpt'
return {
"required": {
"model": (model_list, {'default': default_path}),
"images": ("IMAGE",),
"steps": (["25", "50", "100", "250", "500", "1000"], {"default": "100"}),
"pre_downscale": (['None', '1/2', '1/4'], {"default": "None"}),
"post_downscale": (['None', 'Original Size', '1/2', '1/4'], {"default": "None"}),
"downsample_method": (['Nearest', 'Lanczos'], {"default": "Lanczos"}),
}
}
RETURN_TYPES = ("IMAGE",)
RETURN_NAMES = ("images",)
FUNCTION = "upscale"
CATEGORY = "Flowty LDSR"
def upscale(self, model, images, steps, pre_downscale="None", post_downscale="None", downsample_method="Lanczos"):
model_path = get_full_path("upscale_models", model)
pbar = ProgressBar(int(steps))
p = {"prev": 0}
def prog(i):
i = i + 1
if i < p["prev"]:
p["prev"] = 0
pbar.update(i - p["prev"])
p["prev"] = i
ldsr = LDSR(modelPath=model_path, torchdevice=get_torch_device(), on_progress=prog)
outputs = []
for image in images:
outputs.append(ldsr.superResolution(image, int(steps), pre_downscale, post_downscale, downsample_method))
return (torch.stack(outputs),)
NODE_CLASS_MAPPINGS = {
"LDSRUpscaler": LDSRUpscaler,
"LDSRModelLoader": LDSRModelLoader,
"LDSRUpscale": LDSRUpscale
}
NODE_DISPLAY_NAME_MAPPINGS = {
"LDSRUpscaler": "LDSR Upscale (all-in-one)",
"LDSRModelLoader": "Load LDSR Model",
"LDSRUpscale": "LDSR Upscale"
}
__all__ = ['NODE_CLASS_MAPPINGS', 'NODE_DISPLAY_NAME_MAPPINGS']