1

I search to draw the diagram of this RNN stacked LSTM based on this model:

model = Sequential()

model.add(LSTM(units=100, input_shape=(x_train.shape[1],5), return_sequences=True))
model.add(Dropout(0.2))

model.add(LSTM(50, return_sequences=False))
model.add(Dropout(0.2))

model.add(Dense(units=1))
model.add(Activation('linear'))

start = time.time()
model.compile(loss='mse', optimizer='rmsprop')

But by doing the bibliography I cannot find precisely how the LSTM cells are connected to each other and especially how the different layers of the neural network. I tried:

tf.keras.utils.plot_model(model, show_shapes=True, to_file="diagram_model.png")

But it didn't give me the result with precision and I also tried netron but the same result. so can you help me to find a solution? Thanks in advance.

Nadhir
  • 528
  • 3
  • 12
  • Have you imagined if your model gets bigger, how will it look if it is possible to plot! This type of plot mostly used in blogs or publications where the author tries to demonstrate the interactivity of each cell. – Innat Mar 31 '21 at 15:22
  • I completely agree with you and I need that kind of plot for future research's publication. So I am only looking to know how they are connected between several layers after in my case study actually I have a bigger model. But if you show me the connection diagram only with 4 lstm followed by 2 or 6 followed by 3 for example I would be equally satisfied! – Nadhir Mar 31 '21 at 16:34
  • Honestly speaking, I actually like the concept. But AFAIK, with current methods from `tf. keras` AP, it hardly possible and less intuitive. I would love to see if current tools have such a feature where we can pass a build layer from the model (like LSTM) and it plots its unit connectivity. – Innat Mar 31 '21 at 16:39
  • in fact compared to a traditional neural network, I don't see how the lstm neurons are connected to each other ... – Nadhir Mar 31 '21 at 16:45
  • maybe you've encountered this but if not check this out [lstm in keras](https://stackoverflow.com/questions/38714959/understanding-keras-lstms). – Innat Mar 31 '21 at 17:21

1 Answers1

2

Tensorflow provides a utils function for this: tf.keras.utils.plot_model

import tensorflow as tf

... # code to build your model

tf.keras.utils.plot_model(model, show_shapes=True, to_file="diagram_model.png")
  • thanks for your help, but I search something like this : https://adventuresinmachinelearning.com/wp-content/uploads/2018/02/Keras-LSTM-tutorial-architecture.png – Nadhir Mar 29 '21 at 17:25
  • 1
    This link seems broken but I just checked the update of your post and indeed the tensorflow utils won't do the job. Maybe you can try this one: https://github.com/lutzroeder/netron, I have not use it yet but it might offer some features that you are looking for! – M. Perier--Dulhoste Mar 31 '21 at 12:17
  • i used it just last night and i get the same results as tensorflow – Nadhir Mar 31 '21 at 12:23