Skip to content
This repository was archived by the owner on Jan 2, 2021. It is now read-only.

Commit de047d6

Browse files
committed
Fix for images that are not multiples of 2 or 4, depending on the rescaling.
1 parent 29bfe58 commit de047d6

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

enhance.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,9 +561,17 @@ def train(self):
561561
print(ansi.ENDC)
562562

563563
def process(self, original):
564+
# Snap the image to a shape that's compatible with the generator (2x, 4x)
565+
s = 2 ** max(args.generator_upscale, args.generator_downscale)
566+
by, bx = original.shape[0] % s, original.shape[1] % s
567+
original = original[by-by//2:original.shape[0]-by//2,bx-bx//2:original.shape[1]-bx//2,:]
568+
569+
# Prepare paded input image as well as output buffer of zoomed size.
564570
s, p, z = args.rendering_tile, args.rendering_overlap, args.zoom
565-
image = np.pad(original, ((p*z, p*z), (p*z, p*z), (0, 0)), mode='reflect')
571+
image = np.pad(original, ((p, p), (p, p), (0, 0)), mode='reflect')
566572
output = np.zeros((original.shape[0] * z, original.shape[1] * z, 3), dtype=np.float32)
573+
574+
# Iterate through the tile coordinates and pass them through the network.
567575
for y, x in itertools.product(range(0, original.shape[0], s), range(0, original.shape[1], s)):
568576
img = np.transpose(image[y:y+p*2+s,x:x+p*2+s,:] / 127.5 - 1.0, (2, 0, 1))[np.newaxis].astype(np.float32)
569577
*_, repro = self.model.predict(img)

0 commit comments

Comments
 (0)