You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importtensorflowastfimportnumpyasnpfromqkerasimportQActivation# build the modell_0=tf.keras.layers.Input(shape=2)
l_1=QActivation("bernoulli")(l_0)
l_2=tf.keras.layers.Dense(units=10, activation="sigmoid")(l_1)
l_3=QActivation("bernoulli")(l_2)
out=tf.keras.layers.Dense(units=1, activation="sigmoid")(l_3)
# create the modelmodel=tf.keras.models.Model(inputs=l_0, outputs=out)
model.compile(loss='binary_crossentropy')
# create some datax=np.array([[1,2],[3,4],[5,6]])
y=np.array([[0],[1],[1]])
# fit the modelmodel.fit(x, y)
# eval the model layerslayer_out=Noneforlayerinmodel.layers:
if"input"inlayer.name:
layer_out=layer(x)
if"input"notinlayer.name:
layer_out=layer(layer_out)
Until fitting everything works well but in the evaluation step of my model layers I encounter the following errro:
Traceback (most recent call last):
File "test.py", line 30, in <module>
layer_out = layer(layer_out)
File "keras/utils/traceback_utils.py", line 70, in error_handler
raise e.with_traceback(filtered_tb) from None
File "qkeras/qlayers.py", line 177, in call
return self.quantizer(inputs)
File "qkeras/quantizers.py", line 796, in __call__
p = tf.keras.backend.sigmoid(self.temperature * x / std)
TypeError: Exception encountered when calling layer 'q_activation' (type QActivation).
Cannot convert 6.0 to EagerTensor of dtype int64
Call arguments received by layer 'q_activation' (type QActivation):
• inputs=tf.Tensor(shape=(3, 2), dtype=int64)
I think the problem is caused because in quantizers.py the variables std and temperature are not match up with the input data type of x. One way to fix it is to change the code from line 790 to:
Hi all,
My setup is:
Arch Linux 5.15.78-1-lts
Python 3.10.8
Tensorflow 2.11.0
Numpy 1.23.0
qkeras 0.9.0
I am running the following example code:
Until fitting everything works well but in the evaluation step of my model layers I encounter the following errro:
I think the problem is caused because in
quantizers.py
the variablesstd
andtemperature
are not match up with the input data type ofx
. One way to fix it is to change the code from line 790 to:with this one forces the type to be
tf.float32
.Cheers,
Marius
The text was updated successfully, but these errors were encountered: