divamgupta / divamgupta/stable-diffusion-tensorflow

TF Lite convert error

Open
#58 18 comments 3 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
1.6k
Forks
229
PR merge metrics
No merged PRs in 30d

Description

Hi,
Leaving this here in case someone is also trying to convert to a TF lite model.

From the keras_cv documentation:
```
!pip install --upgrade keras-cv
!pip install --upgrade tensorflow
```
Load the model:

```py
import time
import keras_cv
from tensorflow import keras
import matplotlib.pyplot as plt

model = keras_cv.models.StableDiffusion(img_width=512, img_height=512)
# Convert the model.
converter = tf.lite.TFLiteConverter.from_keras_model(model.diffusion_model)
tflite_model = converter.convert()
```

It seems a similar error occurs when trying to save the model.
```
model.diffusion_model.save(save_dir)
```

The error in conversion:
```
[/usr/local/lib/python3.7/dist-packages/keras_cv/models/generative/stable_diffusion/__internal__/layers/group_normalization.py](https://localhost:8080/#) in _create_broadcast_shape(self, input_shape)
85
86 def _create_broadcast_shape(self, input_shape):
---> 87 broadcast_shape = [1] * len(input_shape)
88 broadcast_shape[self.axis] = input_shape[self.axis] // self.groups

TypeError: Exception encountered when calling layer 'group_normalization_60' (type GroupNormalization).

len is not well defined for a symbolic Tensor (Shape:0). Please call `x.shape` rather than `len(x)` for shape information.

Call arguments received by layer 'group_normalization_60' (type GroupNormalization):
• args=('tf.Tensor(shape=(None, 64, 64, 320), dtype=float32)',)
• kwargs=
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.