TensorFlow,Julia//图中已经存在节点名称 [英] TensorFlow, Julia // Node name already exists in the Graph

查看:137
本文介绍了TensorFlow,Julia//图中已经存在节点名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将TensorFlow与Julia结合使用,我想使用以下内容来简化表达式:

I'm using TensorFlow with Julia and I would like to reduce an expression with the following:

cross_entropy = nn.sparse_softmax_cross_entropy_with_logits( logits, labels) 

optimizer = train.GradientDescentOptimizer(learning_rate)

train_op = train.minimize(optimizer,reduce_mean(cross_entropy))

我遇到以下错误:

 ERROR: Tensorflow error: Status: Node name 'gradients/reduce_grad/Reshape' already exists in the Graph

Stacktrace:
 [1] check_status at /home/jabou/.julia/v0.6/TensorFlow/src/core.jl:459 [inlined]
 [2] import_graph_def(::TensorFlow.Graph, ::Array{UInt8,1}, ::TensorFlow.GraphImportOptions) at /home/jabou/.julia/v0.6/TensorFlow/src/core.jl:1680
 [3] import_graph_def(::TensorFlow.Graph, ::TensorFlow.tensorflow.GraphDef, ::TensorFlow.GraphImportOptions) at /home/jabou/.julia/v0.6/TensorFlow/src/core.jl:1690
 [4] extend_graph(::TensorFlow.Graph, ::Array{Any,1}) at /home/jabou/.julia/v0.6/TensorFlow/src/core.jl:427
 [5] extend_graph(::Array{Any,1}) at /home/jabou/.julia/v0.6/TensorFlow/src/core.jl:291
 [6] gradients(::TensorFlow.Tensor{Float32}, ::Array{Any,1}, ::Void) at /home/jabou/.julia/v0.6/TensorFlow/src/core.jl:1583
 [7] gradients(::TensorFlow.Tensor{Float32}, ::Array{Any,1}) at /home/jabou/.julia/v0.6/TensorFlow/src/core.jl:1575
 [8] compute_gradients(::TensorFlow.train.GradientDescentOptimizer, ::TensorFlow.Tensor{Float32}, ::Void) at /home/jabou/.julia/v0.6/TensorFlow/src/train.jl:48
 [9] #minimize#1(::Void, ::Void, ::Void, ::Function, ::TensorFlow.train.GradientDescentOptimizer, ::TensorFlow.Tensor{Float32}) at /home/jabou/.julia/v0.6/TensorFlow/src/train.jl:40
 [10] minimize(::TensorFlow.train.GradientDescentOptimizer, ::TensorFlow.Tensor{Float32}) at /home/jabou/.julia/v0.6/TensorFlow/src/train.jl:37

在python中,有一条指令可以避免该错误:tf.reset_default_graph(),但在Julia中没有类似的命令,我向GitHub提出了要求: https://github.com/malmaud/TensorFlow.jl/issues/374

In python, there is an instruction to avoid the error: tf.reset_default_graph() but there is not the similar command in Julia, I asked it to GitHub: https://github.com/malmaud/TensorFlow.jl/issues/374

你能帮我吗?

编辑

有时,我会收到有关python版本的警告.我使用指示的命令升级了该版本,但是没有用.也许问题出在这里?

Sometimes, I have this warning about the python version. I upgraded the version with the indicated commands, but it did not work. Maybe the problem is here ?

WARNING: Your Python TensorFlow client version (1.5.0) is below the TensorFlow backend version (1.6.0). This can cause various errors. Please upgrade your Python TensorFlow installation and then restart Julia.
You can upgrade by calling `using Conda; Conda.update();` from Julia.

这是我的代码:

ENV["CUDA_VISIBLE_DEVICES"] = "0" # It is to use the GPU

using TensorFlow
using Distributions

rng = MersenneTwister(1235) 

function weight_variable(shape)
   initial = map(Float32, rand(Normal(0, .001), shape...))
   return Variable(initial)
end

function bias_variable(shape)
   initial = fill(Float32(.1), shape...)
   return Variable(initial)
end


# Inputs

num_pixels = 12

num_classes = 10

x = placeholder(Float32, shape=[nothing, num_pixels])

Weight = weight_variable([num_pixels,num_classes]) 

biases = bias_variable([num_classes]) 

logits = x*Weight  + biases

labels = rand(rng,0:9,10) # Random labels for the test

cross_entropy = nn.sparse_softmax_cross_entropy_with_logits( logits = logits, labels = labels)


cross_entropy_reduce = reduce_mean(cross_entropy)

optimizer = train.GradientDescentOptimizer(0.001)

train_op = train.minimize(optimizer,cross_entropy_reduce) # Here is the crash

我在julia 0.6.2.中使用原子用于IDE.

I use atom for IDE, with julia 0.6.2.

谢谢.

推荐答案

在此示例中,我遇到了相同的问题:

I've encountered the same problem with this example:

using TensorFlow

sess = Session(Graph())
W = Variable([1.0, 1.0])
loss = nn.l2_loss(W)
optimizer = train.GradientDescentOptimizer(0.5)
train_step = train.minimize(optimizer, loss) # crash

这似乎是版本问题. TensorFlow 1.5和1.6失败,并显示与您相同的错误.但是使用TensorFlow 1.4.0可以正常工作.我还尝试了您的示例,一切看起来都很好.

It seems to be a version problem. TensorFlow 1.5 and 1.6 are failing with the same error as you have. But with TensorFlow 1.4.0 it works fine. I also tried your example and all looks good.

请确保文件/home/name/.julia/v0.6/TensorFlow/deps/build.jl中的第四行和第五行是

Make sure, the fourth and fifth line in the file /home/name/.julia/v0.6/TensorFlow/deps/build.jl are

const cur_version = "1.4.0"
const cur_py_version = "1.4.0"

,然后在julia命令行中使用Pkg.build("TensorFlow")重建软件包. 如果它不起作用,则可以尝试删除并重新安装该软件包.

and rebuild the package with Pkg.build("TensorFlow") in the julia command line. If it does not work, you can try to remove and reinstall the package.

这篇关于TensorFlow,Julia//图中已经存在节点名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆