Wrong version of get_layer function getting called
pallavijog13 opened this issue · comments
I am working on retrieving Inception V3 model's top layer in Keras/Tensorflow (in Jupyter Notebook).
I could retrieve the Inception V3 model and its weights correctly. Now, I am trying to get Fully Connected layer (top layer) using following code snippet.
base_model = InceptionV3(weights=weights)
base_model.get_layer('flatten')
However, the function is failed saying "ValueError: No such layer: flatten"
When I looked at the stacktrace, get_layer() function from topology.py is getting called which is under 'keras/engine'.
Rather than this function, get_layer() function from models.py directly under keras should have been called.
What possibly can be the problem? How can I force Python to call the correct version? Or is there any other way to get the weights from InceptionV3 model?
Just tried enumerating base_model.layers list contents and found that the name of the layers are different and no layer named flatten is found.
So I replaced flatten with the last presumably FC layer named 'mixed10' and the code worked.
Is this the right thing to do? or I am doing something improper?
This is really a question for the Keras forum rather than here. But yes, you would print model.summary()
to get a list of layer-names and then see which one you want to use. You may have to experiment with which layer that works best in Transfer Learning.