# TensorFlow: Basic example fails on "Variable"

**URL:** https://discourse.julialang.org/t/tensorflow-basic-example-fails-on-variable/6560
**Category:** Machine Learning
**Tags:** tensorflow
**Created:** [October 19, 2017, 1:48pm UTC](https://discourse.julialang.org/t/tensorflow-basic-example-fails-on-variable/6560 "2017-10-19T13:48:57Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Colin\_Beckingham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/colin_beckingham/32/4878_2.png) [@Colin\_Beckingham](https://discourse.julialang.org/u/Colin_Beckingham)
#### Post date: [October 19, 2017, 1:48pm UTC](https://discourse.julialang.org/t/tensorflow-basic-example-fails-on-variable/6560/1 "2017-10-19T13:48:58Z")

</div>

When using the basic example from [https://malmaud.github.io/tfdocs/basic\_usage/](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):

```julia
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:

```julia
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

```

---

<div class="post-metadata">

### Author: ![Colin\_Beckingham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/colin_beckingham/32/4878_2.png) [@Colin\_Beckingham](https://discourse.julialang.org/u/Colin_Beckingham)
#### Post date: [October 19, 2017, 3:38pm UTC](https://discourse.julialang.org/t/tensorflow-basic-example-fails-on-variable/6560/2 "2017-10-19T15:38:02Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![malmaud](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/malmaud/32/29_2.png) [@malmaud](https://discourse.julialang.org/u/malmaud)
#### Post date: [October 19, 2017, 8:15pm UTC](https://discourse.julialang.org/t/tensorflow-basic-example-fails-on-variable/6560/3 "2017-10-19T20:15:57Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Colin\_Beckingham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/colin_beckingham/32/4878_2.png) [@Colin\_Beckingham](https://discourse.julialang.org/u/Colin_Beckingham)
#### Post date: [October 19, 2017, 8:30pm UTC](https://discourse.julialang.org/t/tensorflow-basic-example-fails-on-variable/6560/4 "2017-10-19T20:30:04Z")

</div>

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)`.

---

<div class="post-metadata">

### Author: ![malmaud](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/malmaud/32/29_2.png) [@malmaud](https://discourse.julialang.org/u/malmaud)
#### Post date: [October 19, 2017, 9:56pm UTC](https://discourse.julialang.org/t/tensorflow-basic-example-fails-on-variable/6560/5 "2017-10-19T21:56:06Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Colin\_Beckingham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/colin_beckingham/32/4878_2.png) [@Colin\_Beckingham](https://discourse.julialang.org/u/Colin_Beckingham)
#### Post date: [October 20, 2017, 9:23am UTC](https://discourse.julialang.org/t/tensorflow-basic-example-fails-on-variable/6560/6 "2017-10-20T09:23:42Z")

</div>

Well, it was just a simple Google search, and the third item in my list points to [https://malmaud.github.io/tfdocs/](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.
