Tensorflow reported an error when reading the picture

1. The program is very simple to read picture data

2. Code
import tensorflow as tf
import os

def read_image (file_list):

def _parse_function(file_list):
    
    image_decoded = tf.image.decode_png(file_list)
    image_resized = tf.image.resize_images(image_decoded,[144,144])
    return image_resized
 
dataset = tf.data.Dataset.from_tensor_slices(file_list)  
dataset = dataset.map(_parse_function)
print(dataset)

iterator = dataset.make_one_shot_iterator()
x = iterator.get_next()

with tf.Session() as sess: 
    for i in range(2):
        print(sess.run(x))

return None

if name ="_ _ main__":

file_name = os.listdir("./data/img")

file_list = [os.path.join("./data/img",file) for file in file_name]  
print(file_list)
file_list = tf.constant(file_list)
print(file_list)
read_image(file_list)

3. Error report:
InvalidArgumentError: Expected image (JPEG, PNG, or GIF), got unknown format starting with". / data/img/.DS_S"

 [[{{node DecodePng}} = DecodePng[channels=0, dtype=DT_UINT8](arg0)]]
 [[node IteratorGetNext_2 (defined at /Users/apple/PythonProjects/dl/read.py:29)  = IteratorGetNext[output_shapes=[[144,144,?]], output_types=[DT_FLOAT], _device="/job:localhost/replica:0/task:0/device:CPU:0"](OneShotIterator_2)]]

Apr.19,2022
Menu