层conv2d_30的输入0与该层不兼容:预期的ndim = 4,找到的ndim = 3。收到完整的形状:[无,621,2]

时间:2020-06-24 22:07:20

标签: tensorflow audio keras deep-learning shapes

我是深度学习的新手,并且正在研究音频数据。我尝试开发我的第一个模型,我不理解这些层的不同功能,参数和定义顺序(如果有的话,请让我知道)。现在,根据我看到的教程,我尝试了一个实验模型。

这是我的模特:

input_shape = (1245, 1025)
print(input_shape)

inputs = tf.keras.Input(shape=(input_shape))

conv1 = tf.keras.layers.Conv1D(filters = 2 , kernel_size= 3, input_shape= input_shape, activation='relu')(inputs)

max1 = tf.keras.layers.MaxPooling1D( pool_size=2,
   strides=2, padding='valid')(conv1)

conv2 = tf.keras.layers.Conv2D(filters = 2, input_shape = max1.shape,  kernel_size=3, activation = 'relu')(max1)

max2 = tf.keras.layers.MaxPooling1D(pool_size=2,
   strides=2, padding='valid') (conv2)


conv3 = tf.keras.layers.Conv2D(filters = 2, kernel_size=3, input_shape= max2.shape, activation = 'relu')(max2)


max3 = tf.keras.layers.MaxPooling1D( pool_size=2,
   strides=2, padding='valid') (conv3)



dropout = tf.keras.layers.Dropout( .2, input_shape= max3.shape)(max3)



x = Flatten()(dropout)
x = Dense(classes)(x)
x = Activation("softmax")(x)


model = Model(inputs, x)
    # return the constructed network architecture
return model

我知道每一层都将上一层的输入形状作为输入(我错了吗?)。 我有这个错误:

ValueError                                Traceback (most recent call last)
<ipython-input-16-4912ccd4ab70> in <module>()
      9    strides=2, padding='valid')(conv1)
     10 
---> 11 conv2 = tf.keras.layers.Conv2D(filters = 2, input_shape = max1.shape,  kernel_size=3, activation = 'relu')(max1)
     12 
     13 max2 = tf.keras.layers.MaxPooling1D(pool_size=2,

1 frames
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/input_spec.py in assert_input_compatibility(input_spec, inputs, layer_name)
    178                          'expected ndim=' + str(spec.ndim) + ', found ndim=' +
    179                          str(ndim) + '. Full shape received: ' +
--> 180                          str(x.shape.as_list()))
    181     if spec.max_ndim is not None:
    182       ndim = x.shape.ndims

ValueError: Input 0 of layer conv2d_30 is incompatible with the layer: expected ndim=4, found ndim=3. Full shape received: [None, 621, 2]

有人可以帮助我解决问题并理解输入形状问题背后的逻辑。

0 个答案:

没有答案