关于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用于url解码和中文解析的小脚本(python url decoder)
Aug 11 Python
Python实现压缩与解压gzip大文件的方法
Sep 18 Python
浅谈python中的正则表达式(re模块)
Oct 17 Python
Python环境搭建之OpenCV的步骤方法
Oct 20 Python
Python语言实现百度语音识别API的使用实例
Dec 13 Python
python实现学生信息管理系统
Apr 05 Python
Python面向对象程序设计之继承与多继承用法分析
Jul 13 Python
python os模块简单应用示例
May 23 Python
在Python中表示一个对象的方法
Jun 25 Python
python3.6+django2.0+mysql搭建网站过程详解
Jul 24 Python
python爬虫 execjs安装配置及使用
Jul 30 Python
Python max函数中key的用法及原理解析
Jun 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
造就帕卡马拉的帕卡斯是怎么被发现的
2021/03/03 咖啡文化
php5数字型字符串加解密代码
2008/04/24 PHP
PHP 程序员也要学会使用“异常”
2009/06/16 PHP
PHP设计模式之装饰者模式
2012/02/29 PHP
Yii框架获取当前controlle和action对应id的方法
2014/12/03 PHP
PHP PDO fetch 模式各种参数的输出结果一览
2015/01/07 PHP
如何用PHP做到页面注册审核
2017/03/02 PHP
原生JS操作网页给p元素添加onclick事件及表格隔行变色
2013/12/01 Javascript
jQuery $.extend()用法总结
2014/06/15 Javascript
jQuery实现的多滑动门,多选项卡效果代码
2016/03/28 Javascript
JS图片延迟加载插件LazyImgv1.0用法分析【附demo源码下载】
2017/09/04 Javascript
Vue代码分割懒加载的实现方法
2017/11/23 Javascript
JS匿名函数和匿名自执行函数概念与用法分析
2018/03/16 Javascript
浅谈vue项目如何打包扔向服务器
2018/05/08 Javascript
关于NodeJS中的循环引用详解
2019/07/23 NodeJs
Quasar Input:type="number" 去掉上下小箭头 实现加减按钮样式功能
2020/04/09 Javascript
[43:03]LGD vs Newbee 2019国际邀请赛小组赛 BO2 第一场 8.16
2019/08/19 DOTA
python超简单解决约瑟夫环问题
2015/05/12 Python
Python3实现将文件树中所有文件和子目录归档到tar压缩文件的方法
2015/05/22 Python
Python3使用requests包抓取并保存网页源码的方法
2016/03/15 Python
python去除文件中空格、Tab及回车的方法
2016/04/12 Python
python中实现迭代器(iterator)的方法示例
2017/01/19 Python
python快速编写单行注释多行注释的方法
2019/07/31 Python
Python求平面内点到直线距离的实现
2020/01/19 Python
纯CSS改变webkit内核浏览器的滚动条样式
2014/04/17 HTML / CSS
H5 canvas中width、height和style的宽高区别详解
2018/11/02 HTML / CSS
Peter Millar官网:美国高档生活服饰品牌
2018/07/02 全球购物
怀旧香味蜡烛:Homesick
2019/11/02 全球购物
优秀毕业生自我鉴定
2014/01/19 职场文书
不假外出检讨书
2014/01/27 职场文书
2014年党员公开承诺书范文
2014/03/28 职场文书
十八大演讲稿
2014/05/22 职场文书
法人委托书
2014/07/31 职场文书
出国签证在职证明
2014/09/20 职场文书
区政府领导班子个人对照检查材料
2014/09/25 职场文书
完美处理python与anaconda环境变量的冲突问题
2021/04/07 Python