iis服务器助手广告广告
返回顶部
首页 > 资讯 > 后端开发 > Python >pycharm中TensorFlow调试常见问题小结
  • 489
分享到

pycharm中TensorFlow调试常见问题小结

2024-04-02 19:04:59 489人浏览 泡泡鱼

Python 官方文档:入门教程 => 点击学习

摘要

目录1.RuntimeError:AttemptedtouseaclosedSession.2.AttributeError:module‘Tensorflow'hasnoattri

1. RuntimeError: Attempted to use a closed Session.

PyCharm下调用tensorflow库时,运行出现以下问题:

RuntimeError: Attempted to use a closed Session.

这里写图片描述

解决方法:将STEP=5000开始的程序整体右移,包含在“with”内

这里写图片描述

可能遇见的问题:python代码如何整体移动

  • 选中代码,按下“Tab”键即可整体右移
  • 选中代码,按下“Shift+Tab”键即可整体左移

2. AttributeError: module ‘tensorflow' has no attribute ‘select'

调用tf.select出错

这里写图片描述

将tf.select替换为tf.where即可

3. UnicodeDecodeError: ‘utf-8' codec can't decode byte 0xff in position 0: invalid start byte

利用TensorFlow的tf.gfile.FastGFile读入图像发生上述错误:

这里写图片描述 

原始代码:


image_raw_data=tf.gfile.FastGFile('anglababy.jpg','r').read()

将'r'修改为'rb'即可

这里写图片描述

4. python中用plt.imshow()显示图像之后,程序就停止运行,必须关掉显示的图像才继续运行

可以将show()写在进程里,通过调用进程来打开图片,那么进程的运行状态就不会影响到主程序的往下执行了


import threading 
import Image 
class ThreadClass(threading.Thread): 
def run(self): 
im=Image.open(‘z.jpg') 
im.show()

print (1) 
t = ThreadClass() 
t.start() 
print (2) 
a=input(‘End')

运行结果为:先打印出‘1',然后显示图片z.jpg,接着再不关闭图片的情况下打印出‘2'。
具体应用的时候你根据需要组织代码。

5. AttributeError: module ‘tensorflow.python.ops.image_ops' has no attribute ‘per_image_whitening'

这里写图片描述

TensorFlow对归一化函数tf.image.per_image_whitening(img_data)进行了修改,变为以下形式:


adjusted = tf.image.per_image_standardization(img_data)

这里写图片描述

6. ValueError: Tried to convert ‘min_object_covered' to a tensor and failed. Error: None values not supported.

这里写图片描述

解决方法:


 begin, size, bbox_for_draw = tf.image.sample_distorted_bounding_box(
        tf.shape(img_data), bounding_boxes=boxes,min_object_covered=0.1)

7. NameError:name ‘xrange' is not defined

这里写图片描述

解决方式:在Python 3中,range()与xrange()合并为range( )

这里写图片描述

8. tensorflow.python.framework.errors_impl.FailedPreconditionError: Attempting to use uninitialized value matching_filenames

TensorFlow实战Google深度学习框架中,输入文件队列的程序中报错

这里写图片描述

原因在于:tf.global_variables_initializer().run()

要改为:sess.run([tf.global_variables_initializer(),tf.local_variables_initializer()])

tf.local_variables_initializer():返回一个初始化所有局部变量的操作(Op)。要是你把图“投放进一个”session中后,你就能够通过run 这个操作来初始化所有的局部变量,本质相当于variable_initializers(local_variables())

到此这篇关于pycharm中TensorFlow调试常见问题小结的文章就介绍到这了,更多相关TensorFlow调试问题内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!

--结束END--

本文标题: pycharm中TensorFlow调试常见问题小结

本文链接: https://www.lsjlt.com/news/129030.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作