paulgavrikov / visualkeras

Visualkeras is a Python package to help visualize Keras (either standalone or included in TensorFlow) neural network architectures. It allows easy styling to fit most needs. This module supports layered style architecture generation which is great for CNNs (Convolutional Neural Networks), and a graph style architecture, which works great for most models including plain feed-forward networks.
MIT License
582 stars 67 forks source link

Simple NLP model with LSTM fails to visualize with TypeError: unsupported operand type(s) for *: 'NoneType' and 'int' [BUG] #29

Closed prabathbr closed 1 year ago

prabathbr commented 2 years ago

Describe the bug Simple NLP model with LSTM fails to visualize with TypeError: unsupported operand type(s) for *: 'NoneType' and 'int'

Minimal Code To Reproduce

model_test = tf.keras.Sequential([
    tf.keras.layers.Embedding(100, 32),
    tf.keras.layers.LSTM(32),
    tf.keras.layers.Dense(1, activation='sigmoid')
])

model_test.summary()

visualkeras.layered_view(model_test)

Expected behavior Properly visualize NLP model with LSTM

Screenshots Error:

---------------------------------------------------------------------------

TypeError                                 Traceback (most recent call last)

[<ipython-input-60-4d4452ad0f8c>](https://localhost:8080/#) in <module>
----> 1 visualkeras.layered_view(model_test)

[/usr/local/lib/python3.7/dist-packages/visualkeras/layered.py](https://localhost:8080/#) in layered_view(model, to_file, min_z, min_xy, max_z, max_xy, scale_z, scale_xy, type_ignore, index_ignore, color_map, one_dim_orientation, background_fill, draw_volume, padding, spacing, draw_funnel, shade_step, legend, font, font_color)
     96             z = min(max(self_multiply(shape[3:]) * scale_z, z), max_z)
     97         elif len(shape) == 3:
---> 98             x = min(max(shape[1] * scale_xy, x), max_xy)
     99             y = min(max(shape[2] * scale_xy, y), max_xy)
    100             z = min(max(z), max_z)

TypeError: unsupported operand type(s) for *: 'NoneType' and 'int'

Environment (please complete the following information):

Additional context model_test.summary() output works properly :

Model: "sequential_15"
_________________________________________________________________
 Layer (type)                Output Shape              Param #   
=================================================================
 embedding_9 (Embedding)     (None, None, 32)          3200      

 lstm_13 (LSTM)              (None, 32)                8320      

 dense_22 (Dense)            (None, 1)                 33        

=================================================================
Total params: 11,553
Trainable params: 11,553
Non-trainable params: 0
_________________________________________________________________
github-actions[bot] commented 2 years ago

Stale issue message

sudoVenomSnake commented 1 year ago

I have encountered the same issue, did you come up with a fix?

sudoVenomSnake commented 1 year ago

Nevermind, seems like I needed to specify the input shape in my model, I had a prebuilt CNN (InceptionV3) and during model declaration I did not specify the input shape, which in my case was (224, 224, 3).