关于TensorFlow新旧版本函数接口变化详解
作者:furuit 发布时间:2022-12-29 19:00:21
标签:TensorFlow,新旧,版本,接口
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'
来源:https://blog.csdn.net/fu6543210/article/details/79845902


猜你喜欢
- 一、背景我们日常测试中存在大量重复的造数操作,且流程较长,为了提升测试效率,我们搭建了数据构造平台。平台采用了前端 + 脚本分离的形式,数据
- 利用python,可以实现填充网页表单,从而自动登录WEB门户。(注意:以下内容只针对python3)环境准备:(1)安装python (2
- 目录Python 数据化运营1、内容介绍2、一般应用场景3、聚类的常见方法4、Keans聚类实现5、聚类的评估指标6、聚类效果可视化7、数据
- 1,System.ComponentModelSystem.ComponentModel 命名空间提供用于实现组件和控件的运行时和设计时行为
- 这里主要是讲在asp下两次由access数据库升级到sql server数据库后的经验及注意事项,其它语言也可以参考一下。欢迎讨论补充。1.
- 01. 装饰器语法糖如果你接触 Python 有一段时间了的话,想必你对 @ 符号一定不陌生了,没错 @ 符号就是装饰器的语法糖。它放在一个
- 概要 简单介绍几种用于判断numpy数组是否全
- 这篇文章主要介绍了python处理RSTP视频流过程解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的
- 不敢说得太明显太仔细,反正你懂的。有两种方法,一种是搭建本地授权服务器,另一种是直接替换核心文件,修改对应的注册码。先说第一种。 下载Int
- 第一种方式: $(document).ready(function(){ $("#clickme").click(fun
- /*ajax提交的延时等待效果*/var AjaxLoding = new Object();//wraperid : 显示loding图片
- 目录安装sakila索引扫描排序表结构可以使用索引扫描来做排序的情况补足前导列order by 中只包含一种排序无法使用索引扫描的情况查询条
- 1.导言现今的公司需要易访问的和可用性好的商业数据,以便他们可以在全球市场中获得一席之地。与易访问数据的这个需求相呼应的,关系数据库和分析数
- 窗外下着小雨,作为单身程序员的我逛着逛着发现一篇好东西,来自知乎 你都用 Python 来做什么?的第一个高亮答案。到上面去看了看,地址都是
- Gradio 是做什么的?先决条件:Gradio 需要 Python 3.7 或更高版本,仅此而已!gradio.app/quickstar
- 前言最近开始学习python数据库编程后,在了解了基本概念,打算上手试验一下时,卡在了MYSQLdb包的安装上,折腾了半天才解决。记录一下我
- IE8主页http://www.microsoft.com/windows/products/winfamily/ie/ie8/defaul
- 这里使用FSO对象来删除指定文件夹 代码和说明如下:<% set fs=createobject(&qu
- 在《多进程并发与同步》中介绍了进程创建与信息共享,除此之外python还提供了更方便的进程间通讯方式。进程间通讯multiprocessin
- Django cors跨域问题前后端分离项目中的跨域问题 即同源策略同源策略:同源策略/SOP(Same origin policy)是一种