d. nye commited on
Commit
b5fbf6d
·
1 Parent(s): dd39126

Image resize

Browse files
Files changed (1) hide show
  1. app.py +7 -10
app.py CHANGED
@@ -586,15 +586,6 @@ print(os.listdir(os.path.join("pretrained")))
586
 
587
  # plot_images(images, 5)
588
 
589
- def pixelate_rgb(img, window):
590
- n, m, _ = img.shape
591
- n, m = n - n % window, m - m % window
592
- img1 = np.zeros((n, m, 3))
593
- for x in range(0, n, window):
594
- for y in range(0, m, window):
595
- img1[x:x+window,y:y+window] = img[x:x+window,y:y+window].mean(axis=(0,1))
596
- return img1
597
-
598
  class InferenceWrapper:
599
  def __init__(self, model):
600
  self.model = model
@@ -613,7 +604,13 @@ class InferenceWrapper:
613
  self.noise = self.style_gan.generate_noise(batch_size=batch_size)
614
  else:
615
  print(f"Model '{self.model}' already loaded, reusing it.")
616
- return pixelate_rgb(self.style_gan({"style_code": self.w, "noise": self.noise, "alpha": 1.0})[0],64)
 
 
 
 
 
 
617
 
618
 
619
  wrapper = InferenceWrapper('celeba')
 
586
 
587
  # plot_images(images, 5)
588
 
 
 
 
 
 
 
 
 
 
589
  class InferenceWrapper:
590
  def __init__(self, model):
591
  self.model = model
 
604
  self.noise = self.style_gan.generate_noise(batch_size=batch_size)
605
  else:
606
  print(f"Model '{self.model}' already loaded, reusing it.")
607
+
608
+ image = self.style_gan({"style_code": self.w, "noise": self.noise, "alpha": 1.0})[0]
609
+ res = 64
610
+ image = tf.image.resize(image, (res, res), method=tf.image.ResizeMethod.NEAREST_NEIGHBOR)
611
+ image = tf.cast(image, tf.float32) / 127.5 - 1.0
612
+
613
+ return image
614
 
615
 
616
  wrapper = InferenceWrapper('celeba')