TypeError: Fetch argument None has invalid type <class 'NoneType'>解决方案
来源:互联网 发布:微商软件总代理 编辑:程序博客网 时间:2024/05/22 03:05
Tensorflow报错:
TypeError: Fetch argument None has invalid type <class 'NoneType'>
报错完整内容:
File "D:/Workspace/SpyderWorkspace/Models/RBM_mnist.py", line 211, in main sess.run(rbm.train_ops(k, step, i),feed_dict={X: X_batch}) File "D:\Program Files\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 767, in run run_metadata_ptr) File "D:\Program Files\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 952, in _run fetch_handler = _FetchHandler(self._graph, fetches, feed_dict_string) File "D:\Program Files\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 408, in __init__ self._fetch_mapper = _FetchMapper.for_fetch(fetches) File "D:\Program Files\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 227, in for_fetch (fetch, type(fetch)))TypeError: Fetch argument None has invalid type <class 'NoneType'>
发现是从sess.run()那行报错。
构建图的代码中,RBM是一个类,train_ops是该类下的函数。rbm是类RBM的一个对象,调用train_ops函数。
train_ops函数定义如下:
def train_ops(self, k, step, batch_count): ...(省略) with tf.name_scope("update_params"): tf.assign(self.W, self.W + self.learning_rate * delta_W,name="update_W") tf.assign(self.bv, self.bv + self.learning_rate*delta_bv,name="update_bv") tf.assign(self.bh, self.bh + self.learning_rate*delta_bh,name="update_bh")函数的主要功能是更新参数,于是定义了更新参数操作。而报错的原因在于定义的train_ops函数没有返回值。
正确的代码如下:
def train_ops(self, k, step, batch_count): ...(省略) with tf.name_scope("update_params"): new_W = tf.assign(self.W, self.W + self.learning_rate * delta_W,name="update_W") new_bv = tf.assign(self.bv, self.bv + self.learning_rate*delta_bv,name="update_bv") new_bh = tf.assign(self.bh, self.bh + self.learning_rate*delta_bh,name="update_bh") return (new_W, new_bv, new_bh)至此,报错解决。
阅读全文
0 0
- TypeError: Fetch argument None has invalid type <class 'NoneType'>解决方案
- [tensorflow]TypeError: Fetch argument .+ has invalid type
- TypeError: object of type 'NoneType' has no len()
- 'NoneType' object has no attribute '__getitem__'和argument of type 'NoneType' is not iterable 异常的解决办法
- TypeError: Input 'b' of 'MatMul' Op has type float32 that does not match type int32 of argument 'a'.
- has invalid type <class 'numpy.ndarray'>, must be a string or Tensor
- class has no zero argument constructor
- TypeError: argument of type 'int' is not iterable
- TypeError: exchange_declare() got an unexpected keyword argument 'type'的解决办法
- J版bug之_get_host_numa_topolo TypeError: unsupported operand type(s) for /: 'NoneType' and 'int'
- TypeError:'NoneType' object is unsubscriptable
- python3 pycurl 出现 TypeError: string argument expected, got 'bytes' 解决方案
- SSLSessionCache: Invalid argument: size has to be >= 8192 bytes
- invalid argument
- TypeError: object of type 'zip' has no len()
- python 2.7版本解决TypeError: 'encoding' is an invalid keyword argument for this function
- invalid use of imcomplete type 'class QKeyEvent'
- invalid use of incomplete type 'class QWidget'
- oracle instr
- 关于Access restriction: The type basic is not accessible due to restriction on required library异常
- job命令
- 1. javascript继承的方式
- Redis链接方式
- TypeError: Fetch argument None has invalid type <class 'NoneType'>解决方案
- Lua学习笔记(1)-基础知识、表达式语法
- 67. Add Binary
- C语言中变量的作用域和生命周期
- meta标签的属性介绍
- 集成——Mac电脑上app自动化测试(Appium + xcode 8.2 + python)环境搭建
- swagger API 摆脱手写API的烦恼(ssm + swagger)
- mybatis疑难杂症之配置文件无限加载 Property 'configLocation' not specified, using default MyBatis Configuration
- 小米手机开启debug模式