python variable shape 不匹配_Python:keras形状不匹配错误(Python: keras shape mismatch error)...

Python:keras形状不匹配错误(Python: keras shape mismatch error)

我正在尝试在keras构建一个非常简单的多层感知器(MLP):

model = Sequential()

model.add(Dense(16, 8, init='uniform', activation='tanh'))

model.add(Dropout(0.5))

model.add(Dense(8, 2, init='uniform', activation='tanh'))

sgd = SGD(lr=0.01, decay=1e-6, momentum=0.9, nesterov=True)

model.compile(loss='mean_squared_error', optimizer=sgd)

model.fit(X_train, y_train, nb_epoch=1000, batch_size=50)

score = model.evaluate(X_test, y_test, batch_size=50)

我的训练数据形状: X_train.shape给出(34180, 16)

标签属于具有形状的二进制类: y_train.shape给出(34180,)

所以我的keras代码应该产生以下连接的网络: 16x8 => 8x2

这会产生形状不匹配误差:

ValueError: Input dimension mis-match. (input[0].shape[1] = 2, input[1].shape[1] = 1)

Apply node that caused the error: Elemwise{sub,no_inplace}(Elemwise{Composite{tanh((i0 + i1))}}[(0, 0)].0, )

Inputs types: [TensorType(float64, matrix), TensorType(float64, matrix)]

Inputs shapes: [(50, 2), (50, 1)]

Inputs strides: [(16, 8), (8, 8)]

在model.fit(X_train, y_train, nb_epoch=1000, batch_size=50) Epoch 0处。 我在监督Keras中显而易见的事情吗?

编辑:我在这里经历了这个问题,但没有解决我的问题

I am trying to buil

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值