save CIFAR-100 images

15 次查看(过去 30 天)
Abo
Abo 2017-3-13
评论: Komal B 2019-11-8
dear all, I'm working with CIFAR-100 images for training CNN, available here: https://www.cs.toronto.edu/~kriz/cifar-10-matlab.tar.gz
as im extracting the file, would see different mat files (each contain one called 'labels' another 'data'). any body know what is labels and data? how can i do the same for my own data? I meant save my images as mat file with data and labels? thanks

回答(1 个)

Antonio Cedillo Hernandez
编辑:Antonio Cedillo Hernandez 2018-5-5
Hi Abo! I apologize if my answer is too late, but as there is 21 views of this question in last 30 days, so I will post my answer to your question. There are three MAT files called meta.dat, test.mat and train.mat. All of them are matrices with data in order to guide the correct extracting process of the images. Here is my code to extract the images from the dataset:
if true
clc;
clear all;
load('meta.mat');
%Create folders
for i=1:length(fine_label_names)
mkdir('CIFAR-100\TEST\',fine_label_names{i});
mkdir('CIFAR-100\TRAIN\',fine_label_names{i});
end
%%Training images
load('train.mat');
im=zeros(32,32,3);
for cpt=1:50000
R=data(cpt,1:1024);
G=data(cpt,1025:2048);
B=data(cpt,2049:3072);
k=1;
for x=1:32
for i=1:32
im(x,i,1)=R(k);
im(x,i,2)=G(k);
im(x,i,3)=B(k);
k=k+1;
end
end
im=uint8(im);
pathdest = strcat('CIFAR-100\TRAIN\',fine_label_names{fine_labels(cpt)+1},'\',filenames{cpt});
imwrite(im,pathdest,'png');
end
%%Test images
load('test.mat');
im=zeros(32,32,3);
for cpt=1:10000
R=data(cpt,1:1024);
G=data(cpt,1025:2048);
B=data(cpt,2049:3072);
k=1;
for x=1:32
for i=1:32
im(x,i,1)=R(k);
im(x,i,2)=G(k);
im(x,i,3)=B(k);
k=k+1;
end
end
im=uint8(im);
pathdest = strcat('CIFAR-100\TEST\',fine_label_names{fine_labels(cpt)+1},'\',filenames{cpt});
imwrite(im,pathdest,'png');
end
end
  4 个评论
Toshi Sinha
Toshi Sinha 2019-6-3
Download 7-zip and extract the ".tar.gz" files using it. They will be extracted to a folder now you can see all .mat files
Komal B
Komal B 2019-11-8
Thanks a lot Antonio. That program works like a charm.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Image Data Workflows 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by