Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sess.run() with Keras model and TFRecord tensor based images #5368

Closed
ahundt opened this issue Feb 12, 2017 · 3 comments
Closed

sess.run() with Keras model and TFRecord tensor based images #5368

ahundt opened this issue Feb 12, 2017 · 3 comments

Comments

@ahundt
Copy link
Contributor

ahundt commented Feb 12, 2017

There isn't much documentation on how to run a keras model with image tensors loaded from a TFRecord, there is the keras as a simplified interface to tensorflow blog post, but it loads up all the images as a numpy array.

Since I already have TFRecords loaded from a function read_tfrecord_and_decode_into_image_annotation_pair_tensors() and tensors storing my images I don't think I need to go back to a feed dict. However, when I try to call sess.run, Keras expects a numpy array feed_dict for the keras.model.layers.Input() as I encountered in this error.

How do I use keras models with a keras.layers.Input() node, input tensor images, TFRecords, and queue runners together?

some of the key code lines:


        coord = tf.train.Coordinator()
        threads = tf.train.start_queue_runners(sess=sess,coord=coord)
        
        print('starting training...')

        # 10 epochs
        for i in xrange(11127 * number_of_epochs):
        
            cross_entropy, summary_string, _ = sess.run([ cross_entropy_sum,
                                                        merged_summary_op,
                                                        train_step ],
                                                        feed_dict={K.learning_phase(): 1})
            
            print("Current loss: " + str(cross_entropy))
            
            summary_string_writer.add_summary(summary_string, i)
            
            if i % 11127 == 0:
                save_path = saver.save(sess, FLAGS.save_dir + "model_fcn8s_epoch_" + str(i) + ".ckpt")
                print("Model saved in file: %s" % save_path)

I will update with more details once tf is reinstalled, though I don't think the error is key to these questions as it is primarily about Keras + TF integration.

@ahundt
Copy link
Contributor Author

ahundt commented Feb 12, 2017

I also created a stackoverflow question in case that's more appropriate:
http://stackoverflow.com/questions/42184863/tensorflow-session-run-tfrecord-keras-example

@ahundt
Copy link
Contributor Author

ahundt commented Jun 12, 2017

A first pass of keras support for TFRecords is in #6928, feedback + fixes would be appreciated!

Also, if you want to go the other way with mostly TF code and keras layers see https://github.com/ppwwyyxx/tensorpack/blob/master/examples/mnist-keras.py

@stale stale bot removed the stale label Jun 12, 2017
@ahundt
Copy link
Contributor Author

ahundt commented Jun 12, 2017

I consider this issue resolved.

@ahundt ahundt closed this as completed Jun 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant