简体   繁体   中英

Negative dimension size caused by subtracting 3 from 1 for 'conv2d_1/convolution' (op: 'Conv2D') with input shapes: [?,1,10000,80], [3,3,80,16]

I am using Keras version 2.3.1 and TensorFlow 2.0.0.

I induce the titular error on my instantiation of the first convolutional layer in my network:

model = Sequential([
    Conv2D(16, 3, input_shape=(1, 10000, 80)),
    LeakyReLU(alpha=0.01),
    MaxPooling2D(pool_size=3),
    Conv2D(16, 3),
    LeakyReLU(alpha=0.01),
    MaxPooling2D(pool_size=3),
    Conv2D(16, 3),
    LeakyReLU(alpha=0.01),
    MaxPooling2D(pool_size=3),
    Conv2D(16, 3),
    LeakyReLU(alpha=0.01),
    MaxPooling2D(pool_size=3),
    Dense(256),
    LeakyReLU(alpha=0.01),
    Dense(32),
    LeakyReLU(alpha=0.01),
    Dense(1, activation='sigmoid')])

As I am aware, the TF dimensional ordering should be set as (samples, rows, columns). My input is an array of shape 1000, 80.

I have tried all of the fixes I have found online, including:

K.common.set_image_dim_ordering('tf')
K.set_image_data_format('channels_last')
K.tensorflow_backend.set_image_dim_ordering('tf')
K.set_image_dim_ordering('tf')

However, all of these either do not change anything (as in the case of the first two) or fail at those lines (the latter two).

None of these fixes will work if the input_shape is wrong. The input_shape for a Conv2D layers should be (width, height, channels) , the samples dimension is not included as its implictly inserted by Keras.

The input_shape you gave would be interpreted with width of one, which is a problem. You need to format your input_shape correctly and also add the channels dimension.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM