关于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获取当前日期和时间的方法
Apr 30 Python
Python 编码处理-str与Unicode的区别
Sep 06 Python
python学习入门细节知识点
Mar 29 Python
PyQt实现界面翻转切换效果
Apr 20 Python
python实现时间o(1)的最小栈的实例代码
Jul 23 Python
学习python可以干什么
Feb 26 Python
在PyTorch中Tensor的查找和筛选例子
Aug 18 Python
python 使用while写猜年龄小游戏过程解析
Oct 07 Python
python字典setdefault方法和get方法使用实例
Dec 25 Python
解决python 虚拟环境删除包无法加载的问题
Jul 13 Python
python 还原梯度下降算法实现一维线性回归
Oct 22 Python
pandas中DataFrame检测重复值的实现
May 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
使用Apache的rewrite技术
2006/06/22 PHP
PHP数组实例总结与说明
2011/08/23 PHP
php针对cookie操作的队列操作类实例
2014/12/10 PHP
PHP文件系统管理(实例讲解)
2017/09/19 PHP
php + WebUploader实现图片批量上传功能
2019/05/06 PHP
yii框架使用分页的方法分析
2019/07/25 PHP
JavaScript的目的分析
2007/01/05 Javascript
JavaScript设计模式学习之“类式继承”
2015/03/12 Javascript
javascript实现2016新年版日历
2016/01/25 Javascript
使用javascript插入样式
2016/03/14 Javascript
js中动态创建json,动态为json添加属性、属性值的实例
2016/12/02 Javascript
微信小程序 欢迎页面的制作(源码下载)
2017/01/09 Javascript
浅谈原生JS实现jQuery的animate()动画示例
2017/03/08 Javascript
详解axios在vue中的简单配置与使用
2017/05/10 Javascript
详解AngularJS controller调用factory
2017/05/19 Javascript
vue-cli webpack2项目打包优化分享
2018/02/07 Javascript
Angular 容器部署的方法
2018/04/17 Javascript
JS中使用new Option()实现时间联动效果
2018/12/10 Javascript
js中arguments对象的深入理解
2019/05/14 Javascript
微信小程序开发中var that =this的用法详解
2020/01/18 Javascript
js实现简单的贪吃蛇游戏
2020/04/23 Javascript
Python set集合类型操作总结
2014/11/07 Python
Python中使用gzip模块压缩文件的简单教程
2015/04/08 Python
使用Python的Zato发送AMQP消息的教程
2015/04/16 Python
python访问系统环境变量的方法
2015/04/29 Python
Python中的函数作用域
2018/05/07 Python
python爬取网页转换为PDF文件
2018/06/07 Python
python画一个玫瑰和一个爱心
2020/08/18 Python
python处理DICOM并计算三维模型体积
2019/02/26 Python
python面向对象 反射原理解析
2019/08/12 Python
使用Jupyter notebooks上传文件夹或大量数据到服务器
2020/04/14 Python
小白教你PyCharm从下载到安装再到科学使用PyCharm2020最新激活码
2020/09/25 Python
荷兰鞋子在线:Nelson Schoenen
2017/12/25 全球购物
与美同行演讲稿
2014/09/13 职场文书
2014年办公室人员工作总结
2014/12/09 职场文书
升学宴祝酒词
2015/08/11 职场文书