python - Tensorflow TypeError on session.run arguments/output -


i'm training cnn quite similar 1 in this example, image segmentation. images 1500x1500x1, , labels of same size.

after defining cnn structure, , in launching session in code sample: (conv_net_test.py)

with tf.session() sess: sess.run(init) summ = tf.train.summarywriter('/tmp/logdir/', sess.graph_def) step = 1 print ("import data, read read_data_sets()...")  #data defined me, returns dataset object testing , training images , labels segmentation problem. data = import_data_test.read_data_sets('dataset')  # keep training until reach max iterations while step * batch_size < training_iters:     batch_x, batch_y = data.train.next_batch(batch_size)     print ("running backprop step %d" % step)     batch_x = batch_x.reshape(batch_size, n_input, n_input, n_channels)     batch_y = batch_y.reshape(batch_size, n_input, n_input, n_channels)     batch_y = np.int64(batch_y)     sess.run(optimizer, feed_dict={x: batch_x, y: batch_y, keep_prob: dropout})     if step % display_step == 0:         # calculate batch loss , accuracy         #pdb.set_trace()         loss, acc = sess.run([loss, accuracy], feed_dict={x: batch_x, y: batch_y, keep_prob: 1.})     step += 1 print "optimization finished" 

i hit upon following typeerror (stacktrace below):

    conv_net_test.py in <module>()     178             #pdb.set_trace() --> 179             loss, acc = sess.run([loss, accuracy], feed_dict={x: batch_x, y: batch_y, keep_prob: 1.})     180         step += 1     181     print "optimization finished!"  tensorflow/python/client/session.pyc in run(self, fetches, feed_dict, options, run_metadata)     370     try:     371       result = self._run(none, fetches, feed_dict, options_ptr, --> 372                          run_metadata_ptr)     373       if run_metadata:     374         proto_data = tf_session.tf_getbuffer(run_metadata_ptr)  tensorflow/python/client/session.pyc in _run(self, handle, fetches, feed_dict, options, run_metadata)     582      583     # validate , process fetches. --> 584     processed_fetches = self._process_fetches(fetches)     585     unique_fetches = processed_fetches[0]     586     target_list = processed_fetches[1]  tensorflow/python/client/session.pyc in _process_fetches(self, fetches)     538           raise typeerror('fetch argument %r of %r has invalid type %r, '     539                           'must string or tensor. (%s)' --> 540                           % (subfetch, fetch, type(subfetch), str(e)))  typeerror: fetch argument 1.4415792e+2 of 1.4415792e+2 has invalid type <type 'numpy.float32'>, must string or tensor. (can not convert float32 tensor or operation.) 

i stumped @ point. maybe simple case of converting type, i'm not sure how/where. also, why loss have string? (assuming same error pop accuracy well, once fixed).

any appreciated!

where use loss = sess.run(loss), redefine in python variable loss.

the first time run fine. second time, try do:

sess.run(1.4415792e+2) 

because loss float.


you should use different names like:

loss_val, acc = sess.run([loss, accuracy], feed_dict={x: batch_x, y: batch_y, keep_prob: 1.}) 

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -