How to check weight after each epic in Keras model

I am using a consistent model in Keras. I would like to check the weight of the model after each era. Could you advise me how to do this.

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')) 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)) 

Thanks in advance.

+5
source share
1 answer

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

+1
source

Source: https://habr.com/ru/post/1263816/


All Articles