簡體   English   中英

提取參數None具有無效的類型<class 'NoneType'>

[英]Fetch argument None has invalid type <class 'NoneType'>

我是Tensorflow的新手,所以請多多包涵,我正在學習教程,並且遇到一個我不知道如何解決的錯誤。 誰能幫我嗎? 提前致謝。

這是我嘗試執行的代碼:

def train():
    model = Model()

    with tf.Graph().as_default():
        images, val_images, labels, val_labels = load_training_data()

        x = tf.placeholder(shape=[FLAGS.batch_size, IMAGE_SIZE, IMAGE_SIZE, 1], dtype=tf.float32, name='x')
        y = tf.placeholder(shape=[FLAGS.batch_size, NUM_LABELS], dtype=tf.float32, name='y')
        keep_prob = tf.placeholder(tf.float32, name='dropout_prob')
        global_step = tf.contrib.framework.get_or_create_global_step()

        logits = model.inference(x, keep_prob=keep_prob)
        loss = model.loss(logits=logits, labels=y)

        accuracy = model.accuracy(logits, y)
        summary_op = tf.summary.merge_all()
        train_op = model.train(loss, global_step=global_step)

        init = tf.global_variables_initializer()
        saver = tf.train.Saver()

        with tf.Session(config=tf.ConfigProto(log_device_placement=True)) as sess:
            writer = tf.summary.FileWriter(FLAGS.summary_dir, sess.graph)
            print(writer)
            sess.run(init)
            for i in range(FLAGS.num_iter):

                offset = (i * FLAGS.batch_size) % (len(images) - FLAGS.batch_size)
                batch_x, batch_y = images[offset:(offset + FLAGS.batch_size), :], labels[
                                                                                  offset:(offset + FLAGS.batch_size), :]

                _, cur_loss, summary = sess.run([train_op, 
                                                 loss, 
                                                 summary_op],
                                                feed_dict={
                                                    x: batch_x, 
                                                    y: batch_y, 
                                                    keep_prob: 0.5
                                                })

                writer.add_summary(summary, i)

                print(i, cur_loss)
                if i % 1000 == 0:
                    validation_accuracy = accuracy.eval(feed_dict={x: val_images, y: val_labels, keep_prob: 1.0})
                    print('Iter {} Accuracy: {}'.format(i, validation_accuracy))

                if i == FLAGS.num_iter - 1:
                    saver.save(sess, FLAGS.checkpoint_file_path, global_step)

這是錯誤日志:

TypeError                                 Traceback (most recent call last)
<ipython-input-72-8d21e7b24473> in <module>()
     49                     saver.save(sess, FLAGS.checkpoint_file_path, global_step)
     50 
---> 51 train()

<ipython-input-72-8d21e7b24473> in train()
     36                                                     x: batch_x,
     37                                                     y: batch_y,
---> 38                                                     keep_prob: 0.5
     39                                                 })
     40 

我還需要補充一點,我目前正在研究Kaggle筆記本電腦,因此,如果這影響到事情,請告訴我。

看起來train_oplosssummary_op為None。

您沒有提供完整的代碼,所以我不能多說。 檢查您的Model類的相應功能。

另外,如果在筆記本環境中工作,請確保在進行一些更改后執行了所有相關的單元格。 例如,您可以嘗試從頭開始執行所有單元。

Tensorflow TypeError: Fetch argument None has invalid type <type 'n< div><div id="text_translate"><pre> a=tf.Variable(0, name='input') b=tf.constant(1) mid_val =tf.add(a,b) update_value =tf.compat.v1.assign(a,mid_val) tg=initialize_all_variables() with tf.compat.v1.Session() as sess: sess.run(tg) print(sess.run(a)) for i in range(3): sess.run(update_value) print(sess.run(a))</pre><p> 它在sess.run(tg)中給我錯誤並引發類型錯誤,在運行時它給出以下錯誤:</p><pre> &lt;ipython-input-20-fd2283cdd3bd&gt; in &lt;module&gt;() 10 11 with tf.compat.v1.Session() as sess: ---&gt; 12 sess.run(tg) 13 print(sess.run(a)) 14 3 frames /usr/local/lib/python3.7/dist-packages/tensorflow/python/client/session.py in for_fetch(fetch) 263 """ 264 if fetch is None: --&gt; 265 raise TypeError(f'Argument `fetch` = {fetch} has invalid type ' 266 f'"{type(fetch).__name__}". Cannot be None') 267 elif isinstance(fetch, (list, tuple)):</pre><p> 我應該怎么辦?</p></div></type>

[英]Tensorflow TypeError: Fetch argument None has invalid type <type 'N

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

相關問題 Tensorflow:TypeError:獲取參數None具有無效的類型<class 'NoneType'> tensorflow TypeError:Fetch參數None具有無效類型<class 'NoneType'> Tensorflow TypeError:Fetch參數None具有無效類型 <type 'NoneType'> ? TypeError:獲取參數None具有無效的類型<type 'NoneType'> TypeError:獲取參數 None 的類型無效<class 'NoneType'> , 張量傳遞問題 多個網絡產生Tensorflow TypeError:獲取參數None具有無效的類型<class 'NoneType'> TensorFlow session 有兩個神經網絡 - TypeError: Fetch argument None has invalid type<class 'nonetype'></class> Tensorflow TypeError:獲取參數None具有無效的類型 <class 'NoneType'> 在尋找梯度的同時 使用tf.gradients時的Tensorflow錯誤:TypeError:Fetch參數None具有無效類型<type 'NoneType'> Tensorflow TypeError: Fetch argument None has invalid type <type 'n< div><div id="text_translate"><pre> a=tf.Variable(0, name='input') b=tf.constant(1) mid_val =tf.add(a,b) update_value =tf.compat.v1.assign(a,mid_val) tg=initialize_all_variables() with tf.compat.v1.Session() as sess: sess.run(tg) print(sess.run(a)) for i in range(3): sess.run(update_value) print(sess.run(a))</pre><p> 它在sess.run(tg)中給我錯誤並引發類型錯誤,在運行時它給出以下錯誤:</p><pre> &lt;ipython-input-20-fd2283cdd3bd&gt; in &lt;module&gt;() 10 11 with tf.compat.v1.Session() as sess: ---&gt; 12 sess.run(tg) 13 print(sess.run(a)) 14 3 frames /usr/local/lib/python3.7/dist-packages/tensorflow/python/client/session.py in for_fetch(fetch) 263 """ 264 if fetch is None: --&gt; 265 raise TypeError(f'Argument `fetch` = {fetch} has invalid type ' 266 f'"{type(fetch).__name__}". Cannot be None') 267 elif isinstance(fetch, (list, tuple)):</pre><p> 我應該怎么辦?</p></div></type>
 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM