keras-surgeon icon indicating copy to clipboard operation
keras-surgeon copied to clipboard

Keras symbolic inputs/outputs do not implement `__len__`.

Open Linkstus opened this issue 3 years ago • 4 comments

I am not sure if I am using this correctly but I am trying to experiment with Kerassurgeon to delete and add layers. Currently me and my team are struggling to get the delete function from operations to work properly. Below is how the model is being created, and the final line is how we are trying to delete a layer.

model = Sequential() model.add(Dense(12, input_dim = 8, activation = "relu")) model.add(Dense(8, activation = "relu")) model.add(Dense(1, activation = "sigmoid")) model.compile(loss = "binary_crossentropy", optimizer = "adam", metrics = ["accuracy"])

model.fit(X, y, epochs = 150, batch_size = 10)

model = delete_layer(model, model.layers[1])

The issue comes about that when we go to do this we get the error.

TypeError: Keras symbolic inputs/outputs do not implement __len__. You may be trying to pass Keras symbolic inputs/outputs to a TF API that does not register dispatching, preventing Keras from automatically converting the API call to a lambda layer in the Functional Model. This error will also get raised if you try asserting a symbolic input/output directly.

Not really sure what is going on in this scenario. Any light on the issue would be helpful.

Linkstus avatar Aug 02 '21 21:08 Linkstus

I had the same error with TF2.4.0 and TF2.5.0. Downgrading to TF2.3.0 fixed the problem. I guess this repo needs an upgrade tot support the later TF releases.

maartenvds avatar Aug 04 '21 20:08 maartenvds

Any updates on this?

marcelroed avatar Sep 20 '21 01:09 marcelroed

downgrading fixed this issue, but caused a few issues with the keras and tensorflow side of things.

Linkstus avatar Sep 20 '21 15:09 Linkstus

I had the same error with TF2.4.0 and TF2.5.0. Downgrading to TF2.3.0 fixed the problem. I guess this repo needs an upgrade tot support the later TF releases.

Downgrading cannot fix my problem😭😭😭

MT010104 avatar Dec 27 '22 09:12 MT010104