關(guān)于TensorFlow新舊版本函數(shù)接口變化詳解
TensorFlow版本更新太快 了,所以導(dǎo)致一些以前接口函數(shù)不一致,會(huì)報(bào)錯(cuò)。
這里總結(jié)了一下自己犯的錯(cuò),以防以后再碰到,也可以給別人參考。
首先我的cifar10的代碼都是找到當(dāng)前最新的tf官網(wǎng)給的,所以后面還有新的tf出來(lái)改動(dòng)了的話(huà),可能又會(huì)失效了。
1.python3:(unicode error) 'utf-8' codec can't decode
剛開(kāi)始執(zhí)行的時(shí)候就報(bào)這個(gè)錯(cuò),很郁悶后來(lái)發(fā)現(xiàn)是因?yàn)槲矣枚鄠€(gè)編輯器編寫(xiě),
保存。導(dǎo)致不同編輯器編碼解碼不一致,會(huì)報(bào)錯(cuò)。所以唯一的辦法全程用
一個(gè)編輯器去寫(xiě),保存?;蛘弑WC都是用一種方式編碼解碼就OK了
一:Tersorflow CIFAR-10 訓(xùn)練示例報(bào)錯(cuò)及解決方案(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. 報(bào)錯(cuò):(這個(gè)暫時(shí)沒(méi)有遇到)
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'
###解決方案:
由于訓(xùn)練樣本的路徑需要修改,給cifar10_input.py中data_dir賦值為本地?cái)?shù)據(jù)所在的文件夾
二:Tersorflow CIFAR-10 訓(xùn)練示例報(bào)錯(cuò)及解決方案
1,F(xiàn)ile"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'

以上這篇關(guān)于TensorFlow新舊版本函數(shù)接口變化詳解就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
- TensorFlow2.1.0最新版本安裝詳細(xì)教程
- 手把手教你安裝Windows版本的Tensorflow
- 解決Keras 與 Tensorflow 版本之間的兼容性問(wèn)題
- win10系統(tǒng)Anaconda和Pycharm的Tensorflow2.0之CPU和GPU版本安裝教程
- 解決tensorflow1.x版本加載saver.restore目錄報(bào)錯(cuò)的問(wèn)題
- 淺談Tensorflow由于版本問(wèn)題出現(xiàn)的幾種錯(cuò)誤及解決方法
- 終端命令查看TensorFlow版本號(hào)及路徑的方法
- 查看已安裝tensorflow版本的方法示例
相關(guān)文章
在linux系統(tǒng)下安裝python librtmp包的實(shí)現(xiàn)方法
今天小編就為大家分享一篇在linux系統(tǒng)下安裝python librtmp包的實(shí)現(xiàn)方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-07-07
使用matplotlib的pyplot模塊繪圖的實(shí)現(xiàn)示例
這篇文章主要介紹了使用matplotlib的pyplot模塊繪圖的實(shí)現(xiàn)示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-07-07
感知器基礎(chǔ)原理及python實(shí)現(xiàn)過(guò)程詳解
這篇文章主要介紹了感知器基礎(chǔ)原理及python實(shí)現(xiàn)過(guò)程詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-09-09
利用LyScript實(shí)現(xiàn)應(yīng)用層鉤子掃描器
Capstone 是一個(gè)輕量級(jí)的多平臺(tái)、多架構(gòu)的反匯編框架。本篇文章將運(yùn)用LyScript插件結(jié)合Capstone反匯編引擎實(shí)現(xiàn)一個(gè)鉤子掃描器,感興趣的可以了解一下2022-08-08
Python DNS查詢(xún)放大攻擊實(shí)現(xiàn)原理解析
這篇文章主要介紹了Python DNS查詢(xún)放大攻擊實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧2022-10-10
python和numpy?matplotlib版本匹配及安裝指定版本庫(kù)
Matplotlib 是 Python 的繪圖庫(kù),它經(jīng)常與NumPy一起使用,從而提供一種能夠代替Matlab的方案,這篇文章主要給大家介紹了關(guān)于python和numpy?matplotlib版本匹配及安裝指定版本庫(kù)的相關(guān)資料,文中通過(guò)圖文介紹的非常詳細(xì),需要的朋友可以參考下2023-10-10
python使用knn實(shí)現(xiàn)特征向量分類(lèi)
這篇文章主要為大家詳細(xì)介紹了python使用knn實(shí)現(xiàn)特征向量分類(lèi),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-12-12

