malmaud / TensorFlow.jl

A Julia wrapper for TensorFlow
Other
884 stars 110 forks source link

MNIST Tutorial Fails #352

Open rickhg12hs opened 6 years ago

rickhg12hs commented 6 years ago

Both the MNIST softmax regression model and the multi-layer convolutional network fail with accuracies of 0.0.

Interestingly, both the Basic usage and Logistic regression examples seem to work fine.

In addition, with my libtensorflow.so, both mnist_softmax.py and mnist_deep.py from TensorFlow's Python examples work fine with Python 2.7 and Python 3.6.

julia> versioninfo()
Julia Version 0.6.1
Commit 0d7248e2ff (2017-10-24 22:15 UTC)
Platform Info:
  OS: Linux (x86_64-redhat-linux)
  CPU: Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.9.1 (ORCJIT, skylake)
julia> Pkg.installed("TensorFlow")
v"0.7.5"
julia> tf_version()
v"1.4.0"
...
for i in 1:1000
    batch = next_batch(loader, 50)
    if i%100 == 1
        train_accuracy = run(session, accuracy, Dict(x=>batch[1], y_=>batch[2], keep_prob=>1.0))
        info("step $i, training accuracy $train_accuracy")
    end
    run(session, train_step, Dict(x=>batch[1], y_=>batch[2], keep_prob=>.5))
end

testx, testy = load_test_set()
test_accuracy = run(session, accuracy, Dict(x=>testx, y_=>testy, keep_prob=>1.0))
info("test accuracy $test_accuracy")

INFO: step 1, training accuracy 0.0
INFO: step 101, training accuracy 0.0
INFO: step 201, training accuracy 0.0
INFO: step 301, training accuracy 0.0
INFO: step 401, training accuracy 0.0
INFO: step 501, training accuracy 0.0
INFO: step 601, training accuracy 0.0
INFO: step 701, training accuracy 0.0
INFO: step 801, training accuracy 0.0
INFO: step 901, training accuracy 0.0
INFO: test accuracy 0.0
tkluck commented 6 years ago

I ran into a similar issue, and traced it down to the following. The tutorial gives this line of code:

julia> correct_prediction = indmax(y,2) .== indmax(y_, 2)
false

But as you can see, this doesn't return a Tensor but the constant value false. The intended line seems to have been:

julia> correct_prediction = equal(indmax(y,2), indmax(y_, 2))
<Tensor Equal:1 shape=unknown dtype=Bool>

and indeed, this allows me to reproduce the stated accuracy for the softmax model.

Recent changes to . and broadcast may be to blame, but I haven't dug into that (yet).

Thoughts?

malmaud commented 6 years ago

Ah ya, that's possible. A PR fixing the documentation would be welcome.

rickhg12hs commented 6 years ago

I ran into a similar issue, and traced it down to the following. The tutorial gives this line of code:

julia> correctprediction = indmax(y,2) .== indmax(y, 2) false But as you can see, this doesn't return a Tensor but the constant value false. The intended line seems to have been:

julia> correctprediction = equal(indmax(y,2), indmax(y, 2))

and indeed, this allows me to reproduce the stated accuracy for the softmax model. Recent changes to . and broadcast may be to blame, but I haven't dug into that (yet). Thoughts?

Or is the true intention to overload ==? ... Or something like:

julia> import Base.==

julia> ==(x::T, y::T) where T<:TensorFlow.Tensor = equal(x, y)
== (generic function with 275 methods)
rickhg12hs commented 6 years ago

Same issue reported at #364 .