关于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获取apk文件URL地址实例
Nov 01 Python
python网络编程之文件下载实例分析
May 20 Python
python实现将英文单词表示的数字转换成阿拉伯数字的方法
Jul 02 Python
详解pyqt5 动画在QThread线程中无法运行问题
May 05 Python
Python3中详解fabfile的编写
Jun 24 Python
解决每次打开pycharm直接进入项目的问题
Oct 28 Python
python3实现猜数字游戏
Dec 07 Python
django表单的Widgets使用详解
Jul 22 Python
什么是python的函数体
Jun 19 Python
python如何编写类似nmap的扫描工具
Nov 06 Python
Python包管理工具pip的15 个使用小技巧
May 17 Python
python编程学习使用管道Pipe编写优化代码
Nov 20 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
Smarty安装配置方法
2008/04/10 PHP
JS实现php的伪分页
2008/05/25 PHP
PHP 命令行参数详解及应用
2011/05/18 PHP
laravel 根据不同组织加载不同视图的实现
2019/10/14 PHP
TP5框架安全机制实例分析
2020/04/05 PHP
js跟随滚动条滚动浮动代码
2009/12/31 Javascript
javascript 函数调用的对象和方法
2010/07/01 Javascript
网站如何做到完全不需要jQuery也可以满足简单需求
2013/06/27 Javascript
浅析js封装和作用域
2013/07/09 Javascript
jquery 根据name名获取元素的value值
2015/02/27 Javascript
浅谈JavaScript的事件
2015/02/27 Javascript
深入理解JavaScript系列(28):设计模式之工厂模式详解
2015/03/03 Javascript
jQuery Ajax File Upload实例源码
2016/12/12 Javascript
js生成随机颜色方法代码分享(三种)
2016/12/29 Javascript
node.js实现登录注册页面
2017/04/08 Javascript
webpack之devtool详解
2018/02/10 Javascript
Vue使用vux-ui自定义表单验证遇到的问题及解决方法
2018/05/10 Javascript
vue 巧用过渡效果(小结)
2018/09/22 Javascript
JavaScript实现的级联算法示例【省市二级联动功能】
2018/12/25 Javascript
小程序云开发如何实现图片上传及发表文字
2019/05/17 Javascript
微信小程序实现动态列表项的顺序加载动画
2019/07/25 Javascript
[02:02]DOTA2英雄基础教程 斯拉达
2013/12/11 DOTA
解决python xlrd无法读取excel文件的问题
2018/12/25 Python
学习和使用python的13个理由
2019/07/30 Python
Python多线程多进程实例对比解析
2020/03/12 Python
opencv 形态学变换(开运算,闭运算,梯度运算)
2020/07/07 Python
Pytorch 中的optimizer使用说明
2021/03/03 Python
个人求职简历中英文自我评价
2013/12/16 职场文书
航海技术专业毕业生求职信
2014/04/06 职场文书
房地产开发项目建议书
2014/05/16 职场文书
经济管理自荐书
2014/06/09 职场文书
个人总结与自我评价2015
2015/03/11 职场文书
小学班级管理心得体会
2016/01/07 职场文书
教您怎么制定西餐厅运营方案 ?
2019/07/05 职场文书
MySQL中datetime时间字段的四舍五入操作
2021/10/05 MySQL
python blinker 信号库
2022/05/04 Python