我一直在试图找出解决这个问题的方法。
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)
我正在搜索的是在.replace("\\", "/")
函数中os.path.join
之后使用setAnnotation()
。但是我不知道为什么指向第211行,因为我使用1
作为representation
参数,该参数必须在第一个条件中输入。
??有什么主意吗?
答案 0 :(得分:0)
如上所述。我解决了修改路径的问题。 C:/img/
。因此,负责读取文件的功能只是在/img
之后开始搜索子文件夹,而文件以.jpg
结尾,从而避免尝试将JPG文件作为子文件夹。