pms-nvidia-processor 2.4.0__tar.gz → 2.5.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pms_nvidia_processor-2.4.0 → pms_nvidia_processor-2.5.1}/PKG-INFO +1 -1
- {pms_nvidia_processor-2.4.0 → pms_nvidia_processor-2.5.1}/pms_nvidia_processor/__init__.py +3 -1
- {pms_nvidia_processor-2.4.0 → pms_nvidia_processor-2.5.1}/pms_nvidia_processor/processor/base/config.py +13 -0
- pms_nvidia_processor-2.5.1/pms_nvidia_processor/processor/col_en/config.py +27 -0
- pms_nvidia_processor-2.5.1/pms_nvidia_processor/processor/col_en/context.py +38 -0
- pms_nvidia_processor-2.5.1/pms_nvidia_processor/processor/col_en/processor.py +168 -0
- pms_nvidia_processor-2.5.1/pms_nvidia_processor/utility/patcher/__init__.py +2 -0
- {pms_nvidia_processor-2.4.0 → pms_nvidia_processor-2.5.1}/pms_nvidia_processor/utility/patcher/_patcher.py +31 -0
- pms_nvidia_processor-2.5.1/pms_nvidia_processor/utility/patcher/_patcher_w.py +109 -0
- {pms_nvidia_processor-2.4.0 → pms_nvidia_processor-2.5.1}/pyproject.toml +1 -1
- pms_nvidia_processor-2.4.0/pms_nvidia_processor/utility/patcher/__init__.py +0 -1
- {pms_nvidia_processor-2.4.0 → pms_nvidia_processor-2.5.1}/README.md +0 -0
- {pms_nvidia_processor-2.4.0 → pms_nvidia_processor-2.5.1}/pms_nvidia_processor/processor/base/dependency.py +0 -0
- {pms_nvidia_processor-2.4.0 → pms_nvidia_processor-2.5.1}/pms_nvidia_processor/processor/base/logger.py +0 -0
- {pms_nvidia_processor-2.4.0 → pms_nvidia_processor-2.5.1}/pms_nvidia_processor/processor/base/processor.py +0 -0
- {pms_nvidia_processor-2.4.0 → pms_nvidia_processor-2.5.1}/pms_nvidia_processor/processor/color_resnet/config.py +0 -0
- {pms_nvidia_processor-2.4.0 → pms_nvidia_processor-2.5.1}/pms_nvidia_processor/processor/color_resnet/context.py +0 -0
- {pms_nvidia_processor-2.4.0 → pms_nvidia_processor-2.5.1}/pms_nvidia_processor/processor/color_resnet/processor_post.py +0 -0
- {pms_nvidia_processor-2.4.0 → pms_nvidia_processor-2.5.1}/pms_nvidia_processor/processor/color_resnet/processor_pre.py +0 -0
- {pms_nvidia_processor-2.4.0 → pms_nvidia_processor-2.5.1}/pms_nvidia_processor/processor/dpir/config.py +0 -0
- {pms_nvidia_processor-2.4.0 → pms_nvidia_processor-2.5.1}/pms_nvidia_processor/processor/dpir/context.py +0 -0
- {pms_nvidia_processor-2.4.0 → pms_nvidia_processor-2.5.1}/pms_nvidia_processor/processor/dpir/processor.py +0 -0
- {pms_nvidia_processor-2.4.0 → pms_nvidia_processor-2.5.1}/pms_nvidia_processor/processor/dru_asm_sr_f3/config.py +0 -0
- {pms_nvidia_processor-2.4.0 → pms_nvidia_processor-2.5.1}/pms_nvidia_processor/processor/dru_asm_sr_f3/context.py +0 -0
- {pms_nvidia_processor-2.4.0 → pms_nvidia_processor-2.5.1}/pms_nvidia_processor/processor/dru_asm_sr_f3/processor.py +0 -0
- {pms_nvidia_processor-2.4.0 → pms_nvidia_processor-2.5.1}/pms_nvidia_processor/processor/dru_rbpn_deinter_f3_gloss/config.py +0 -0
- {pms_nvidia_processor-2.4.0 → pms_nvidia_processor-2.5.1}/pms_nvidia_processor/processor/dru_rbpn_deinter_f3_gloss/context.py +0 -0
- {pms_nvidia_processor-2.4.0 → pms_nvidia_processor-2.5.1}/pms_nvidia_processor/processor/dru_rbpn_deinter_f3_gloss/processor.py +0 -0
- {pms_nvidia_processor-2.4.0 → pms_nvidia_processor-2.5.1}/pms_nvidia_processor/processor/dru_rbpn_deinter_pc_f2/config.py +0 -0
- {pms_nvidia_processor-2.4.0 → pms_nvidia_processor-2.5.1}/pms_nvidia_processor/processor/dru_rbpn_deinter_pc_f2/context.py +0 -0
- {pms_nvidia_processor-2.4.0 → pms_nvidia_processor-2.5.1}/pms_nvidia_processor/processor/dru_rbpn_deinter_pc_f2/processor.py +0 -0
- {pms_nvidia_processor-2.4.0 → pms_nvidia_processor-2.5.1}/pms_nvidia_processor/processor/dru_rbpn_sr_f3/config.py +0 -0
- {pms_nvidia_processor-2.4.0 → pms_nvidia_processor-2.5.1}/pms_nvidia_processor/processor/dru_rbpn_sr_f3/context.py +0 -0
- {pms_nvidia_processor-2.4.0 → pms_nvidia_processor-2.5.1}/pms_nvidia_processor/processor/dru_rbpn_sr_f3/processor.py +0 -0
- {pms_nvidia_processor-2.4.0 → pms_nvidia_processor-2.5.1}/pms_nvidia_processor/processor/dru_rbpn_sr_f5/config.py +0 -0
- {pms_nvidia_processor-2.4.0 → pms_nvidia_processor-2.5.1}/pms_nvidia_processor/processor/dru_rbpn_sr_f5/context.py +0 -0
- {pms_nvidia_processor-2.4.0 → pms_nvidia_processor-2.5.1}/pms_nvidia_processor/processor/dru_rbpn_sr_f5/processor.py +0 -0
- {pms_nvidia_processor-2.4.0 → pms_nvidia_processor-2.5.1}/pms_nvidia_processor/processor/fisf/config.py +0 -0
- {pms_nvidia_processor-2.4.0 → pms_nvidia_processor-2.5.1}/pms_nvidia_processor/processor/fisf/context.py +0 -0
- {pms_nvidia_processor-2.4.0 → pms_nvidia_processor-2.5.1}/pms_nvidia_processor/processor/fisf/processor.py +0 -0
- {pms_nvidia_processor-2.4.0 → pms_nvidia_processor-2.5.1}/pms_nvidia_processor/processor/gg/config.py +0 -0
- {pms_nvidia_processor-2.4.0 → pms_nvidia_processor-2.5.1}/pms_nvidia_processor/processor/gg/context.py +0 -0
- {pms_nvidia_processor-2.4.0 → pms_nvidia_processor-2.5.1}/pms_nvidia_processor/processor/gg/processor.py +0 -0
- {pms_nvidia_processor-2.4.0 → pms_nvidia_processor-2.5.1}/pms_nvidia_processor/utility/batch.py +0 -0
- {pms_nvidia_processor-2.4.0 → pms_nvidia_processor-2.5.1}/pms_nvidia_processor/utility/caster.py +0 -0
- {pms_nvidia_processor-2.4.0 → pms_nvidia_processor-2.5.1}/pms_nvidia_processor/utility/normalizer/__init__.py +0 -0
- {pms_nvidia_processor-2.4.0 → pms_nvidia_processor-2.5.1}/pms_nvidia_processor/utility/normalizer/_factory.py +0 -0
- {pms_nvidia_processor-2.4.0 → pms_nvidia_processor-2.5.1}/pms_nvidia_processor/utility/normalizer/_multi_normalizer.py +0 -0
- {pms_nvidia_processor-2.4.0 → pms_nvidia_processor-2.5.1}/pms_nvidia_processor/utility/normalizer/_normalization_param.py +0 -0
- {pms_nvidia_processor-2.4.0 → pms_nvidia_processor-2.5.1}/pms_nvidia_processor/utility/normalizer/_single_normalizer.py +0 -0
- {pms_nvidia_processor-2.4.0 → pms_nvidia_processor-2.5.1}/pms_nvidia_processor/utility/patcher/_patch_collection.py +0 -0
- {pms_nvidia_processor-2.4.0 → pms_nvidia_processor-2.5.1}/pms_nvidia_processor/utility/patcher/_patch_position.py +0 -0
- {pms_nvidia_processor-2.4.0 → pms_nvidia_processor-2.5.1}/pms_nvidia_processor/utility/patcher/_patcher_v2.py +0 -0
|
@@ -10,6 +10,7 @@ from .processor.fisf.processor import FISFProcessor
|
|
|
10
10
|
from .processor.color_resnet.processor_pre import COLORRESNETPREProcessor
|
|
11
11
|
from .processor.color_resnet.processor_post import COLORRESNETPOSTProcessor
|
|
12
12
|
from .processor.gg.processor import GGProcessor
|
|
13
|
+
from .processor.col_en.processor import COLENProcessor
|
|
13
14
|
|
|
14
15
|
|
|
15
16
|
__all__: list[str] = [
|
|
@@ -23,6 +24,7 @@ __all__: list[str] = [
|
|
|
23
24
|
"COLORRESNETPREProcessor",
|
|
24
25
|
"COLORRESNETPOSTProcessor",
|
|
25
26
|
"GGProcessor",
|
|
27
|
+
"COLENProcessor",
|
|
26
28
|
]
|
|
27
29
|
|
|
28
|
-
__version__ = "2.
|
|
30
|
+
__version__ = "2.5.1"
|
|
@@ -67,3 +67,16 @@ class TRTIOConfig:
|
|
|
67
67
|
self.patch_size * self.upscale_ratio,
|
|
68
68
|
self.patch_size * self.upscale_ratio,
|
|
69
69
|
)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
@dataclass
|
|
73
|
+
class PatcherWIOConfig(PatcherIOConfig):
|
|
74
|
+
|
|
75
|
+
@property
|
|
76
|
+
def output_shape(self) -> tuple[int, int, int]:
|
|
77
|
+
output_patch_size = self.patch_size * self.upscale_ratio
|
|
78
|
+
return (
|
|
79
|
+
output_patch_size,
|
|
80
|
+
output_patch_size,
|
|
81
|
+
self.number_of_output_channels,
|
|
82
|
+
)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from ..base.config import *
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class ColEnConfig:
|
|
5
|
+
NUMBER_OF_FRAMES = 3
|
|
6
|
+
NUMBER_OF_INPUT_CHANNELS: int = 3 * NUMBER_OF_FRAMES
|
|
7
|
+
NUMBER_OF_OUTPUT_CHANNELS: int = 3
|
|
8
|
+
UPSCALE_RATIO: int = 1
|
|
9
|
+
PATCH_SIZE = 1536
|
|
10
|
+
MAX_BATCH_SIZE = 1
|
|
11
|
+
MIN_BATCH_SIZE = 1
|
|
12
|
+
OPT_BATCH_SIZE = 1
|
|
13
|
+
INPUT_OVERLAB_LENGTH = PATCH_SIZE // 2
|
|
14
|
+
|
|
15
|
+
PATCHER_CONFIG = PatcherWIOConfig(
|
|
16
|
+
patch_size=PATCH_SIZE,
|
|
17
|
+
upscale_ratio=UPSCALE_RATIO,
|
|
18
|
+
number_of_input_channels=NUMBER_OF_INPUT_CHANNELS,
|
|
19
|
+
number_of_output_channels=NUMBER_OF_OUTPUT_CHANNELS,
|
|
20
|
+
input_overlab_length=INPUT_OVERLAB_LENGTH,
|
|
21
|
+
)
|
|
22
|
+
TRT_CONFIG = TRTIOConfig(
|
|
23
|
+
patch_size=PATCH_SIZE,
|
|
24
|
+
upscale_ratio=UPSCALE_RATIO,
|
|
25
|
+
number_of_input_channels=NUMBER_OF_INPUT_CHANNELS,
|
|
26
|
+
number_of_output_channels=NUMBER_OF_OUTPUT_CHANNELS,
|
|
27
|
+
)
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
from .config import *
|
|
2
|
+
from ..base.dependency import *
|
|
3
|
+
from ..base.processor import *
|
|
4
|
+
from ...utility import patcher, normalizer
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class ColEnContext:
|
|
8
|
+
|
|
9
|
+
def __init__(
|
|
10
|
+
self,
|
|
11
|
+
input_vector: np.ndarray,
|
|
12
|
+
input_patcher: patcher.PatcherW,
|
|
13
|
+
) -> None:
|
|
14
|
+
config = ColEnConfig()
|
|
15
|
+
|
|
16
|
+
self.input_vector = input_vector
|
|
17
|
+
self.input_pathcer = input_patcher
|
|
18
|
+
self.padded_input_image = patcher.pad_vector(
|
|
19
|
+
vector=self.input_vector,
|
|
20
|
+
overlap_length=config.PATCHER_CONFIG.input_overlab_length,
|
|
21
|
+
mode="edge",
|
|
22
|
+
)
|
|
23
|
+
self.input_patches: list[np.ndarray] = self.input_pathcer.slice(
|
|
24
|
+
self.padded_input_image
|
|
25
|
+
)
|
|
26
|
+
self.output_patches: np.ndarray = np.zeros(
|
|
27
|
+
(
|
|
28
|
+
len(self.input_patches),
|
|
29
|
+
config.PATCH_SIZE * config.UPSCALE_RATIO,
|
|
30
|
+
config.PATCH_SIZE * config.UPSCALE_RATIO,
|
|
31
|
+
3,
|
|
32
|
+
),
|
|
33
|
+
np.float32,
|
|
34
|
+
)
|
|
35
|
+
self.output_vector: np.ndarray = np.zeros(
|
|
36
|
+
(*self.padded_input_image.shape[:-1], 3),
|
|
37
|
+
np.float32,
|
|
38
|
+
)
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
from .config import *
|
|
2
|
+
from .context import *
|
|
3
|
+
from ..base.dependency import *
|
|
4
|
+
from ..base.processor import *
|
|
5
|
+
from ...utility import patcher, normalizer, batch, caster
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def _pre_processing(
|
|
9
|
+
batch_input_images: list[np.ndarray],
|
|
10
|
+
input_buffer: np.ndarray,
|
|
11
|
+
) -> None:
|
|
12
|
+
b = len(batch_input_images)
|
|
13
|
+
|
|
14
|
+
for batch_idx in range(b):
|
|
15
|
+
image = batch_input_images[batch_idx]
|
|
16
|
+
h, w, c = image.shape
|
|
17
|
+
for channel_idx in range(c):
|
|
18
|
+
input_buffer[batch_idx, channel_idx, :h, :w] = image[:, :, channel_idx]
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _post_processing(
|
|
22
|
+
output_buffer: np.ndarray, # BxCxHxW
|
|
23
|
+
output_image: np.ndarray, # BxHxWxC
|
|
24
|
+
) -> None:
|
|
25
|
+
|
|
26
|
+
b, h, w, c = output_image.shape
|
|
27
|
+
for i in range(3):
|
|
28
|
+
np.copyto(src=output_buffer[:b, i, :h, :w], dst=output_image[:, :, :, i])
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@register
|
|
32
|
+
class COLENProcessor(NVIDIAProcessorBase[EngineIOData, EngineIOData]):
|
|
33
|
+
|
|
34
|
+
def __init__(
|
|
35
|
+
self,
|
|
36
|
+
concurrency: int,
|
|
37
|
+
index: int,
|
|
38
|
+
model_path: str,
|
|
39
|
+
device: Literal["auto"] | int = "auto",
|
|
40
|
+
normalization: str = "color-basic",
|
|
41
|
+
):
|
|
42
|
+
# super
|
|
43
|
+
super().__init__(
|
|
44
|
+
concurrency=concurrency,
|
|
45
|
+
index=index,
|
|
46
|
+
model_path=model_path,
|
|
47
|
+
device=device,
|
|
48
|
+
)
|
|
49
|
+
self.config = ColEnConfig
|
|
50
|
+
self.normalizer = normalizer.NormalizerFactory.create_multi(normalization)
|
|
51
|
+
|
|
52
|
+
async def inference(
|
|
53
|
+
self,
|
|
54
|
+
batch_input_data: list[np.ndarray],
|
|
55
|
+
batch_output_data: np.ndarray,
|
|
56
|
+
):
|
|
57
|
+
session = self.session
|
|
58
|
+
batch = len(batch_input_data)
|
|
59
|
+
|
|
60
|
+
_pre_processing(
|
|
61
|
+
batch_input_images=batch_input_data,
|
|
62
|
+
input_buffer=self.input_buffer,
|
|
63
|
+
)
|
|
64
|
+
session.run()
|
|
65
|
+
_post_processing(
|
|
66
|
+
output_buffer=self.output_buffer,
|
|
67
|
+
output_image=batch_output_data,
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
async def _run(self, input_data: EngineIOData) -> EngineIOData:
|
|
71
|
+
max_batch_size = self.io_shapes["input"][0][0]
|
|
72
|
+
|
|
73
|
+
# 여기서 patching
|
|
74
|
+
input_vector = self.caster.cast(input_data.frame)
|
|
75
|
+
[
|
|
76
|
+
self.normalizer.normalize(input_vector[:, :, i * 3 : (i + 1) * 3], 2)
|
|
77
|
+
for i in range(self.config.NUMBER_OF_FRAMES)
|
|
78
|
+
]
|
|
79
|
+
context = ColEnContext(input_vector, self.patcher)
|
|
80
|
+
|
|
81
|
+
# batch inference
|
|
82
|
+
for batch_input_patches, batch_output_patches in zip(
|
|
83
|
+
batch.BatchTool.batch_list(context.input_patches, max_batch_size),
|
|
84
|
+
batch.BatchTool.batch_vector(context.output_patches, max_batch_size),
|
|
85
|
+
):
|
|
86
|
+
await self.inference(
|
|
87
|
+
batch_input_data=batch_input_patches,
|
|
88
|
+
batch_output_data=batch_output_patches,
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
self.patcher.merge(
|
|
92
|
+
patches=context.output_patches,
|
|
93
|
+
output_vector=context.output_vector,
|
|
94
|
+
)
|
|
95
|
+
context.output_vector = patcher.crop_vector(
|
|
96
|
+
context.output_vector, context.input_pathcer._input_overlap_length
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
self.normalizer.denormalize(context.output_vector, 2)
|
|
100
|
+
return EngineIOData(
|
|
101
|
+
frame_id=input_data.frame_id,
|
|
102
|
+
frame=self.caster.uncast(context.output_vector),
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
def _ready_processor(self) -> bool:
|
|
106
|
+
return True
|
|
107
|
+
|
|
108
|
+
def _bind_io(self, input_data: EngineIOData):
|
|
109
|
+
self.caster = caster.Caster(input_data.frame)
|
|
110
|
+
|
|
111
|
+
patcher_config = self.config.PATCHER_CONFIG
|
|
112
|
+
trt_config = self.config.TRT_CONFIG
|
|
113
|
+
|
|
114
|
+
input_image: np.ndarray = input_data.frame # type: ignore
|
|
115
|
+
padded_input_image = patcher.pad_vector(
|
|
116
|
+
input_image,
|
|
117
|
+
overlap_length=patcher_config.input_overlab_length,
|
|
118
|
+
)
|
|
119
|
+
output_image: np.ndarray = np.zeros(
|
|
120
|
+
(
|
|
121
|
+
input_image.shape[0] * self.config.UPSCALE_RATIO,
|
|
122
|
+
input_image.shape[1] * self.config.UPSCALE_RATIO,
|
|
123
|
+
self.config.NUMBER_OF_OUTPUT_CHANNELS,
|
|
124
|
+
)
|
|
125
|
+
)
|
|
126
|
+
self.patcher = patcher.PatcherW(
|
|
127
|
+
**patcher_config.build_patcher_params(
|
|
128
|
+
input_vector=padded_input_image,
|
|
129
|
+
output_vector=output_image,
|
|
130
|
+
)
|
|
131
|
+
)
|
|
132
|
+
n_patches = len(self.patcher.slice(input_vector=padded_input_image))
|
|
133
|
+
|
|
134
|
+
# set io shape
|
|
135
|
+
self.batch_size = min(n_patches, self.config.MAX_BATCH_SIZE)
|
|
136
|
+
self.io_shapes = {
|
|
137
|
+
"input": (
|
|
138
|
+
[self.batch_size, *trt_config.input_shape],
|
|
139
|
+
np.float32,
|
|
140
|
+
),
|
|
141
|
+
"output": (
|
|
142
|
+
[self.batch_size, *trt_config.output_shape],
|
|
143
|
+
np.float32,
|
|
144
|
+
),
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
# init trt engine
|
|
148
|
+
self.initialize_trt_session(
|
|
149
|
+
required_batch_size=self.batch_size,
|
|
150
|
+
io_shape=self.io_shapes,
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
# set io buffer
|
|
154
|
+
self.input_buffer = self.session._input_bindings[0].host_buffer.reshape(
|
|
155
|
+
self.io_shapes["input"][0]
|
|
156
|
+
)
|
|
157
|
+
self.input_buffer.fill(0 / 255.0)
|
|
158
|
+
self.output_buffer = self.session._output_bindings[0].host_buffer.reshape(
|
|
159
|
+
*self.io_shapes["output"][0]
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
return True
|
|
163
|
+
|
|
164
|
+
def _get_live(self) -> bool:
|
|
165
|
+
return True
|
|
166
|
+
|
|
167
|
+
def _get_concurrency(self) -> int:
|
|
168
|
+
return self._concurrency
|
|
@@ -80,3 +80,34 @@ class Patcher:
|
|
|
80
80
|
patches=patches,
|
|
81
81
|
overlab_length=self._output_overlap_length,
|
|
82
82
|
)
|
|
83
|
+
|
|
84
|
+
def merge_w(
|
|
85
|
+
self, output_vector: np.ndarray, patches: list[np.ndarray] | np.ndarray
|
|
86
|
+
):
|
|
87
|
+
import cv2
|
|
88
|
+
|
|
89
|
+
n = 0
|
|
90
|
+
|
|
91
|
+
pos_collection = self._output_pos_collection
|
|
92
|
+
vector = output_vector
|
|
93
|
+
weight_vector = np.ones((*output_vector.shape[:-1], 1), np.float32) * (1e-8)
|
|
94
|
+
overlab_length = self._output_overlap_length
|
|
95
|
+
print(f"pos_collection.size: {pos_collection.size}")
|
|
96
|
+
print(f"pos_collection.patch_pos_list: {pos_collection.patch_pos_list}")
|
|
97
|
+
for pos, patch in zip(pos_collection, patches, strict=True): # inplace copy
|
|
98
|
+
h, w, c = patch.shape
|
|
99
|
+
np.add(
|
|
100
|
+
vector[pos.y.range, pos.x.range],
|
|
101
|
+
patch[
|
|
102
|
+
overlab_length : overlab_length + pos.y.dp,
|
|
103
|
+
overlab_length : overlab_length + pos.x.dp,
|
|
104
|
+
],
|
|
105
|
+
out=vector[pos.y.range, pos.x.range],
|
|
106
|
+
)
|
|
107
|
+
weight_vector[pos.y.range, pos.x.range] += 1.0
|
|
108
|
+
cv2.imwrite(
|
|
109
|
+
f"/home/hskim/pms-nvidia-processor/.pytest_cache/2025-04-29 color test/{n:04d}.jpg",
|
|
110
|
+
np.clip(vector * 255, 0, 255).astype(np.uint8),
|
|
111
|
+
)
|
|
112
|
+
n += 1
|
|
113
|
+
# np.divide(vector, weight_vector, out=vector)
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
from typing import Literal
|
|
2
|
+
import numpy as np
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def crop_vector(
|
|
6
|
+
vector: np.ndarray,
|
|
7
|
+
overlap_length: int,
|
|
8
|
+
) -> np.ndarray:
|
|
9
|
+
return vector[overlap_length:-overlap_length, overlap_length:-overlap_length].copy()
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class PatcherW:
|
|
13
|
+
|
|
14
|
+
def __init__(
|
|
15
|
+
self,
|
|
16
|
+
input_vector_shape: tuple[int, int, int],
|
|
17
|
+
input_patch_shape: tuple[int, int, int],
|
|
18
|
+
input_overlap_length: int,
|
|
19
|
+
output_vector_shape: tuple[int, int, int],
|
|
20
|
+
output_patch_shape: tuple[int, int, int],
|
|
21
|
+
output_overlap_length: int,
|
|
22
|
+
) -> None:
|
|
23
|
+
assert input_overlap_length > -1, "assert input_overlap_length > -1"
|
|
24
|
+
assert all(
|
|
25
|
+
[e > 0 for e in input_patch_shape]
|
|
26
|
+
), "assert all([e > 0 for e in input_patch_shape])"
|
|
27
|
+
assert (
|
|
28
|
+
len(input_patch_shape) == 3
|
|
29
|
+
), "assert len(input_patch_shape) == 3" # only allow image-like vector
|
|
30
|
+
self._input_vector_shape = input_vector_shape
|
|
31
|
+
self._input_patch_shape = input_patch_shape
|
|
32
|
+
self._input_overlap_length = input_overlap_length
|
|
33
|
+
|
|
34
|
+
self._patch_pos_list = self._get_patch_pos_list()
|
|
35
|
+
self._weight_mask = self._make_weight_mask(output_patch_shape)
|
|
36
|
+
|
|
37
|
+
def _get_patch_pos_list(self):
|
|
38
|
+
input_vector_width = self._input_vector_shape[1]
|
|
39
|
+
input_vector_height = self._input_vector_shape[0]
|
|
40
|
+
input_patch_width = self._input_patch_shape[1]
|
|
41
|
+
input_patch_height = self._input_patch_shape[0]
|
|
42
|
+
input_overlap_length = self._input_overlap_length
|
|
43
|
+
patchs: list[tuple[slice, slice]] = []
|
|
44
|
+
for y0 in range(
|
|
45
|
+
0, input_vector_height, input_patch_height - input_overlap_length
|
|
46
|
+
):
|
|
47
|
+
y1 = min(y0 + input_patch_height, input_vector_height)
|
|
48
|
+
for x0 in range(
|
|
49
|
+
0, input_vector_width, input_patch_width - input_overlap_length
|
|
50
|
+
):
|
|
51
|
+
x1 = min(x0 + input_patch_width, input_vector_width)
|
|
52
|
+
patchs.append((slice(y0, y1), slice(x0, x1)))
|
|
53
|
+
return patchs
|
|
54
|
+
|
|
55
|
+
def _make_weight_mask(
|
|
56
|
+
self,
|
|
57
|
+
shape: tuple[int, int, int],
|
|
58
|
+
min_val=0.0,
|
|
59
|
+
max_val=1.0,
|
|
60
|
+
sigma_scale=0.25,
|
|
61
|
+
):
|
|
62
|
+
"""
|
|
63
|
+
h, w: 패치 높이/너비
|
|
64
|
+
sigma_scale: 중심에서 분포하는 정도 (0.25이면 가우시안 표준편차가 크기 대비 1/4)
|
|
65
|
+
"""
|
|
66
|
+
import cv2
|
|
67
|
+
|
|
68
|
+
h, w, c = shape
|
|
69
|
+
y = np.linspace(-1, 1, h)
|
|
70
|
+
x = np.linspace(-1, 1, w)
|
|
71
|
+
yy, xx = np.meshgrid(y, x, indexing="ij")
|
|
72
|
+
d2 = xx**2 + yy**2
|
|
73
|
+
sigma2 = sigma_scale**2
|
|
74
|
+
weights = np.exp(-d2 / (2 * sigma2))
|
|
75
|
+
np.subtract(weights, weights.min(), out=weights)
|
|
76
|
+
np.divide(weights, weights.max(), out=weights)
|
|
77
|
+
weights = weights * (max_val - min_val) + min_val
|
|
78
|
+
cv2.imwrite(
|
|
79
|
+
"/home/hskim/pms-nvidia-processor/.pytest_cache/weights.png",
|
|
80
|
+
(weights * 255).astype(np.uint8),
|
|
81
|
+
)
|
|
82
|
+
return weights.astype(np.float32)[:, :, None] # type cast and add dimension
|
|
83
|
+
# return np.stack([weights for _ in range(c)], axis=-1, dtype=np.float32)
|
|
84
|
+
|
|
85
|
+
def slice(self, input_vector: np.ndarray) -> list[np.ndarray]:
|
|
86
|
+
patchs = []
|
|
87
|
+
for ys, xs in self._get_patch_pos_list():
|
|
88
|
+
patchs.append(input_vector[ys, xs])
|
|
89
|
+
return patchs
|
|
90
|
+
|
|
91
|
+
def merge(
|
|
92
|
+
self,
|
|
93
|
+
patches: list[np.ndarray] | np.ndarray,
|
|
94
|
+
output_vector: np.ndarray,
|
|
95
|
+
scale: int = 1,
|
|
96
|
+
):
|
|
97
|
+
w_vector = np.ones((*output_vector.shape[:-1], 1), np.float32) * (1e-8)
|
|
98
|
+
for (ys, xs), patch in zip(self._patch_pos_list, patches, strict=True):
|
|
99
|
+
ys_out = slice(ys.start * scale, ys.stop * scale)
|
|
100
|
+
xs_out = slice(xs.start * scale, xs.stop * scale)
|
|
101
|
+
target_vector = output_vector[ys_out, xs_out]
|
|
102
|
+
target_patch = patch[: target_vector.shape[0], : target_vector.shape[1]]
|
|
103
|
+
target_weight_mask = self._weight_mask[
|
|
104
|
+
: target_patch.shape[0], : target_patch.shape[1]
|
|
105
|
+
]
|
|
106
|
+
np.multiply(target_patch, target_weight_mask, out=target_patch)
|
|
107
|
+
np.add(target_vector, target_patch, out=target_vector)
|
|
108
|
+
w_vector[ys_out, xs_out] += target_weight_mask
|
|
109
|
+
output_vector /= w_vector
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
from ._patcher import Patcher, pad_vector
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pms_nvidia_processor-2.4.0 → pms_nvidia_processor-2.5.1}/pms_nvidia_processor/utility/batch.py
RENAMED
|
File without changes
|
{pms_nvidia_processor-2.4.0 → pms_nvidia_processor-2.5.1}/pms_nvidia_processor/utility/caster.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|