关于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中动态创建类实例的方法
Mar 24 Python
Python3+django2.0+apache2+ubuntu14部署网站上线的方法
Jul 07 Python
WxPython建立批量录入框窗口
Feb 27 Python
python实现两个dict合并与计算操作示例
Jul 01 Python
详解Selenium+PhantomJS+python简单实现爬虫的功能
Jul 14 Python
基于Django静态资源部署404的解决方法
Jul 28 Python
python能做什么 python的含义
Oct 12 Python
通过python调用adb命令对App进行性能测试方式
Apr 23 Python
numpy矩阵数值太多不能全部显示的解决
May 14 Python
Django框架请求生命周期实现原理
Nov 13 Python
Django中日期时间型字段进行年月日时分秒分组统计
Nov 27 Python
PyTorch 如何自动计算梯度
May 23 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
全国FM电台频率大全 - 2 天津市
2020/03/11 无线电
PHP实现根据浏览器跳转不同语言页面代码
2013/08/02 PHP
PHP查找数值数组中不重复最大和最小的10个数的方法
2015/04/20 PHP
php实现的美国50个州选择列表实例
2015/04/20 PHP
详解PHP使用Redis存储session时的一个Warning定位
2017/07/05 PHP
javascript全局变量封装模块实现代码
2012/11/28 Javascript
javascript使用location.search的示例
2013/11/05 Javascript
JavaScript实现的购物车效果可以运用在好多地方
2014/05/09 Javascript
JS根据年月获得当月天数的实现代码
2014/07/03 Javascript
jquery实现简单的自动播放幻灯片效果
2015/06/13 Javascript
谈谈jQuery Ajax用法详解
2015/11/27 Javascript
使用jQuery监听DOM元素大小变化
2016/02/24 Javascript
纯JS实现可拖拽表单的简单实例
2016/09/02 Javascript
JS实现瀑布流布局
2017/10/21 Javascript
使用Angular-CLI构建NPM包的方法
2018/09/07 Javascript
微信小程序实现星星评价效果
2018/11/02 Javascript
tracking.js页面人脸识别插件使用方法
2020/04/16 Javascript
Vue实现浏览器打印功能的代码
2020/04/17 Javascript
[54:41]2018DOTA2亚洲邀请赛3月30日 小组赛B组 VGJ.T VS paiN
2018/03/31 DOTA
深入讲解Python编程中的字符串
2015/10/14 Python
Python的Twisted框架中使用Deferred对象来管理回调函数
2016/05/25 Python
Python基础篇之初识Python必看攻略
2016/06/23 Python
Python打包方法Pyinstaller的使用
2018/10/09 Python
[原创]Python入门教程5. 字典基本操作【定义、运算、常用函数】
2018/11/01 Python
Python分析彩票记录并预测中奖号码过程详解
2019/07/09 Python
简单了解Python3 bytes和str类型的区别和联系
2019/12/19 Python
python实现引用其他路径包里面的模块
2020/03/09 Python
美国床垫和床上用品公司:Nest Bedding
2017/06/12 全球购物
解释DataSet(ds) 和 ds as DataSet 的含义
2014/07/27 面试题
铭立家具面试题
2012/12/06 面试题
十八大报告观后感
2014/01/28 职场文书
2015年秋季运动会加油稿
2015/07/22 职场文书
银行柜员优质服务心得体会
2016/01/22 职场文书
《比的意义》教学反思
2016/02/18 职场文书
quickjs 封装 JavaScript 沙箱详情
2021/11/02 Javascript
VMware虚拟机安装 Windows Server 2022的详细图文教程
2022/09/23 Servers