首页 > 解决方案 > 为什么尝试打开目录时会出现错误?

问题描述

所以基本上我要做的是从我的目录中获取我的文件,遵循本教程: https ://www.youtube.com/watch?v= j-3vuBynnOE 和这个 kaggle 数据集:https://www。 kaggle.com/rishianand/devanagari-character-set

但它似乎错误?


#loading in data from kaggle 
#from :https://www.youtube.com/watch?v=j-3vuBynnOE

#importing the libraries to see the actual images
import numpy as np 
import matplotlib.pyplot as plt 
import os
import cv2

#the kaggle download had three folders(consonants, vowels and numbers), looking at the vowels number

DATADIR=  "C:/Users/binju/Downloads/archive.zip/Images/Images"
CAT= ['character_1_ka', 'character_2_kha',  'character_3_ga',  'character_4_gha',  'character_5_kna']
#paths directory


for category in CAT:
    path= os.path.join(DATADIR, category)
    print("this is the path:", path)
    for img in os.listdir(path):
        print(img)
        #converting images into arrays
        img_array= cv2.imread(os.path.join(path, img), cv2.IMREAD_GRAYSCALE)
        plt.imshow(img_array, cmap="gray")
        plt.show()
        break
    break

和错误:

  File "c:\Users\binju\csgr12project.py", line 29, in <module>Images\character_1_ka                                                              _ka
    for img in os.listdir(path):
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'C:/Users/binju/Downloads/archive.zip/Images/Images/character_1_ka'                                            

但是当我下载我的实际文件并按下它时,这就是显示的内容:

C:\Users\binju\Downloads\archive.zip\Images\Images\character_01_ka

我更改了斜线,因为 \ 似乎不起作用但 / 确实......但我不认为斜线是问题

标签: pythondirectory

解决方案


您的 CAT 包含

CAT= ['character_1_ka', 'character_2_kha',  'character_3_ga',  'character_4_gha',  'character_5_kna']

当文件被调用时

CAT= ['character_01_ka', 'character_02_kha',  'character_03_ga',  'character_04_gha',  'character_05_kna']

推荐阅读