Tensorflow调试Bug解决办法记录

1、ascii' codec can't encode characters in position 0-4: ordinal not in range(128)

原因是python2.X默认的编码是ASCII码,只能处理通过ASCII编码的字符,自然汉字就不行了。

解决方法,在django项目的manage.py文件头部加上下面代码:

import sys
reload(sys)
sys.setdefaultencoding('utf8')

然后就可以采用utf8编码了,也就可以处理中文数据了。

参考 https://blog.csdn.net/swordboy_fire/article/details/81590866

2、tensorflow中报错:You must feed a value for placeholder tensor

错误描述为:

InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'image_feed' with dtype string
         [[Node: image_feed = Placeholder[dtype=DT_STRING, shape=[], _device="/job:localhost/replica:0/task:0/cpu:0"]()]]

导致本错误的原因有:

1)Tensorflow定义的图中的变量有None出现

2)没有向image_feed这个Placeholder节点中传值,向此节点中传值即可。

3)程序中有多个sess.run(),向第一个sess.run()传入值后参与计算,后面sess.run()的计算节点依赖第一个sess.run()传入的值,但是在本次sess.run()中你没有再次传入。此时你可以重新传入,或保存计算后的节点传入计算后的节点,后者避免了重复计算,建议使用后者。

原文地址:https://www.cnblogs.com/ying-chease/p/10033191.html