自己的分类数据集处理为ILSVRC数据集的格式 | 您所在的位置:网站首页 › ilsvrc数据集 › 自己的分类数据集处理为ILSVRC数据集的格式 |
文章目录
前言一、原始数据集二、格式转换总结
前言
本篇主要介绍如何将已有的图像分类数据集转换为ILSVRC格式的数据集 一、原始数据集原始分类数据集的数据结构大致如下: 转换代码如下: 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,如图: 以上就是本篇的全部内容,如有问题,欢迎评论区交流 |
CopyRight 2018-2019 实验室设备网 版权所有 |