关于TensorFlow新旧版本函数接口变化详解


Posted in Python onFebruary 10, 2020

TensorFlow版本更新太快 了,所以导致一些以前接口函数不一致,会报错。

这里总结了一下自己犯的错,以防以后再碰到,也可以给别人参考。

首先我的cifar10的代码都是找到当前最新的tf官网给的,所以后面还有新的tf出来改动了的话,可能又会失效了。

1.python3:(unicode error) 'utf-8' codec can't decode

刚开始执行的时候就报这个错,很郁闷后来发现是因为我用多个编辑器编写,

保存。导致不同编辑器编码解码不一致,会报错。所以唯一的办法全程用

一个编辑器去写,保存。或者保证都是用一种方式编码解码就OK了

一:Tersorflow CIFAR-10 训练示例报错及解决方案(1)
 
1.AttributeError:'module' object has noattribute 'random_crop'
 
##解决方案:
 
将distorted_image= tf.image.random_crop(reshaped_image,[height, width])改为:
 
distorted_image = tf.random_crop(reshaped_image,[height,width,3])
 
 
 
2. AttributeError:'module'object has no attribute 'SummaryWriter'
 
##解决方案:tf.train.SummaryWriter改为:tf.summary.FileWriter
 
 
 
3. AttributeError:'module'object has no attribute 'summaries'
 
解决方案: tf.merge_all_summaries()改为:summary_op =tf.summaries.merge_all()
 
 
 
4. AttributeError: 'module' object hasno attribute'histogram_summary
 
tf.histogram_summary(var.op.name,var)改为: tf.summaries.histogram()
 
 
 
5. AttributeError: 'module' object hasno attribute'scalar_summary'
 
tf.scalar_summary(l.op.name+ ' (raw)', l)
 
##解决方案:
 
tf.scalar_summary('images',images)改为:tf.summary.scalar('images', images)
 
tf.image_summary('images',images)改为:tf.summary.image('images', images)
 
 
 
6. ValueError: Only call`softmax_cross_entropy_with_logits` withnamed arguments (labels=...,logits=..., ...)
 
##解决方案:
 
 cifar10.loss(labels, logits) 改为:cifar10.loss(logits=logits,labels=labels)
 
 cross_entropy=tf.nn.softmax_cross_entropy_with_logits(logits,dense_labels,name='cross_entropy_per_example')
 
改为:
 
 cross_entropy =tf.nn.softmax_cross_entropy_with_logits(logits=logits, labels=dense_labels,name='cross_entropy_per_example')
 
 
 
7. TypeError: Using a `tf.Tensor` as a Python `bool`isnot allowed. Use `if t is not None:` instead of `if t:` to test if a tensorisdefined, and use TensorFlow ops such as tf.cond to execute subgraphsconditionedon the value of a tensor.
 
##解决方案:
 
if grad: 改为 if grad is not None:
 
 
 
8. ValueError: Shapes (2, 128, 1) and () are incompatible
 
###解决方案:
 
concated = tf.concat(1, [indices, sparse_labels])改为:
 
concated= tf.concat([indices, sparse_labels], 1)
 
 
 
9. 报错:(这个暂时没有遇到)
 
File"/home/lily/work/Tensorflow/CIRFAR-10/tensorflow.cifar10-master/cifar10_input.py",line83, in read_cifar10
 
  result.key, value=reader.read(filename_queue)
 
 File"/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/io_ops.py",line326, in read
 
queue_ref = queue.queue_ref
 
AttributeError: 'str' object hasno attribute 'queue_ref'
 
###解决方案:
 
由于训练样本的路径需要修改,给cifar10_input.py中data_dir赋值为本地数据所在的文件夹

二:Tersorflow CIFAR-10 训练示例报错及解决方案

1,File"tensorflow/models/slim/preprocessing/cifarnet_preproces.py", line70, in preprocess_for_train
return tf.image.per_image_whitening(distorted_image)
AttributeError: 'module' object has no attribute'per_image_whitening'

关于TensorFlow新旧版本函数接口变化详解

以上这篇关于TensorFlow新旧版本函数接口变化详解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持三水点靠木。

Python 相关文章推荐
python通过pil为png图片填充上背景颜色的方法
Mar 17 Python
python列表的常用操作方法小结
May 21 Python
python中set常用操作汇总
Jun 30 Python
Python WXPY实现微信监控报警功能的代码
Oct 20 Python
详解python string类型 bytes类型 bytearray类型
Dec 16 Python
解决pyqt5中QToolButton无法使用的问题
Jun 21 Python
Python之虚拟环境virtualenv,pipreqs生成项目依赖第三方包的方法
Jul 23 Python
Python+OpenCV 实现图片无损旋转90°且无黑边
Dec 12 Python
Django跨域资源共享问题(推荐)
Mar 09 Python
django 扩展user用户字段inlines方式
Mar 30 Python
python如何利用paramiko执行服务器命令
Nov 07 Python
Python 处理表格进行成绩排序的操作代码
Jul 26 Python
TensorFlow 多元函数的极值实例
Feb 10 #Python
给 TensorFlow 变量进行赋值的方式
Feb 10 #Python
Python 中的pygame安装与配置教程详解
Feb 10 #Python
Tensorflow 定义变量,函数,数值计算等名字的更新方式
Feb 10 #Python
Python数据可视化处理库PyEcharts柱状图,饼图,线性图,词云图常用实例详解
Feb 10 #Python
Python的pygame安装教程详解
Feb 10 #Python
windows下python安装pip方法详解
Feb 10 #Python
You might like
PHP实现图片压缩的两则实例
2014/07/19 PHP
JS宝典学习笔记(下)
2007/01/10 Javascript
JavaScript 对象的属性和方法4种不同的类型
2010/03/19 Javascript
js注意img图片的onerror事件的分析
2011/01/01 Javascript
《JavaScript高级程序设计》阅读笔记(二) ECMAScript中的原始类型
2012/02/27 Javascript
JS 获取鼠标左右键的键值方法
2014/10/11 Javascript
10条建议帮助你创建更好的jQuery插件
2015/05/18 Javascript
教你用javascript实现随机标签云效果_附代码
2016/03/16 Javascript
微信小程序 SocketIO 实例讲解
2016/10/13 Javascript
开发一个Parcel-vue脚手架工具(详细步骤)
2018/09/22 Javascript
解决vue-router 二级导航默认选中某一选项的问题
2019/11/01 Javascript
jquery轮播图插件使用方法详解
2020/07/31 jQuery
python实现下载文件的三种方法
2017/02/09 Python
django rest framework之请求与响应(详解)
2017/11/06 Python
python 3.6 tkinter+urllib+json实现火车车次信息查询功能
2017/12/20 Python
如何用Python实现简单的Markdown转换器
2018/07/16 Python
python 3.7.0 下pillow安装方法
2018/08/27 Python
Python如何处理大数据?3个技巧效率提升攻略(推荐)
2019/04/15 Python
Python Datetime模块和Calendar模块用法实例分析
2019/04/15 Python
Under Armour瑞典官方网站:美国高端运动科技品牌
2018/11/21 全球购物
Pretty Green美国:英式摇滚服饰风格代表品牌之一
2019/01/23 全球购物
使用Vue.js和MJML创建响应式电子邮件
2021/03/23 Vue.js
汽车驾驶求职信
2013/10/25 职场文书
小学毕业感言150字
2014/02/05 职场文书
小学英语课后反思
2014/04/26 职场文书
大学生心理活动总结
2014/07/04 职场文书
三八活动策划方案
2014/08/17 职场文书
我的梦想演讲稿500字
2014/08/21 职场文书
工作失职造成投诉的检讨书范文
2014/10/05 职场文书
个人欠款协议书范本2014
2014/11/02 职场文书
安全生产隐患排查制度
2015/08/05 职场文书
2016秋季校长开学典礼致辞
2015/11/26 职场文书
工作报告范文
2019/06/20 职场文书
超级详细实用的pycharm常用快捷键
2021/05/12 Python
Java输出Hello World完美过程解析
2021/06/13 Java/Android
Python3中最常用的5种线程锁实例总结
2021/07/07 Python