簡體   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