[英]Invalid directory name Spyder Python
I've been trying to figure out how to solve this issue. 我一直在试图找出解决这个问题的方法。
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'
I'm using this fuction to set an annotation for all the images I send through the path. 我正在使用此功能来设置我通过路径发送的所有图像的注释。
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)
Here I set the path to use with the function above. 在这里,我设置了上面的函数使用的路径。
path = "C:/img/soft"
And here I call the setAnnotation()
function described before. 在这里,我调用了
setAnnotation()
描述的setAnnotation()
函数。
X_BW, y_BW = setAnnotation(path, 1, nclusters = clusters, clf = clf)
The error points to the following line in the setAnnotation()
function: 该错误指向
setAnnotation()
函数中的以下行:
X = getVLAD(os.path.join(newPath, file), clf, centroids, alpha)
I What I've search around is to use a .replace("\\\\", "/")
after os.path.join
in the setAnnotation()
function. 我正在搜索的是在
setAnnotation()
函数中的os.path.join
之后使用.replace("\\\\", "/")
。 But I don't know why is pointing to line 211 since I'm using 1
as representation
parameter, which must enter just in the first conditional. 但是我不知道为什么指向第211行,因为我使用
1
作为representation
参数,该参数必须在第一个条件中输入。
¿Any idea? 任何想法?
As mentioned above. 正如刚才提到的。 I solved the issue modifing the path.
我解决了修改路径的问题。
C:/img/
. C:/img/
。 So the function in charge of reading the files just starts searching for sub-folders after /img
and files ended with .jpg
, avoiding to try to put the JPG file as a sub-folder. 因此,负责读取文件的功能只是在
/img
之后开始搜索子文件夹,而文件以.jpg
结尾,避免尝试将JPG文件作为子文件夹。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.