1. 程式人生 > >tensorflow 各種報錯總結

tensorflow 各種報錯總結

1. 'list' object has no attribute 'lower' 報錯如下
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)