目录名称无效NotADirectoryError

问题遇到的现象和发生背景

在读取文件目录时发生错误
NotADirectoryError: [WinError 267] 目录名称无效。: 'D:\keras\face detect_project\data\wanggeng\0.jpg'

问题相关代码,请勿粘贴截图

images=[]
labels=[]
def read_path(path_name):
#得到该路径下所有图片的绝对路径
for dir_item in os.listdir(path_name):#列出path_name中所有文件夹的名称
full_path=os.path.abspath(os.path.join(path_name,dir_item))
if os.path.isdir(path_name):
read_path(full_path)
else:
if dir_item.endswith(".jpg"):
image=cv2.imread(full_path)
image=resize_image(image,IMAGE_SIZE,IMAGE_SIZE)
cv2.imwrite("1.jpg",image)
images.append(image)
labels.append(path_name)
return images,labels

运行结果及报错内容

NotADirectoryError: [WinError 267] 目录名称无效。: 'D:\keras\face detect_project\data\wanggeng\0.jpg'

我的解答思路和尝试过的方法
我想要达到的结果