Search code examples
pythontensorflowkerasneural-network

How to get more information out of my loaded keras model?


Currently I work at optimizing my neural network that I trained with keras. For this, played with several activation functions within the layers and I save the models automatically with model.save() and do an evaluation.

Unfortunately, I forgot the exact setup of my best performing network, but how can I recreate all network information from keras? Of course, I use model.load() and there is helpful model.summary(). But how would I get the activation functions, that were used?

model.summary() just provides information about the network architecture itself:

_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
...                             ...                     ...
_________________________________________________________________
dense (Dense)                (None, 64)                288064    
_________________________________________________________________
dense_1 (Dense)              (None, 128)               8320      
=================================================================
Total params: 586,408
Trainable params: 586,408
Non-trainable params: 0
_________________________________________________________________

Solution

  • you can get read layers with model.layers and then use that for finding the weights or activation functions. For example

    act_fncs = [l.activation for l in model.layers]