关于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导入oracle数据的方法
Jul 10 Python
详解Django中的form库的使用
Jul 18 Python
利用PyInstaller将python程序.py转为.exe的方法详解
May 03 Python
Django中cookie的基本使用方法示例
Feb 03 Python
Flask框架工厂函数用法实例分析
May 25 Python
Python PyCharm如何进行断点调试
Jul 05 Python
Python实现快速排序的方法详解
Oct 25 Python
python带参数打包exe及调用方式
Dec 21 Python
python 数据库查询返回list或tuple实例
May 15 Python
使用BeautifulSoup4解析XML的方法小结
Dec 07 Python
详解pandas映射与数据转换
Jan 22 Python
python之np.argmax()及对axis=0或者1的理解
Jun 02 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文件中是否含有bom的函数
2012/05/31 PHP
浅析linux下apache服务器的配置和管理
2013/08/10 PHP
Thinkphp框架 表单自动验证登录注册 ajax自动验证登录注册
2016/12/27 PHP
用JS剩余字数计算的代码
2008/07/03 Javascript
js chrome浏览器判断代码
2010/03/28 Javascript
JavaScript EasyPager 分页函数
2011/05/25 Javascript
Web跨浏览器进程通信(Web跨域)
2013/04/17 Javascript
JavaScript中的Math.atan2()方法使用详解
2015/06/15 Javascript
js结合正则实现国内手机号段校验
2015/06/19 Javascript
json+jQuery实现的无限级树形菜单效果代码
2015/08/27 Javascript
JavaScript中双向数据绑定详解
2017/05/03 Javascript
基于ajax和jsonp的原生封装(实例)
2017/10/16 Javascript
JS和JQuery实现雪花飘落效果
2017/11/30 jQuery
vue.js绑定事件监听器示例【基于v-on事件绑定】
2018/07/07 Javascript
layer弹出框确定前验证:弹出消息框的方法(弹出两个layer)
2019/09/21 Javascript
JavaScript的console命令使用实例
2019/12/03 Javascript
从零开始用webpack构建一个vue3.0项目工程的实现
2020/09/24 Javascript
python增加图像对比度的方法
2019/07/12 Python
简单了解python反射机制的一些知识
2019/07/13 Python
使用OpenCV实现仿射变换—平移功能
2019/08/29 Python
python如何更新包
2020/06/11 Python
英文版区域经理求职信
2013/10/23 职场文书
写演讲稿要注意的六件事
2014/01/14 职场文书
餐厅销售主管职责范本
2014/02/19 职场文书
人事专员的岗位职责
2014/03/01 职场文书
一年级评语大全
2014/04/23 职场文书
生产助理岗位职责
2014/06/18 职场文书
超市周年庆活动方案
2014/08/16 职场文书
五四青年节的活动方案
2014/08/20 职场文书
党员四风问题对照检查材料
2014/09/27 职场文书
党的群众路线教育实践活动心得体会(医院)
2014/11/03 职场文书
2014幼儿园教育教学工作总结
2014/12/17 职场文书
钱学森电影观后感
2015/06/04 职场文书
致我们终将逝去的青春观后感
2015/06/10 职场文书
国富论读书笔记
2015/06/26 职场文书
java实现对Hadoop的操作
2021/07/01 Java/Android