首先,我是神經(jīng)網(wǎng)絡(luò)和Keras的新手。我正在嘗試使用Keras創(chuàng)建一個簡單的神經(jīng)網(wǎng)絡(luò),其中輸入是一個時間序列,輸出是另一個相同長度的時間序列(一維矢量)。我制作了偽代碼,以使用Conv1D層創(chuàng)建隨機(jī)的輸入和輸出時間序列。然后,Conv1D層輸出6個不同的時間序列(因為我有6個濾波器),并且我定義的下一層將這些輸出的全部6個相加到一個,即整個網(wǎng)絡(luò)的輸出。import numpy as npimport tensorflow as tffrom tensorflow.python.keras.models import Modelfrom tensorflow.python.keras.layers import Conv1D, Input, Lambdadef summation(x): y = tf.reduce_sum(x, 0) return ytime_len = 100 # total length of time seriesnum_filters = 6 # number of filters/outputs to Conv1D layerkernel_len = 10 # length of kernel (memory size of convolution)# create random input and output time seriesX = np.random.randn(time_len)Y = np.random.randn(time_len)# Create neural network architectureinput_layer = Input(shape = X.shape)conv_layer = Conv1D(filters = num_filters, kernel_size = kernel_len, padding = 'same')(input_layer)summation_layer = Lambda(summation)(conv_layer)model = Model(inputs = input_layer, outputs = summation_layer)model.compile(loss = 'mse', optimizer = 'adam', metrics = ['mae'])model.fit(X,Y,epochs = 1, metrics = ['mae'])我得到的錯誤是:ValueError: Input 0 of layer conv1d_1 is incompatible with the layer: expected ndim=3, found ndim=2. Full shape received: [None, 100]查看有關(guān)Conv1D的Keras文檔,輸入形狀應(yīng)該是3D張量的形狀(批,階,通道),如果我們使用一維數(shù)據(jù),我將無法理解。您能否解釋每一項的含義:批次,步驟和渠道?我應(yīng)該如何調(diào)整我的一維向量以允許網(wǎng)絡(luò)運行?
添加回答
舉報
0/150
提交
取消