關(guān)于TensorFlow新舊版本函數(shù)接口變化詳解
TensorFlow版本更新太快 了,所以導(dǎo)致一些以前接口函數(shù)不一致,會報錯。
這里總結(jié)了一下自己犯的錯,以防以后再碰到,也可以給別人參考。
首先我的cifar10的代碼都是找到當(dāng)前最新的tf官網(wǎng)給的,所以后面還有新的tf出來改動了的話,可能又會失效了。
1.python3:(unicode error) 'utf-8' codec can't decode
剛開始執(zhí)行的時候就報這個錯,很郁悶后來發(fā)現(xiàn)是因為我用多個編輯器編寫,
保存。導(dǎo)致不同編輯器編碼解碼不一致,會報錯。所以唯一的辦法全程用
一個編輯器去寫,保存。或者保證都是用一種方式編碼解碼就OK了
一:Tersorflow CIFAR-10 訓(xùn)練示例報錯及解決方案(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' ###解決方案: 由于訓(xùn)練樣本的路徑需要修改,給cifar10_input.py中data_dir賦值為本地數(shù)據(jù)所在的文件夾
二:Tersorflow CIFAR-10 訓(xùn)練示例報錯及解決方案
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ù)接口變化詳解就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
在linux系統(tǒng)下安裝python librtmp包的實現(xiàn)方法
今天小編就為大家分享一篇在linux系統(tǒng)下安裝python librtmp包的實現(xiàn)方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-07-07使用matplotlib的pyplot模塊繪圖的實現(xiàn)示例
這篇文章主要介紹了使用matplotlib的pyplot模塊繪圖的實現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-07-07感知器基礎(chǔ)原理及python實現(xiàn)過程詳解
這篇文章主要介紹了感知器基礎(chǔ)原理及python實現(xiàn)過程詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2019-09-09利用LyScript實現(xiàn)應(yīng)用層鉤子掃描器
Capstone 是一個輕量級的多平臺、多架構(gòu)的反匯編框架。本篇文章將運用LyScript插件結(jié)合Capstone反匯編引擎實現(xiàn)一個鉤子掃描器,感興趣的可以了解一下2022-08-08python和numpy?matplotlib版本匹配及安裝指定版本庫
Matplotlib 是 Python 的繪圖庫,它經(jīng)常與NumPy一起使用,從而提供一種能夠代替Matlab的方案,這篇文章主要給大家介紹了關(guān)于python和numpy?matplotlib版本匹配及安裝指定版本庫的相關(guān)資料,文中通過圖文介紹的非常詳細(xì),需要的朋友可以參考下2023-10-10