In case you have one of the following cases:
InvalidArgumentError: input_X:Y is both fed and fetched
You need to do the following changes:
outputs
variablefunctors
loopMinimum 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]