2023年11月29日发(作者:)

pycharmTensorFlow调试常见问题⼩结

⽬录

eError:AttemptedtouseaclosedSession.

uteError:module‘tensorflow'hasnoattribute‘select'

eDecodeError:‘utf-8'codeccan'tdecodebyte0xffinposition0:invalidstartbyte

中⽤()显⽰图像之后,程序就停⽌运⾏,必须关掉显⽰的图像才继续运⾏

uteError:module‘_ops'hasnoattribute‘per_image_whitening'

rror:Triedtoconvert‘min_object_covered':Nonevaluesnotsupported.

ror:name‘xrange'isnotdefined

_PreconditionError:Attemptingtouseuninitializedvaluematching_filenames

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'

调⽤出错

替换为即可

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

利⽤TensorFlowile读⼊图像发⽣上述错误:

原始代码:

image_raw_data=ile('','r').read()

'r'修改为'rb'即可

4. python中⽤()显⽰图像之后,程序就停⽌运⾏,必须关掉显⽰的图像才继续运⾏

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

import threading

import Image

class ThreadClass():

def run(self):

im=(‘')

()

print (1)

t = ThreadClass()

()

print (2)

a=input(‘End')

运⾏结果为:先打印出‘1',然后显⽰图⽚,接着再不关闭图⽚的情况下打印出‘2'

具体应⽤的时候你根据需要组织代码。

TensorFlow对归⼀化函数进⾏了修改,变为以下形式:

_image_whitening(img_data)

adjusted = _image_standardization(img_data)

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

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

8. _PreconditionError: Attempting to use uninitialized value

matching_filenames

TensorFlow实战google深度学习框架中,输⼊⽂件队列的程序中报错

原因在于:

_variables_initializer().run()

要改为:

([_variables_initializer(),_variables_initializer()])

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

variable_initializers(local_variables())

到此这篇关于pycharmTensorFlow调试常见问题⼩结的⽂章就介绍到这了,更多相关TensorFlow调试问题内容请搜索以前的⽂章或继续浏览下⾯的相关⽂章希望⼤家以后多多⽀持!