% dataset: voc07, voc12;
% train ml via vgg16 and vgg19
% loss: klloss,l2loss, cross-entropy;
% modelType: vgg16, vgg19;
% pool5Type: avg, max;
% how to choose P_D Evaulation on VOC07 validation set
addpath(genpath('./Multi-label'))
run(fullfile('/home/gaobb/SoftToolBox/matconvnet-1.0-beta18', 'matlab', 'vl_setupnn.m')) ;
% Compile the MatConvNet toolbox
% vl_compilenn('EnableGpu', false); % cpu
% vl_compilenn('EnableGpu', true);  % gpu
% vl_compilenn('enableGpu', true, ...
%                'cudaRoot', '/usr/local/cuda-7.5', ...
%                'cudaMethod', 'nvcc', ...
%                'enableCudnn', true, ...
%                'cudnnRoot', '/usr/local/cuda-7.5-cudnn-v5') ;


opts.dataDir = '/mnt/data3/gaobb/image_data/PASCAL/';
P_D = [0,0.1,0.5,0.7,0.9,1];
for n = 3
[net, info] = IFDLDLNet('dataset','voc07',...
                          'modelType','vgg16',...
                          'loss','klloss',...
                          'pool5Type','avg',...
                          'PD', P_D(n),...
                          'trainval_set', 'trainval+test',...
                          'gpus_id',10);
end
[net, info] = IFDLDLNet('dataset','voc07',...
                          'modelType','vgg16',...
                          'loss','klloss',...
                          'pool5Type','avg',...
                          'PD', 0.3,...
                          'trainval_set', 'trainval+test',...
                          'gpus_id',8);


P_D = [0,0.1,0.5,0.7,0.9,1];
for n = 4:6
[net, info] = IFDLDLNet('dataset','voc07',...
                          'modelType','vgg16',...
                          'loss','klloss',...
                          'pool5Type','avg',...
                          'PD', P_D(n),...
                          'trainval_set', 'trainval+test',...
                          'gpus_id',7);
end


P_D = [0,0.1,0.5,0.7,0.9,1];
for n = 1:3
[net, info] = IFDLDLNet('dataset','voc07',...
                          'modelType','vgg16',...
                          'loss','klloss',...
                          'pool5Type','max',...
                          'PD', P_D(n),...
                          'trainval_set', 'trainval+test',...
                          'gpus_id',10);
end


P_D = [0,0.1,0.5,0.7,0.9,1];
for n = 4:6
[net, info] = IFDLDLNet('dataset','voc07',...
                          'modelType','vgg16',...
                          'loss','klloss',...
                          'pool5Type','max',...
                          'PD', P_D(n),...
                          'trainval_set', 'trainval+test',...
                          'gpus_id',9);
end
[net, info] = IFDLDLNet('dataset','voc07',...
                          'modelType','vgg16',...
                          'loss','klloss',...
                          'pool5Type','avg',...
                          'PD', P_D(n),...
                          'trainval_set', 'trainval+test',...
                          'gpus_id',10);
                      
 %% voc 07  learning_rate 10-4
[net, info] = IFDLDLNet('dataset','voc07',...
                          'modelType','vgg16',...
                          'loss','klloss',...
                          'pool5Type','avg',...
                          'trainval_set','trainval+test',...
                          'gpus_id',12);
                      
                      
[net, info] = IFDLDLNet('dataset','voc07',...
                          'modelType','vgg16',...
                          'loss','klloss',...
                          'pool5Type','max',...
                          'trainval_set','trainval+test',...
                          'gpus_id',10);
                      
                      
[net, info] = IFDLDLNet('dataset','voc07',...
                          'modelType','vgg19',...
                          'loss','klloss',...
                          'pool5Type','avg',...
                          'trainval_set','trainval+test',...
                          'gpus_id',9);
                      
                      
[net, info] = IFDLDLNet('dataset','voc07',...
                          'modelType','vgg19',...
                          'loss','klloss',...
                          'pool5Type','max',...
                          'trainval_set','trainval+test',...
                          'gpus_id',8);
                      
                      
%% sigmoid-cross-entropy loss                
%% voc 07
[net, info] = IFDLDLNet('dataset','voc07',...
                          'modelType','vgg16',...
                          'loss','sigmoid_cross_entropy_loss',...
                          'pool5Type','avg',...
                          'trainval_set','trainval+test',...
                          'gpus_id',12);
                      
                      
[net, info] = IFDLDLNet('dataset','voc07',...
                          'modelType','vgg16',...
                          'loss','sigmoid_cross_entropy_loss',...
                          'pool5Type','max',...
                          'trainval_set','trainval+test',...
                          'gpus_id',10);
                      
                      
[net, info] = IFDLDLNet('dataset','voc07',...
                          'modelType','vgg19',...
                          'loss','sigmoid_cross_entropy_loss',...
                          'pool5Type','avg',...
                          'trainval_set','trainval+test',...
                          'gpus_id',14);
                      
                      
[net, info] = IFDLDLNet('dataset','voc07',...
                          'modelType','vgg19',...
                          'loss','sigmoid_cross_entropy_loss',...
                          'pool5Type','max',...
                          'gpus_id',14);                      
    
%% voc 12                     
[net, info] = IFDLDLNet('dataset','voc12',...
                          'modelType','vgg16',...
                          'loss','sigmoid_cross_entropy_loss',...
                          'pool5Type','avg',...              
                          'gpus_id',11);
                      
                      
[net, info] = IFDLDLNet('dataset','voc12',...
                          'modelType','vgg16',...
                          'loss','sigmoid_cross_entropy_loss',...
                          'pool5Type','max',...
                          'gpus_id',6);
                      
                       
[net, info] = IFDLDLNet('dataset','voc12',...
                          'modelType','vgg19',...
                          'loss','sigmoid_cross_entropy_loss',...
                          'pool5Type','avg',...
                          'gpus_id',5);
                      
                      
[net, info] = IFDLDLNet('dataset','voc12',...
                          'modelType','vgg19',...
                          'loss','sigmoid_cross_entropy_loss',...
                          'pool5Type','max',...
                          'gpus_id',2);                     
                   
%% KL (baseline 0,1 label normalizing)      
%% voc 07
[net, info] = IFDLDLNet('dataset','voc07',...
                          'modelType','vgg16',...
                          'loss','baseline_klloss',...
                          'pool5Type','avg',...
                          'trainval_set','trainval+test',...
                          'gpus_id',5);  % gpu3
                      
                      
[net, info] = IFDLDLNet('dataset','voc07',...
                          'modelType','vgg16',...
                          'loss','baseline_klloss',...
                          'pool5Type','max',...
                          'trainval_set','trainval+test',...
                          'gpus_id',6);
                      
                      
[net, info] = IFDLDLNet('dataset','voc07',...
                          'modelType','vgg19',...
                          'loss','baseline_klloss',...
                          'pool5Type','avg',...
                          'trainval_set','trainval+test',...
                          'gpus_id',9);
                      
                      
[net, info] = IFDLDLNet('dataset','voc07',...
                          'modelType','vgg19',...
                          'loss','baseline_klloss',...
                          'pool5Type','max',...
                          'gpus_id',12);                      
    
%% voc 12                     
[net, info] = IFDLDLNet('dataset','voc12',...
                          'modelType','vgg16',...
                          'loss','baseline_klloss',...
                          'pool5Type','avg',...              
                          'gpus_id',2);
                      
                      
[net, info] = IFDLDLNet('dataset','voc12',...
                          'modelType','vgg16',...
                          'loss','baseline_klloss',...
                          'pool5Type','max',...
                          'gpus_id',4);   %gpu4
                      
                       
[net, info] = IFDLDLNet('dataset','voc12',...
                          'modelType','vgg19',...
                          'loss','baseline_klloss',...
                          'pool5Type','avg',...
                          'gpus_id',7);
                      
                      
[net, info] = IFDLDLNet('dataset','voc12',...
                          'modelType','vgg19',...
                          'loss','baseline_klloss',...
                          'pool5Type','max',...
                          'gpus_id',8);       %gpu4              
%% label smooth sigmoid-cross-entropy == DLDL (binary classification)        
%% voc 07
[net, info] = IFDLDLNet('dataset','voc07',...
                          'modelType','vgg16',...
                          'loss','ls_sigmoid_cross_entropy_loss',...
                          'pool5Type','avg',...
                          'trainval_set','trainval+test',...
                          'gpus_id',9);  % gpu3
                      
                      
[net, info] = IFDLDLNet('dataset','voc07',...
                          'modelType','vgg16',...
                          'loss','ls_sigmoid_cross_entropy_loss',...
                          'pool5Type','max',...
                          'trainval_set','trainval+test',...
                          'gpus_id',4);
                      
                      
[net, info] = IFDLDLNet('dataset','voc07',...
                          'modelType','vgg19',...
                          'loss','ls_sigmoid_cross_entropy_loss',...
                          'pool5Type','avg',...
                          'trainval_set','trainval+test',...
                          'gpus_id',5);
                      
                      
[net, info] = IFDLDLNet('dataset','voc07',...
                          'modelType','vgg19',...
                          'loss','ls_sigmoid_cross_entropy_loss',...
                          'pool5Type','max',...
                          'gpus_id',8);                      
    
%% voc 12                     
[net, info] = IFDLDLNet('dataset','voc12',...
                          'modelType','vgg16',...
                          'loss','ls_sigmoid_cross_entropy_loss',...
                          'pool5Type','avg',...              
                          'gpus_id',9);
                      
                      
[net, info] = IFDLDLNet('dataset','voc12',...
                          'modelType','vgg16',...
                          'loss','ls_sigmoid_cross_entropy_loss',...
                          'pool5Type','max',...
                          'gpus_id',5);   %gpu3
                      
                       
[net, info] = IFDLDLNet('dataset','voc12',...
                          'modelType','vgg19',...
                          'loss','ls_sigmoid_cross_entropy_loss',...
                          'pool5Type','avg',...
                          'gpus_id',16);
                      
                      
[net, info] = IFDLDLNet('dataset','voc12',...
                          'modelType','vgg19',...
                          'loss','ls_sigmoid_cross_entropy_loss',...
                          'pool5Type','max',...
                          'gpus_id',12);       %gpu3                                     
                      
                      
                      
                      
                      
                      
                      
[net, info] = IFDLDLNet('dataset','voc07',...
                          'modelType','vgg16',...
                          'loss','l2loss',...
                          'pool5Type','avg',...
                          'trainval_set','trainval+test',...
                          'gpus_id',12);
                      
                      
                      
                      
                      
                      
                      
                      
%% sigmoid + cross-entropy loss
%% voc 07
[net, info] = IFDLDLNet('dataset','voc07',...
                          'modelType','vgg16',...
                          'loss','cross_entropy_loss',...
                          'pool5Type','avg',...
                          'trainval_set','trainval+test',...
                          'gpus_id',8);
                      
                      
[net, info] = IFDLDLNet('dataset','voc07',...
                          'modelType','vgg16',...
                          'loss','cross_entropy_loss',...
                          'pool5Type','max',...
                          'trainval_set','trainval+test',...
                          'gpus_id',9);
                      
                      
[net, info] = IFDLDLNet('dataset','voc07',...
                          'modelType','vgg19',...
                          'loss','cross_entropy_loss',...
                          'pool5Type','avg',...
                          'trainval_set','trainval+test',...
                          'gpus_id',10);
                      
                      
[net, info] = IFDLDLNet('dataset','voc07',...
                          'modelType','vgg19',...
                          'loss','cross_entropy_loss',...
                          'pool5Type','max',...
                          'gpus_id',16);                      
                      
                  
%% voc 12                     
[net, info] = IFDLDLNet('dataset','voc12',...
                          'modelType','vgg16',...
                          'loss','cross_entropy_loss',...
                          'pool5Type','avg',...              
                          'gpus_id',13);
                      
                      
[net, info] = IFDLDLNet('dataset','voc12',...
                          'modelType','vgg16',...
                          'loss','cross_entropy_loss',...
                          'pool5Type','max',...
                          'gpus_id',12);
                      
                       
[net, info] = IFDLDLNet('dataset','voc12',...
                          'modelType','vgg19',...
                          'loss','cross_entropy_loss',...
                          'pool5Type','avg',...
                          'gpus_id',10);
                      
                      
[net, info] = IFDLDLNet('dataset','voc12',...
                          'modelType','vgg19',...
                          'loss','cross_entropy_loss',...
                          'pool5Type','max',...
                          'gpus_id',9);                     
                      
                      
%% v4 corss-entropy loss              
% 0.1-0.9
% 0.3~0.7
%% voc 07
[net, info] = IFDLDLNet('dataset','voc07',...
                          'modelType','vgg16',...
                          'loss','sigmoid_cross_entropy_loss',...
                          'pool5Type','avg',...
                          'trainval_set','trainval+test',...
                          'gpus_id',10);
                      
                      
[net, info] = IFDLDLNet('dataset','voc07',...
                          'modelType','vgg16',...
                          'loss','sigmoid_cross_entropy_loss',...
                          'pool5Type','max',...
                          'trainval_set','trainval+test',...
                          'gpus_id',10);
                      
                      
[net, info] = IFDLDLNet('dataset','voc07',...
                          'modelType','vgg19',...
                          'loss','sigmoid_cross_entropy_loss',...
                          'pool5Type','avg',...
                          'trainval_set','trainval+test',...
                          'gpus_id',14);
                      
                      
[net, info] = IFDLDLNet('dataset','voc07',...
                          'modelType','vgg19',...
                          'loss','sigmoid_cross_entropy_loss',...
                          'pool5Type','max',...
                          'gpus_id',14);                      
                      
                  
%% voc 12                     
[net, info] = IFDLDLNet('dataset','voc12',...
                          'modelType','vgg16',...
                          'loss','sigmoid_cross_entropy_loss',...
                          'pool5Type','avg',...              
                          'gpus_id',11);
                      
                      
[net, info] = IFDLDLNet('dataset','voc12',...
                          'modelType','vgg16',...
                          'loss','sigmoid_cross_entropy_loss',...
                          'pool5Type','max',...
                          'gpus_id',6);
                      
                       
[net, info] = IFDLDLNet('dataset','voc12',...
                          'modelType','vgg19',...
                          'loss','sigmoid_cross_entropy_loss',...
                          'pool5Type','avg',...
                          'gpus_id',5);
                      
                      
[net, info] = IFDLDLNet('dataset','voc12',...
                          'modelType','vgg19',...
                          'loss','sigmoid_cross_entropy_loss',...
                          'pool5Type','max',...
                          'gpus_id',2);                     
                      
%% PF-DLDL training
%% voc 07
addpath('./External/edges'); 
addpath(genpath('./External/Piotr-CV')); 
addpath('./External/Ncut_9'); 

[net, info] = PFDLDLNet('dataset','voc07',...
                          'modelType','vgg16',...
                          'loss','klloss',...
                          'pool5Type','avg',...
                          'trainval_set','trainval+NaN',...
                          'gpus_id',11); %gpu4
                      
                      
[net, info] = PFDLDLNet('dataset','voc07',...
                          'modelType','vgg16',...
                          'loss','klloss',...
                          'pool5Type','max',...
                          'trainval_set','trainval+NaN',...
                          'gpus_id',12);% gpu4
                      
                      
[net, info] = PFDLDLNet('dataset','voc07',...
                          'modelType','vgg19',...
                          'loss','klloss',...
                          'pool5Type','avg',...
                          'trainval_set','trainval+NaN',...
                          'gpus_id',2);% gpu2
                      
                      
[net, info] = PFDLDLNet('dataset','voc07',...
                          'modelType','vgg19',...
                          'loss','klloss',...
                          'pool5Type','max',...
                          'trainval_set','trainval+NaN',...
                          'gpus_id',4);%gpu2   
                      
                      
                      
% voc 12
[net, info] = PFDLDLNet('dataset','voc12',...
                          'modelType','vgg16',...
                          'loss','klloss',...
                          'pool5Type','avg',...
                          'trainval_set','trainval+NaN',...
                          'gpus_id',13); %gpu3
                      
                      
[net, info] = PFDLDLNet('dataset','voc12',...
                          'modelType','vgg16',...
                          'loss','klloss',...
                          'pool5Type','max',...
                          'trainval_set','trainval+NaN',...
                          'gpus_id',15);% gpu4
                      
                      
[net, info] = PFDLDLNet('dataset','voc12',...
                          'modelType','vgg19',...
                          'loss','klloss',...
                          'pool5Type','avg',...
                          'trainval_set','trainval+NaN',...
                          'gpus_id',16);% gpu4
                      
                      
[net, info] = PFDLDLNet('dataset','voc12',...
                          'modelType','vgg19',...
                          'loss','klloss',...
                          'pool5Type','max',...
                          'trainval_set','trainval+NaN',...
                          'gpus_id',15);%gpu3:16     gpu4:15
                      
                      
                      
[net, info] = IFDLDLNet('dataset','voc07',...
                          'modelType','vgg16',...
                          'loss','l2loss',...
                          'pool5Type','avg',...
                          'trainval_set','trainval+test',...
                          'gpus_id',12);
