我写的这个程序

import tensorflow as tf

sess=tf.InteractiveSession()

x=tf.Variable([1.0,2.0])

a=tf.constant([3.0,3.0])

x.initializer.run()

sun=tf.div(x,a)

print(sub.eval())

sess.close()

出现了如下所示的错误:

原因是倒数第二行的sub没有初始化,倒数第三行应该是初始化sub的,但是打错了,成了sun,这样后面出现的sub就相当于没有初始化,所以出现了变量没有初始化的错误。

FailedPreconditionError Traceback (most recent call last)

C:\Users\SKJ\Anaconda3\lib\site-packages\tensorflow\python\client\session.py in _do_call(self, fn, *args)

1360 try:

-> 1361 return fn(*args)

1362 except errors.OpError as e:

C:\Users\SKJ\Anaconda3\lib\site-packages\tensorflow\python\client\session.py in _run_fn(session, feed_dict, fetch_list, target_list, options, run_metadata)

1339 return tf_session.TF_Run(session, options, feed_dict, fetch_list,

-> 1340 target_list, status, run_metadata)

1341

C:\Users\SKJ\Anaconda3\lib\site-packages\tensorflow\python\framework\errors_impl.py in __exit__(self, type_arg, value_arg, traceback_arg)

515 compat.as_text(c_api.TF_Message(self.status.status)),

--> 516 c_api.TF_GetCode(self.status.status))

517 # Delete the underlying status object from memory otherwise it stays alive

FailedPreconditionError: Attempting to use uninitialized value Variable_1

[[Node: Variable_1/read = Identity[T=DT_FLOAT, _class=["loc:@Variable_1"], _device="/job:localhost/replica:0/task:0/device:CPU:0"](Variable_1)]]

During handling of the above exception, another exception occurred:

FailedPreconditionError Traceback (most recent call last)

in ()

5 x.initializer.run()

6 sun=tf.div(x,a)

----> 7 print(sub.eval())

8 sess.close()

C:\Users\SKJ\Anaconda3\lib\site-packages\tensorflow\python\framework\ops.py in eval(self, feed_dict, session)

654

655 """

--> 656 return _eval_using_default_session(self, feed_dict, self.graph, session)

657

658

C:\Users\SKJ\Anaconda3\lib\site-packages\tensorflow\python\framework\ops.py in _eval_using_default_session(tensors, feed_dict, graph, session)

4899 "the tensor's graph is different from the session's "

4900 "graph.")

-> 4901 return session.run(tensors, feed_dict)

4902

4903

C:\Users\SKJ\Anaconda3\lib\site-packages\tensorflow\python\client\session.py in run(self, fetches, feed_dict, options, run_metadata)

903 try:

904 result = self._run(None, fetches, feed_dict, options_ptr,

--> 905 run_metadata_ptr)

906 if run_metadata:

907 proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)

C:\Users\SKJ\Anaconda3\lib\site-packages\tensorflow\python\client\session.py in _run(self, handle, fetches, feed_dict, options, run_metadata)

1135 if final_fetches or final_targets or (handle and feed_dict_tensor):

1136 results = self._do_run(handle, final_targets, final_fetches,

-> 1137 feed_dict_tensor, options, run_metadata)

1138 else:

1139 results = []

C:\Users\SKJ\Anaconda3\lib\site-packages\tensorflow\python\client\session.py in _do_run(self, handle, target_list, fetch_list, feed_dict, options, run_metadata)

1353 if handle is None:

1354 return self._do_call(_run_fn, self._session, feeds, fetches, targets,

-> 1355 options, run_metadata)

1356 else:

1357 return self._do_call(_prun_fn, self._session, handle, feeds, fetches)

C:\Users\SKJ\Anaconda3\lib\site-packages\tensorflow\python\client\session.py in _do_call(self, fn, *args)

1372 except KeyError:

1373 pass

-> 1374 raise type(e)(node_def, op, message)

1375

1376 def _extend_graph(self):

FailedPreconditionError: Attempting to use uninitialized value Variable_1

[[Node: Variable_1/read = Identity[T=DT_FLOAT, _class=["loc:@Variable_1"], _device="/job:localhost/replica:0/task:0/device:CPU:0"](Variable_1)]]

Caused by op 'Variable_1/read', defined at:

File "C:\Users\SKJ\Anaconda3\lib\runpy.py", line 184, in _run_module_as_main

"__main__", mod_spec)

File "C:\Users\SKJ\Anaconda3\lib\runpy.py", line 85, in _run_code

exec(code, run_globals)

File "C:\Users\SKJ\Anaconda3\lib\site-packages\ipykernel\__main__.py", line 3, in

app.launch_new_instance()

File "C:\Users\SKJ\Anaconda3\lib\site-packages\traitlets\config\application.py", line 653, in launch_instance

app.start()

File "C:\Users\SKJ\Anaconda3\lib\site-packages\ipykernel\kernelapp.py", line 474, in start

ioloop.IOLoop.instance().start()

File "C:\Users\SKJ\Anaconda3\lib\site-packages\zmq\eventloop\ioloop.py", line 162, in start

super(ZMQIOLoop, self).start()

File "C:\Users\SKJ\Anaconda3\lib\site-packages\tornado\ioloop.py", line 887, in start

handler_func(fd_obj, events)

File "C:\Users\SKJ\Anaconda3\lib\site-packages\tornado\stack_context.py", line 275, in null_wrapper

return fn(*args, **kwargs)

File "C:\Users\SKJ\Anaconda3\lib\site-packages\zmq\eventloop\zmqstream.py", line 440, in _handle_events

self._handle_recv()

File "C:\Users\SKJ\Anaconda3\lib\site-packages\zmq\eventloop\zmqstream.py", line 472, in _handle_recv

self._run_callback(callback, msg)

File "C:\Users\SKJ\Anaconda3\lib\site-packages\zmq\eventloop\zmqstream.py", line 414, in _run_callback

callback(*args, **kwargs)

File "C:\Users\SKJ\Anaconda3\lib\site-packages\tornado\stack_context.py", line 275, in null_wrapper

return fn(*args, **kwargs)

File "C:\Users\SKJ\Anaconda3\lib\site-packages\ipykernel\kernelbase.py", line 276, in dispatcher

return self.dispatch_shell(stream, msg)

File "C:\Users\SKJ\Anaconda3\lib\site-packages\ipykernel\kernelbase.py", line 228, in dispatch_shell

handler(stream, idents, msg)

File "C:\Users\SKJ\Anaconda3\lib\site-packages\ipykernel\kernelbase.py", line 390, in execute_request

user_expressions, allow_stdin)

File "C:\Users\SKJ\Anaconda3\lib\site-packages\ipykernel\ipkernel.py", line 196, in do_execute

res = shell.run_cell(code, store_history=store_history, silent=silent)

File "C:\Users\SKJ\Anaconda3\lib\site-packages\ipykernel\zmqshell.py", line 501, in run_cell

return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)

File "C:\Users\SKJ\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2717, in run_cell

interactivity=interactivity, compiler=compiler, result=result)

File "C:\Users\SKJ\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2821, in run_ast_nodes

if self.run_code(code, result):

File "C:\Users\SKJ\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2881, in run_code

exec(code_obj, self.user_global_ns, self.user_ns)

File "", line 3, in

x=tf.Variable([1.0,2.0])

File "C:\Users\SKJ\Anaconda3\lib\site-packages\tensorflow\python\ops\variables.py", line 233, in __init__

constraint=constraint)

File "C:\Users\SKJ\Anaconda3\lib\site-packages\tensorflow\python\ops\variables.py", line 381, in _init_from_args

self._snapshot = array_ops.identity(self._variable, name="read")

File "C:\Users\SKJ\Anaconda3\lib\site-packages\tensorflow\python\ops\array_ops.py", line 131, in identity

return gen_array_ops.identity(input, name=name)

File "C:\Users\SKJ\Anaconda3\lib\site-packages\tensorflow\python\ops\gen_array_ops.py", line 2656, in identity

"Identity", input=input, name=name)

File "C:\Users\SKJ\Anaconda3\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 787, in _apply_op_helper

op_def=op_def)

File "C:\Users\SKJ\Anaconda3\lib\site-packages\tensorflow\python\framework\ops.py", line 3271, in create_op

op_def=op_def)

File "C:\Users\SKJ\Anaconda3\lib\site-packages\tensorflow\python\framework\ops.py", line 1650, in __init__

self._traceback = self._graph._extract_stack() # pylint: disable=protected-access

FailedPreconditionError (see above for traceback): Attempting to use uninitialized value Variable_1

[[Node: Variable_1/read = Identity[T=DT_FLOAT, _class=["loc:@Variable_1"], _device="/job:localhost/replica:0/task:0/device:CPU:0"](Variable_1)]]

以上这篇解决tensorflow由于未初始化变量而导致的错误问题就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持我们。

本文标题: 解决tensorflow由于未初始化变量而导致的错误问题

本文地址: http://www.cppcns.com/jiaoben/python/297279.html

python变量初始化的位置不当、程序结果可能会出现问题_解决tensorflow由于未初始化变量而导致的错误问题...相关推荐

  1. mysql my.ini位置错误_解决mysql导入数据量很大导致失败及查找my.ini 位置(my.ini)在哪...

    数据库数据量很大的数据库导入到本地时,会等很久,然而等很久之后还是显示失败: 这是就要看看自己本地的没mysql是否设置了超时等待,如果报相关time_out这些,可以把mysql.ini尾部添加ma ...

  2. python编译环境对cpu要求高不高_解决Tensorflow 使用时cpu编译不支持警告的问题

    使用TensorFlow模块时,弹出错误Your CPU supports instructions that this TensorFlow binary was not compiled to u ...

  3. python动态库反初始化_解决TensorFlow的ImportError: DLL load failed: 动态链接库(DLL)初始化例程失败...

    [背景] 在scikit-learn基础上系统结合数学和编程的角度学习了机器学习后(我的github:https://github.com/wwcom614/machine-learning),意犹未 ...

  4. python spyder跑出的数据部分有些不变是怎么回事_解决Python spyder显示不全df列和行的问题...

    python中有的df列比较长head的时候会出现省略号,现在数据分析常用的就是基于anaconda的notebook和sypder,在spyder下head的时候就会比较明显的遇到显示不全.这时候我 ...

  5. 微信小程序网络请求异常怎么办_解决·微信小程序开发-网络请求报Invalid request 400错误...

    今天学习了一下微信小程序的入门开发,在使用网络请求时,发现根据微信官方的API的方法进行操作出现Invalid request 400错误,到底怎么回事呢? 首先我们来看微信API网络请求 示例代码: ...

  6. 目的:使用CUDA环境变量CUDA_VISIBLE_DEVICES来限定CUDA程序所能使用的GPU

    目的:使用CUDA环境变量CUDA_VISIBLE_DEVICES来限定CUDA程序所能使用的GPU 目的:使用CUDA环境变量CUDA_VISIBLE_DEVICES来限定CUDA程序所能使用的GP ...

  7. CSP认证 202203-1 未初始化警告

    题目传送门 题目背景 一个未经初始化的变量,里面存储的值可能是任意的.因此直接使用未初始化的变量,比如将其赋值给另一个变量,并不符合一般的编程逻辑.代码中出现这种情况,往往是因为遗漏了初始化语句.或是 ...

  8. 4454. 未初始化警告(只是题的长别怕,详细解读)

    题目 一个未经初始化的变量,里面存储的值可能是任意的. 因此直接使用未初始化的变量,比如将其赋值给另一个变量,并不符合一般的编程逻辑. 代码中出现这种情况,往往是因为遗漏了初始化语句.或是打错了变量名 ...

  9. Go 知识点(08) — 对未初始化的 channel 进行读写操作

    1. 对未初始化的 channel 进行写操作 先看下面代码 func main() {var ch chan int // 只声明,并没有初始化fmt.Printf("ch is %v\n ...

最新文章

  1. Mysql4种方式避免重复插入数据!
  2. System.OutOfMemoryException
  3. CSS技巧和经验列表
  4. 使用Advanced Installer制作IIS安装包(二:配置安装包依赖项和自定义dll)
  5. Android数据库高手秘籍(二):创建表和LitePal的基本用法
  6. 74 计算机图形学开源处理库
  7. SAP CRM One Order里item quantity和CUMULAT_H的联动
  8. techempower之Plaintext上7百万RPS
  9. 【网络流】最大流问题(EK算法带模板,Dinic算法带模板及弧优化,ISAP算法带模板及弧优化)上下界网络流
  10. 解决sonar scanner扫描报错Please provide compiled classes of your project with sonar.java.binaries property
  11. Qt笔记-递归获取文件夹中文件(含过滤文件名)
  12. VS2010中水晶报表安装应用及实例
  13. 家里门不小心反锁应该怎么办?
  14. TIOBE 6 月编程语言排行榜:C 与 Java 进一步拉开差距、Rust 跃进 TOP 20
  15. linux的dhcp的安装,linux下DHCP的安装配置
  16. Gartner:智能SOC/情报驱动的SOC的五大特征
  17. Mercurial (hg)
  18. PDF图形(PDF graphics)
  19. edptrayicon怎么卸载_谁知道怎样删除北信源内网管理软件客户端?
  20. elementUI实现表格序号自增

热门文章

  1. python在中国的发展-python在中国的现状和发展趋势
  2. python常用内置模块-python 常用内置模块使用
  3. 对于python来说、一个模块就是一个文件-python常用模块
  4. python爬虫代码实例-Python爬虫之urllib示例
  5. 用python画烟花-用python做一个烟花show
  6. python3.5安装-Linux:Python3.5安装和配置
  7. python使用教程视频-Python入门教程视频分享
  8. python创建txt文件并写入 编码-Python文本文件读写操作时的字符编码问题
  9. python读取文件一行-Python逐行读取文件内容
  10. mysql数据库约束无符号_mysql 数据类型 约束条件