tensorflow 各种报错总结

Traceback (most recent call last):
File "H:/FasionAI/MyNet/train.py", line 27, in <module>
train_logits = model.inference(train_batch, BATCH_SIZE, N_CLASSES)
File "H:\FasionAI\MyNet\CnnNet.py", line 60, in inference
pool2 = tf.nn.pool(conv2, [1, 2, 2, 1], [1, 2, 2, 1], padding='SAME', name='pooling2')
File "E:\softinstall\Anaconda\lib\site-packages\tensorflow\python\ops\nn_ops.py", line 931, in pool
(pooling_type.lower()), [input]) as scope:
AttributeError: 'list' object has no attribute 'lower'
问题原因:是tf.nn.max_pool()而不是tf.nn.pool()
2.tensorflow版本不一致
1)AttributeError: module 'tensorflow' has no attribute 'scalar_summary'
tf.image_summary('images', images)改为:tf.summary.image('images', images)
2)AttributeError: 'module' object has no attribute 'scalar_summary'
tf.scalar_summary('images', images)改为:tf.summary.scalar('images', images)
3)AttributeError: module 'tensorflow' has no attribute 'merge_all_summaries'
tf.merge_all_summaries()改为:summary_op = tf.summary.merge_all()
4)AttributeError: 'module' object has no attribute 'SummaryWriter'
tf.train.SummaryWritter改为tf.summary.FileWriter
3.pycharm程序无法识别自己写的程序import时显示红线
1)打开File--》Setting—》打开 Console下的Python Console,把选项(Add source roots to PYTHONPAT)点击勾选上
2)右键点击自己的工作空间,找下面的Mark Directory as 选择Source Root,就可以解决上面的问题了
4.ValueError: Both labels and logits must be provided.
File "H:\FasionAI\MyNet\resnetmodel\resnet_train.py", line 35, in train
loss_ = loss(logits=logits, labels=labels)
File "H:\FasionAI\MyNet\resnetmodel\resnet.py", line 148, in loss
cross_entropy = tf.nn.sparse_softmax_cross_entropy_with_logits(labels=labels,logits=logits)
File "E:\softinstall\Anaconda\lib\site-packages\tensorflow\python\ops\nn_ops.py", line 1935, in sparse_softmax_cross_entropy_with_logits
labels, logits)
File "E:\softinstall\Anaconda\lib\site-packages\tensorflow\python\ops\nn_ops.py", line 1715, in _ensure_xent_args
raise ValueError("Both labels and logits must be provided.")
ValueError: Both labels and logits must be provided.
查看源码后发现是:
if labels is None or logits is None:
raise ValueError("Both labels and logits must be provided.")
也就是说有一个输入为空,后检查发现调用函数 inference_small_config(x, c)时没有return 正确应该是
return inference_small_config(x, c)




更多推荐
所有评论(0)