5

I'm trying to visualize my Deep Learning model using visual keras, but i am getting an error which i am not sure i understand. This is my first time using visual keras, and i am not sure what to do. As an example

!pip install visual keras 

import visualkeras
import tensorflow as tf 

tf.keras.utils.plot_model(model, show_shapes=True)
input = tf.keras.Input(shape=(100,), dtype='int32', name='input')
x = tf.keras.layers.Embedding(output_dim=512, input_dim=10000, input_length=100)(input)
x = tf.keras.layers.LSTM(32)(x)
x = tf.keras.layers.Dense(64, activation='relu')(x)
x = tf.keras.layers.Dense(64, activation='relu')(x)
x = tf.keras.layers.Dense(64, activation='relu')(x)
output = tf.keras.layers.Dense(1, activation='sigmoid', name='output')(x)
model = tf.keras.Model(inputs=[input], outputs=[output])
visualkeras.layered_view(model, legend=True, draw_volume=False)

and the error looks like this TypeError: 'int' object is not iterable. Any help will be much appreciated.

1 Answer 1

5

It is a bug as you can read here. The author suggests to install a newer version of the library:

!pip install git+https://github.com/paulgavrikov/visualkeras --upgrade

If for some reason you cannot update the version. Go to the source code of the library (where it was installed) and navigate to visualkeras/layered.py. In line 100 of this file, change z = min(max(z), max_z) to z = min(max([z]), max_z). Save the changes and it will work. An example:

!pip install git+https://github.com/paulgavrikov/visualkeras --upgrade
import visualkeras
import tensorflow as tf 

input = tf.keras.Input(shape=(100,), dtype='int32', name='input')
x = tf.keras.layers.Embedding(output_dim=512, input_dim=10000, input_length=100)(input)
x = tf.keras.layers.LSTM(32)(x)
x = tf.keras.layers.Dense(64, activation='relu')(x)
x = tf.keras.layers.Dense(64, activation='relu')(x)
x = tf.keras.layers.Dense(64, activation='relu')(x)
output = tf.keras.layers.Dense(1, activation='sigmoid', name='output')(x)
model = tf.keras.Model(inputs=[input], outputs=[output])
visualkeras.layered_view(model, legend=True, draw_volume=False)

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

I've tried it, and no it does not work still. Getting the same error.
@OliveYew did you run the example ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.