Trying to get the execution time of each layer of a model. When I call intermediate_model  error is raised.
input =Input((10,))
next_layer=input
def profiling(model, test_input):
    # output_of_all_layers = []
    for layer in model.layers:
        layer = layer(next_layer)
        x=layer
        intermediate_moddel= keras.Model(layer,x)
        start = time.time()
        intermediate_output = intermediate_layer.predict(test_input)
        end = time.time() - start
        print(end)
result = profiling(model,features)