Spaces:
Runtime error
Runtime error
Commit
·
18a451e
1
Parent(s):
2e506d2
Update app.py
Browse files
app.py
CHANGED
@@ -2,12 +2,11 @@ import tensorflow as tf
|
|
2 |
import huggingface_hub as hf_hub
|
3 |
import gradio as gr
|
4 |
|
5 |
-
|
6 |
num_rows = 3
|
7 |
num_cols = 3
|
8 |
num_images = num_rows * num_cols
|
9 |
image_size = 64
|
10 |
-
plot_image_size =
|
11 |
|
12 |
model = hf_hub.from_pretrained_keras("beresandras/denoising-diffusion-model")
|
13 |
|
@@ -26,6 +25,7 @@ def generate_images(diffusion_steps, stochasticity, min_signal_rate, max_signal_
|
|
26 |
step_size = 1.0 / diffusion_steps
|
27 |
initial_noise = tf.random.normal(shape=(num_images, image_size, image_size, 3))
|
28 |
|
|
|
29 |
noisy_images = initial_noise
|
30 |
for step in range(diffusion_steps):
|
31 |
diffusion_times = tf.ones((num_images, 1, 1, 1)) - step * step_size
|
@@ -45,8 +45,14 @@ def generate_images(diffusion_steps, stochasticity, min_signal_rate, max_signal_
|
|
45 |
+ sample_noise_rates * sample_noises
|
46 |
)
|
47 |
|
|
|
48 |
generated_images = tf.clip_by_value(0.5 + 0.3 * pred_images, 0.0, 1.0)
|
|
|
|
|
49 |
generated_images = tf.image.resize(generated_images, (plot_image_size, plot_image_size), method="nearest")
|
|
|
|
|
|
|
50 |
return generated_images.numpy()
|
51 |
|
52 |
gr.Interface(
|
|
|
2 |
import huggingface_hub as hf_hub
|
3 |
import gradio as gr
|
4 |
|
|
|
5 |
num_rows = 3
|
6 |
num_cols = 3
|
7 |
num_images = num_rows * num_cols
|
8 |
image_size = 64
|
9 |
+
plot_image_size = 256
|
10 |
|
11 |
model = hf_hub.from_pretrained_keras("beresandras/denoising-diffusion-model")
|
12 |
|
|
|
25 |
step_size = 1.0 / diffusion_steps
|
26 |
initial_noise = tf.random.normal(shape=(num_images, image_size, image_size, 3))
|
27 |
|
28 |
+
# reverse diffusion
|
29 |
noisy_images = initial_noise
|
30 |
for step in range(diffusion_steps):
|
31 |
diffusion_times = tf.ones((num_images, 1, 1, 1)) - step * step_size
|
|
|
45 |
+ sample_noise_rates * sample_noises
|
46 |
)
|
47 |
|
48 |
+
# denormalize
|
49 |
generated_images = tf.clip_by_value(0.5 + 0.3 * pred_images, 0.0, 1.0)
|
50 |
+
|
51 |
+
# make grid
|
52 |
generated_images = tf.image.resize(generated_images, (plot_image_size, plot_image_size), method="nearest")
|
53 |
+
generated_images = tf.reshape(generated_images, (num_rows, num_cols, plot_image_size, plot_image_size, 3))
|
54 |
+
generated_images = tf.transpose(generated_images, (0, 2, 1, 3, 4))
|
55 |
+
generated_images = tf.reshape(generated_images, (num_rows * plot_image_size, num_cols * plot_image_size, 3))
|
56 |
return generated_images.numpy()
|
57 |
|
58 |
gr.Interface(
|