Closed joeytepp closed 5 years ago
Use ANN_visualizer to visualize an LSTM neural network in Keras
ANN_visualizer
You can use the basic LSTM in the snippet below to test, before creating a generic method to visualize any model (ie. a function called visualize_model)
visualize_model
import numpy as np from keras.models import Sequential from keras.layers import Dense, Dropout, Activation, LSTM input_data = np.array([ [[1, 0], [2, 0], [3, 0], [4, 0]], [[1, 0], [2, 0], [3, 0], [4, 0]], [[1, 0], [2, 0], [3, 0], [4, 0]], [[1, 0], [2, 0], [3, 0], [4, 0]], [[1, 0], [2, 0], [3, 0], [4, 0]], [[1, 0], [2, 0], [3, 0], [4, 0]], [[1, 0], [2, 0], [3, 0], [4, 0]], [[1, 0], [2, 0], [3, 0], [4, 0]], [[1, 0], [2, 0], [3, 0], [4, 0]], [[1, 0], [2, 0], [3, 0], [4, 0]] ]) output_data = np.array([ [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], ]) model = Sequential() model.add(LSTM( 512, input_shape=(4, 2), return_sequences=True )) model.add(Dropout(0.3)) model.add(LSTM(512, return_sequences=True)) model.add(Dropout(0.3)) model.add(LSTM(512)) model.add(Dense(256)) model.add(Dropout(0.3)) model.add(Dense(4)) model.add(Activation('softmax')) model.compile(loss='categorical_crossentropy', optimizer='rmsprop') model.fit(input_data, output_data, batch_size=64, epochs=200)
To get an idea of what's actually going on behind the scenes 🤖
Can close this now 👌
Summary
Use
ANN_visualizer
to visualize an LSTM neural network in KerasBasic Example
You can use the basic LSTM in the snippet below to test, before creating a generic method to visualize any model (ie. a function called
visualize_model
)Motivation
To get an idea of what's actually going on behind the scenes 🤖