From de047d6a744c126dbabe71285e7f5b154a5aa34f Mon Sep 17 00:00:00 2001 From: "Alex J. Champandard" Date: Fri, 4 Nov 2016 00:32:08 +0100 Subject: [PATCH] Fix for images that are not multiples of 2 or 4, depending on the rescaling. --- enhance.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/enhance.py b/enhance.py index d7d64eb..f7ebb75 100755 --- a/enhance.py +++ b/enhance.py @@ -561,9 +561,17 @@ class NeuralEnhancer(object): print(ansi.ENDC) def process(self, original): + # Snap the image to a shape that's compatible with the generator (2x, 4x) + s = 2 ** max(args.generator_upscale, args.generator_downscale) + by, bx = original.shape[0] % s, original.shape[1] % s + original = original[by-by//2:original.shape[0]-by//2,bx-bx//2:original.shape[1]-bx//2,:] + + # Prepare paded input image as well as output buffer of zoomed size. s, p, z = args.rendering_tile, args.rendering_overlap, args.zoom - image = np.pad(original, ((p*z, p*z), (p*z, p*z), (0, 0)), mode='reflect') + image = np.pad(original, ((p, p), (p, p), (0, 0)), mode='reflect') output = np.zeros((original.shape[0] * z, original.shape[1] * z, 3), dtype=np.float32) + + # Iterate through the tile coordinates and pass them through the network. for y, x in itertools.product(range(0, original.shape[0], s), range(0, original.shape[1], s)): 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) *_, repro = self.model.predict(img)