The added layer must be an instance of class Layer. Found:

后端 未结 3 608
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-15 18:15

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.k         


        
3条回答
  •  [愿得一人]
    2020-12-15 18:49

    Adding to @Manoj Mohan's answer, you can add an input_layer to your model using input_layer from Keras layers as below:

    import keras
    from keras.models import Sequential
    from keras.layers import InputLayer
    
    model = Sequential()
    model.add(InputLayer(input_shape=shape, name=name))
    ....
    

    if you are using the TensorFlow builtin Keras then import is different other things are still the same

    import tensorflow as tf
    import tensorflow.keras as keras
    from tensorflow.keras.models import Sequential
    from tensorflow.keras.layers import InputLayer
    
    model = Sequential()
    model.add(InputLayer(input_shape=shape, name=name))
    ....
    

    Coming to the main part, if you want to import layers to your sequential model, you can use the following syntax.

    import keras
    from keras.models import Sequential, load_model
    from keras import optimizers
    from keras.applications.vgg16 import VGG16
    from keras.applications.vgg19 import VGG19
    
    # For VGG16 loading to sequential model  
    model = Sequential(VGG16().layers)
    # For VGG19 loading to sequential model  
    model = Sequential(VGG19().layers)
    

提交回复
热议问题