TensorFlow: Basic example fails on "Variable"

tensorflow

#1

When using the basic example from https://malmaud.github.io/tfdocs/basic_usage/ the only way I can get it to complete without error is by suppressing the y “Variable”. This version works correctly (but the test fails):

using TensorFlow
using Base.Test
sess = Session(Graph())
x = constant(Float64[1,2])
y = Variable(Float64[3,4])
z = placeholder(Float64)
w = exp(x + z) # originally exp(x + z + -y)
init = global_variables_initializer()
res = run(sess, w, Dict(z=>Float64[1,2]))
println(res)
@test res[1] ≈ exp(-1)

Is this my error or has there been some change to Variable? I am using a custom libtensorflow.so generated locally with bazel.

Error is:

ERROR: LoadError: Tensorflow error: Status: Attempting to use uninitialized value node
	 [[Node: Neg = Neg[T=DT_DOUBLE, _device="/job:localhost/replica:0/task:0/cpu:0"](node)]]

Stacktrace:
 [1] check_status at /home/colin/.julia/v0.6/TensorFlow/src/core.jl:459 [inlined]
 [2] run(::TensorFlow.Session, ::Array{TensorFlow.Port,1}, ::Array{Any,1}, ::Array{TensorFlow.Port,1}, ::Array{Ptr{Void},1}) at /home/colin/.julia/v0.6/TensorFlow/src/run.jl:100
 [3] run(::TensorFlow.Session, ::Array{TensorFlow.Tensor{Float64},1}, ::Dict{TensorFlow.Tensor{Float64},Array{Float64,1}}) at /home/colin/.julia/v0.6/TensorFlow/src/run.jl:172
 [4] run(::TensorFlow.Session, ::TensorFlow.Tensor{Float64}, ::Dict{TensorFlow.Tensor{Float64},Array{Float64,1}}) at /home/colin/.julia/v0.6/TensorFlow/src/run.jl:190
 [5] include_from_node1(::String) at ./loading.jl:569
 [6] include(::String) at ./sysimg.jl:14
 [7] process_options(::Base.JLOptions) at ./client.jl:305
 [8] _start() at ./client.jl:371
while loading /home/colin/courses/deeplearn/tfx.jl

#2

OK I have it, because y is a variable, like placeholder z it needs to be set explicitly in the Dict input when the function is called. At least that gets it working again.


#3

You need to call run(sess, init) to actually initialize the variable.


#4

OK thanks, got it. Quite right, with run(sess, init) I can remove the y item from Dict. It’s a good little basic example but needs the using Base.Test and the run(sess, init).


#5

I’m not sure how you found that old doc page, but just FYI the current doc is http://malmaud.github.io/TensorFlow.jl/latest/basic_usage.html.


#6

Well, it was just a simple Google search, and the third item in my list points to https://malmaud.github.io/tfdocs/ and the link to basic example looks like just the ticket for a beginner. Perhaps Google indexing has not yet caught up with the latest offerings and needs some redirection help? I realize I have been pointed at the latest docs before and so am guilty of failure to make a note, but it might be of assistance to new people looking for information.