以下報錯主要是由于TensorFlow更新1.0後與以前代碼不相容所緻。主要轉載自CIFAR-10訓練例子報錯解決,并添加了一些報錯解決方法。
-
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])
-
AttributeError: ‘module’object has no attribute ‘SummaryWriter’
解決方案:
tf.train.SummaryWriter改為:tf.summary.FileWriter
-
AttributeError: ‘module’object has no attribute ‘summaries’
解決方案:
tf.merge_all_summaries()改為:summary_op =tf.summary.merge_all()
-
AttributeError: ‘module’ object hasno attribute ‘histogram_summary’
tf.histogram_summary(var.op.name,var)改為: tf.summaries.histogram()
-
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)
- 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’)
- TypeError: Using a
as a Pythontf.Tensor
isnot allowed. Usebool
instead ofif t is not None:
if t:
to test if a tensor isdefined, and use TensorFlow ops such as tf.cond to execute subgraphsconditioned on the value of a tensor.
解決方案:
if grad: 改為 if grad is not None:
-
ValueError: Shapes (2, 128, 1) and () are incompatible
解決方案:
concated = tf.concat(1, [indices, sparse_labels])改為:
concated= tf.concat([indices, sparse_labels], 1)
-
報錯:
File”/home/lily/work/Tensorflow/CIRFAR-10/tensorflow.cifar10-master/cifar10_input.py”,line 83, in read_cifar10
result.key, value =reader.read(filename_queue)
File”/usr/local/lib/python2.7/dist-packages/tensorflow/Python/ops/io_ops.py”,line 326, in read
queue_ref = queue.queue_ref
AttributeError: ‘str’ object hasno attribute ‘queue_ref’
解決方案:
由于訓練樣本的路徑需要修改,給cifar10_input.py中data_dir指派為本地資料所在的檔案夾
AttributeError: ‘module’ object has no attribute ‘SummaryWriter’
tf.train.SummaryWriter改為:tf.summary.FileWriter
-
AttributeError: ‘module’ object has no attribute ‘summaries’
tf.merge_all_summaries()改為:summary_op = tf.summaries.merge_all()
tf.histogram_summary(var.op.name, var)
-
AttributeError: ‘module’ object has no attribute ‘histogram_summary’
改為: tf.summaries.histogram()
tf.scalar_summary(l.op.name + ’ (raw)’, l)
AttributeError: ‘module’ object has no attribute ‘scalar_summary’
tf.scalar_summary(‘images’, images)改為:tf.summary.scalar(‘images’, images)
tf.image_summary(‘images’, images)改為:tf.summary.image(‘images’, images)
- ValueError: Only call
softmax_cross_entropy_with_logits
with named 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’)
- TypeError: Using a
as a Pythontf.Tensor
is not allowed. Usebool
instead ofif t is not None:
if t:
to test if a tensor is defined, and use TensorFlow ops such as tf.cond to execute subgraphs conditioned on the value of a tensor.
if grad: 改為 if grad is not None:
ValueError: Shapes (2, 128, 1) and () are incompatible
concated = tf.concat(1, [indices, sparse_labels])改為:
concated = tf.concat([indices, sparse_labels], 1)
tensorflow1.0
-
AttributeError: ‘module’ object has no attribute ‘mul’
解決方法:
,tf.mul
andtf.sub
are deprecated in favor oftf.neg
,tf.multiply
andtf.subtract
.tf.negative
-
has no attribute 'per_image_whitening
改為per_image_standardization
主要 API 改進
- BusAdjacency 枚舉被協定緩沖 DeviceLocality 代替。總線索引現在從 1 而不是 0 開始,同時,使用 bus_id==0,之前為 BUS_ANY。
- Env::FileExists 和 FileSystem::FileExists 現在傳回 tensorflow::Status 而不是一個 bool。任何此函數的調用者都可以通過向調用添加.ok()将傳回轉換為 bool。
- C API:TF_SessionWithGraph 類型更名為 TF_Session,其在 TensorFlow 的綁定語言中成為首選。原來的 TF_Session 已更名為 TF_DeprecatedSession。
- C API: TF_Port 被更名為 TF_Output。
- C API: 調用者保留提供給 TF_Run、 TF_SessionRun、TF_SetAttrTensor 等的 TF_Tensor 對象的所有權。
- 将 tf.image.per_image_whitening() 更名為 tf.image.per_image_standardization()。
- 将 Summary protobuf 構造函數移動到了 tf.summary 子子產品。
- 不再使用 histogram_summary、audio_summary、 scalar_summary,image_summary、merge_summary 和 merge_all_summaries。
- 組合 batch_ 和正常版本的線性代數和 FFT 運算。正常運算現在也處理批處理。所有 batch_ python 接口已删除。
- tf.all_variables,tf.VARIABLES 和 tf.initialize_all_variables 更名為 tf.global_variables,tf.GLOBAL_VARIABLES 和 tf.global_variable_initializers respectively。