dmlc / MXNet.jl

MXNet Julia Package - flexible and efficient deep learning in Julia
371 stars 70 forks source link

Digit-Recognition-on-MNIST-1 example code question #409

Closed LTGZZ closed 6 years ago

LTGZZ commented 6 years ago

Hi,

in this tutorial: http://dmlc.ml/MXNet.jl/latest/tutorial/mnist/#convolutional-neural-networks

This portion of code doesn't work:

# collect all labels from eval data
labels = Array[]
for batch in eval_provider
  push!(labels, copy(mx.get_label(batch)))
end
labels = cat(1, labels...)

# Now we use compute the accuracy
correct = 0
for i = 1:length(labels)
  # labels are 0...9
  if indmax(probs[:,i]) == labels[i]+1
    correct += 1
  end
end
println(mx.format("Accuracy on eval set: {1:.2f}%", 100correct/length(labels)))`

I guess that push!(labels, copy(mx.get_label(batch))) must be push!(labels, copy(mx.get_label(eval_provider,batch)))

But I don't understand if indmax(probs[:,i]) == labels[i]+1 because it's not comparing the same type of object, so it doesn't work.

iblislin commented 6 years ago

oh, doc is out-of-date. It should be like this: https://github.com/dmlc/MXNet.jl/blob/ec2b6995dc2283e52f40b8ab1f6485230d02c779/examples/mnist/mlp.jl#L49-L63

About if indmax(probs[:,i]) == labels[i]+1 Both of right-hand side and left-hand side are normal Julia Array. So, it's no problem.

LTGZZ commented 6 years ago

It works, thanks !

I hope the info http://dmlc.ml/MXNet.jl/latest/tutorial/mnist/#Digit-Recognition-on-MNIST-1 will be updated.

iblislin commented 6 years ago

sure, will do