function imdb = cnn_gender_setup_data(varargin)

opts.dataDir = fullfile('data','CelebA') ;
opts.lite = false ;
opts = vl_argparse(opts, varargin) ;

% -------------------------------------------------------------------------
%                                                  Load categories metadata
% -------------------------------------------------------------------------
trainFile = fullfile(opts.dataDir, 'Files', 'celebA_gender_train.txt') ;
valFile = fullfile(opts.dataDir, 'Files', 'celebA_gender_val.txt') ;
testFile = fullfile(opts.dataDir, 'Files', 'celebA_gender_test.txt') ;

fprintf('using training data in %s\n', trainFile) ;
fprintf('using validation data in %s\n', valFile) ;

%male corresponds to the value 1 in the files, and female corresponds to
%the value 2 in the files
cats = {'1','2'};
descrs = {'male', 'female'};

imdb.classes.name = cats ;
imdb.classes.description = descrs ;
imdb.imageDir = fullfile(opts.dataDir, 'images') ;

% -------------------------------------------------------------------------
%                                                           Training images
% -------------------------------------------------------------------------
trainData = importdata(trainFile,' ');
names = trainData(1).textdata;
labels = trainData(1).data; 

if numel(names) ~= 10000
  warning('Found %d training images instead of 10,000. Dropping training set.', numel(names)) ;
  names = {} ;
  labels =[] ;
end

imdb.images.id = numel(names) ;
imdb.images.name = names' ;
imdb.images.set = ones(1, numel(names)) ;
imdb.images.label = labels' ;

% -------------------------------------------------------------------------
%                                                         Validation images
% -------------------------------------------------------------------------

valData = importdata(valFile,' ');
names = valData(1).textdata;
labels = valData(1).data;

if numel(names) ~= 5000
  warning('Found %d instead of 5,000 validation images. Dropping validation set.', numel(names))
  names = {} ;
  labels =[] ;
end

imdb.images.id = horzcat(imdb.images.id, (1:numel(names)) + 100000) ;
imdb.images.name = horzcat(imdb.images.name, names') ;
imdb.images.set = horzcat(imdb.images.set, 2*ones(1,numel(names))) ;
imdb.images.label = horzcat(imdb.images.label, labels') ;

% -------------------------------------------------------------------------
%                                                               Test images
% -------------------------------------------------------------------------

testData = importdata(testFile,' ');
names = testData(1).textdata;
labels = testData(1).data;

if numel(names) ~= 5000
  warning('Found %d instead of 5,000 test images', numel(names))
end

imdb.images.id = horzcat(imdb.images.id, (1:numel(names)) + 200000) ;
imdb.images.name = horzcat(imdb.images.name, names') ;
imdb.images.set = horzcat(imdb.images.set, 3*ones(1,numel(names))) ;
imdb.images.label = horzcat(imdb.images.label, labels') ;

