这些问题都是由于tensorflow版本的原因,大家可以看一下自己tensorflow版本
python
import tensorflow as tf
tf.__version__
我的tensorflow版本是1.0.0,一般在1.0.0以上的版本都会有这些问题。对于0.12一下版本的不会出现,这些仅供大家参考
AttributeError: ‘module’ object has no attribute ‘SummaryWriter’
tf.train.SummaryWriter改为:tf.summary.FileWriter
AttributeError: ‘module’ object has no attribute ‘summaries’
tf.merge_all_summary()改为:summary_op = tf.summary.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 tf.Tensor
as a Python bool
is not allowed. Use if t is not None:
instead of 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)
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’
‘per_image_whitening 改为:’per_image_standardization
tensorflow:AttributeError: ‘module’ object has noattribute ‘mul’
tf.mul改为:tf.multiply
出现这些问题的每一个函数都得改变,不然还是会报错