删除VOC数据集,没有对应xml的图片文件

        path =""
        dirs_img = os.listdir(os.path.join(path, "JPEGImages"))
        dirs_annotations = os.listdir(os.path.join(path, "annotations"))

        for item_img in dirs_img:
            name_img = str(item_img).split(".")[0]

            isFound = False
            for item_annotations in dirs_annotations:
                if name_img in item_annotations:
                    isFound = True

            if not isFound:
                os.remove(os.path.join(path, "JPEGImages", item_img))

  

 

posted @ 2023-08-02 15:09  Lyxin_c  阅读(15)  评论(0编辑  收藏  举报