Python 使用4通道DNA数据输入到Keras的格式错误

Python 使用4通道DNA数据输入到Keras的格式错误,python,tensorflow,neural-network,keras,reshape,Python,Tensorflow,Neural Network,Keras,Reshape,我有我正试图输入到Keras的DNA数据,我有一个热编码的数据,每个DNA序列是4个通道(每种核苷酸一个通道)。我学习了一些教程,但我似乎遇到了格式问题。也许有人能帮我?这是我第一次尝试将自己的数据输入Keras。我的数据如下所示: ###Setup Keras to create a convolutional recurrent NN # set parameters: batch_size = 32 filters = (32, 1, 2) #(number of filters, row

我有我正试图输入到Keras的DNA数据,我有一个热编码的数据,每个DNA序列是4个通道(每种核苷酸一个通道)。我学习了一些教程,但我似乎遇到了格式问题。也许有人能帮我?这是我第一次尝试将自己的数据输入Keras。我的数据如下所示:

###Setup Keras to create a convolutional recurrent NN
# set parameters:
batch_size = 32
filters = (32, 1, 2) #(number of filters, rows per convolution kernel, columns per convolution kernel)
kernel_size = 16
x_shape = (1509, 1, 476, 4) #(samples, height, width, depth)
epochs = 3

#declare model
model = Sequential()

#CNN Input layer
model.add(Conv2D(filters,
                 kernel_size,
                 padding='same',
                 activation='relu',
                 strides=(1,0),
                 input_shape=x_shape))
print(model.output_shape)
打印(x_列形状)
(1509, 4, 476)
打印(y_列形状)
(1509,)

我的模型(到目前为止)如下所示:

###Setup Keras to create a convolutional recurrent NN
# set parameters:
batch_size = 32
filters = (32, 1, 2) #(number of filters, rows per convolution kernel, columns per convolution kernel)
kernel_size = 16
x_shape = (1509, 1, 476, 4) #(samples, height, width, depth)
epochs = 3

#declare model
model = Sequential()

#CNN Input layer
model.add(Conv2D(filters,
                 kernel_size,
                 padding='same',
                 activation='relu',
                 strides=(1,0),
                 input_shape=x_shape))
print(model.output_shape)
但我得到了以下错误:

ValueError: Input 0 is incompatible with layer conv2d_0: expected ndim=4, found ndim=5

当我指定4个维度时,我不清楚为什么模型会为
input\u shape
参数找到5个维度。我遗漏了什么?

输入形状参数中不应包含样本数。这就是错误的含义。 批次大小维度将自动添加

此外,还应重塑x_train表的形状,以匹配输入_形状:

x_train = np.reshape(np.transpose(x_train, (0, 2, 1)), (x_train.shape[0], 1, x_train.shape[1], x_train.shape[2]))
这样,我首先将数组转换为(1509476,4),然后添加一个维度:(1509476,4)

我希望这有帮助