FileNotFoundError: [Errno 2] No such file or directory: ‘./mnist_image_label/mnist_train_jpg_6000028

FileNotFoundError: [Errno 2] No such file or directory: ‘./mnist_image_label/mnist_train_jpg_6000028755_0.jpg’

在tensorflow中读取文件报错

Traceback (most recent call last):
  File "Tensorflow/Test/9-26 mnist_train_ex1.py", line 43, in <module>
    x_train,y_train = generateds(train_path,train_txt)
  File "Tensorflow/Test/9-26 mnist_train_ex1.py", line 25, in generateds
    img = Image.open(img_path) #读入图片
  File "\envs\tf2.0-gpu\lib\site-packages\PIL\Image.py", line 2878, in open
    fp = builtins.open(filename, "rb")
FileNotFoundError: [Errno 2] No such file or directory: './mnist_image_label/mnist_train_jpg_6000028755_0.jpg'

定位到第25行代码

img = Image.open(img_path) #读入图片

读入图片出错
查看路径

train_path = './mnist_image_label/mnist_train_jpg_60000'

发现是少了 " \ "

反思基础,在此总结

此处要读取的是文件下的内容,所有要加反斜杠

本人小白,欢迎交流

你可能感兴趣的:(tensorflow,python)