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

module 'tensorflow.keras.layers' has no attribute 'AbstractRNNCell' #65

Open
Pasha-Akito opened this issue May 13, 2024 · 3 comments
Open

Comments

@Pasha-Akito
Copy link

Hi,

I'm following this guide on using LTC with tensorflow: https://ncps.readthedocs.io/en/latest/examples/tf_first_steps.html

When running the imports as described here, I run into an issue, in particular this import: from ncps.tf import LTC

I get the following error: AttributeError: module 'tensorflow.keras.layers' has no attribute 'AbstractRNNCell'

From looking into it, it seems like tensorflow no longer supports AbstractRNNCell, this is fine as I can downgrade my tensorflow version to one which does support AbstractRNNCell.

My question is whether or not there is any intention of fixing this for newer tensorflow versions?

Thanks

@noorchauhan
Copy link

noorchauhan commented May 14, 2024

Yes I have faced similar issues, downgrading the Tensorflow works but that's not the good workaround, the ncp package needs to be updated for the same correction.

For start you can try other supporting versions of tensorflow.

@mlech26l , @raminmh Any insights on this bug?

@gabewillen
Copy link

This is actually a fairly simple fix. AbstractRNNCell was just an abstract class (Protocol) with methods stubbed out that the RNN class requires for a cell. To fix this simply replace tf.keras.layers.AbstractRNNCell with tf.keras.layers.Layer

@chrootlogin
Copy link

I also stumbled over this bug. But he already has a Keras 3-compatible version in his repo, it's just not documented. I think they should just update the documentation. Just use ncps.keras instead of ncps.tf and all your problems are solved.

import keras
from ncps import wirings
from ncps.keras import LTC

wiring = wirings.AutoNCP(8,1) # 8 neurons in total, 1 output (motor neuron)
model = keras.models.Sequential(
    [
        keras.layers.InputLayer(shape=(None, 32)),
        LTC(wiring, return_sequences=True)
    ]
)
model.compile(
    optimizer=keras.optimizers.Adam(0.01), loss='mean_squared_error'
)

model.summary()

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

5 participants
@chrootlogin @Pasha-Akito @noorchauhan @gabewillen and others