Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
for
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
|
|
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>"
|