Skip to content

Commit b4dd786

Browse files
authored
Do image clipping in numpy space (outputs are already numpy arrays after predict(), no need to go back to TF then to numpy again) (#838)
1 parent c39df7c commit b4dd786

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

keras_cv/models/generative/stable_diffusion/stable_diffusion.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import math
2525

26+
import numpy as np
2627
import tensorflow as tf
2728
from tensorflow import keras
2829

@@ -168,7 +169,7 @@ def text_to_image(
168169
# Decoding stage
169170
decoded = self.decoder.predict_on_batch(latent)
170171
decoded = ((decoded + 1) / 2) * 255
171-
return tf.cast(tf.clip_by_value(decoded, 0, 255), dtype=tf.uint8)
172+
return np.clip(decoded, 0, 255).astype("uint8")
172173

173174
def _get_timestep_embedding(self, timestep, batch_size, dim=320, max_period=10000):
174175
half = dim // 2

0 commit comments

Comments
 (0)