ValueError: Variable rnn/basic_lstm_cell/kernel already exists, disallowed. Did you mean to set reuse=True or reuse=tf.AUTO_REUSE in VarScope? Originally defined at:
问题
ValueError: Variable rnn/basic_lstm_cell/kernel already exists, disallowed. Did you mean to set reuse=True or reuse=tf.AUTO_REUSE in VarScope? Originally defined at:
原因
调用了两次RNN网络,在第二次调用的时候报了上面这个错误。主要是因为第二次的变量名和第一次的变量名一样,导致了变量命名相同的冲突。在Tensorflow中有两种方法生成变量variable,tf.get_variable()和tf.Variable()。在tf.AUTO_REUSEtf.name_scope()的框架下使用这两种方法,使用tf.Variable(),尽管name一样,但为了不重复变量名,Tensorflow输出的变量名并不一样,所以本质上是不一样的变量;使用tf.get_variable()定义的变量虽然不会被tf.name_scope()中的名字影响,但在未指定共享变量时,如果重名了会报错。要实现变量共享,可以使用tf.variable_scope(reuse=)创建具有相同名称的作用域。
# 出错代码
with tf.name_scope("fw_side"): # 改成
with tf.name_scope("fw_side"), tf.variable_scope("fw_side", reuse=tf.AUTO_REUSE):
改了之后,在第二次调用RNN时就不会报错了。
详情了解:https://morvanzhou.github.io/tutorials/machine-learning/tensorflow/5-12-scope/
ValueError: Variable rnn/basic_lstm_cell/kernel already exists, disallowed. Did you mean to set reuse=True or reuse=tf.AUTO_REUSE in VarScope? Originally defined at:的更多相关文章
- tensoflow模型中提示:ValueError: Variable rnn/basic_rnn_cell/kernel already exists, disallowed. Did you mean to set reuse=True or reuse=tf.AUTO_REUSE in VarScope? 解决办法
在利用tensorflow框架进行模型训练的时候,有时我们需要多次训练对结果求均值来得到一个均衡的评测结论.比如训练十次求平均值.但是tf的本质就是图,当变量第一次定义使用后,第二次再使用就是提示: ...
- ValueError: Variable conv1/weights already exists.
跑TensorFlow程序的过程中出现了错误,解决之后再次跑时,报如下错误: ValueError: Variable conv1/weights already exists, 原因: 这是因为我在 ...
- asp.net core 3.1 中Synchronous operations are disallowed. Call FlushAsync or set AllowSynchronousIO to true instead
在Action中解决措施: var syncIOFeature = HttpContext.Features.Get<IHttpBodyControlFeature>(); if (syn ...
- tensorflow(4)踩过的一些坑
版本问题 1.1 版本的一个BUG ValueError: Variable rnn/basic_lstm_cell/weights already exists, disallowed. 结合这个文 ...
- TensorFlow入门(四) name / variable_scope 的使
name/variable_scope 的作用 欢迎转载,但请务必注明原文出处及作者信息. @author: huangyongye @creat_date: 2017-03-08 refer to: ...
- 5 TensorFlow入门笔记之RNN实现手写数字识别
------------------------------------ 写在开头:此文参照莫烦python教程(墙裂推荐!!!) ---------------------------------- ...
- tensorflow中的name_scope, variable_scope
在训练深度网络时,为了减少需要训练参数的个数(比如LSTM模型),或者是多机多卡并行化训练大数据.大模型等情况时,往往就需要共享变量.另外一方面是当一个深度学习模型变得非常复杂的时候,往往存在大量的变 ...
- tf之变量与作用域
生成变量 tensorflow生成变量有两种方式,Variable 和 get_variable Variable(initial_value=None, trainable=True, collec ...
- tf.variable_scope()和tf.name_scope()
1.tf.variable_scope 功能:tf.variable_scope可以让不同命名空间中的变量取相同的名字,无论tf.get_variable或者tf.Variable生成的变量 Tens ...
随机推荐
- IDEA上创建 Maven SpringBoot + zookeeper +dubbo 实例
概述 首先声明,本文是学习总结类型的博客内容,如有雷同纯属学习.本位主要结合zookeeper和dubbo做个简单实例.目前来说,一般网站架构随着业务的发展,逻辑越来越复杂,数据量越来越大,交互越来越 ...
- Palindrome POJ - 3974 (字符串hash+二分)
Andy the smart computer science student was attending an algorithms class when the professor asked t ...
- aspnet core运行后台任务
之前在公司的一个项目中需要用到定时程序,当时使用的是aspnet core提供的IHostedService接口来实现后台定时程序,具体的示例可去官网查看.现在的dotnet core中默认封装了实现 ...
- 英语口语练习系列-C36-城市-谈论活动-登高
词汇-城市 city your favorite city a place you would like to visit metropolis capital landscape enchantin ...
- 浅析uWSGI、uwsgi、wsgi
WSGI协议 首先弄清下面几个概念: WSGI:全称是Web Server Gateway Interface,WSGI不是服务器,python模块,框架,API或者任何软件,只是一种规范,描述web ...
- 12树莓派VNC远程桌面
2017-09-04 23:11:28 http://bbs.elecfans.com/forum.php?mod=viewthread&tid=583803&extra= 开 ...
- 杭电1506 java
求最大子矩阵面积(dp) import java.util.*; public class Main1{ public static void main(String[] args) { Scanne ...
- (55)Wangdao.com第八天_JavaScript 字符串中使用 \u 输出Unicode字符
JavaScript中,使用Unicode 需要 \u 进行转义,格式 "\u十六进制" console.log(\u0031); console.log(\u0041); // ...
- 20175324 《Java程序设计》第4周学习总结
学号 20175324 <Java程序设计>第4周学习总结 第五章主要内容子类的继承性子类和父类如果在同一包中除private外其余都继承子类和父类如果不在同一包中那么只继承public和 ...
- jsp 自定义标签解决jsp页面中int时间戳的时间格式化问题
jsp 自定义标签解决jsp页面中int时间戳的时间格式化问题 之前在项目中根据需求,需要自定义标签,经过查询w3c文档,自己也踩了一些坑,特此记录自定义标签的步骤,下面就以我之前的一个例子中的定义一 ...