1. Use of the framework:
Tensorflow+keras
2. The core function of extracting a layer of depth network features:
Import Keras.backend as K
def get_activation (model, layer, X_batch):
Get_activations= k.function ([Model.layers[0].input, K.learning_phase ()],[model.layers[layer].output])
Activations=get_activations ([X_batch, 0])
return activations
Use examples:
# Generate Extract-feature Data
X_extractfeature = Hdf5matrix (Hdf5path, ' X ', 0, datasetlength, normalizer = scaledata)
Y_extractfeature = Hdf5matrix (Hdf5path, ' Y ', 0, Datasetlength)
Count=range (0, Len (x_extractfeature), 100)
For I in range (Len (count)):
If I<len (count)-1:
Myfeature=get_activation (model, one, x_extractfeature[count[i]:count[i+1]])
If I==len (count)-1:
Myfeature=get_activation (model, one, X_extractfeature[count[i]:len (x_extractfeature))
3. Extract the depth of the network information at all levels:
For layer in Model.layers:
Print ("{} output shape: {}". Format (Layer.name, Layer.output_shape))
Print Layer.output