python - 为什么尝试打开目录时会出现错误?
问题描述
所以基本上我要做的是从我的目录中获取我的文件,遵循本教程: 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
我更改了斜线,因为 \ 似乎不起作用但 / 确实......但我不认为斜线是问题
解决方案
您的 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']
推荐阅读
- java - 如何切换到新窗口并在 selenium webdriver 中打印标题(没有窗口句柄)
- python - 标准偏差和平均值计算的移动窗口
- sql - 为什么 SQL 语句中的 ORDER BY 子句不起作用
- c# - Blazor WASM - Link to file on .Server from .Client
- angular - POST 中的 Angular-oauth2-oidc loadDiscoveryDocument
- python - 几个气泡上有奇怪的颜色 - 情节/袖扣
- google-apps-script - 电子邮件中的按钮可更改谷歌表格中的单元格值
- python - 将对象列表到 DataFrame 到 Azure 上的 MySQL DB
- reactjs - React Semantic UI 分页(使用右箭头导航时第 2 页未突出显示)
- c - Makefile 在 C 中编译 2 个应用程序