When training your own dataset, you often report errors:
tensorflow2.3 InvalidArgumentError: jpeg::Uncompress failed [[{{node decode_image/DecodeImage}}]] [Op:IteratorGetNext]
Solution:
check whether the picture is damaged before training:
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
import os
num_skipped = 0
for folder_name in ("Fruit apples", "Fruit bananas", "Fruit oranges"):
folder_path = os.path.join(".\data\image_data", folder_name)
for fname in os.listdir(folder_path):
fpath = os.path.join(folder_path, fname)
try:
fobj = open(fpath, mode="rb")
is_jfif = tf.compat.as_bytes("JFIF") in fobj.peek(10)
finally:
fobj.close()
if not is_jfif:
num_skipped += 1
# Delete corrupted image
os.remove(fpath)
print("Deleted %d images" % num_skipped)
Delete the damaged picture and train again to solve the problem
if an error is prompted again, use:
# Determine if an image is corrupt from local
def is_valid_image(path):
'''
Check if the file is corrupt
'''
try:
bValid = True
fileObj = open(path, 'rb') # Open in binary form
buf = fileObj.read()
if not buf.startswith(b'\xff\xd8'): # whether to start with \xff\xd8
bValid = False
elif buf[6:10] in (b'JFIF', b'Exif'): # ASCII code of "JFIF"
if not buf.rstrip(b'\0\r\n').endswith(b'\xff\xd9'): # whether it ends with \xff\xd9
bValid = False
else:
try:
Image.open(fileObj).verify()
except Exception as e:
bValid = False
print(e)
except Exception as e:
return False
return bValid
num_skipped = 0
for folder_name in ("fruit-apple", "fruit-banana", "fruit-orange"):
#os.path.join() joins two or more pathname components
folder_path = os.path.join(". \data\image_data", folder_name)
# os.listdir(path) lists the subdirectories under this directory
for fname in os.listdir(folder_path):
fpath = os.path.join(folder_path, fname)
flag1 = is_valid_image(fpath)
if not flag1:
print(flag1)
print(fpath)#Print the path and name of the error file
Adjust the error file and train again to solve the problem.
Read More:
- jpeg4py.JPEG(path).decode() Open Image Error [How to Solve]
- [Solved] Python Image Library fails with message “decoder JPEG not available” – PIL
- [Solved] TensorFlow Error: GetNext() failed because the iterator has not been initialized
- [Solved] TensorFlow Error: UnknownError (see above for traceback): Failed to get convolution algorithm.
- How to Solve Python Importerror: DLL load failed: unable to find the specified program using tensorflow
- ModuleNotFoundError: No module named ‘tensorflow.python’ And the pits encountered after installation
- [Solved] RuntimeError: Numpy is not available (Associated Torch or Tensorflow)
- Tensorflow: Common Usage of tf.get_variable_scope()
- [Solved] AttributeError: module ‘tensorflow._api.v2.train‘ has no attribute ‘AdampOptimizer‘
- [Solved] Tensorflow Error: NameError: name ‘layers‘ is not defined
- [Solved] Error: AttributeError: module ‘tensorflow‘ has no attribute ‘placeholder‘
- [Solved] Pytorch call tensorboard error: AttributeError: module ‘tensorflow’ has no attribute ‘gfile’
- PyCharm: How to Solve Tensorflow_datasets Import Error
- How to Fix tensorflow2.0 tf.placeholder Error
- [Solved] AttributeError: module ‘tensorflow‘ has no attribute ‘distributions‘
- Python AttributeError: module ‘tensorflow‘ has no attribute ‘InteractiveSession‘
- [Solved] R Error: Python module tensorflow.keras was not found.
- [Solved] bert_as_service startup error: Tensorflow 2.1.0 is not tested!
- from keras.preprocessing.text import Tokenizer error: AttributeError: module ‘tensorflow.compat.v2‘ has..
- Tensorflow import Error: ImportError: libcuda.so.1: cannot open shared object file: No such file or dire