@@ -609,7 +609,7 @@ def match_histograms(self, A, B, rng=(0.0, 255.0), bins=64):
609609 map_Hb = scipy .interpolate .interp1d (Hpb , X , bounds_error = False )
610610 return map_Hb (inv_Ha (A ).clip (0.0 , 255.0 ))
611611
612- def process (self , original ):
612+ def process (self , filename , original ):
613613 # Snap the image to a shape that's compatible with the generator (2x, 4x)
614614 s = 2 ** max (args .generator_upscale , args .generator_downscale )
615615 by , bx = original .shape [0 ] % s , original .shape [1 ] % s
@@ -620,12 +620,15 @@ def process(self, original):
620620 image = np .pad (original , ((p , p ), (p , p ), (0 , 0 )), mode = 'reflect' )
621621 output = np .zeros ((original .shape [0 ] * z , original .shape [1 ] * z , 3 ), dtype = np .float32 )
622622
623+ tileslist = list (itertools .product (range (0 , original .shape [0 ], s ), range (0 , original .shape [1 ], s )))
624+
623625 # Iterate through the tile coordinates and pass them through the network.
624- for y , x in itertools .product (range (0 , original .shape [0 ], s ), range (0 , original .shape [1 ], s )):
626+ for tilenumber , (y , x ) in enumerate (tileslist ):
627+ print ("\r %s (tile %d of %d)" % (filename , tilenumber , len (tileslist )), end = '' , flush = True )
625628 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 )
626629 * _ , repro = self .model .predict (img )
627630 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 ,:]
628- print ( '.' , end = '' , flush = True )
631+ print ( " \r %s (tile %d of %d)" % ( filename , len ( tileslist ), len ( tileslist )), end = '\n ' , flush = True )
629632 output = output .clip (0.0 , 1.0 ) * 255.0
630633
631634 # Match color histograms if the user specified this option.
@@ -644,9 +647,8 @@ def process(self, original):
644647 else :
645648 enhancer = NeuralEnhancer (loader = False )
646649 for filename in args .files :
647- print (filename , end = ' ' )
650+ print (filename , end = ' ' , flush = True )
648651 img = scipy .ndimage .imread (filename , mode = 'RGB' )
649- out = enhancer .process (img )
652+ out = enhancer .process (filename , img )
650653 out .save (os .path .splitext (filename )[0 ]+ '_ne%ix.png' % args .zoom )
651- print (flush = True )
652654 print (ansi .ENDC )
0 commit comments