import os import cv2 if __name__ == '__main__': img_path=r'/home/cui/tianrui_projects/darknet53/code_data/raw_data/images/' label_path=r'/home/cui/tianrui_projects/darknet53/code_data/raw_data/labels/' #保证数据一致性 all_imgs=set(map(lambda p:p.split('.')[0],os.listdir(img_path))) all_labels=set(map(lambda p:p.split('.')[0],os.listdir(label_path))) print(all_imgs.issubset(all_labels) and all_labels.issubset(all_imgs))