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

QKeras fails due to missing modules and numpy error message with latest TensorFlow version 2.16.1 #130

Open
lp247 opened this issue Mar 27, 2024 · 2 comments

Comments

@lp247
Copy link

lp247 commented Mar 27, 2024

I have the following code:

#!/usr/bin/env python
# coding: utf-8
from tensorflow.keras.datasets import mnist
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Activation, Flatten, Input
from tensorflow.keras.utils import to_categorical
from qkeras.qlayers import QDense
from qkeras.quantizers import quantized_bits

(train_data, train_labels), (test_data, test_labels) = mnist.load_data()
train_data = train_data.astype('float32') / 255.0
test_images = test_data.astype('float32') / 255.0
train_labels = to_categorical(train_labels)
test_labels = to_categorical(test_labels)
model = Sequential([
    Input(name="Input", shape=(28, 28)),
    Flatten(name="Flatten"),
    QDense(32, name="QDense1", kernel_quantizer=quantized_bits(2, 0), bias_quantizer=quantized_bits(2, 0)),
    Activation("softmax", name="Softmax")
])
model.compile()
model.fit(train_data, train_labels)

I installed tensorflow (2.16.1) and QKeras (0.9.0). Trying to run this code gives me ModuleNotFoundError: No module named 'pyparsing'.. After installing that module (3.1.2) I get ModuleNotFoundError: No module named 'tf_keras'.. After installing that (2.16.0) I get the following error:

Traceback (most recent call last):
  File "/home/me/wtf/test.py", line 22, in <module>
    model.fit(train_data, train_labels)
  File "/home/me/.pyenv/versions/3.11.8/lib/python3.11/site-packages/keras/src/utils/traceback_utils.py", line 122, in error_handler
    raise e.with_traceback(filtered_tb) from None
  File "/home/me/.pyenv/versions/3.11.8/lib/python3.11/site-packages/qkeras/qlayers.py", line 629, in call
    quantized_kernel = self.kernel_quantizer_internal(self.kernel)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/me/.pyenv/versions/3.11.8/lib/python3.11/site-packages/qkeras/quantizers.py", line 558, in __call__
    x = K.cast_to_floatx(x)
        ^^^^^^^^^^^^^^^^^^^
NotImplementedError: Exception encountered when calling QDense.call().

numpy() is only available when eager execution is enabled.

Arguments received by QDense.call():
  • inputs=tf.Tensor(shape=(32, 784), dtype=float32)

Using python 3.11.8 with pip 24.0 on Ubuntu 22.04.4 LTS.

Note: It is working with tensorflow==2.15.1 and tf_keras==2.15.1.

@lp247 lp247 changed the title Installation fails due to missing modules and numpy error message QKeras fails due to missing modules and numpy error message with latest TensorFlow version 2.16.1 Apr 6, 2024
@AlexanderHD27
Copy link

This issue is still a thing!

@lp247
Copy link
Author

lp247 commented Aug 16, 2024

Yeah, seems like the project is dead.

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

2 participants