当我要在文件夹中获取图像路径时出现错误。
path = os.fspath(path)
TypeError:预期的str,字节或os.PathLike对象,而不是列表
这是我的代码:
root_dir = './test/'
#######################Enumerate classes###################################
class_folders_train = glob.glob(os.path.join(root_dir, '*'))
print("class_folders_train :",class_folders_train)
train_paths = []
for idx, class_folder in enumerate(class_folders_train):
print("ok")
image_paths = glob.glob(os.path.join(class_folders_train, '*.tif'))
print("image_paths :",image_paths)
train_paths.extend([(im_path, idx) for im_path in image_paths])
print("train_paths :",train_paths)
所以我的代码在print(“ ok”)之后就死了...
答案 0 :(得分:1)
image_paths = glob.glob(os.path.join(class_folders_train, '*.tif'))
您在这里的意思可能是class_folder
,而不是class_folders_train
。