Did you mean to set reuse=True or reuse=tf.AUTO_REUSE in VarScope? Originally defined at:

在使用Inception V3等预训练模型,训练新的模型的时候,出现以下错误

ValueError: Variable InceptionV3/Conv2d_1a_3x3/weights already exists, disallowed. Did you mean to set reuse=True or reuse=tf.AUTO_REUSE in VarScope? Originally  defined at:

 

原因:原因是我要做十交叉验证,所以每次都要加载预训练的模型,但是之所以报这样的错,是因为再进入第二折实验时,之前的模型session graph没有清楚,导致之前的变量什么的还存在。所以应该每折训练的时候清空graph。

在调用模型之前加入tf.reset_default_graph()这句就可以了

参考链接

https://github.com/kratzert/finetune_alexnet_with_tensorflow/issues/8

I don't get this error with neither of the two TensorFlow versions. Note that code block 3 should only be executed once! If you want to execute the block of the graph creation again, TensorFlow will raise this error, because the graph (with it's layer names) already exists. If you run this notebook block after block there should be absolutely no problem.
In the case you want to re-run codeblock 3 (for what ever reason) just insert a simple tf.reset_default_graph() at the beginning of the block. This will reset the graph you have already create and though you can create it again.

你可能感兴趣的:(tensorflow)