function rgbdtrain(CAT)
% Train category detectors

addpath(genpath('..'));

CAT = sscanf(CAT,'%d');

OBJECTS = {'bowl', 'cap', 'cereal_box', 'coffee_mug', 'soda_can'};
OBJECT = OBJECTS{CAT};

DATADIR = '/projects/robomap3/nobackup/kevinlai/rgbddata/';

MODELDIR = [pwd '/model/'];
mkdir(MODELDIR);

% set model parameters
model.category = OBJECT;
model.instance = 0; % 0 = train category model
model.imagetag = 1;
model.depthtag = 1; 
model.bboxfactor = 0.8;
model.grid = 6;
model.samgrid = 200;
model.datadir.bgdir = [DATADIR 'background/'];
model.datadir.objdir = [DATADIR 'train/'];

model

% crop image;
model = rgbdcrop(model);
% set model parameters
model.sfactor = 1.1;
% crop background;
model = rgbdneg(model);
% train detector
model = rgbdclassifier(model);
% save model
model.cropfea = [];
model.negfea = [];
if model.instance == 0
   if model.imagetag == 1 & model.depthtag == 1
      model.datadir.modeldir = [MODELDIR model.category '_joint'];
   elseif model.imagetag == 1 & model.depthtag == 0
      model.datadir.modeldir = [MODELDIR model.category '_image'];
   elseif model.imagetag == 0 & model.depthtag == 1
      model.datadir.modeldir = [MODELDIR model.category '_depth'];
   end
else
   if model.imagetag == 1 & model.depthtag == 1
      model.datadir.modeldir = [MODELDIR model.category '_' num2str(model.instance) '_joint'];
   elseif model.imagetag == 1 & model.depthtag == 0
      model.datadir.modeldir = [MODELDIR model.category '_' num2str(model.instance) '_image'];
   elseif model.imagetag == 0 & model.depthtag == 1
      model.datadir.modeldir = [MODELDIR model.category '_' num2str(model.instance) '_depth'];
   end
end
save(model.datadir.modeldir,'model');

