'Error when using visual keras for plotting model

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.



Solution 1:[1]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1