rajrathi commited on
Commit
26a32e5
1 Parent(s): 51bae4f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -15
app.py CHANGED
@@ -19,21 +19,22 @@ def generate_latent_points(digit, latent_dim, n_samples, n_classes=10):
19
  return tf.concat([random_latent_vectors, labels], 1)
20
 
21
  def create_digit_samples(digit, n_samples):
22
- latent_dim = 128
23
- random_vector_labels = generate_latent_points(int(digit), latent_dim, int(n_samples))
24
- examples = model.predict(random_vector_labels)
25
- examples = examples * 255.0
26
- size = ceil(sqrt(n_samples))
27
- digit_images = np.zeros((28*size, 28*size), dtype=float)
28
- n = 0
29
- for i in range(size):
30
- for j in range(size):
31
- if n == n_samples:
32
- break
33
- digit_images[i* 28 : (i+1)*28, j*28 : (j+1)*28] = examples[n, :, :, 0]
34
- n += 1
35
- digit_images = (digit_images/127.5) -1
36
- return digit_images
 
37
 
38
  description = "Keras implementation for Conditional GAN to generate samples for specific digit of MNIST"
39
  article = "Author:<a href=\"https://huggingface.co/rajrathi\"> Rajeshwar Rathi</a>; Based on the keras example by <a href=\"https://keras.io/examples/generative/conditional_gan/\">Sayak Paul</a>"
 
19
  return tf.concat([random_latent_vectors, labels], 1)
20
 
21
  def create_digit_samples(digit, n_samples):
22
+ if digit in range(10):
23
+ latent_dim = 128
24
+ random_vector_labels = generate_latent_points(int(digit), latent_dim, int(n_samples))
25
+ examples = model.predict(random_vector_labels)
26
+ examples = examples * 255.0
27
+ size = ceil(sqrt(n_samples))
28
+ digit_images = np.zeros((28*size, 28*size), dtype=float)
29
+ n = 0
30
+ for i in range(size):
31
+ for j in range(size):
32
+ if n == n_samples:
33
+ break
34
+ digit_images[i* 28 : (i+1)*28, j*28 : (j+1)*28] = examples[n, :, :, 0]
35
+ n += 1
36
+ digit_images = (digit_images/127.5) -1
37
+ return digit_images
38
 
39
  description = "Keras implementation for Conditional GAN to generate samples for specific digit of MNIST"
40
  article = "Author:<a href=\"https://huggingface.co/rajrathi\"> Rajeshwar Rathi</a>; Based on the keras example by <a href=\"https://keras.io/examples/generative/conditional_gan/\">Sayak Paul</a>"