DeepLearnToolbox
DeepLearnToolbox copied to clipboard
how to create my dataset
how to create my dataset I wonder what is differrent between train_x and train_y
Please let me know
Thank you in advance :-)
something like this:
clear;
n=900; % number of samples per class
w=28;
h=28;
pos_path= 'C:\positives';
im_list= dir([pos_path filesep '*.png']);
if(n>length(im_list))
n= length(im_list);
end
pos= zeros(h,w,n,'uint8');
for i=1:n
im= imresize(rgb2gray(imread([pos_path filesep im_list(i).name])),[h w]);
imshow(im,[]);
end
neg_path= 'C:\negatives';
im_list= dir([neg_path filesep '*.png']);
if(n>length(im_list))
n= length(im_list);
end
neg= zeros(h,w,n,'uint8');
for i=1:n
im= imresize(imread([neg_path filesep im_list(i).name]),[h w]);
neg(:,:,i)= im;
end
data = cat(3, neg, pos);
pos_y= [zeros(n,1)';ones(n,1)'];
neg_y= [ones(n,1)';zeros(n,1)'];
y= uint8([pos_y neg_y]);
%test-train split
idx= randperm(n*2);
per= 0.9; % 90%
train_x= data(:,:,idx(1:per*n*2));
train_y= y(:,idx(1:per*n*2));
test_x= data(:,:,idx(per*n*2+1:n*2));
test_y= y(:,idx(per*n*2+1:n*2));
% train_x= double(data(:,:,idx(1:0.8*n*2)))/255;
% train_y= double(y(:,idx(1:0.8*n*2)));
% test_x= double(data(:,:,idx(0.8*n*2+1:n*2)))/255;
% test_y= double(y(:,idx(0.8*n*2+1:n*2)));
save data/mydata_uint8.mat train_x train_y test_x test_y