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"]]
python tensorflow-datasets
add a comment |
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"]]
python tensorflow-datasets
add a comment |
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"]]
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 at 5:12
Rajesh Pandya
1,2731819
1,2731819
asked Nov 13 at 5:09
WEN WEN
54
54
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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