【问题标题】:ValueError: Error when checking input: expected conv1d_1_input to have shape (None, 500000, 3253) but got array with shape (500000, 3253, 1)ValueError:检查输入时出错:预期 conv1d_1_input 具有形状 (None, 500000, 3253) 但得到的数组具有形状 (500000, 3253, 1)
【发布时间】:2018-01-01 16:59:58
【问题描述】:

我想用卷积神经网络训练我的数据,我已经重塑了我的数据: 这些是我使用过的参数:

'x_train.shape'=(500000, 3253)
'y_train.shape', (500000,)
'y_test.shape', (20000,)
'y_train[0]', 97
'y_test[0]', 99
'y_train.shape', (500000, 256)
'y_test.shape', (20000, 256)

这就是我定义模型架构的方式:

# 3. Define model architecture
model = Sequential()

model.add(Conv1D(64, 8, strides=1, padding='valid',
                        dilation_rate=1, activation=None, use_bias=True, kernel_initializer='glorot_uniform',
                        bias_initializer='zeros', kernel_regularizer=None, bias_regularizer=None,
                        activity_regularizer=None, kernel_constraint=None, bias_constraint=None, input_shape=x_train.shape))
# input_traces=N_Features   
# input_shape=(batch_size, trace_lenght,num_of_channels)            
model.add(MaxPooling1D(pool_size=2,strides=None, padding='valid'))
model.add(Flatten())
model.add(Dropout(0.5))
model.add(Dense(1, activation='relu'))

model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
print(model.summary())


model.fit(x_train, y_train, batch_size=100, epochs=500,verbose=2)

但我有两个错误: 1-

ValueError: Error when checking input: expected conv1d_1_input to have shape (None, 500000, 3253) but got array with shape (500000, 3253, 1)

2-model.fit()

我该如何解决这个问题?

【问题讨论】:

    标签: deep-learning keras-layer conv-neural-network


    【解决方案1】:

    输入形状错误,对于 Theano 应该是 input_shape = (1, 3253) 或者对于 TensorFlow 应该是 (3253, 1)。输入形状不包括样本数。

    然后您需要重塑数据以包含通道轴:

    x_train = x_train.reshape((500000, 1, 3253))
    

    如果您使用 TensorFlow,则将通道维度移至末尾。经过这些更改后,它应该可以工作了。

    【讨论】:

      【解决方案2】:
      input_shape = (3253, 1)
      

      这必须是第一个卷积层的 Input_shape Conv1D

      model.fit() 出现错误,因为您还没有构建模型。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-09-01
        • 1970-01-01
        • 1970-01-01
        • 2022-11-03
        • 2021-02-26
        • 2019-08-21
        • 2020-04-05
        • 2020-12-05
        相关资源
        最近更新 更多