{"action":"created","issue":{"url":"https://api.github.com/repos/tensorflow/tensorflow/issues/3389","repository_url":"https://api.github.com/repos/tensorflow/tensorflow","labels_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/3389/labels{/name}","comments_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/3389/comments","events_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/3389/events","html_url":"https://github.com/tensorflow/tensorflow/issues/3389","id":166322179,"number":3389,"title":"Why doesn't tensorflow support tensor as the feed_dict?","user":{"login":"wishforgood","id":9963412,"avatar_url":"https://avatars.githubusercontent.com/u/9963412?v=3","gravatar_id":"","url":"https://api.github.com/users/wishforgood","html_url":"https://github.com/wishforgood","followers_url":"https://api.github.com/users/wishforgood/followers","following_url":"https://api.github.com/users/wishforgood/following{/other_user}","gists_url":"https://api.github.com/users/wishforgood/gists{/gist_id}","starred_url":"https://api.github.com/users/wishforgood/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wishforgood/subscriptions","organizations_url":"https://api.github.com/users/wishforgood/orgs","repos_url":"https://api.github.com/users/wishforgood/repos","events_url":"https://api.github.com/users/wishforgood/events{/privacy}","received_events_url":"https://api.github.com/users/wishforgood/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-07-19T12:45:36Z","updated_at":"2016-07-19T13:43:00Z","closed_at":null,"body":"**What I'm trying to do**\r\n\r\nI am trying to extract CNN features for my own images with residual-net based on https://github.com/ry/tensorflow-resnet. I plan to input image data from JPG files before exploring how to convert the images into a single file.\r\n\r\n\r\n**What I have done**\r\n\r\nI have read https://www.tensorflow.org/versions/r0.9/how_tos/reading_data/index.html and some related materials about how to input data like feeding and placeholder. Here is my code:\r\n\r\n    import tensorflow as tf\r\n    from convert import print_prob, checkpoint_fn, meta_fn\r\n    from image_processing import image_preprocessing\r\n    tf.app.flags.DEFINE_integer('batch_size', 1, \"batch size\")\r\n    tf.app.flags.DEFINE_integer('input_size', 224, \"input image size\")\r\n    tf.app.flags.DEFINE_integer('min_after_dequeue', 224, \"min after dequeue\")\r\n    tf.app.flags.DEFINE_integer('layers', 152, \"The number of layers in the net\")\r\n    tf.app.flags.DEFINE_integer('image_number', 6951, \"number of images\")\r\n    FLAGS = tf.app.flags.FLAGS\r\n     \r\n    \r\n    def placeholder_inputs():\r\n        images_placeholder = tf.placeholder(tf.float32, shape=(FLAGS.batch_size, FLAGS.input_size, FLAGS.input_size, 3))\r\n        label_placeholder = tf.placeholder(tf.int32, shape=FLAGS.batch_size)\r\n        return images_placeholder, label_placeholder\r\n\r\n\r\n    def fill_feed_dict(image_ba, label_ba, images_pl, labels_pl):\r\n        feed_dict = {\r\n            images_pl: image_ba,\r\n        }\r\n        return feed_dict\r\n\r\n    min_fraction_of_examples_in_queue = 0.4\r\n    min_queue_examples = int(FLAGS.image_number *\r\n                         min_fraction_of_examples_in_queue)\r\n    dataset = tf.train.string_input_producer([\"hollywood_test.txt\"])\r\n    reader = tf.TextLineReader()\r\n    _, file_content = reader.read(dataset)\r\n    image_name, label, _ = tf.decode_csv(file_content, [[\"\"], [\"\"], [\"\"]], \" \")\r\n    label = tf.string_to_number(label)\r\n    num_preprocess_threads = 10\r\n    images_and_labels = []\r\n    with tf.Session() as sess:\r\n        for thread_id in range(num_preprocess_threads):\r\n            image_buffer = tf.read_file(image_name)\r\n            bbox = []\r\n            train = False\r\n            image = image_preprocessing(image_buffer, bbox, train, thread_id)\r\n            image = image_buffer\r\n            images_and_labels.append([image, label])\r\n        image_batch, label_batch = tf.train.batch_join(images_and_labels,\r\n                                                batch_size=FLAGS.batch_size,\r\n                                                capacity=min_queue_examples + 3 * FLAGS.batch_size)\r\n        images_placeholder, labels_placeholder = placeholder_inputs()\r\n        new_saver = tf.train.import_meta_graph(meta_fn(FLAGS.layers))\r\n        new_saver.restore(sess, checkpoint_fn(FLAGS.layers))\r\n        graph = tf.get_default_graph()\r\n        prob_tensor = graph.get_tensor_by_name(\"prob:0\")\r\n        images = graph.get_tensor_by_name(\"images:0\")\r\n        feed_dict = fill_feed_dict(image_batch, label_batch, images, labels_placeholder)\r\n        coord = tf.train.Coordinator()\r\n        threads = tf.train.start_queue_runners(coord=coord)\r\n        sess.run(tf.initialize_all_variables())\r\n        prob = sess.run(prob_tensor, feed_dict=feed_dict)\r\n        print_prob(prob[0])\r\n        coord.request_stop()\r\n        coord.join(threads)\r\n\r\n\r\n**What my question is**\r\n\r\nThe code above got the error `TypeError: The value of a feed cannot be a tf.Tensor object. Acceptable feed values include Python scalars, strings, lists, or numpy ndarrays.` You can see I am trying to do all the work in the context of tensorflow. As far as I know, tensorflow is a framework where all the inputs and outputs of the nodes are tensors. However, I am quite confused why feed_dict doesn't support tensor as an input. But the batch_join function return a tensor and so do other ops. I found that in the mnist example of tensorflow there is even another function to produce a batch when tensorflow is providing methods for batching. So I wonder if there is an elegant way to do these things. If this is because of my lack of searching and careful reading I really apologize.\r\n"},"comment":{"url":"https://api.github.com/repos/tensorflow/tensorflow/issues/comments/233636510","html_url":"https://github.com/tensorflow/tensorflow/issues/3389#issuecomment-233636510","issue_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/3389","id":233636510,"user":{"login":"zakizhou","id":19201532,"avatar_url":"https://avatars.githubusercontent.com/u/19201532?v=3","gravatar_id":"","url":"https://api.github.com/users/zakizhou","html_url":"https://github.com/zakizhou","followers_url":"https://api.github.com/users/zakizhou/followers","following_url":"https://api.github.com/users/zakizhou/following{/other_user}","gists_url":"https://api.github.com/users/zakizhou/gists{/gist_id}","starred_url":"https://api.github.com/users/zakizhou/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zakizhou/subscriptions","organizations_url":"https://api.github.com/users/zakizhou/orgs","repos_url":"https://api.github.com/users/zakizhou/repos","events_url":"https://api.github.com/users/zakizhou/events{/privacy}","received_events_url":"https://api.github.com/users/zakizhou/received_events","type":"User","site_admin":false},"created_at":"2016-07-19T13:43:00Z","updated_at":"2016-07-19T13:43:00Z","body":"I new to tensorflow, according to my experience, you really don't need to feed a tf.tensor to feed_dict. Once you have a tensor with value, you can get this value with your_tensor.eval() or sess.run(you_tensor) and then you can feed the output to your feed_dict"}}
{"actor":{"display_login":"zakizhou"}}