Keras

Notes about Keras.


Problems encountered

2017-12-04 · Get variable’s value in middle layer

Problem description: I want to get the value of a variable in the model.

Reference: How can I get hidden layer representation of the given data? #41

The simplest way is using the same code of the original model, and

# replace the output with the variable you want
# code ...

new_model.set_weights(trained_model.get_weights())
new_model.predict(input_data, batch_size=32)

Note the batch_size is import for large amount of samples. The K.function() mentioned in the issue #41 raised OOM exception. Of course you can split data into batches by yourself and use the K.function() method, but the method showed above is more convinient for me in my case.