输入形状为[?,1,1,5],[1,6,5,5]的'conv1d_2 / convolution / Conv2D'(op:'Conv2D')从1中减去6引起的负尺寸大小

时间:2019-06-05 11:21:01

标签: keras

我正在尝试为CNN模型创建一个输入为x[18324,6]形式的CNN模型 其中18324是输入数量,6是输入向量的大小。
但是我在使用此代码时遇到上述错误:

indata = np.loadtxt("D:\\iit ropar intern\\alllog.txt.txt",dtype='float')
x = indata[:,0:6]
y = indata[:,6:11]

print(np.shape(x))
print(x.shape[0])

scaler = MinMaxScaler()
X_tr ain, X_test, y_train, y_test =sk.model_selection.train_test_split(x, y, test_size=0.10)

min_max_scaler = preprocessing.MinMaxScaler()
X_train = min_max_scaler.fit_transform(X_train)
X_test=min_max_scaler.fit_transform(X_test)

print(X_train.shape)

model = Sequential()
model.add(Conv1D(filters=5, kernel_size=6, activation='relu', input_shape=(X_train.shape[1],1)))
model.add(Conv1D(filters=5, kernel_size=6, activation='relu'))
model.add(Dropout(0.5))
model.add(MaxPooling1D(pool_size=2))
model.add(Flatten())
model.add(Dense(50, activation='relu'))
model.add(Dense(5, activation='linear'))
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics= 
['accuracy'])
#X_train = np.reshape(X_train, (X_train.shape[0],X_train.shape[1],1))
history=model.fit(X_train,y_train, epochs=50, 
batch_size=10,validation_split=0.1,verbose=1)

scores = model.evaluate(X_train,y_train)

1 个答案:

答案 0 :(得分:0)

该错误起源于第二个Conv1D,因为您的内核变得比张量维大。要解决此问题,请使用padding='same'或在第一个kernel_size=1之后更改Conv1D