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

Commit 6de7f71

Browse files
committed
Nicer console output while enhancing
file.png (tile 4 of 9) instead of just printing dots
1 parent 559e66b commit 6de7f71

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

enhance.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ def match_histograms(self, A, B, rng=(0.0, 255.0), bins=64):
544544
map_Hb = scipy.interpolate.interp1d(Hpb, X, bounds_error=False)
545545
return map_Hb(inv_Ha(A).clip(0.0, 255.0))
546546

547-
def process(self, original):
547+
def process(self, filename, original):
548548
# Snap the image to a shape that's compatible with the generator (2x, 4x)
549549
s = 2 ** max(args.generator_upscale, args.generator_downscale)
550550
by, bx = original.shape[0] % s, original.shape[1] % s
@@ -555,12 +555,15 @@ def process(self, original):
555555
image = np.pad(original, ((p, p), (p, p), (0, 0)), mode='reflect')
556556
output = np.zeros((original.shape[0] * z, original.shape[1] * z, 3), dtype=np.float32)
557557

558+
tileslist = list(itertools.product(range(0, original.shape[0], s), range(0, original.shape[1], s)))
559+
558560
# Iterate through the tile coordinates and pass them through the network.
559-
for y, x in itertools.product(range(0, original.shape[0], s), range(0, original.shape[1], s)):
561+
for tilenumber, (y, x) in enumerate(tileslist):
562+
print("\r%s (tile %d of %d)" % (filename, tilenumber, len(tileslist)), end='', flush=True)
560563
img = np.transpose(image[y:y+p*2+s,x:x+p*2+s,:] / 255.0 - 0.5, (2, 0, 1))[np.newaxis].astype(np.float32)
561564
*_, repro = self.model.predict(img)
562565
output[y*z:(y+s)*z,x*z:(x+s)*z,:] = np.transpose(repro[0] + 0.5, (1, 2, 0))[p*z:-p*z,p*z:-p*z,:]
563-
print('.', end='', flush=True)
566+
print("\r%s (tile %d of %d)" % (filename, len(tileslist), len(tileslist)), end='\n', flush=True)
564567
output = output.clip(0.0, 1.0) * 255.0
565568

566569
# Match color histograms if the user specified this option.
@@ -579,9 +582,8 @@ def process(self, original):
579582
else:
580583
enhancer = NeuralEnhancer(loader=False)
581584
for filename in args.files:
582-
print(filename, end=' ')
585+
print(filename, end=' ', flush=True)
583586
img = scipy.ndimage.imread(filename, mode='RGB')
584-
out = enhancer.process(img)
587+
out = enhancer.process(filename, img)
585588
out.save(os.path.splitext(filename)[0]+'_ne%ix.png' % args.zoom)
586-
print(flush=True)
587589
print(ansi.ENDC)

0 commit comments

Comments
 (0)