I am new to machine learning. I was following this tutorial on fine tuning VGG16 models.
The model loaded fine with this code:
vgg_model = tensorflow.keras.applications.vgg16.VGG16()
but gets this ERROR:
TypeError: The added layer must be an instance of class Layer. Found: <tensorflow.python.keras.engine.input_layer.InputLayer object at 0x000001FA104CBB70>
When running this code:
model = Sequential()
for layer in vgg_model.layers[:-1]:
model.add(layer)
Dependencies:
- Keras 2.2.3
- Tensorflow 1.12.0
- tensorflow-gpu1.12.0
- Python 3.6.0
I am following this blog but instead I want to use VGG16.
Any help to fix this would be appreciated. Thank you so much.
This won't work because a tensorflow.keras layer is getting added to a keras Model.
Instantiate tensorflow.keras.Sequential(). This will work.
You do not need to create an InputLayer, you simply must import the BatchNormalization layer in the same manner as your Conv2D/other layers, e.g:
Instead of importing it as an independent Keras layer, i.e:
Adding to @Manoj Mohan's answer, you can add an
input_layer
to yourmodel
usinginput_layer
fromKeras
layers
as below:if you are using the
TensorFlow
builtinKeras
then import is different other things are still the sameComing to the main part, if you want to import layers to your sequential model, you can use the following syntax.