[英]The system cannot find the path specified: ' '
I am trying to split my image data set into train test and val.我正在尝试将我的图像数据集拆分为训练测试和验证。 It has already created the train, test and val folders, but its empty as I keep encountering an error.它已经创建了 train、test 和 val 文件夹,但它是空的,因为我一直遇到错误。 This is the code I am trying to run on jupyter notebook, I have imported the required libraries like os, numoy, shutil, random:这是我试图在 jupyter notebook 上运行的代码,我已经导入了所需的库,如 os、numoy、shutil、random:
# # Creating Train / Val / Test folders
root_dir = 'Desktop/sem_8_project/brain/brain_tumor_dataset/' # data root path
classes_dir = ['no', 'yes'] #total labels
val_ratio = 0.15
test_ratio = 0.05
for cls in classes_dir:
os.makedirs(root_dir +'train/' + cls)
os.makedirs(root_dir +'val/' + cls)
os.makedirs(root_dir +'test/' + cls)
for cls in classes_dir:
src = root_dir + cls # Folder to copy images from
allFileNames = os.listdir(src)
np.random.shuffle(allFileNames)
train_FileNames, val_FileNames, test_FileNames = np.split(np.array(allFileNames),
and this is the error it shows:这是它显示的错误:
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
<ipython-input-34-e2cee9006649> in <module>
3 src = root_dir + cls # Folder to copy images from
4
----> 5 allFileNames = os.listdir(src)
6 np.random.shuffle(allFileNames)
7 train_FileNames, val_FileNames, test_FileNames = np.split(np.array(allFileNames),
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'Desktop/sem_8_project/brain/brain_tumor_dataset/no'
As the error message stated, python can not find the directory you provided.如错误消息所述,python 找不到您提供的目录。 You can not access to Desktop/ directly, but have to specify address of it.您不能直接访问 Desktop/,但必须指定它的地址。 Try this code as the link to desktop.试试这个代码作为桌面的链接。
os.path.join(os.environ['HOMEPATH'], 'Desktop')
In the last 4 lines of code instead of using: allFileNames = os.listdir(src)
I used:在最后 4 行代码而不是使用: allFileNames = os.listdir(src)
我使用:
allFileNames = []
for filename in os.listdir(src):
img = cv2.imread(os.path.join(src,filename))
if img is not None:
allFileNames.append(img)
This worked for me and the directory error got fixed.这对我有用,目录错误得到了修复。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.