keras-team / keras-cv

Industry-strength Computer Vision workflows with Keras
Other
1.01k stars 330 forks source link

StableDiffusion errors out with any backend other than TF #2187

Closed fchollet closed 10 months ago

fchollet commented 11 months ago

When using the method generate_image you get:

File ~/.local/lib/python3.10/site-packages/keras_cv/src/models/stable_diffusion/stable_diffusion.py:203, in StableDiffusionBase.generate_image(self, encoded_text, negative_prompt, batch_size, num_steps, unconditional_guidance_scale, diffusion_noise, seed)
    201 if diffusion_noise is not None:
    202     diffusion_noise = ops.squeeze(diffusion_noise)
--> 203     if diffusion_noise.shape.rank == 3:
    204         diffusion_noise = ops.repeat(
    205             ops.expand_dims(diffusion_noise, axis=0), batch_size, axis=0
    206         )
    207     latent = diffusion_noise

AttributeError: 'tuple' object has no attribute 'rank'

When using a backend other than TF, tensor shapes do not have a rank attribute. Instead, use len(ops.shape(diffusion_noise)) which will work across all backends.

divyashreepathihalli commented 10 months ago

fixed here - https://github.com/keras-team/keras-cv/pull/2208