繁体   English   中英

无效的目录名称Spyder Python

[英]Invalid directory name Spyder 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()描述的setAnnotation()函数。

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

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

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

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

任何想法?

正如刚才提到的。 我解决了修改路径的问题。 C:/img/ 因此,负责读取文件的功能只是在/img之后开始搜索子文件夹,而文件以.jpg结尾,避免尝试将JPG文件作为子文件夹。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM