以下内容基于以下文章中作者的开放源代码: https://arxiv.org/abs/1808.03668
我用1D卷积层替换了2D卷积层。
但是,我需要重塑输入数据以适用于转换图层。典型错误如下: ValueError:检查输入时出错:预期input_1具有3维,但数组的形状为(39413、100、40、1)
以下是Conv2D图层的输入数据形状的印刷品:
[[[[ 0.40827462]
[-0.50940506]
[ 0.40357732]
...
[-0.41494966]
[ 0.38972651]
[-0.46409597]]
[[ 0.40827462]
[-0.6042721 ]
[ 0.40357732]
...
请帮助特定的规定输入数据在馈入Conv1D层之前如何进行更改和调整?另外,正确的代码是什么?
非常感谢您提供任何反馈意见。
下面是尝试的代码,说明如何为Conv1D图层准备和成形数据。我不知道是什么导致了代码中的错误:
def prepare_x(data):
df1 = data[:40, :].T
return np.array(df1)
def get_label(data):
lob = data[-5:, :].T
return lob
def data_classification(X, Y, T):
[N, D] = X.shape
df = np.array(X)
dY = np.array(Y)
dataY = dY[T - 1:N]
dataX = np.zeros((N - T + 1, T, D))
for i in range(T, N + 1):
dataX[i - T] = df[i - T:i, :]
return dataX.reshape(dataX.shape+ (1,)), dataY
dec_train = np.loadtxt('/Train_Dst_NoAuction_ZScore_CF_1.txt')
dec_test = np.loadtxt('/Test_Dst_NoAuction_ZScore_CF_3.txt')
# extract data from the dataset
train_lob = prepare_x(dec_train)
test_lob = prepare_x(dec_test)
# extract label from the dataset
train_label = get_label(dec_train)
test_label = get_label(dec_test)
# prepare training data.
trainX_CNN, trainY_CNN = data_classification(train_lob, train_label, T=100)
trainY_CNN = trainY_CNN[:,3] - 1
trainY_CNN = np_utils.to_categorical(trainY_CNN, 3)
# prepare test data.
testX_CNN, testY_CNN = data_classification(test_lob, test_label, T=100)
testY_CNN = testY_CNN[:,3] - 1
testY_CNN = np_utils.to_categorical(testY_CNN, 3)