自己的分类数据集处理为ILSVRC数据集的格式 您所在的位置:网站首页 ilsvrc数据集 自己的分类数据集处理为ILSVRC数据集的格式

自己的分类数据集处理为ILSVRC数据集的格式

2023-08-15 09:38| 来源: 网络整理| 查看: 265

文章目录 前言一、原始数据集二、格式转换总结

前言

本篇主要介绍如何将已有的图像分类数据集转换为ILSVRC格式的数据集

一、原始数据集

原始分类数据集的数据结构大致如下: 在这里插入图片描述 然后train和val目录下是我们以类别名命名的文件夹,如图: 在这里插入图片描述 也就是需要满足如下结构:

-数据集 -train -class1 -class2 ... -val -class1 -class2 二、格式转换

转换代码如下:

import os root=""#数据集根目录 class_id={} #类别对应id的字典,如:{class1:0,class2:1} ,这个一定要记住 def create_txt(filename,mode): filepath=os.path.join(root,filename) with open(filepath,"a+") as f: img_dir=os.path.join(root,mode) for root1,dirs,files in os.walk(img_dir): for file in files: classname=root1.split(os.path.sep)[-1] imgpath=os.path.join(root1,file) data=imgpath+" "+str(class_id[classname])+"\n" f.write(data) if __name__ == '__main__': create_txt("val.txt","val") #训练集即为create_txt("train.txt","train")

执行完后,会在train和val的统计目录生成train.txt和val.txt,如图: 在这里插入图片描述 里面记录的信息就是图片路径+类别id

总结

以上就是本篇的全部内容,如有问题,欢迎评论区交流



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有