What you are looking for is the CallBack feature. Callback is a Keras function that repeats during training at key points. This may be after the party, era or the entire training. See here for a document and a list of existing callbacks.
What you want is a custom CallBack that can be created using the LambdaCallBack object.
from keras.callbacks import LambdaCallback model = Sequential() model.add(Embedding(max_features, 128, dropout=0.2)) model.add(LSTM(128, dropout_W=0.2, dropout_U=0.2)) model.add(Dense(1)) model.add(Activation('sigmoid')) print_weights = LambdaCallback(on_epoch_end=lambda batch, logs: print(model.layers[0].get_weights())) model.compile(loss='binary_crossentropy',optimizer='adam',metrics['accuracy']) model.fit(X_train, y_train, batch_size=batch_size, nb_epoch=5 validation_data=(X_test, y_test), callbacks = [print_weights])
the code above should print your immersion weights model.layers[0].get_weights() at the end of each era. It is up to you to print it where you want to make it readable, upload it to a pickle file, ...
Hope this helps
source share