Keras, How to get the output of each layer?

后端 未结 10 1854
借酒劲吻你
借酒劲吻你 2020-11-22 07:34

I have trained a binary classification model with CNN, and here is my code

model = Sequential()
model.add(Convolution2D(nb_filters, kernel_size[0], kernel_si         


        
10条回答
  •  情话喂你
    2020-11-22 08:13

    In case you have one of the following cases:

    • error: InvalidArgumentError: input_X:Y is both fed and fetched
    • case of multiple inputs

    You need to do the following changes:

    • add filter out for input layers in outputs variable
    • minnor change on functors loop

    Minimum example:

    from keras.engine.input_layer import InputLayer
    inp = model.input
    outputs = [layer.output for layer in model.layers if not isinstance(layer, InputLayer)]
    functors = [K.function(inp + [K.learning_phase()], [x]) for x in outputs]
    layer_outputs = [fun([x1, x2, xn, 1]) for fun in functors]
    

提交回复
热议问题