我有 DNA 数据,我试图将其输入 Keras,并且我对其进行了 one-hot 编码,使得每个 DNA 序列都是 4 个 channel (每种类型的核苷酸一个)。我遵循了一些教程,但似乎遇到了格式问题。也许有人可以帮助我?这是我第一次尝试将自己的数据输入 Keras。我的数据如下所示:
打印(x_train.shape)
(1509, 4, 476)
打印(y_train.shape)
(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_shape
参数找到 5 个维度。我错过了什么?
最佳答案
您不应在 input_shape 参数中包含样本数。这就是错误的含义。 批量大小尺寸会自动添加。
此外,您应该重新调整 x_train 表的形状以匹配 input_shape :
x_train = np.reshape(np.transpose(x_train, (0, 2, 1)), (x_train.shape[0], 1, x_train.shape[1], x_train.shape[2]))
这样我首先将数组转置为 (1509, 476, 4),然后添加一个维度:(1509, 1, 476, 4)
希望这有帮助
关于python - 使用 4 channel DNA 数据输入 Keras 时出现格式错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44980787/