tf.data.Dataset InvalidArgumentError: Expected image (JPEG, PNG, or GIF), got empty file
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
add a comment |
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
add a comment |
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
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
python tensorflow-datasets
edited Nov 13 '18 at 5:12
Rajesh Pandya
1,3112819
1,3112819
asked Nov 13 '18 at 5:09
WEN WENWEN WEN
517
517
add a comment |
add a comment |
0
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',
autoActivateHeartbeat: false,
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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