CLH blog AI CV Algorithm

TensorFlow Inference Error

2018-11-20
CLH

TensorFlow Inference Error

When run Tensorflow_Inference.ipynb in ipython, an error occurred:

ValueError: Variable resnet_v1_50/conv1/weights already exists, disallowed. Did you mean to set reuse=True or reuse=tf.AUTO_REUSE in VarScope? Originally defined at:
File “/home/lc/lcl/py3/lib/python3.6/site-packages/tensorflow/contrib/framework/python/ops/variables.py”, line 277, in variable aggregation=aggregation)
File “/home/lc/lcl/py3/lib/python3.6/site-packages/tensorflow/contrib/framework/python/ops/arg_scope.py”, line 182, in func_with_args
return func(*args, **current_args)
File “/home/lc/lcl/py3/lib/python3.6/site-packages/tensorflow/contrib/framework/python/ops/variables.py”, line 350, in model_variable
aggregation=aggregation)

Solution:
Insert the following code at the beginning of the block.

tf.reset_default_graph() # To clear the default graph 重置当前的张量图,即清空所有的张量,在ipython中run jupyter notebook代码时,需要重置张量图,否则会报错        

注:在training的时候,如果是在ipython中运行jupyter notebook,提示如下错误:

ValueError: Variable output/kernel already exists, disallowed. Did you mean to set reuse=True or reuse=tf.AUTO_REUSE in VarScope? Originally defined at:
File “", line 24, in create_symbol logits = tf.layers.dense(drop3, n_classes, name='output') File "", line 8, in File "/home/lc/lcl/py3/lib/python3.6/site-packages/IPython/core/magics/execution.py", line 1238, in time exec(code, glob, local_ns)

同样需要加上述代码。

Ref

[1] DeepLearningFrameworks
[2] TensorFlow-Slim image classification model library
[3] Error in notebook: “ValueError: Variable conv1/weights already exists, disallowed. Did you mean to set reuse=True in VarScope” #8
[4] TF API r1.12
[5] Remove nodes from graph or reset entire default graph


上一篇 Google Colab Demo

下一篇 SenseTime HPC

Comments

Content