我正在尝试在Julia 0.6.0中重现一些Python MXNet代码,如果我尝试使用小于输出维度的批量大小,我会得到一个BoundsError。如果我在玩具示例中使用更大的批量大小,事情正常并且网络会聚到正确的解决方案,但在我的应用程序中输出维度很大,因此这是不实际的。
这是一个给出此错误的线性回归示例:
using MXNet
net = mx.Variable(:data)
net = mx.FullyConnected(net, name=:fc0, num_hidden=5)
net = mx.LinearRegressionOutput(net, name=:output)
mod = mx.FeedForward(net, context=mx.cpu(0))
batch_size = 4 # works for batch_size > 4
A = randn(5,100)
train_in = randn(100,1000)
train_out = A*train_in + .1*randn(5,1000)
train_provider = mx.ArrayDataProvider(:data=>train_in,
:output_label=>train_out,
shuffle=true,
batch_size=batch_size)
optimizer = mx.SGD(lr=0.001, momentum=0.9, weight_decay=0.00001)
mx.fit(mod, optimizer, train_provider)
这会产生
INFO: Start training on MXNet.mx.Context[CPU0]
INFO: Initializing parameters...
INFO: Creating KVStore...
INFO: TempSpace: Total 0 MB allocated on CPU0
INFO: Start training...
ERROR: LoadError: BoundsError: attempt to access 5×4 Array{Float32,2} at index [Base.Slice(Base.OneTo(5)), 5]
如果我将批量大小增加到5或更大,它会按预期工作。我错过了什么?
答案 0 :(得分:1)