【发布时间】:2021-09-21 23:30:03
【问题描述】:
我从文件中获取数据
y = np.genfromtxt('dataY.txt', dtype=np.float32) #input data for target dataset
x = np.genfromtxt('dataX.txt', dtype=np.float32)#input data for input dataset
我相应地拆分数据:
xtrain, xtest, ytrain, ytest = train_test_split (x,y,test_size=.2)
train_data = tf.data.Dataset.from_tensor_slices((xtrain, ytrain))
valid_data = tf.data.Dataset.from_tensor_slices((xtest, ytest))
dataY.txt 文件由 1000 行组成。在给定输入 X 的情况下,每行包含 30 个我希望 NN 在训练后猜测的数字。
dataX.txt 文件由 1000 行组成,每个 Y 行。每行包含 100 个数字。
问题:如何使以下代码工作?
model = Sequential()
#whad do I need to write in the following line(s)?
model.add(Conv2D(100,(7,7)))
model.add(LeakyReLU())
model.compile( loss='mse', metrics=['mse'])
model.fit(train_data, epochs=10, validation_data=valid_data)
ypred = model.predict(x)
错误:
ValueError: Input 0 of layer sequential is incompatible with the layer: : expected min_ndim=4, found ndim=2. Full shape received: (100, 1)
【问题讨论】:
-
你知道
Conv2D是什么吗?为什么要尝试将二维卷积应用于矢量数据? -
谢谢,我该如何解决?
标签: python numpy tensorflow neural-network