热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

tensorflow代码实战报错集合整理

1、在xxx.sh脚本里使用python-O(大写英文O)关闭assert断言AssertError报错python-O到百度首页百度首页登录Python中使用assert语句需要

1、在xxx.sh脚本里使用 python -O(大写英文O)  关闭 assert 断言 AssertError 报错

python -O

到百度首页 百度首页登录 Python中使用assert语句需要注意什么


python 错误处理 assert


2、Debug 报下面错误:

Traceback (most recent call last):File "D:\Program Files\JetBrains\PyCharm\helpers\pydev\_pydevd_bundle\pydevd_comm.py", line 393, in _on_runr = r.decode('utf-8')
UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 1022-1023: unexpected end of data

解决方案:

在pycharm中两个地方设置成utf-8,页面右下角和File>setting中编码设置成UTF-8

参考:pycharm中可以运行脚本但是不能debug脚本

pycharm debug出现UnicodeDecodeError: 'utf-8' codec can't decode 解决办法

第一处:

上图右下角被水印覆盖掉,去除的方式:

自定义CSDN博客中图片上的水印内容

下面是插入图片的时候csdn-markdown编辑器中生成的代码:

https://img.php1.cn/3cd4a/1eebe/cd5/011ac27956d007f0.webp?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3hyaW5vc3ZpcA==,size_16,color_FFFFFF,t_70

注意:这里的参数用Base64加密算法


对上面的链接作仔细观察,发现有“?x-oss-process=image”字样。接下来尝试把代码中“?x-oss-process=image”后面的部分去掉, 即:

https://img.php1.cn/3cd4a/1eebe/cd5/011ac27956d007f0.webp?

 如下图,便去掉了水印

第二处:

若上述方法还不行,试试下面的方法: 

3、训练 rsgan 报如下错误:

Traceback (most recent call last):File "E:/python/Tensorflow/随书资源/代码/12-9 rsgan.py", line 288, in showresult(163,"near",imagesv,x_nearestv)File "E:/python/Tensorflow/随书资源/代码/12-9 rsgan.py", line 61, in showresultypsnr=batch_y_psnr(conimg)File "E:/python/Tensorflow/随书资源/代码/12-9 rsgan.py", line 34, in batch_y_psnrpsnr=np.mean(20*np.log10(255.0/np.sqrt(mse)))
UnboundLocalError: local variable 'mse' referenced before assignment

原因:代码第34行  局部变量 mse 先调用    后定义 导致报错

解决办法: 对调上图的两行代码


4、run out of memory 


Tensor Flow: Ran out of memory trying to allocate

Allocator (GPU_0_bfc) ran out of memory trying to allocate 2.14GiB. The caller indicates that this is not a failure, but may mean that there could be performance gains if more memory were available.

解决办法: 减小 batch_size


5、在tensorflow训练model时,添加 vgg_19 网络,报下面错误:


ValueError: Negative dimension size caused by subtracting 7 from 4 for 'vgg_19/fc6/Conv2D' (op: 'Conv2D') with input shapes: [48,4,2,512], [7,7,512,4096].


原因: vgg_19 的输入图片的大小应为  256x256x3 的图片,若出入的不是这个 shape 就会报这个错误 


解决办法: 通过 padding 或者 clip 将输入图片修改为 256x256x3 的图片


6  、AttributeError: 'dict' object has no attribute 'SerializeToString'

 参考: TensorFlow报错:'dict' object has no attribute 'SerializeToString'

Traceback (most recent call last):File "main.py", line 37, in main(config)File "main.py", line 29, in maintrainer.train()File "/home/hyw/zp/tf/Pose-Guided-Person-Image-Generation-master/trainer.py", line 397, in trainself.generate(x, x_target, pose_target_fixed, self.model_dir, idx=step)File "/home/hyw/zp/tf/Pose-Guided-Person-Image-Generation-master/trainer.py", line 476, in generateG, G_1 = self.sess.run(self.G, self.G1, {self.x: x_fixed, self.pose_target: pose_target_fixed})File "/home/hyw/zp/anaconda2/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 884, in runcompat.as_bytes(options.SerializeToString())) if options else None
AttributeError: 'dict' object has no attribute 'SerializeToString'

原因: 这个报错是因为sess.run(a,b,c)里要运行的多个变量没有用中括号括起来


解决办法: 把run() 要运行的多个变量用中括号括起来,即 sess.run([a,b,c], {x:x,y:y}

7、IOError: CRC check failed 0x49a91344 != 0x6adf6a7L

Traceback (most recent call last):File "score.py", line 13, in import tflib.inception_scoreFile "/home/hyw/zp/tf/Pose-Guided-Person-Image-Generation-master/tflib/inception_score.py", line 101, in _init_inception()File "/home/hyw/zp/tf/Pose-Guided-Person-Image-Generation-master/tflib/inception_score.py", line 73, in _init_inceptiontarfile.open(filepath, 'r:gz').extractall(MODEL_DIR)File "/home/hyw/zp/anaconda2/lib/python2.7/tarfile.py", line 2081, in extractallself.extract(tarinfo, path)File "/home/hyw/zp/anaconda2/lib/python2.7/tarfile.py", line 2118, in extractself._extract_member(tarinfo, os.path.join(path, tarinfo.name))File "/home/hyw/zp/anaconda2/lib/python2.7/tarfile.py", line 2194, in _extract_memberself.makefile(tarinfo, targetpath)File "/home/hyw/zp/anaconda2/lib/python2.7/tarfile.py", line 2235, in makefilecopyfileobj(source, target)File "/home/hyw/zp/anaconda2/lib/python2.7/tarfile.py", line 266, in copyfileobjshutil.copyfileobj(src, dst)File "/home/hyw/zp/anaconda2/lib/python2.7/shutil.py", line 63, in copyfileobjbuf = fsrc.read(length)File "/home/hyw/zp/anaconda2/lib/python2.7/tarfile.py", line 831, in readbuf += self.fileobj.read(size - len(buf))File "/home/hyw/zp/anaconda2/lib/python2.7/tarfile.py", line 743, in readreturn self.readnormal(size)File "/home/hyw/zp/anaconda2/lib/python2.7/tarfile.py", line 758, in readnormalreturn self.__read(size)File "/home/hyw/zp/anaconda2/lib/python2.7/tarfile.py", line 748, in __readbuf = self.fileobj.read(size)File "/home/hyw/zp/anaconda2/lib/python2.7/gzip.py", line 267, in readself._read(readsize)File "/home/hyw/zp/anaconda2/lib/python2.7/gzip.py", line 314, in _readself._read_eof()File "/home/hyw/zp/anaconda2/lib/python2.7/gzip.py", line 353, in _read_eofhex(self.crc)))
IOError: CRC check failed 0x49a91344 != 0x6adf6a7L
Traceback (most recent call last):File "score_mask.py", line 13, in import tflib.inception_scoreFile "/home/hyw/zp/tf/Pose-Guided-Person-Image-Generation-master/tflib/inception_score.py", line 101, in _init_inception()File "/home/hyw/zp/tf/Pose-Guided-Person-Image-Generation-master/tflib/inception_score.py", line 73, in _init_inceptiontarfile.open(filepath, 'r:gz').extractall(MODEL_DIR)File "/home/hyw/zp/anaconda2/lib/python2.7/tarfile.py", line 2081, in extractallself.extract(tarinfo, path)File "/home/hyw/zp/anaconda2/lib/python2.7/tarfile.py", line 2118, in extractself._extract_member(tarinfo, os.path.join(path, tarinfo.name))File "/home/hyw/zp/anaconda2/lib/python2.7/tarfile.py", line 2194, in _extract_memberself.makefile(tarinfo, targetpath)File "/home/hyw/zp/anaconda2/lib/python2.7/tarfile.py", line 2235, in makefilecopyfileobj(source, target)File "/home/hyw/zp/anaconda2/lib/python2.7/tarfile.py", line 266, in copyfileobjshutil.copyfileobj(src, dst)File "/home/hyw/zp/anaconda2/lib/python2.7/shutil.py", line 63, in copyfileobjbuf = fsrc.read(length)File "/home/hyw/zp/anaconda2/lib/python2.7/tarfile.py", line 831, in readbuf += self.fileobj.read(size - len(buf))File "/home/hyw/zp/anaconda2/lib/python2.7/tarfile.py", line 743, in readreturn self.readnormal(size)File "/home/hyw/zp/anaconda2/lib/python2.7/tarfile.py", line 758, in readnormalreturn self.__read(size)File "/home/hyw/zp/anaconda2/lib/python2.7/tarfile.py", line 748, in __readbuf = self.fileobj.read(size)File "/home/hyw/zp/anaconda2/lib/python2.7/gzip.py", line 267, in readself._read(readsize)File "/home/hyw/zp/anaconda2/lib/python2.7/gzip.py", line 314, in _readself._read_eof()File "/home/hyw/zp/anaconda2/lib/python2.7/gzip.py", line 353, in _read_eofhex(self.crc)))
IOError: CRC check failed 0x49a91344 != 0x6adf6a7L

原因分析: 通过使用 vscode 中的 go to  defination 查看 import tflib.inception_score 中的 inception_score 模块中的函数,发现里面有个需要下载的文件链接,要下载  inception-2015-12-05.tgz,结合报错中出现了 tarflie 和 gzip 这些和解压压缩有关模块,所以初步怀疑,是文件不存在或者 下载的文件有缺陷造成的

到ubuntu 的 /tmp/imagenet 目录下查看 发现 inception-2015-12-05.tgz 这个文件只有 2.3M,而真实大小应该是 88.9M,所以怀疑该文件并未下载完整,导致的莫名错误


解决办法: 手动下载 inception-2015-12-05.tgz 文件,放到  /tmp/imagenet  目录下,问题解决


提醒一点: 报  IO错误    无非就是 文件  或者  路径目录  找不到

参考: python open打开文件失败 IOError: [Errno 2] No such file or directory: 'E://aaa.txt'

 

 

 

 

 

 

 

 

 

 

 

 


推荐阅读
author-avatar
自由飘落de花瓣
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有