当前位置:网站首页>处理imagenet2012数据集
处理imagenet2012数据集
2022-07-20 18:00:00 【Fu_Xingwen】
下载的imagenet2012数据集是
ILSVRC2012_img_train.tar 和 ILSVRC2012_img_val.tar这样的两个数据
首先解压文件
mkdir train
mkdir val
tar xvf ILSVRC2012_img_train.tar -C ./train
tar xvf ILSVRC2012_img_val.tar -C ./val
对于train的压缩包,解压之后其实还是1000个tar压缩包(对应1000个类别),需要再次解压
import tarfile
import os
def un_tar(file_name):
tar = tarfile.open(file_name)
file_name = file_name.split('.')[0]
"""解压tar"""
print(file_name)
names = tar.getnames()
temp_file_path = ''
if os.path.isdir(file_name):
print('文件已存在')
temp_file_path = os.path.isdir(file_name)
else:
temp_file_path = os.mkdir(file_name)
print('创建一个新的文件名')
#因为解压后是很多文件,预先建立同名目录
for name in names:
tar.extract(name, file_name)
tar.close()
return temp_file_path
filePath = 'train'
for tar in os.listdir(filePath):
un_tar(filePath + '/' + tar)
os.remove(filePath + '/' + tar)
整理测试集(需要ILSVRC2012_devkit_t12.tar.gz)
from scipy import io
import os
import shutil
def move_valimg(val_dir='./val', devkit_dir='./ILSVRC2012_devkit_t12'):
""" move valimg to correspongding folders. val_id(start from 1) -> ILSVRC_ID(start from 1) -> WIND organize like: /val /n01440764 images /n01443537 images ..... """
# load synset, val ground truth and val images list
synset = io.loadmat(os.path.join(devkit_dir, 'data', 'meta.mat'))
ground_truth = open(os.path.join(devkit_dir, 'data', 'ILSVRC2012_validation_ground_truth.txt'))
lines = ground_truth.readlines()
labels = [int(line[:-1]) for line in lines]
root, _, filenames = next(os.walk(val_dir))
for filename in filenames:
# val image name -> ILSVRC ID -> WIND
val_id = int(filename.split('.')[0].split('_')[-1])
ILSVRC_ID = labels[val_id-1]
WIND = synset['synsets'][ILSVRC_ID-1][0][1][0]
print("val_id:%d, ILSVRC_ID:%d, WIND:%s" % (val_id, ILSVRC_ID, WIND))
# move val images
output_dir = os.path.join(root, WIND)
if os.path.isdir(output_dir):
pass
else:
os.mkdir(output_dir)
shutil.move(os.path.join(root, filename), os.path.join(output_dir, filename))
if __name__ == '__main__':
move_valimg()
边栏推荐
- 看了这篇我也懂了this
- Leetcode exercise - Sword finger offer 66 Build product array
- In case of misdiagnosis and / or missed diagnosis or misdiagnosis of hepatobiliary surgical diseases, the medical institution shall bear the main liability for compensation
- 国密curl的用法指南
- 【Matplotlib 画图】
- 使用 GCC 避免堆栈粉碎攻击
- WinForm UI interface design routine - multi thread access UI control
- 绘图库MatplotlibMatplotlib快速入门
- Develop a remote control software using easy language
- 731. 我的日程安排表 II(线段树或查分数组)
猜你喜欢
Qt简单串口助手
shell基础之逻辑控制
[email protected]"/>
@typescript-eslint/[email protected]
华为路由器:ISIS基本原理与配置(含实验)
Unhandled JS Exception: Unexpected identifier ‘_ classCallCheck‘. import call expects exactly one arg
重新定义分析 - EventBridge 实时事件分析平台发布
22张图带你深入剖析前缀、中缀、后缀表达式以及表达式求值
How to set measurable project goals?
WinForm UI interface design routine - multi thread access UI control
shell简介以及变量定义
随机推荐
选择ECS上的自建数据库这种接入方式,有哪些需要注意的事项?
When does MySQL use table locks and row locks?
新手小白如何搭建个人的服务器?
中国钨粉行业市场研究与投资预测报告(2022版)
一代「博雅」大师离世!缅怀复旦大学原校长、中国科学院院士杨福家教授
LED数显驱动IC、抗干扰LED数码管显示驱动IC-VK1S68C SSOP24,适用指夹式脉搏血氧仪、臂式电子血压计、体温计、胎心仪、理疗仪、监护仪等,支持70/66/60/52点阵。
Markdown syntax - mathematical expressions
What is a database without public ip: port?
【格式化字符串】格式化字符串漏洞的原理与利用
[译]深入了解现代web浏览器(四)
Shutter animation animation
中国1,2-戊二醇行业研究与投资战略报告(2022版)
和前面just K那题一个类型的题目
MQ发布确认
如何实现FinClip微信授权登录的三种方案
A generation of "Boya" masters passed away! Memory of Professor yangfujia, former president of Fudan University and academician of the Chinese Academy of Sciences
选择RDS实例接入数据库方式时,需要怎么做?
正则表达式获取两个标识中间的内容
shell基础之逻辑控制
【图像处理】Pyefd.elliptic_fourier_descriptors的使用方式