python - Tensorflow TypeError: Fetch argument None has invalid type <type 'NoneType'>? -


i'm making rnn loosely based off of tensorflow's tutorial. relevant parts of model follows ("comment if need see more, don't want make post long xd):

input_sequence = tf.placeholder(tf.float32, [batch_size, time_steps, pixel_count + aux_inputs]) output_actual = tf.placeholder(tf.float32, [batch_size, output_size])  lstm_cell = tf.nn.rnn_cell.basiclstmcell(cell_size, state_is_tuple=false) stacked_lstm = tf.nn.rnn_cell.multirnncell([lstm_cell] * cell_layers, state_is_tuple=false)  initial_state = state = stacked_lstm.zero_state(batch_size, tf.float32) outputs = []  tf.variable_scope("lstm"):     step in xrange(time_steps):         if step > 0:             tf.get_variable_scope().reuse_variables()         cell_output, state = stacked_lstm(input_sequence[:, step, :], state)         outputs.append(cell_output)  final_state = state 

and feeding:

cross_entropy = tf.reduce_mean(-tf.reduce_sum(output_actual * tf.log(prediction), reduction_indices=[1])) train_step = tf.train.adamoptimizer(learning_rate=learning_rate).minimize(cross_entropy) correct_prediction = tf.equal(tf.argmax(prediction, 1), tf.argmax(output_actual, 1)) accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))  tf.session() sess:     sess.run(tf.initialize_all_variables())     numpy_state = initial_state.eval()      in xrange(1, iterations):         batch = di.next_batch()          print i, type(batch[0]), np.array(batch[1]).shape, numpy_state.shape          if % log_step == 0:             train_accuracy = accuracy.eval(feed_dict={                 initial_state: numpy_state,                 input_sequence: batch[0],                 output_actual: batch[1]             })              print "iteration " + str(i) + " training accuracy " + str(train_accuracy)          numpy_state, train_step = sess.run([final_state, train_step], feed_dict={             initial_state: numpy_state,             input_sequence: batch[0],             output_actual: batch[1]             }) 

and when run this, following error:

traceback (most recent call last):   file "/home/agupta/documents/projects/image-recognition-with-lstm/rnn/feature_tracking/model.py", line 109, in <module>     output_actual: batch[1]   file "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 698, in run     run_metadata_ptr)   file "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 838, in _run     fetch_handler = _fetchhandler(self._graph, fetches)   file "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 355, in __init__     self._fetch_mapper = _fetchmapper.for_fetch(fetches)   file "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 181, in for_fetch     return _listfetchmapper(fetch)   file "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 288, in __init__     self._mappers = [_fetchmapper.for_fetch(fetch) fetch in fetches]   file "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 178, in for_fetch     (fetch, type(fetch))) typeerror: fetch argument none has invalid type <type 'nonetype'> 

perhaps weirdest part error gets thrown second iteration, , first works fine. i'm ripping hair trying fix this, appreciated.

you re-assigning train_step variable second element of result of sess.run() (which happens none). hence, on second iteration, train_step none, leads error.

the fix fortunately simple:

for in xrange(1, iterations):      # ...      # discard second element of result.     numpy_state, _ = sess.run([final_state, train_step], feed_dict={         initial_state: numpy_state,         input_sequence: batch[0],         output_actual: batch[1]         }) 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

python 3.5 - Pyqtgraph string in x tick -