gpt4 book ai didi

python - MXNet 后向形状不一致

转载 作者:太空宇宙 更新时间:2023-11-03 14:51:52 27 4
gpt4 key购买 nike

升级到 MXNet 0.11.0 后,我的旧代码中出现奇怪的错误:

使用 scikit-learn 的波士顿住房数据集:

data = mx.sym.Variable("data")
y = mx.sym.Variable("output_label")
fc = mx.sym.FullyConnected(data=data,num_hidden=20,name='FC1')
fc = mx.sym.Activation(data=fc, act_type='relu', name='act1')
regularization_cost = regularization_cost + mx.sym.sum(mx.sym.abs(fc.get_internals()['FC1_weight']))
fc = mx.sym.FullyConnected(data=fc,num_hidden=1,name='FC2')
regularization_cost = regularization_cost + mx.sym.sum(mx.sym.abs(fc.get_internals()['FC2_weight']))
ce = l1_reg * regularization_cost + 0.5 * mx.sym.mean(mx.symbol.square(fc - y))

train_iter = mx.io.NDArrayIter(data=x_train[:-44], label=y_train[:-44][:, np.newaxis], batch_size=20, shuffle=False,
label_name='output_label', last_batch_handle='pad')
mod = mx.mod.Module(symbol=loss,
context=mx.cpu(),
data_names=['data'],
label_names=['output_label'])
mod.fit(train_iter, num_epoch=10, batch_end_callback=f, monitor=mon)

这会引发以下错误:

---------------------------------------------------------------------------
MXNetError Traceback (most recent call last)
~/dev/mxnet/python/mxnet/symbol.py in simple_bind(self, ctx, grad_req, type_dict, group2ctx, shared_arg_names, shared_exec, shared_buffer, **kwargs)
1472 shared_exec_handle,
-> 1473 ctypes.byref(exe_handle)))
1474 except MXNetError as e:

~/dev/mxnet/python/mxnet/base.py in check_call(ret)
128 if ret != 0:
--> 129 raise MXNetError(py_str(_LIB.MXGetLastError()))
130

MXNetError: [12:45:50] src/pass/infer_shape_type.cc:112: Check failed: rshape[eid] == rshape[idx.entry_id(fnode.inputs[i])] ((1,20) vs. ()) Backward shape inconsistent with the forward shape

Stack trace returned 10 entries:
RuntimeError: simple_bind error. Arguments:
output_label: (20, 1)
data: (20, 13)
[12:45:50] src/pass/infer_shape_type.cc:112: Check failed: rshape[eid] == rshape[idx.entry_id(fnode.inputs[i])] ((1,20) vs. ()) Backward shape inconsistent with the forward shape

最佳答案

关于python - MXNet 后向形状不一致,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45845352/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com