function init_wb(in_out=[4096,5])
w=[xavier(Float32,(in_out[2],in_out[1])),zeros(Float32,in_out[2])]
end
predict(w,x)=w[1]*mat(x).+w[2]
loss(w,x,ygold)=nll(predict(w,x),ygold)
lossgradient=grad(loss)
julia> w[1]
5×4096 Array{Float32,2}:
0.022014 0.0192639 0.00160997 … 0.027218 0.00113881
-0.0140597 -0.0636935 -0.00497378 -0.00697153 -0.0373464
0.0818167 0.0728172 0.013256 0.0259867 0.0501119
-0.118777 -0.0914147 -0.00677145 -0.0326031 -0.0659944
0.0523701 0.0537148 0.0220276 0.00529148 0.00907731
julia> y
100-element Array{UInt8,1}:
0x00
0x00
0x00
0x00
0x00
0x00
0x00
0x00
0x00
0x00
⋮
julia> x
1×1×4096×100 Array{Float32,4}:
[:, :, 1, 1] =
2.3000634
[:, :, 2, 1] =
2.5095005
[:, :, 3, 1] =
0.0
...
julia> st=w[1]*mat(x)
5×100 Array{Float32,2}:
405.496 357.088 389.276 321.994 … 476.868 406.444 482.75
-232.119 -203.723 -228.6 -187.018 -245.119 -219.343 -252.767
444.043 397.126 435.921 374.369 511.754 441.204 520.46
-854.678 -760.229 -831.479 -704.527 -1040.34 -882.174 -1049.85
249.883 221.303 246.57 208.232 300.835 257.746 304.266
julia> st.+=w[2]
5×100 Array{Float32,2}:
405.51 357.103 389.291 322.009 … 476.882 406.458 482.765
-232.127 -203.731 -228.609 -187.027 -245.128 -219.351 -252.776
444.064 397.148 435.943 374.391 511.776 441.226 520.482
-854.716 -760.267 -831.517 -704.565 -1040.38 -882.212 -1049.89
249.893 221.314 246.58 208.242 300.845 257.757 304.276
julia> loss(w,x,ygold) = nll(predict(w,x),ygold;dims=1);
julia> lo=loss(w,x,y)
ERROR: BoundsError: attempt to access 5×100 Array{Float32,2} at index [[0, 5, 10, 15, 20, 25, 30, 35, 40, 45 … 450, 455, 460, 465, 470, 475, 480, 485, 490, 495]]
Stacktrace:
[1] throw_boundserror(::Array{Float32,2}, ::Tuple{Array{Int64,1}}) at ./abstractarray.jl:484
[2] checkbounds at ./abstractarray.jl:449 [inlined]
[3] _getindex at ./multidimensional.jl:588 [inlined]
[4] getindex at ./abstractarray.jl:905 [inlined]
[5] #nll#599(::Int64, ::Bool, ::Function, ::Array{Float32,2}, ::Array{UInt8,1}) at /home/users/xdlan/.julia/packages/Knet/rKugL/src/loss.jl:219
[6] (::getfield(Knet, Symbol("#kw##nll")))(::NamedTuple{(:dims,),Tuple{Int64}}, ::typeof(nll), ::Array{Float32,2}, ::Array{UInt8,1}) at ./none:0
[7] loss(::Array{Array{Float32,N} where N,1}, ::Array{Float32,4}, ::Array{UInt8,1}) at ./REPL[74]:1
[8] top-level scope at none:0
`
你使用了 0 index