无效的目录名称Spyder Python

2024-10-02 00:26:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在想办法解决这个问题。你知道吗

 File "<ipython-input-27-0b2b3f4a72cc>", line 5, in <module>
    X_BW, y_BW = setAnnotation(path, 1, nclusters = clusters, clf = clf)

  File "<ipython-input-26-6f5632d48ec5>", line 211, in setAnnotation
    for file in os.listdir(newPath):

NotADirectoryError: [WinError 267] Invalid directory name: 'C:/img/soft/leftshoe10.jpg'

我用这个函数为我通过路径发送的所有图像设置注释。你知道吗

def setAnnotation(path, representation, nclusters = None, clf = None, centroids = None, gmm = None, alpha = None):
    c = 0
    for folder in os.listdir(path):
        newPath = os.path.join(path, folder).replace("\\", "/")
        annotation = os.path.basename(newPath)
        print(newPath)
        for file in os.listdir(newPath):
            if file.endswith(".jpg"):
                if c == 0:
                    if representation == 1:
                        X = getBOF(os.path.join(newPath, file), clf, nclusters)
                        print("PRUEBA CON BOW")
                    elif representation == 2:
                        X = getVLAD(os.path.join(newPath, file), clf, centroids, alpha)
                        print("PRUEBA CON VLAD")
                    elif representation == 3:
                        X = getFV(os.path.join(newPath, file), gmm)
                        y = annotation
                        c = c + 1
                        print("PRUEBA CON FV")
                else:
                    if representation == 1:
                        X = np.vstack((X, getBOF(os.path.join(newPath, file), clf, nclusters)))
                        print("PRUEBA CON BOW")
                    elif representation == 2:
                        X = np.vstack((X, getVLAD(os.path.join(newPath, file), clf, centroids, alpha)))
                        print("PRUEBA CON VLAD")
                    elif representation == 3:
                        X = np.vstack((X, getFV(os.path.join(newPath, file), gmm)))
                        print("PRUEBA CON FV")
                y = np.concatenate((y, annotation), axis = None)
    print("Anotación finalizada.")
    return(X,y)

在这里,我设置了与上述函数一起使用的路径。你知道吗

path = "C:/img/soft"

这里我调用前面描述的setAnnotation()函数。你知道吗

X_BW, y_BW = setAnnotation(path, 1, nclusters = clusters, clf = clf)

错误指向setAnnotation()函数中的以下行:

X = getVLAD(os.path.join(newPath, file), clf, centroids, alpha)

我搜索的是在setAnnotation()函数中的.replace("\\", "/")后面使用os.path.join。但是我不知道为什么指向211行,因为我使用1作为representation参数,它必须在第一个条件中输入。你知道吗

有什么想法吗?你知道吗


Tags: path函数innoneosconfileprueba
1条回答
网友
1楼 · 发布于 2024-10-02 00:26:56

如上所述。我解决了修改路径的问题。C:/img/。因此,负责读取文件的函数只在/img之后开始搜索子文件夹,文件以.jpg结束,避免将JPG文件作为子文件夹。你知道吗

相关问题 更多 >

    热门问题