Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Images are not generating because of "pred must not be a Python bool" error #1912

Closed
saadbinmanjur opened this issue Aug 16, 2024 · 3 comments
Assignees

Comments

@saadbinmanjur
Copy link

Issue Type

Bug

Source

source

Keras Version

3

Custom Code

No

OS Platform and Distribution

No response

Python version

3.9

GPU model and memory

T4 16gb

Current Behavior?

I got this error after running this line of codes

images = model.text_to_image(
    "cute magical flying dog, fantasy art, "
    "golden color, high quality, highly detailed, elegant, sharp focus, "
    "concept art, character concepts, digital painting, mystery, adventure",
    batch_size=3,
)
plot_images(images)

error:

/usr/local/lib/python3.10/dist-packages/keras/src/layers/layer.py:1383: UserWarning: Layer 'clip_encoder_layer_3' looks like it has unbuilt state, but Keras is not able to trace the layer call() in order to build it automatically. Possible causes:
1. The call() method of your layer may be crashing. Try to __call__() the layer eagerly on some test input first to see if it works. E.g. x = np.random.random((3, 4)); y = layer(x)
2. If the call() method is correct, then you may need to implement the def build(self, input_shape) method on your layer. It should create all variables used by the layer (e.g. by calling layer.build() on all its children layers).
Exception encountered: ''Exception encountered when calling CLIPAttention.call().

pred must not be a Python bool

Arguments received by CLIPAttention.call():
  • inputs=tf.Tensor(shape=(None, 77, 768), dtype=float32)
  • attention_mask=None''
  warnings.warn(
/usr/local/lib/python3.10/dist-packages/keras/src/layers/layer.py:391: UserWarning: build() was called on layer 'clip_encoder_layer_3', however the layer does not have a build() method implemented and it looks like it has unbuilt state. This will cause the layer to be marked as built, despite not being actually built, which may cause failures down the line. Make sure to implement a proper build() method.
  warnings.warn(
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-8-38f6a1767415> in <cell line: 1>()
----> 1 images = model.text_to_image(
      2     "cute magical flying dog, fantasy art, "
      3     "golden color, high quality, highly detailed, elegant, sharp focus, "
      4     "concept art, character concepts, digital painting, mystery, adventure",
      5     batch_size=3,

6 frames
/usr/local/lib/python3.10/dist-packages/keras_cv/src/models/stable_diffusion/text_encoder.py in call(self, inputs, attention_mask)
    134         if attention_mask is None and self.causal:
    135             length = ops.shape(inputs)[1]
--> 136             attention_mask = ops.triu(
    137                 ops.ones((1, 1, length, length), dtype=self.compute_dtype)
    138                 * -float("inf"),

TypeError: Exception encountered when calling CLIPEncoderLayer.call().

Could not automatically infer the output shape / dtype of 'clip_encoder_layer_3' (of type CLIPEncoderLayer). Either the CLIPEncoderLayer.call() method is incorrect, or you need to implement the CLIPEncoderLayer.compute_output_spec() / compute_output_shape() method. Error encountered:

Exception encountered when calling CLIPAttention.call().

pred must not be a Python bool

Arguments received by CLIPAttention.call():
  • inputs=tf.Tensor(shape=(None, 77, 768), dtype=float32)
  • attention_mask=None

Arguments received by CLIPEncoderLayer.call():
  • args=('<KerasTensor shape=(None, 77, 768), dtype=float32, sparse=False, name=keras_tensor_7>',)
  • kwargs=<class 'inspect._empty'>

Standalone code to reproduce the issue or tutorial link

https://keras.io/guides/keras_cv/generate_images_with_stable_diffusion/

Relevant log output

No response

@zhangleye
Copy link

I have the same Error.

@zhangleye
Copy link

I have solved the problem. Keras-CV must match keras and tensorflow versions. My successful version is : python3.11.0, tensorflow2.15.0, keras2.15.0, cuda12.3, keras-cv0.6.0, tensorflow_datasets4.9.6, keras_core0.1.7.

@saadbinmanjur
Copy link
Author

great! thanks your suggestion helped me to solve it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants