Keras:1DConv的输入尺寸图层

时间:2020-08-10 12:30:38

标签: python keras deep-learning keras-layer

我在输入尺寸方面遇到了重塑问题,我不知道如何解决。我在下面附加了代码:

tot_comm_files = tot_comm_files.sort_values('Info2')
l = list(tot_comm_files.index)
tot_num_files = tot_num_files[l]

# split data
(X_train, X_test, Y_train, Y_test) = train_test_split(tot_num_files, shelf_life, test_size = 0.2)



X_train = np.array(X_train, dtype = np.float)
X_test = np.array(X_test, dtype =np.float)
Y_train = np.array(Y_train, dtype = np.float)
Y_test = np.array(Y_test, dtype = np.float)

X_train = X_train.reshape((400001, len(X_train)))#.astype(int)
#X_test = X_test.reshape((-1,400001))
#Y_train = np.transpose(Y_train).reshape((-1,2224))
#Y_test = Y_test.reshape((-1,400001))


BATCH_SIZE = 32
EPOCHS = 10

#input_shape = (1, len(X_train))

def model():
    m = Sequential()
    m.add(Conv1D(128, 7, activation = 'relu'))#input_shape = input_shape
    m.add(Conv1D(128, 2, activation = 'relu'))
    m.add(MaxPool1D(pool_size=7))
    m.add(Conv1D(64, 7, activation = 'relu'))
    m.add(Conv1D(64, 5, activation = 'relu'))
    m.add(GlobalAveragePooling1D())
        
    opt = Adam(lr=0.0001, decay=1e-2/EPOCHS)
    m.compile(loss='mean_squared_error', optimizer = opt, metrics = ['accuracy'])
    # Fit data to model m
    m.fit(X_train, Y_train, batch_size = BATCH_SIZE, epochs = EPOCHS, validation_data = (X_test, Y_test))
    m.summary()
       
    test_loss, test_acc = m.evaluate(X_test, Y_test, verbose = 0)
    print('Test loss:', test_loss[0])
    print('Test accuracy:', test_acc[1])

mod = model()
 
plot_model(model, to_file='model_plot.png', show_shapes=True, show_layer_names=True) 

对于我的输入tot_comm_filestot_num_files ,我具有以下输入尺寸:

tot_comm_files = (1574,8)
tot_num_files = (1574, 400001)

我试图摆弄对象input_shape,但我无法落后于我的错误所在。有人可以帮助我了解我的错误在哪里吗?

0 个答案:

没有答案