tf.data.Dataset InvalidArgumentError: Expected image (JPEG, PNG, or GIF), got empty file











up vote
0
down vote

favorite












import os
from PIL import Image, ImageFile
import tensorflow as tf
import numpy as np


ImageFile.LOAD_TRUNCATED_IMAGES = True

CWD = '/home/qinlong/PycharmProjects/ProgNEU/NEU/cai_nl/classes'

def convert_to_tfrecord(cwd, output):
classes = os.listdir(cwd)
writer = tf.python_io.TFRecordWriter(output)
for index, name in enumerate(classes):
class_path = cwd + '/' + name + '/'
for img_name in os.listdir(class_path):
img_path = class_path + img_name

img = Image.open(img_path)
img = img.resize((64, 64))
img_raw = img.tobytes()
example = tf.train.Example(features=tf.train.Features(feature={
'label': tf.train.Feature(int64_list=tf.train.Int64List(value=[index])),
'img_raw': tf.train.Feature(bytes_list = tf.train.BytesList(value=[img_raw]))
}))
writer.write(example.SerializeToString())
writer.close()
return output


def dataset_input_fn(batch_size, epoch, buffer_size=2048):
filenames = ['/home/qinlong/PycharmProjects/ProgNEU/NEU/cai_nl/a_4.tfrecord']
dataset = tf.data.TFRecordDataset(filenames)

def parser(record):
keys_to_features = {
"image_data": tf.FixedLenFeature((), tf.string, default_value=""),
"date_time": tf.FixedLenFeature((), tf.int64, default_value=0),
"label": tf.FixedLenFeature((), tf.int64,
default_value=tf.zeros(, dtype=tf.int64)),
}
parsed = tf.parse_single_example(record, keys_to_features)

# Perform additional preprocessing on the parsed data.
image = tf.image.decode_jpeg(parsed["image_data"])
image = tf.reshape(image, [64, 64, 3])
label = tf.cast(parsed["label"], tf.int32)

return {"image_data": image, "date_time": parsed["date_time"]}, label

dataset = dataset.map(parser)
dataset = dataset.shuffle(buffer_size=10000)
dataset = dataset.batch(batch_size=batch_size)
dataset = dataset.repeat(epoch)

iterator = dataset.make_one_shot_iterator()

features, labels = iterator.get_next()
return features, labels



InvalidArgumentError: Expected image (JPEG, PNG, or GIF), got empty
file [[{{node DecodeJpeg}} = DecodeJpegacceptable_fraction=1,
channels=0, dct_method="", fancy_upscaling=true, ratio=1,
try_recover_truncated=false]]
[[node IteratorGetNext (defined at
/home/qinlong/PycharmProjects/ProgNEU/NEU/cai_nl/main.py:23) =
IteratorGetNextoutput_shapes=[[?], [?,64,64,3], [?]],
output_types=[DT_INT64, DT_UINT8, DT_INT32],
_device="/job:localhost/replica:0/task:0/device:CPU:0"]]











share|improve this question




























    up vote
    0
    down vote

    favorite












    import os
    from PIL import Image, ImageFile
    import tensorflow as tf
    import numpy as np


    ImageFile.LOAD_TRUNCATED_IMAGES = True

    CWD = '/home/qinlong/PycharmProjects/ProgNEU/NEU/cai_nl/classes'

    def convert_to_tfrecord(cwd, output):
    classes = os.listdir(cwd)
    writer = tf.python_io.TFRecordWriter(output)
    for index, name in enumerate(classes):
    class_path = cwd + '/' + name + '/'
    for img_name in os.listdir(class_path):
    img_path = class_path + img_name

    img = Image.open(img_path)
    img = img.resize((64, 64))
    img_raw = img.tobytes()
    example = tf.train.Example(features=tf.train.Features(feature={
    'label': tf.train.Feature(int64_list=tf.train.Int64List(value=[index])),
    'img_raw': tf.train.Feature(bytes_list = tf.train.BytesList(value=[img_raw]))
    }))
    writer.write(example.SerializeToString())
    writer.close()
    return output


    def dataset_input_fn(batch_size, epoch, buffer_size=2048):
    filenames = ['/home/qinlong/PycharmProjects/ProgNEU/NEU/cai_nl/a_4.tfrecord']
    dataset = tf.data.TFRecordDataset(filenames)

    def parser(record):
    keys_to_features = {
    "image_data": tf.FixedLenFeature((), tf.string, default_value=""),
    "date_time": tf.FixedLenFeature((), tf.int64, default_value=0),
    "label": tf.FixedLenFeature((), tf.int64,
    default_value=tf.zeros(, dtype=tf.int64)),
    }
    parsed = tf.parse_single_example(record, keys_to_features)

    # Perform additional preprocessing on the parsed data.
    image = tf.image.decode_jpeg(parsed["image_data"])
    image = tf.reshape(image, [64, 64, 3])
    label = tf.cast(parsed["label"], tf.int32)

    return {"image_data": image, "date_time": parsed["date_time"]}, label

    dataset = dataset.map(parser)
    dataset = dataset.shuffle(buffer_size=10000)
    dataset = dataset.batch(batch_size=batch_size)
    dataset = dataset.repeat(epoch)

    iterator = dataset.make_one_shot_iterator()

    features, labels = iterator.get_next()
    return features, labels



    InvalidArgumentError: Expected image (JPEG, PNG, or GIF), got empty
    file [[{{node DecodeJpeg}} = DecodeJpegacceptable_fraction=1,
    channels=0, dct_method="", fancy_upscaling=true, ratio=1,
    try_recover_truncated=false]]
    [[node IteratorGetNext (defined at
    /home/qinlong/PycharmProjects/ProgNEU/NEU/cai_nl/main.py:23) =
    IteratorGetNextoutput_shapes=[[?], [?,64,64,3], [?]],
    output_types=[DT_INT64, DT_UINT8, DT_INT32],
    _device="/job:localhost/replica:0/task:0/device:CPU:0"]]











    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      import os
      from PIL import Image, ImageFile
      import tensorflow as tf
      import numpy as np


      ImageFile.LOAD_TRUNCATED_IMAGES = True

      CWD = '/home/qinlong/PycharmProjects/ProgNEU/NEU/cai_nl/classes'

      def convert_to_tfrecord(cwd, output):
      classes = os.listdir(cwd)
      writer = tf.python_io.TFRecordWriter(output)
      for index, name in enumerate(classes):
      class_path = cwd + '/' + name + '/'
      for img_name in os.listdir(class_path):
      img_path = class_path + img_name

      img = Image.open(img_path)
      img = img.resize((64, 64))
      img_raw = img.tobytes()
      example = tf.train.Example(features=tf.train.Features(feature={
      'label': tf.train.Feature(int64_list=tf.train.Int64List(value=[index])),
      'img_raw': tf.train.Feature(bytes_list = tf.train.BytesList(value=[img_raw]))
      }))
      writer.write(example.SerializeToString())
      writer.close()
      return output


      def dataset_input_fn(batch_size, epoch, buffer_size=2048):
      filenames = ['/home/qinlong/PycharmProjects/ProgNEU/NEU/cai_nl/a_4.tfrecord']
      dataset = tf.data.TFRecordDataset(filenames)

      def parser(record):
      keys_to_features = {
      "image_data": tf.FixedLenFeature((), tf.string, default_value=""),
      "date_time": tf.FixedLenFeature((), tf.int64, default_value=0),
      "label": tf.FixedLenFeature((), tf.int64,
      default_value=tf.zeros(, dtype=tf.int64)),
      }
      parsed = tf.parse_single_example(record, keys_to_features)

      # Perform additional preprocessing on the parsed data.
      image = tf.image.decode_jpeg(parsed["image_data"])
      image = tf.reshape(image, [64, 64, 3])
      label = tf.cast(parsed["label"], tf.int32)

      return {"image_data": image, "date_time": parsed["date_time"]}, label

      dataset = dataset.map(parser)
      dataset = dataset.shuffle(buffer_size=10000)
      dataset = dataset.batch(batch_size=batch_size)
      dataset = dataset.repeat(epoch)

      iterator = dataset.make_one_shot_iterator()

      features, labels = iterator.get_next()
      return features, labels



      InvalidArgumentError: Expected image (JPEG, PNG, or GIF), got empty
      file [[{{node DecodeJpeg}} = DecodeJpegacceptable_fraction=1,
      channels=0, dct_method="", fancy_upscaling=true, ratio=1,
      try_recover_truncated=false]]
      [[node IteratorGetNext (defined at
      /home/qinlong/PycharmProjects/ProgNEU/NEU/cai_nl/main.py:23) =
      IteratorGetNextoutput_shapes=[[?], [?,64,64,3], [?]],
      output_types=[DT_INT64, DT_UINT8, DT_INT32],
      _device="/job:localhost/replica:0/task:0/device:CPU:0"]]











      share|improve this question















      import os
      from PIL import Image, ImageFile
      import tensorflow as tf
      import numpy as np


      ImageFile.LOAD_TRUNCATED_IMAGES = True

      CWD = '/home/qinlong/PycharmProjects/ProgNEU/NEU/cai_nl/classes'

      def convert_to_tfrecord(cwd, output):
      classes = os.listdir(cwd)
      writer = tf.python_io.TFRecordWriter(output)
      for index, name in enumerate(classes):
      class_path = cwd + '/' + name + '/'
      for img_name in os.listdir(class_path):
      img_path = class_path + img_name

      img = Image.open(img_path)
      img = img.resize((64, 64))
      img_raw = img.tobytes()
      example = tf.train.Example(features=tf.train.Features(feature={
      'label': tf.train.Feature(int64_list=tf.train.Int64List(value=[index])),
      'img_raw': tf.train.Feature(bytes_list = tf.train.BytesList(value=[img_raw]))
      }))
      writer.write(example.SerializeToString())
      writer.close()
      return output


      def dataset_input_fn(batch_size, epoch, buffer_size=2048):
      filenames = ['/home/qinlong/PycharmProjects/ProgNEU/NEU/cai_nl/a_4.tfrecord']
      dataset = tf.data.TFRecordDataset(filenames)

      def parser(record):
      keys_to_features = {
      "image_data": tf.FixedLenFeature((), tf.string, default_value=""),
      "date_time": tf.FixedLenFeature((), tf.int64, default_value=0),
      "label": tf.FixedLenFeature((), tf.int64,
      default_value=tf.zeros(, dtype=tf.int64)),
      }
      parsed = tf.parse_single_example(record, keys_to_features)

      # Perform additional preprocessing on the parsed data.
      image = tf.image.decode_jpeg(parsed["image_data"])
      image = tf.reshape(image, [64, 64, 3])
      label = tf.cast(parsed["label"], tf.int32)

      return {"image_data": image, "date_time": parsed["date_time"]}, label

      dataset = dataset.map(parser)
      dataset = dataset.shuffle(buffer_size=10000)
      dataset = dataset.batch(batch_size=batch_size)
      dataset = dataset.repeat(epoch)

      iterator = dataset.make_one_shot_iterator()

      features, labels = iterator.get_next()
      return features, labels



      InvalidArgumentError: Expected image (JPEG, PNG, or GIF), got empty
      file [[{{node DecodeJpeg}} = DecodeJpegacceptable_fraction=1,
      channels=0, dct_method="", fancy_upscaling=true, ratio=1,
      try_recover_truncated=false]]
      [[node IteratorGetNext (defined at
      /home/qinlong/PycharmProjects/ProgNEU/NEU/cai_nl/main.py:23) =
      IteratorGetNextoutput_shapes=[[?], [?,64,64,3], [?]],
      output_types=[DT_INT64, DT_UINT8, DT_INT32],
      _device="/job:localhost/replica:0/task:0/device:CPU:0"]]








      python tensorflow-datasets






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 13 at 5:12









      Rajesh Pandya

      1,2731819




      1,2731819










      asked Nov 13 at 5:09









      WEN WEN

      54




      54





























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53274196%2ftf-data-dataset-invalidargumenterror-expected-image-jpeg-png-or-gif-got-em%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53274196%2ftf-data-dataset-invalidargumenterror-expected-image-jpeg-png-or-gif-got-em%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

          ComboBox Display Member on multiple fields

          Is it possible to collect Nectar points via Trainline?