Why keras does not allow to add a convolutional layer in this way?

后端 未结 2 1413
有刺的猬
有刺的猬 2021-01-28 01:48

The following code

from tensorflow import keras
from keras.layers import Conv2D

model = keras.Sequential()
model.add(Conv2D(1, (3, 3), padding=\'same\', input_s         


        
相关标签:
2条回答
  • 2021-01-28 02:07

    Try this:

    from tensorflow import keras
    from tensorflow.keras.layers import Conv2D
    
    model = keras.Sequential()
    model.add(Conv2D(1, (3, 3), padding='same', input_shape=(28, 28, 1)))
    

    You are mixing a tf.keras Sequential model with a keras Conv2D layer (instead of a tf.keras Conv2D layer.)

    Or, as remarked below, use actual Keras:

    import keras
    from keras.models import Sequential
    from keras.layers import Conv2D
    
    model = Sequential()
    model.add(Conv2D(1, (3, 3), padding='same', input_shape=(28, 28, 1)))
    
    0 讨论(0)
  • 2021-01-28 02:09

    You should import Sequential from keras models

    from keras.models import Sequential
    from keras.layers import Conv2D
    
    model = Sequential()
    model.add(Conv2D(1, (3, 3), padding='same', input_shape=(28, 28, 1)))
    
    0 讨论(0)
提交回复
热议问题