tensorflow各版本間踩過的坑

問題一:TypeError: Expected int32, got list containing Tensors of type ‘_Message’ instead.

tensorflow 函數tf.cocat([fw,bw],2)出錯:

Expected int32, got list containing Tensors of type ‘_Message’ inst 
查看原因是11版本的函數形式爲:tf.concat(2,[fw,bw]),即應把串聯的維度與串聯值位置調換即可.

問題二:Input ‘split_dim’ of ‘Split’ Op has type float32 that does not match expected type of int32

This is because in Tensorflow versions < 0.12.0 the split function takes the arguments as:

x = tf.split(0, n_steps, x) # tf.split(axis, num_or_size_splits, value) 
The tutorial you are working from was written for versions > 0.12.0, which has been changed to be consistent with Numpy’s split syntax:

x = tf.split(x, n_steps, 0) # tf.split(value, num_or_size_splits, axis)

問題三:TypeError: concat() got an unexpected keyword argument ‘axis’

tf.concat(concat_dim=axis, values=inputs, name=name) 
修改爲: tf.concat(inputs,1,name=name)

問題四:ValueError: ‘size’ must be a 1-D Tensor of 2 elements

img = tf.image.resize_images(img, new_shape[0], new_shape[1]) 
改爲 
img = tf.image.resize_images(img, new_shape)

問題五: ‘module’ object has no attribute ‘pack’

因爲TF後面的版本修改了這個函數的名稱,把 tf.pack 改爲 tf.stack。

問題六:The value of a feed cannot be a tf.Tensor object. Acceptable feed values include Python scalars, strings, lists, or numpy ndarrays

數據集是feed輸入的,feed的數據格式是有要求的 
解決:img,label = sess.run[img,label],用返回值

問題七:AttributeError: ‘module’ object has no attribute ‘per_image_whitening’

For anyone else who has this problem, per_image_whitening was replaced by per_image_standardization in v0.12.

問題八:AttributeError: ‘module’ object has no attribute ‘image_summary’

tf.image_summary should be renamed to tf.summary.image;

問題九:AttributeError: ‘module’ object has no attribute ‘mul’

tf.mul(a,b) 這裏的矩陣a和矩陣b的shape必須相等 tf.mul()是矩陣的element-wise相乘(即Hadamard乘積) 
tf.matmul(a,b) 這裏的矩陣a和矩陣b的shape應是a的行數對等與b的列數,tf.matmul()是矩陣的一般相乘。 
解決:[tf.mul,tf.sub ] 和 [tf.neg] 不再使用,改爲 [tf.multiply],[tf.subtract] 和 [tf.negative]。

問題十:AttributeError: ‘module’ object has no attribute ‘scalar_summary’

修改爲:tf.summary.scalar(‘batch_loss’, loss)原因:新版本做了調整 …

發佈了148 篇原創文章 · 獲贊 277 · 訪問量 114萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章