Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make tiling support colorization models #2406

Merged
merged 1 commit into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions backend/src/nodes/impl/upscale/auto_split.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ def _max_split(
# and we only get to know this factor after the first successful upscale.
result: TileBlender | None = None
scale: int = 0
out_channels: int = 0

restart = True
while restart:
Expand Down Expand Up @@ -192,7 +193,7 @@ def _max_split(
break

# figure out by how much the image was upscaled by
up_h, up_w, _ = get_h_w_c(upscale_result)
up_h, up_w, up_c = get_h_w_c(upscale_result)
current_scale = up_h // padded_tile.height
assert current_scale > 0
assert padded_tile.height * current_scale == up_h
Expand All @@ -201,10 +202,11 @@ def _max_split(
if row_result is None:
# allocate the result image
scale = current_scale
out_channels = up_c
row_result = TileBlender(
width=w * scale,
height=padded_tile.height * scale,
channels=c,
channels=out_channels,
direction=BlendDirection.X,
blend_fn=half_sin_blend_fn,
_prev=prev_row_result,
Expand All @@ -229,7 +231,7 @@ def _max_split(
result = TileBlender(
width=w * scale,
height=h * scale,
channels=c,
channels=out_channels,
direction=BlendDirection.Y,
blend_fn=half_sin_blend_fn,
)
Expand Down
10 changes: 6 additions & 4 deletions backend/src/nodes/impl/upscale/exact_split.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def _exact_split_without_padding(
upscale: Callable[[np.ndarray, Region], np.ndarray],
overlap: int,
) -> np.ndarray:
h, w, c = get_h_w_c(img)
h, w, _ = get_h_w_c(img)
exact_w, exact_h = exact_size
assert w >= exact_w and h >= exact_h

Expand All @@ -139,6 +139,7 @@ def _exact_split_without_padding(
# and we only get to know this factor after the first successful upscale.
result: TileBlender | None = None
scale: int = 0
out_channels: int = 0

regions = _exact_split_into_regions(w, h, exact_w, exact_h, overlap)
for row in regions:
Expand All @@ -152,7 +153,7 @@ def _exact_split_without_padding(
upscale_result = upscale(padded_tile.read_from(img), padded_tile)

# figure out by how much the image was upscaled by
up_h, up_w, _ = get_h_w_c(upscale_result)
up_h, up_w, up_c = get_h_w_c(upscale_result)
current_scale = up_h // exact_h
assert current_scale > 0
assert exact_h * current_scale == up_h
Expand All @@ -161,10 +162,11 @@ def _exact_split_without_padding(
if row_result is None:
# allocate the result image
scale = current_scale
out_channels = up_c
row_result = TileBlender(
width=w * scale,
height=exact_h * scale,
channels=c,
channels=out_channels,
direction=BlendDirection.X,
blend_fn=half_sin_blend_fn,
)
Expand All @@ -182,7 +184,7 @@ def _exact_split_without_padding(
result = TileBlender(
width=w * scale,
height=h * scale,
channels=c,
channels=out_channels,
direction=BlendDirection.Y,
blend_fn=half_sin_blend_fn,
)
Expand Down