python如何同时输入一组数据_python – 如何在keras中对输入数据进行整形以与Conv1D一起使用?...

我的虚拟数据集中有12个长度为200的向量,每个向量代表一个样本.假设x_train是一个形状为(12,200)的数组.

当我做:

model = Sequential()

model.add(Conv1D(2, 4, input_shape=(1, 200)))

我收到错误:

ValueError: Error when checking model input: expected conv1d_1_input to have 3 dimensions, but got array with shape (12, 200)

如何正确地塑造输入数组?

这是我更新的脚本:

data = np.loadtxt('temp/data.csv', delimiter=' ')

trainData = []

testData = []

trainlabels = []

testlabels = []

with open('temp/trainlabels', 'r') as f:

trainLabelFile = list(csv.reader(f))

with open('temp/testlabels', 'r') as f:

testLabelFile = list(csv.reader(f))

for i in range(2):

for idx in trainLabelFile[i]:

trainData.append(data[int(idx)])

# append 0 to labels for neg, 1 for pos

trainlabels.append(i)

for i in range(2):

for idx in testLabelFile[i]:

testData.append(data[int(idx)])

# append 0 to labels for neg, 1 for pos

testlabels.append(i)

# print(trainData.shape)

X = np.array(trainData)

Y = np.array(trainlabels)

X2 = np.array(testData)

Y2 = np.array(testlabels)

model = Sequential()

model.add(Conv1D(1, 1, input_shape=(12, 1, 200)))

opt = 'adam'

model.compile(loss='mean_squared_error', optimizer=opt, metrics=['accuracy'])

model.fit(X, Y, epochs=epochs)

我现在收到一个新错误:

ValueError: Input 0 is incompatible with layer conv1d_1: expected ndim=3, found ndim=4

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值