徐瑞年
徐瑞年

Reputation: 11

get the output of intermediate layers using keras as backend

I want to extract four intermediate layers of my model. Here is how I setup my function:

K.function([yolo_model.layers[0].input, yolo_model.layers[4].input, K.learning_phase()],
                                 [yolo_model.layers[1].layers[17].output,
                                  yolo_model.layers[1].layers[27].output,
                                  yolo_model.layers[1].layers[43].output,
                                  yolo_model.layers[1].layers[69].output])

I always got the error that tensorflow.python.framework.errors_impl.InvalidArgumentError: You must feed a value for placeholder tensor 'input_3' with dtype float and shape [?,416,416,3] It seems my input has dimension or type error but I used this input for my model train_on_batch or predict and it worked. I got the same error even when I passed np.zeros((1,416,416,3)) into it. Another wired thing is I don't have input_3 since my model only takes two inputs. I have no idea where input_3 tensor comes from.

Thanks in advance if anyone can give me some hints.

Upvotes: 0

Views: 142

Answers (1)

徐瑞年
徐瑞年

Reputation: 11

I found out where the problem is. My model is composed of one inner model and several layers. When I build the function, my input is from outer model but output is from inner model, which causes disconnection between input and output. I just changed the original input to the input layer of inner model and it works.

Upvotes: 1

Related Questions