{"action":"created","issue":{"url":"https://api.github.com/repos/tensorflow/tensorflow/issues/5234","repository_url":"https://api.github.com/repos/tensorflow/tensorflow","labels_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/5234/labels{/name}","comments_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/5234/comments","events_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/5234/events","html_url":"https://github.com/tensorflow/tensorflow/issues/5234","id":185627666,"number":5234,"title":"tensorflow/core/framework/op_kernel.cc:968 Invalid argument: Could not parse example input","user":{"login":"anjiefang","id":11158020,"avatar_url":"https://avatars.githubusercontent.com/u/11158020?v=3","gravatar_id":"","url":"https://api.github.com/users/anjiefang","html_url":"https://github.com/anjiefang","followers_url":"https://api.github.com/users/anjiefang/followers","following_url":"https://api.github.com/users/anjiefang/following{/other_user}","gists_url":"https://api.github.com/users/anjiefang/gists{/gist_id}","starred_url":"https://api.github.com/users/anjiefang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anjiefang/subscriptions","organizations_url":"https://api.github.com/users/anjiefang/orgs","repos_url":"https://api.github.com/users/anjiefang/repos","events_url":"https://api.github.com/users/anjiefang/events{/privacy}","received_events_url":"https://api.github.com/users/anjiefang/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":12,"created_at":"2016-10-27T10:15:05Z","updated_at":"2016-11-01T18:56:38Z","closed_at":"2016-10-27T17:23:00Z","body":"I'm trying to convert images (PNG) to `tf-records` files. When I read `tf-records` files. I saw lots of unreadable code on the screen. Please help to find the problem. I list my problems and code below:\n\nI need to convert a sequence of images (10 PNGs) into a single `tf-records` file. I have several sequences of images and each sequence (10 PNGs) is in a folder. Here is the code I used to convert images to `tf-records`:\n\n```\nimport os, sys\nimport tensorflow as tf\nimport numpy as np\nfrom PIL import Image\n\ndef _int64_feature(value):\n    return tf.train.Feature(int64_list=tf.train.Int64List(value=[value]))\n\ndef _bytes_feature(value):\n    return tf.train.Feature(bytes_list=tf.train.BytesList(value=[value]))\n\ndef read():\n    # parent folder contains all sequence, each sequence (10 png) is in a sub-folder \n    parent_foler = sys.argv[1]\n    for folder in os.listdir(parent_foler):\n        images = read_images_from(parent_foler + '/' + folder)\n        num_examples = len(images)\n\n        print 'Number of images: ' + str(num_examples)\n        outputFile = os.path.join(parent_foler, folder + '.tfrecords')\n        writer = tf.python_io.TFRecordWriter(outputFile)\n        fs = {}\n        for index in range(num_examples):\n            image_raw = images[index].tostring()\n            image_name = 'move/' + str(index) + '/image/encoded'\n            fs[image_name] = _bytes_feature(image_raw)\n            print folder + ':' + image_name\n        print 'Size of Features:' + str(len(fs))\n        example = tf.train.Example(features=tf.train.Features(feature=fs))\n        writer.write(example.SerializeToString())\n        writer.close()\n\ndef read_images_from(folder_name):\n    images = []\n    files_to_read = [folder_name + '/' + folder_name.split('/')[-1] + '_' + str(i + 1) + '.png' for i in range(10)]\n    for filename in files_to_read:\n        im = Image.open(filename)\n        im = np.asarray(im, np.uint8)\n        images.append(im)\n    images = np.array(images)\n    print'shape of images: ' + str(images.shape)\n    return images\n\nif __name__ == \"__main__\":\n    read()\n```\n\nHere is the code to read these `tf-records` files: (adapted from [this code](https://github.com/tensorflow/models/blob/master/video_prediction/prediction_input.py))\n\n```\nORIGINAL_WIDTH = 2048\nORIGINAL_HEIGHT = 1536\nCOLOR_CHAN = 4\n\ndef build_tfrecord_input(tf_folder):\n    filenames = [foldername + '/' + tf_file for tf_file in os.listdir(tf_folder)]\n    filename_queue = tf.train.string_input_producer(filenames, shuffle=True)\n    reader = tf.TFRecordReader()\n    _, serialized_example = reader.read(filename_queue)\n    image_seq = []\n\n    # FLAGS.sequence_length = 10\n    for i in range(FLAGS.sequence_length): \n        image_name = 'move/' + str(i) + '/image/encoded'\n        features = {image_name: tf.FixedLenFeature([1], tf.string)}\n        features = tf.parse_single_example(serialized_example, features=features)\n        image = tf.decode_raw(features[image_name], tf.uint8)\n        image = tf.reshape(image, shape=[ORIGINAL_HEIGHT,ORIGINAL_WIDTH,COLOR_CHAN])\n        image.set_shape([ORIGINAL_HEIGHT, ORIGINAL_WIDTH, COLOR_CHAN])\n\n        crop_size = min(ORIGINAL_HEIGHT, ORIGINAL_WIDTH)\n        image = tf.image.resize_image_with_crop_or_pad(image, crop_size, crop_size)\n        image = tf.reshape(image, [1, crop_size, crop_size, COLOR_CHAN])\n        image = tf.image.resize_bicubic(image, [IMG_HEIGHT, IMG_WIDTH])\n        image = tf.cast(image, tf.float32) / 255.0\n        image_seq.append(image)\n\n        image_seq = tf.concat(0, image_seq)\n\n    return image_seq\n```\n\nWhen the training code runs to\n\n```\ntf.train.start_queue_runners(sess)\nsess.run(tf.initialize_all_variables())\n```\n\nI saw unreadable code:\n\n��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������~���~���|���|���~�������������������������������������������������������������������������������������������������������������������������������������������~���������������}�������������������������������������������������������������������������������������������������������������������������������������������������������~���}���}���~�������������������������������~���~���~���~���~���}��~|�~}{�~}{�~}{�~}{�~}{��~|���}���}���}���~���~���|���|���|���|���}���~���}���{�~}y�}|x�|{w�|{w�}|x�|{w�{zv�zyu�xws�wvr�vuq�utp�tso�tso�tso�utp�tso�utp�utp�utp�tso�tso�utp�utp�tso�utp�utp�vuq�wvr�xws�yxt�zyu�{zv�|{w�}|x�}|x�}|x�}|x�}|x�}|x�~}y�~}y�~}y�~}y�~}y�~}y�~}y�~}y�~}y�~}y�~}y�~}y�~}y�~}y�~}y�~}y�~}y�~}y�~}y�~}y�~}y�~}y�~}y�~}y�~}y�~}y�~}y�~}y�~}y�~}y�~}y�~}x��~y��~w��~w��~w��~w��~w��~w��~w��~w��~w��~W tensorflow/core/framework/op_kernel.cc:968] Invalid argument: Could not parse example input, value: '\n���<\n����\n�move/7/image/encoded�����\n����\n\nCan anyone tell me which part of the code is wrong?\n\nThanks very much in advance,\nAndy.\n"},"comment":{"url":"https://api.github.com/repos/tensorflow/tensorflow/issues/comments/257660167","html_url":"https://github.com/tensorflow/tensorflow/issues/5234#issuecomment-257660167","issue_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/5234","id":257660167,"user":{"login":"drpngx","id":20959853,"avatar_url":"https://avatars.githubusercontent.com/u/20959853?v=3","gravatar_id":"","url":"https://api.github.com/users/drpngx","html_url":"https://github.com/drpngx","followers_url":"https://api.github.com/users/drpngx/followers","following_url":"https://api.github.com/users/drpngx/following{/other_user}","gists_url":"https://api.github.com/users/drpngx/gists{/gist_id}","starred_url":"https://api.github.com/users/drpngx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/drpngx/subscriptions","organizations_url":"https://api.github.com/users/drpngx/orgs","repos_url":"https://api.github.com/users/drpngx/repos","events_url":"https://api.github.com/users/drpngx/events{/privacy}","received_events_url":"https://api.github.com/users/drpngx/received_events","type":"User","site_admin":false},"created_at":"2016-11-01T18:56:38Z","updated_at":"2016-11-01T18:56:38Z","body":"Wait... you're writing an `Example`, not `SequenceExample`?"}}
{"actor":{"display_login":"drpngx"}}