关于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的Django框架中实现Hacker News的一些功能
Apr 17 Python
python数组过滤实现方法
Jul 27 Python
Python随机生成手机号、数字的方法详解
Jul 21 Python
python的socket编程入门
Jan 29 Python
浅谈python配置与使用OpenCV踩的一些坑
Apr 02 Python
关于torch.optim的灵活使用详解(包括重写SGD,加上L1正则)
Feb 20 Python
python不相等的两个字符串的 if 条件判断为True详解
Mar 12 Python
Python导入数值型Excel数据并生成矩阵操作
Jun 09 Python
python使用建议与技巧分享(一)
Aug 17 Python
Python常用外部指令执行代码实例
Nov 05 Python
教你如何使用Python实现二叉树结构及三种遍历
Jun 18 Python
Python中字符串对象语法分享
Feb 24 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基础知识回顾
2012/08/16 PHP
php中注册器模式类用法实例分析
2015/11/03 PHP
PHP实现的操作数组类库定义与用法示例
2019/05/24 PHP
PHP进阶学习之类的自动加载机制原理分析
2019/06/18 PHP
jQuery UI Dialog控件中的表单无法正常提交的解决方法
2010/12/19 Javascript
js动态给table添加/删除tr的方法
2013/08/02 Javascript
html页面显示年月日时分秒和星期几的两种方式
2013/08/20 Javascript
JavaScript加强之自定义event事件
2013/09/21 Javascript
sliderToggle在写jquery的计时器setTimeouter中不生效
2014/05/26 Javascript
基于JS实现新闻列表无缝向上滚动实例代码
2016/01/22 Javascript
Angular.js 实现数字转换汉字实例代码
2016/07/14 Javascript
获取JS中网页各种高宽与位置的方法总结
2016/07/27 Javascript
Angularjs手动解析表达式($parse)
2016/10/12 Javascript
layui前段框架日期控件使用方法详解
2017/05/19 Javascript
JS传播事件、取消事件默认行为、阻止事件传播详解
2017/08/14 Javascript
浅析为什么a="abc" 不等于 a=new String("abc")
2017/10/25 Javascript
浅谈在vue中使用mint-ui swipe遇到的问题
2018/09/27 Javascript
简单分析js中的this的原理
2019/08/31 Javascript
jquery实现购物车基本功能
2019/10/25 jQuery
基于VUE实现判断设备是PC还是移动端
2020/07/03 Javascript
Vue Element校验validate的实例
2020/09/21 Javascript
用Python实现web端用户登录和注册功能的教程
2015/04/30 Python
windows系统下Python环境的搭建(Aptana Studio)
2017/03/06 Python
python实现AES加密与解密
2019/03/28 Python
Python 中的参数传递、返回值、浅拷贝、深拷贝
2019/06/25 Python
Python 使用多属性来进行排序
2019/09/01 Python
如何获取Python简单for循环索引
2019/11/21 Python
python返回数组的索引实例
2019/11/28 Python
css3实现文字扫光渐变动画效果的示例
2017/11/07 HTML / CSS
adidas旗下高尔夫装备供应商:TaylorMade Golf(泰勒梅高尔夫)
2016/08/28 全球购物
英国婴儿产品专家:Samuel Johnston
2020/04/20 全球购物
小学四年级学生评语
2014/12/26 职场文书
2015年机械设备管理工作总结
2015/05/04 职场文书
员工手册编写范本
2015/05/14 职场文书
2015年社区精神文明工作总结
2015/05/26 职场文书
2016道德模范先进事迹材料
2016/02/26 职场文书