2017-07-07 29 views
1

我有我想要輸入Keras的DNA數據,並且我有一個熱點編碼它使得每個DNA序列是4個通道(每個類型一個核苷酸)。我跟着一些教程,但我似乎有一個格式問題。也許有人可以幫助我?這是我第一次嘗試將自己的數據輸入Keras。我的數據是這樣的:使用4通道DNA數據輸入到Keras中的格式錯誤

print(x_train.shape) (1509, 4, 476) print(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個維度。我錯過了什麼?

回答

2

您不應該在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)

我希望這可以幫助