├── nr.m ├── pic ├── bern_1.bmp ├── bern_2.bmp └── bern_gt.bmp ├── gao_clustering.m ├── Utils ├── nr_enhance.p ├── im2colstep.mexa64 ├── im2colstep.mexw64 ├── mat2imgcell.m ├── im2col_general.m └── im2colstep.m ├── generating_test.m ├── Liblinear ├── predict.mexa64 ├── predict.mexw64 ├── train.mexa64 ├── train.mexw64 ├── libsvmread.mexa64 ├── libsvmread.mexw64 ├── libsvmwrite.mexa64 ├── libsvmwrite.mexw64 ├── linear_model_matlab.h ├── make.m ├── Makefile ├── libsvmwrite.c ├── linear_model_matlab.c ├── libsvmread.c ├── README ├── predict.c └── train.c ├── models └── iter_LCCD.caffemodel ├── train.sh ├── test.sh ├── extract_prob.sh ├── prototxt_files ├── solver.prototxt ├── test_ice.prototxt └── train_ice.prototxt ├── create_train.sh ├── calculating_result.m ├── README.md ├── create_test.sh └── generating_train.m /nr.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/formango/SAR-Change-Detection-MLFN/HEAD/nr.m -------------------------------------------------------------------------------- /pic/bern_1.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/formango/SAR-Change-Detection-MLFN/HEAD/pic/bern_1.bmp -------------------------------------------------------------------------------- /pic/bern_2.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/formango/SAR-Change-Detection-MLFN/HEAD/pic/bern_2.bmp -------------------------------------------------------------------------------- /gao_clustering.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/formango/SAR-Change-Detection-MLFN/HEAD/gao_clustering.m -------------------------------------------------------------------------------- /pic/bern_gt.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/formango/SAR-Change-Detection-MLFN/HEAD/pic/bern_gt.bmp -------------------------------------------------------------------------------- /Utils/nr_enhance.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/formango/SAR-Change-Detection-MLFN/HEAD/Utils/nr_enhance.p -------------------------------------------------------------------------------- /generating_test.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/formango/SAR-Change-Detection-MLFN/HEAD/generating_test.m -------------------------------------------------------------------------------- /Liblinear/predict.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/formango/SAR-Change-Detection-MLFN/HEAD/Liblinear/predict.mexa64 -------------------------------------------------------------------------------- /Liblinear/predict.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/formango/SAR-Change-Detection-MLFN/HEAD/Liblinear/predict.mexw64 -------------------------------------------------------------------------------- /Liblinear/train.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/formango/SAR-Change-Detection-MLFN/HEAD/Liblinear/train.mexa64 -------------------------------------------------------------------------------- /Liblinear/train.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/formango/SAR-Change-Detection-MLFN/HEAD/Liblinear/train.mexw64 -------------------------------------------------------------------------------- /Utils/im2colstep.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/formango/SAR-Change-Detection-MLFN/HEAD/Utils/im2colstep.mexa64 -------------------------------------------------------------------------------- /Utils/im2colstep.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/formango/SAR-Change-Detection-MLFN/HEAD/Utils/im2colstep.mexw64 -------------------------------------------------------------------------------- /Liblinear/libsvmread.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/formango/SAR-Change-Detection-MLFN/HEAD/Liblinear/libsvmread.mexa64 -------------------------------------------------------------------------------- /Liblinear/libsvmread.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/formango/SAR-Change-Detection-MLFN/HEAD/Liblinear/libsvmread.mexw64 -------------------------------------------------------------------------------- /Liblinear/libsvmwrite.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/formango/SAR-Change-Detection-MLFN/HEAD/Liblinear/libsvmwrite.mexa64 -------------------------------------------------------------------------------- /Liblinear/libsvmwrite.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/formango/SAR-Change-Detection-MLFN/HEAD/Liblinear/libsvmwrite.mexw64 -------------------------------------------------------------------------------- /models/iter_LCCD.caffemodel: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/formango/SAR-Change-Detection-MLFN/HEAD/models/iter_LCCD.caffemodel -------------------------------------------------------------------------------- /train.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ./build/tools/caffe train --solver=./examples/Transfer/prototxt_files/solver.prototxt -weights ./examples/Transfer/models/iter_LCCD.caffemodel$@ -------------------------------------------------------------------------------- /Liblinear/linear_model_matlab.h: -------------------------------------------------------------------------------- 1 | const char *model_to_matlab_structure(mxArray *plhs[], struct model *model_); 2 | const char *matlab_matrix_to_model(struct model *model_, const mxArray *matlab_struct); 3 | -------------------------------------------------------------------------------- /test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | set -e 3 | ./build/tools/caffe test --model=./examples/Transfer/prototxt_files/test_ice.prototxt --weights=./examples/Transfer/snapshot/iter_1000.caffemodel -iterations=2048 -gpu=0 4 | 5 | 6 | -------------------------------------------------------------------------------- /Utils/mat2imgcell.m: -------------------------------------------------------------------------------- 1 | function Img = mat2imgcell(D,height,width,ImgFormat) 2 | 3 | N = size(D,2); 4 | Img = cell(N,1); 5 | if strcmp(ImgFormat,'gray') 6 | for i = 1:N 7 | Img{i} = reshape(D(:,i),height,width); 8 | end 9 | elseif strcmp(ImgFormat,'color') 10 | for i = 1:N 11 | Img{i} = reshape(D(:,i),height,width,3); 12 | end 13 | end 14 | 15 | 16 | -------------------------------------------------------------------------------- /Utils/im2col_general.m: -------------------------------------------------------------------------------- 1 | function im = im2col_general(varargin) 2 | % 3 | 4 | NumInput = length(varargin); 5 | InImg = varargin{1}; 6 | patchsize12 = varargin{2}; 7 | 8 | z = size(InImg,3); 9 | im = cell(z,1); 10 | if NumInput == 2 11 | for i = 1:z 12 | im{i} = im2colstep(InImg(:,:,i),patchsize12)'; 13 | end 14 | else 15 | for i = 1:z 16 | im{i} = im2colstep(InImg(:,:,i),patchsize12,varargin{3})'; 17 | end 18 | end 19 | im = [im{:}]'; 20 | 21 | -------------------------------------------------------------------------------- /extract_prob.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | /bin/bash bin/pyspark 3 | 4 | cat result.txt | grep "Batch ., prob" | awk '{print $9}' >& temp1.txt && 5 | cat result.txt | grep "Batch .., prob" | awk '{print $9}' >& temp2.txt && 6 | cat result.txt | grep "Batch ..., prob" | awk '{print $9}' >& temp3.txt && 7 | cat result.txt | grep "Batch ...., prob" | awk '{print $9}' >& temp4.txt && 8 | cat result.txt | grep "Batch ....., prob" | awk '{print $9}' >& temp5.txt 9 | 10 | cat temp5.txt >> temp4.txt && 11 | cat temp4.txt >> temp3.txt && 12 | cat temp3.txt >> temp2.txt && 13 | cat temp2.txt >> temp1.txt && 14 | cat temp1.txt >> prob.txt 15 | 16 | -------------------------------------------------------------------------------- /prototxt_files/solver.prototxt: -------------------------------------------------------------------------------- 1 | # The train/test net protocol buffer definition 2 | net: "./examples/Transfer/prototxt_files/train_ice.prototxt" 3 | # test_iter specifies how many forward passes the test should carry out. 4 | # In the case of ice_part1, we have test batch size 32 and 2048 test iterations, 5 | # covering the full 65536=32*2048 testing images; train smaples: 1029 6 | test_iter: 2048 7 | # Carry out testing every 500 training iterations. 8 | test_interval: 1000 9 | # The base learning rate, momentum and the weight decay of the network. 10 | base_lr: 0.0001 11 | momentum: 0.9 12 | weight_decay: 0.0005 13 | # The learning rate policy 14 | lr_policy: "inv" 15 | power:0.75 16 | gamma:0.01 17 | # Display every 100 iterations 18 | display: 100 19 | # The maximum number of iterations 20 | max_iter: 2000 21 | # snapshot intermediate results 22 | snapshot: 1000 23 | snapshot_prefix: "./examples/Transfer/snapshot/" 24 | # solver mode: CPU or GPU 25 | solver_mode: GPU 26 | -------------------------------------------------------------------------------- /Liblinear/make.m: -------------------------------------------------------------------------------- 1 | % This make.m is for MATLAB and OCTAVE under Windows, Mac, and Unix 2 | 3 | try 4 | Type = ver; 5 | % This part is for OCTAVE 6 | if(strcmp(Type(1).Name, 'Octave') == 1) 7 | mex libsvmread.c 8 | mex libsvmwrite.c 9 | mex train.c linear_model_matlab.c ../linear.cpp ../tron.cpp ../blas/*.c 10 | mex predict.c linear_model_matlab.c ../linear.cpp ../tron.cpp ../blas/*.c 11 | % This part is for MATLAB 12 | % Add -largeArrayDims on 64-bit machines of MATLAB 13 | else 14 | mex CFLAGS="\$CFLAGS -std=c99" -largeArrayDims libsvmread.c 15 | mex CFLAGS="\$CFLAGS -std=c99" -largeArrayDims libsvmwrite.c 16 | mex CFLAGS="\$CFLAGS -std=c99" -largeArrayDims train.c linear_model_matlab.c ../linear.cpp ../tron.cpp "../blas/*.c" 17 | mex CFLAGS="\$CFLAGS -std=c99" -largeArrayDims predict.c linear_model_matlab.c ../linear.cpp ../tron.cpp "../blas/*.c" 18 | end 19 | catch 20 | fprintf('If make.m fails, please check README about detailed instructions.\n'); 21 | end 22 | -------------------------------------------------------------------------------- /create_train.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | # Create the imagenet lmdb inputs 3 | # N.B. set the path to the imagenet train + val data dirs 4 | 5 | EXAMPLE=examples/Transfer/data/test 6 | DATA=/home/ouc/caffe-fast-rcnn/examples/Transfer/data/test 7 | TOOLS=build/tools 8 | TRAIN_DATA_ROOT=examples/Transfer/data/test/train_ice2/ 9 | 10 | # Set RESIZE=true to resize the images to 28x28. Leave as false if images have 11 | # already been resized using another tool. 12 | RESIZE=true 13 | if $RESIZE; then 14 | RESIZE_HEIGHT=28 15 | RESIZE_WIDTH=28 16 | else 17 | RESIZE_HEIGHT=0 18 | RESIZE_WIDTH=0 19 | fi 20 | 21 | if [ ! -d "$TRAIN_DATA_ROOT" ]; then 22 | echo "Error: TRAIN_DATA_ROOT is not a path to a directory: $TRAIN_DATA_ROOT" 23 | echo "Set the TRAIN_DATA_ROOT variable in create_imagenet.sh to the path" \ 24 | "where the ImageNet training data is stored." 25 | exit 1 26 | fi 27 | 28 | 29 | echo "Creating train lmdb......" 30 | 31 | GLOG_logtostderr=1 $TOOLS/convert_imageset \ 32 | --resize_height=$RESIZE_HEIGHT \ 33 | --resize_width=$RESIZE_WIDTH \ 34 | --shuffle \ 35 | $TRAIN_DATA_ROOT \ 36 | $DATA/train_ice2/train.txt \ 37 | $EXAMPLE/train_lmdb 38 | 39 | echo "Done." 40 | -------------------------------------------------------------------------------- /calculating_result.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | 3 | % This script is used to calculating the final result 4 | 5 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 6 | clear all; 7 | close all; 8 | clc; 9 | 10 | % Number of classes 11 | 12 | num_classes = 2; 13 | 14 | pre_result = load('train_ice.mat'); 15 | 16 | prob_data_temp=importdata('./info/prob.txt'); 17 | 18 | im_gt = imread('./pic/bern_gt.bmp'); 19 | im_gt = double(im_gt(:,:,1)); 20 | im_gt(im_gt==255)=1; 21 | 22 | [ylen, xlen] = size(im_gt); 23 | 24 | predict_label = []; 25 | test_prob = []; 26 | 27 | for i = 1:length(prob_data_temp)/num_classes 28 | prob_temp = prob_data_temp((i-1)*num_classes+1:i*num_classes,:)'; 29 | test_prob = [test_prob;prob_temp]; 30 | predict_label = [predict_label;find(prob_temp==max(prob_temp))]; 31 | end 32 | 33 | predict_label = predict_label-1; 34 | resultmap = reshape(predict_label,[ylen,xlen]); 35 | 36 | % Load preclassification result 37 | 38 | for j = 1:600 39 | resultmap(pre_result(j,2))=pre_result(j,1); 40 | end 41 | 42 | % Calculate the matrics 43 | 44 | aa = find(im_gt==0&resultmap~=0); 45 | bb = find(im_gt~=0&resultmap==0); 46 | 47 | FP = numel(aa); 48 | FN = numel(bb); 49 | OE = FP + FN; 50 | 51 | CA = 1-OE/(ylen*xlen); 52 | 53 | imwrite(resultmap,'result_ice.jpg','jpg'); 54 | 55 | figure,imshow(resultmap,[]); 56 | -------------------------------------------------------------------------------- /Utils/im2colstep.m: -------------------------------------------------------------------------------- 1 | %IM2COLSTEP Rearrange matrix blocks into columns. 2 | % B = IM2COLSTEP(A,[N1 N2]) converts each sliding N1-by-N2 block of the 3 | % 2-D matrix A into a column of B, with no zero padding. B has N1*N2 rows 4 | % and will contain as many columns as there are N1-by-N2 neighborhoods in 5 | % A. Each column of B contains a neighborhood of A reshaped as NHOOD(:), 6 | % where NHOOD is a matrix containing an N1-by-N2 neighborhood of A. 7 | % 8 | % B = IM2COLSTEP(A,[N1 N2],[S1 S2]) extracts neighborhoods of A with a 9 | % step size of (S1,S2) between them. The first extracted neighborhood is 10 | % A(1:N1,1:N2), and the rest are of the form A((1:N1)+i*S1,(1:N2)+j*S2). 11 | % Note that to ensure coverage of all A by neighborhoods, 12 | % (size(A,i)-Ni)/Si must be whole for i=1,2. The default function behavior 13 | % corresponds to [S1 S2] = [1 1]. Setting S1>=N1 and S2>=N2 results in no 14 | % overlap between the neighborhoods. 15 | % 16 | % B = IM2COLSTEP(A,[N1 N2 N3],[S1 S2 S3]) operates on a 3-D matrix A. The 17 | % step size [S1 S2 S3] may be ommitted, and defaults to [1 1 1]. 18 | % 19 | % Note: the call IM2COLSTEP(A,[N1 N2]) produces the same output as 20 | % Matlab's IM2COL(A,[N1 N2],'sliding'). However, it is significantly 21 | % faster. 22 | % 23 | % See also COL2IMSTEP, IM2COL, COUNTCOVER. 24 | 25 | 26 | % Ron Rubinstein 27 | % Computer Science Department 28 | % Technion, Haifa 32000 Israel 29 | % ronrubin@cs 30 | % 31 | % August 2009 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This code is for our paper "Transferred deep learning for sea ice change detection from synthetic aperture radar images". 2 | If you use this code, please kindly cite our paper: 3 | Yunhao Gao, Feng Gao*, Junyu Dong, Shenke Wang. "Transferred deep learning for sea ice change detection from synthetic aperture radar Images". IEEE Geoscience and Remote Sensing Letters, vol. 16, no.10, pp. 1655-1659, Oct. 2019. 4 | 5 | If you have any questions, please contact us. 6 | Email: gaoyunhao128@163.com gaofeng@ouc.edu.cn 7 | 8 | Before running this code, you should correctly install ubuntu system and caffe framework. Refer to this guildeline "http://caffe.berkeleyvision.org/installation.html" After correctly installing ubuntu and caffe, you can run this code by the following procedures. 9 | 10 | (1) Opening the Matlab and changing the current path, 11 | running the "generating_train.m" and "generating_test.m" to generate the training and testing samples 12 | 13 | (2) Running the "create_train.sh" and "create_test.sh" in Caffe. 14 | Therefore, the format "png" can be converted to format "lmdb" which is efficent for the caffe input 15 | 16 | (3) Opening the terminal and running this script to execute the training of MLFN: 17 | "sh train.sh" 18 | 19 | (4) After training, running the following script to executes the testing of MLFN and record testing logs: 20 | "sh test.sh >& info/result.txt" 21 | 22 | (5) Running the "extract_prob.sh" in Caffe to extract probability from the "result.txt" 23 | 24 | (6) Running the "calculating_result.m" in Matlab to calculate the matrics (PCC, Kappa, FP and FN) and draw the final change map. 25 | 26 | -------------------------------------------------------------------------------- /create_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | # Create the imagenet lmdb inputs 3 | # N.B. set the path to the imagenet train + val data dirs 4 | 5 | EXAMPLE=examples/Transfer/data/test 6 | DATA=/home/ouc/caffe-fast-rcnn/examples/Transfer/data/test 7 | TOOLS=build/tools 8 | #RAIN_DATA_ROOT=examples/Transfer/data/TRAIN/ 9 | VAL_DATA_ROOT=examples/Transfer/data/test/test_ice2/a/ 10 | 11 | # Set RESIZE=true to resize the images to 28x28. Leave as false if images have 12 | # already been resized using another tool. 13 | RESIZE=true 14 | if $RESIZE; then 15 | RESIZE_HEIGHT=28 16 | RESIZE_WIDTH=28 17 | else 18 | RESIZE_HEIGHT=0 19 | RESIZE_WIDTH=0 20 | fi 21 | 22 | # if [ ! -d "$TRAIN_DATA_ROOT" ]; then 23 | # echo "Error: TRAIN_DATA_ROOT is not a path to a directory: $TRAIN_DATA_ROOT" 24 | # echo "Set the TRAIN_DATA_ROOT variable in create_imagenet.sh to the path" \ 25 | # "where the ImageNet training data is stored." 26 | # exit 1 27 | # fi 28 | 29 | if [ ! -d "$VAL_DATA_ROOT" ]; then 30 | echo "Error: VAL_DATA_ROOT is not a path to a directory: $VAL_DATA_ROOT" 31 | echo "Set the VAL_DATA_ROOT variable in create_imagenet.sh to the path" \ 32 | "where the ImageNet validation data is stored." 33 | exit 1 34 | fi 35 | 36 | #echo "Creating train lmdb......" 37 | 38 | # GLOG_logtostderr=1 $TOOLS/convert_imageset \ 39 | # --resize_height=$RESIZE_HEIGHT \ 40 | # --resize_width=$RESIZE_WIDTH \ 41 | # --shuffle 42 | # $TRAIN_DATA_ROOT \ 43 | # $DATA/TRAIN/train.txt \ 44 | # $EXAMPLE/train_lmdb 45 | 46 | echo "Creating val lmdb......" 47 | 48 | GLOG_logtostderr=1 $TOOLS/convert_imageset \ 49 | --resize_height=$RESIZE_HEIGHT \ 50 | --resize_width=$RESIZE_WIDTH \ 51 | $VAL_DATA_ROOT \ 52 | $DATA/test_ice2/test.txt \ 53 | $EXAMPLE/test_lmdb 54 | 55 | echo "Done." 56 | -------------------------------------------------------------------------------- /Liblinear/Makefile: -------------------------------------------------------------------------------- 1 | # This Makefile is used under Linux 2 | 3 | MATLABDIR ?= /usr/local/matlab 4 | CXX ?= g++ 5 | #CXX = g++-3.3 6 | CC ?= gcc 7 | CFLAGS = -Wall -Wconversion -O3 -fPIC -I$(MATLABDIR)/extern/include -I.. 8 | 9 | MEX = $(MATLABDIR)/bin/mex 10 | MEX_OPTION = CC\#$(CXX) CXX\#$(CXX) CFLAGS\#"$(CFLAGS)" CXXFLAGS\#"$(CFLAGS)" 11 | # comment the following line if you use MATLAB on a 32-bit computer 12 | MEX_OPTION += -largeArrayDims 13 | MEX_EXT = $(shell $(MATLABDIR)/bin/mexext) 14 | 15 | OCTAVEDIR ?= /usr/include/octave 16 | OCTAVE_MEX = env CC=$(CXX) mkoctfile 17 | OCTAVE_MEX_OPTION = --mex 18 | OCTAVE_MEX_EXT = mex 19 | OCTAVE_CFLAGS = -Wall -O3 -fPIC -I$(OCTAVEDIR) -I.. 20 | 21 | all: matlab 22 | 23 | matlab: binary 24 | 25 | octave: 26 | @make MEX="$(OCTAVE_MEX)" MEX_OPTION="$(OCTAVE_MEX_OPTION)" \ 27 | MEX_EXT="$(OCTAVE_MEX_EXT)" CFLAGS="$(OCTAVE_CFLAGS)" \ 28 | binary 29 | 30 | binary: train.$(MEX_EXT) predict.$(MEX_EXT) libsvmread.$(MEX_EXT) libsvmwrite.$(MEX_EXT) 31 | 32 | train.$(MEX_EXT): train.c ../linear.h ../tron.o ../linear.o linear_model_matlab.o ../blas/blas.a 33 | $(MEX) $(MEX_OPTION) train.c ../tron.o ../linear.o linear_model_matlab.o ../blas/blas.a 34 | 35 | predict.$(MEX_EXT): predict.c ../linear.h ../tron.o ../linear.o linear_model_matlab.o ../blas/blas.a 36 | $(MEX) $(MEX_OPTION) predict.c ../tron.o ../linear.o linear_model_matlab.o ../blas/blas.a 37 | 38 | libsvmread.$(MEX_EXT): libsvmread.c 39 | $(MEX) $(MEX_OPTION) libsvmread.c 40 | 41 | libsvmwrite.$(MEX_EXT): libsvmwrite.c 42 | $(MEX) $(MEX_OPTION) libsvmwrite.c 43 | 44 | linear_model_matlab.o: linear_model_matlab.c ../linear.h 45 | $(CXX) $(CFLAGS) -c linear_model_matlab.c 46 | 47 | ../linear.o: ../linear.cpp ../linear.h 48 | make -C .. linear.o 49 | 50 | ../tron.o: ../tron.cpp ../tron.h 51 | make -C .. tron.o 52 | 53 | ../blas/blas.a: ../blas/*.c ../blas/*.h 54 | make -C ../blas OPTFLAGS='$(CFLAGS)' CC='$(CC)'; 55 | 56 | clean: 57 | make -C ../blas clean 58 | rm -f *~ *.o *.mex* *.obj ../linear.o ../tron.o 59 | -------------------------------------------------------------------------------- /Liblinear/libsvmwrite.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "mex.h" 5 | 6 | #ifdef MX_API_VER 7 | #if MX_API_VER < 0x07030000 8 | typedef int mwIndex; 9 | #endif 10 | #endif 11 | 12 | void exit_with_help() 13 | { 14 | mexPrintf( 15 | "Usage: libsvmwrite('filename', label_vector, instance_matrix);\n" 16 | ); 17 | } 18 | 19 | void libsvmwrite(const char *filename, const mxArray *label_vec, const mxArray *instance_mat) 20 | { 21 | FILE *fp = fopen(filename,"w"); 22 | int i, k, low, high, l; 23 | mwIndex *ir, *jc; 24 | int label_vector_row_num; 25 | double *samples, *labels; 26 | mxArray *instance_mat_col; // instance sparse matrix in column format 27 | 28 | if(fp ==NULL) 29 | { 30 | mexPrintf("can't open output file %s\n",filename); 31 | return; 32 | } 33 | 34 | // transpose instance matrix 35 | { 36 | mxArray *prhs[1], *plhs[1]; 37 | prhs[0] = mxDuplicateArray(instance_mat); 38 | if(mexCallMATLAB(1, plhs, 1, prhs, "transpose")) 39 | { 40 | mexPrintf("Error: cannot transpose instance matrix\n"); 41 | return; 42 | } 43 | instance_mat_col = plhs[0]; 44 | mxDestroyArray(prhs[0]); 45 | } 46 | 47 | // the number of instance 48 | l = (int) mxGetN(instance_mat_col); 49 | label_vector_row_num = (int) mxGetM(label_vec); 50 | 51 | if(label_vector_row_num!=l) 52 | { 53 | mexPrintf("Length of label vector does not match # of instances.\n"); 54 | return; 55 | } 56 | 57 | // each column is one instance 58 | labels = mxGetPr(label_vec); 59 | samples = mxGetPr(instance_mat_col); 60 | ir = mxGetIr(instance_mat_col); 61 | jc = mxGetJc(instance_mat_col); 62 | 63 | for(i=0;i 2 | #include 3 | #include "../linear.h" 4 | 5 | #include "mex.h" 6 | 7 | #ifdef MX_API_VER 8 | #if MX_API_VER < 0x07030000 9 | typedef int mwIndex; 10 | #endif 11 | #endif 12 | 13 | #define Malloc(type,n) (type *)malloc((n)*sizeof(type)) 14 | 15 | #define NUM_OF_RETURN_FIELD 6 16 | 17 | static const char *field_names[] = { 18 | "Parameters", 19 | "nr_class", 20 | "nr_feature", 21 | "bias", 22 | "Label", 23 | "w", 24 | }; 25 | 26 | const char *model_to_matlab_structure(mxArray *plhs[], struct model *model_) 27 | { 28 | int i; 29 | int nr_w; 30 | double *ptr; 31 | mxArray *return_model, **rhs; 32 | int out_id = 0; 33 | int n, w_size; 34 | 35 | rhs = (mxArray **)mxMalloc(sizeof(mxArray *)*NUM_OF_RETURN_FIELD); 36 | 37 | // Parameters 38 | // for now, only solver_type is needed 39 | rhs[out_id] = mxCreateDoubleMatrix(1, 1, mxREAL); 40 | ptr = mxGetPr(rhs[out_id]); 41 | ptr[0] = model_->param.solver_type; 42 | out_id++; 43 | 44 | // nr_class 45 | rhs[out_id] = mxCreateDoubleMatrix(1, 1, mxREAL); 46 | ptr = mxGetPr(rhs[out_id]); 47 | ptr[0] = model_->nr_class; 48 | out_id++; 49 | 50 | if(model_->nr_class==2 && model_->param.solver_type != MCSVM_CS) 51 | nr_w=1; 52 | else 53 | nr_w=model_->nr_class; 54 | 55 | // nr_feature 56 | rhs[out_id] = mxCreateDoubleMatrix(1, 1, mxREAL); 57 | ptr = mxGetPr(rhs[out_id]); 58 | ptr[0] = model_->nr_feature; 59 | out_id++; 60 | 61 | // bias 62 | rhs[out_id] = mxCreateDoubleMatrix(1, 1, mxREAL); 63 | ptr = mxGetPr(rhs[out_id]); 64 | ptr[0] = model_->bias; 65 | out_id++; 66 | 67 | if(model_->bias>=0) 68 | n=model_->nr_feature+1; 69 | else 70 | n=model_->nr_feature; 71 | 72 | w_size = n; 73 | // Label 74 | if(model_->label) 75 | { 76 | rhs[out_id] = mxCreateDoubleMatrix(model_->nr_class, 1, mxREAL); 77 | ptr = mxGetPr(rhs[out_id]); 78 | for(i = 0; i < model_->nr_class; i++) 79 | ptr[i] = model_->label[i]; 80 | } 81 | else 82 | rhs[out_id] = mxCreateDoubleMatrix(0, 0, mxREAL); 83 | out_id++; 84 | 85 | // w 86 | rhs[out_id] = mxCreateDoubleMatrix(nr_w, w_size, mxREAL); 87 | ptr = mxGetPr(rhs[out_id]); 88 | for(i = 0; i < w_size*nr_w; i++) 89 | ptr[i]=model_->w[i]; 90 | out_id++; 91 | 92 | /* Create a struct matrix contains NUM_OF_RETURN_FIELD fields */ 93 | return_model = mxCreateStructMatrix(1, 1, NUM_OF_RETURN_FIELD, field_names); 94 | 95 | /* Fill struct matrix with input arguments */ 96 | for(i = 0; i < NUM_OF_RETURN_FIELD; i++) 97 | mxSetField(return_model,0,field_names[i],mxDuplicateArray(rhs[i])); 98 | /* return */ 99 | plhs[0] = return_model; 100 | mxFree(rhs); 101 | 102 | return NULL; 103 | } 104 | 105 | const char *matlab_matrix_to_model(struct model *model_, const mxArray *matlab_struct) 106 | { 107 | int i, num_of_fields; 108 | int nr_w; 109 | double *ptr; 110 | int id = 0; 111 | int n, w_size; 112 | mxArray **rhs; 113 | 114 | num_of_fields = mxGetNumberOfFields(matlab_struct); 115 | rhs = (mxArray **) mxMalloc(sizeof(mxArray *)*num_of_fields); 116 | 117 | for(i=0;inr_class=0; 121 | nr_w=0; 122 | model_->nr_feature=0; 123 | model_->w=NULL; 124 | model_->label=NULL; 125 | 126 | // Parameters 127 | ptr = mxGetPr(rhs[id]); 128 | model_->param.solver_type = (int)ptr[0]; 129 | id++; 130 | 131 | // nr_class 132 | ptr = mxGetPr(rhs[id]); 133 | model_->nr_class = (int)ptr[0]; 134 | id++; 135 | 136 | if(model_->nr_class==2 && model_->param.solver_type != MCSVM_CS) 137 | nr_w=1; 138 | else 139 | nr_w=model_->nr_class; 140 | 141 | // nr_feature 142 | ptr = mxGetPr(rhs[id]); 143 | model_->nr_feature = (int)ptr[0]; 144 | id++; 145 | 146 | // bias 147 | ptr = mxGetPr(rhs[id]); 148 | model_->bias = (int)ptr[0]; 149 | id++; 150 | 151 | if(model_->bias>=0) 152 | n=model_->nr_feature+1; 153 | else 154 | n=model_->nr_feature; 155 | w_size = n; 156 | 157 | // Label 158 | if(mxIsEmpty(rhs[id]) == 0) 159 | { 160 | model_->label = Malloc(int, model_->nr_class); 161 | ptr = mxGetPr(rhs[id]); 162 | for(i=0;inr_class;i++) 163 | model_->label[i] = (int)ptr[i]; 164 | } 165 | id++; 166 | 167 | ptr = mxGetPr(rhs[id]); 168 | model_->w=Malloc(double, w_size*nr_w); 169 | for(i = 0; i < w_size*nr_w; i++) 170 | model_->w[i]=ptr[i]; 171 | id++; 172 | mxFree(rhs); 173 | 174 | return NULL; 175 | } 176 | 177 | -------------------------------------------------------------------------------- /Liblinear/libsvmread.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "mex.h" 8 | 9 | #ifdef MX_API_VER 10 | #if MX_API_VER < 0x07030000 11 | typedef int mwIndex; 12 | #endif 13 | #endif 14 | #ifndef max 15 | #define max(x,y) (((x)>(y))?(x):(y)) 16 | #endif 17 | #ifndef min 18 | #define min(x,y) (((x)<(y))?(x):(y)) 19 | #endif 20 | 21 | void exit_with_help() 22 | { 23 | mexPrintf( 24 | "Usage: [label_vector, instance_matrix] = libsvmread('filename');\n" 25 | ); 26 | } 27 | 28 | static void fake_answer(mxArray *plhs[]) 29 | { 30 | plhs[0] = mxCreateDoubleMatrix(0, 0, mxREAL); 31 | plhs[1] = mxCreateDoubleMatrix(0, 0, mxREAL); 32 | } 33 | 34 | static char *line; 35 | static int max_line_len; 36 | 37 | static char* readline(FILE *input) 38 | { 39 | int len; 40 | 41 | if(fgets(line,max_line_len,input) == NULL) 42 | return NULL; 43 | 44 | while(strrchr(line,'\n') == NULL) 45 | { 46 | max_line_len *= 2; 47 | line = (char *) realloc(line, max_line_len); 48 | len = (int) strlen(line); 49 | if(fgets(line+len,max_line_len-len,input) == NULL) 50 | break; 51 | } 52 | return line; 53 | } 54 | 55 | // read in a problem (in libsvm format) 56 | void read_problem(const char *filename, mxArray *plhs[]) 57 | { 58 | int max_index, min_index, inst_max_index, i; 59 | long elements, k; 60 | FILE *fp = fopen(filename,"r"); 61 | int l = 0; 62 | char *endptr; 63 | mwIndex *ir, *jc; 64 | double *labels, *samples; 65 | 66 | if(fp == NULL) 67 | { 68 | mexPrintf("can't open input file %s\n",filename); 69 | fake_answer(plhs); 70 | return; 71 | } 72 | 73 | max_line_len = 1024; 74 | line = (char *) malloc(max_line_len*sizeof(char)); 75 | 76 | max_index = 0; 77 | min_index = 1; // our index starts from 1 78 | elements = 0; 79 | while(readline(fp) != NULL) 80 | { 81 | char *idx, *val; 82 | // features 83 | int index = 0; 84 | 85 | inst_max_index = -1; // strtol gives 0 if wrong format, and precomputed kernel has start from 0 86 | strtok(line," \t"); // label 87 | while (1) 88 | { 89 | idx = strtok(NULL,":"); // index:value 90 | val = strtok(NULL," \t"); 91 | if(val == NULL) 92 | break; 93 | 94 | errno = 0; 95 | index = (int) strtol(idx,&endptr,10); 96 | if(endptr == idx || errno != 0 || *endptr != '\0' || index <= inst_max_index) 97 | { 98 | mexPrintf("Wrong input format at line %d\n",l+1); 99 | fake_answer(plhs); 100 | return; 101 | } 102 | else 103 | inst_max_index = index; 104 | 105 | min_index = min(min_index, index); 106 | elements++; 107 | } 108 | max_index = max(max_index, inst_max_index); 109 | l++; 110 | } 111 | rewind(fp); 112 | 113 | // y 114 | plhs[0] = mxCreateDoubleMatrix(l, 1, mxREAL); 115 | // x^T 116 | if (min_index <= 0) 117 | plhs[1] = mxCreateSparse(max_index-min_index+1, l, elements, mxREAL); 118 | else 119 | plhs[1] = mxCreateSparse(max_index, l, elements, mxREAL); 120 | 121 | labels = mxGetPr(plhs[0]); 122 | samples = mxGetPr(plhs[1]); 123 | ir = mxGetIr(plhs[1]); 124 | jc = mxGetJc(plhs[1]); 125 | 126 | k=0; 127 | for(i=0;i start from 0 158 | 159 | errno = 0; 160 | samples[k] = strtod(val,&endptr); 161 | if (endptr == val || errno != 0 || (*endptr != '\0' && !isspace(*endptr))) 162 | { 163 | mexPrintf("Wrong input format at line %d\n",i+1); 164 | fake_answer(plhs); 165 | return; 166 | } 167 | ++k; 168 | } 169 | } 170 | jc[l] = k; 171 | 172 | fclose(fp); 173 | free(line); 174 | 175 | { 176 | mxArray *rhs[1], *lhs[1]; 177 | rhs[0] = plhs[1]; 178 | if(mexCallMATLAB(1, lhs, 1, rhs, "transpose")) 179 | { 180 | mexPrintf("Error: cannot transpose problem\n"); 181 | fake_answer(plhs); 182 | return; 183 | } 184 | plhs[1] = lhs[0]; 185 | } 186 | } 187 | 188 | void mexFunction( int nlhs, mxArray *plhs[], 189 | int nrhs, const mxArray *prhs[] ) 190 | { 191 | if(nrhs == 1) 192 | { 193 | char filename[256]; 194 | 195 | mxGetString(prhs[0], filename, mxGetN(prhs[0]) + 1); 196 | 197 | if(filename == NULL) 198 | { 199 | mexPrintf("Error: filename is NULL\n"); 200 | return; 201 | } 202 | 203 | read_problem(filename, plhs); 204 | } 205 | else 206 | { 207 | exit_with_help(); 208 | fake_answer(plhs); 209 | return; 210 | } 211 | } 212 | 213 | -------------------------------------------------------------------------------- /Liblinear/README: -------------------------------------------------------------------------------- 1 | -------------------------------------------- 2 | --- MATLAB/OCTAVE interface of LIBLINEAR --- 3 | -------------------------------------------- 4 | 5 | Table of Contents 6 | ================= 7 | 8 | - Introduction 9 | - Installation 10 | - Usage 11 | - Returned Model Structure 12 | - Other Utilities 13 | - Examples 14 | - Additional Information 15 | 16 | 17 | Introduction 18 | ============ 19 | 20 | This tool provides a simple interface to LIBLINEAR, a library for 21 | large-scale regularized linear classification and regression 22 | (http://www.csie.ntu.edu.tw/~cjlin/liblinear). It is very easy to use 23 | as the usage and the way of specifying parameters are the same as that 24 | of LIBLINEAR. 25 | 26 | Installation 27 | ============ 28 | 29 | On Windows systems, pre-built binary files are already in the 30 | directory '..\windows', so no need to conduct installation. Now we 31 | provide binary files only for 64bit MATLAB on Windows. If you would 32 | like to re-build the package, please rely on the following steps. 33 | 34 | We recommend using make.m on both MATLAB and OCTAVE. Just type 'make' 35 | to build 'libsvmread.mex', 'libsvmwrite.mex', 'train.mex', and 36 | 'predict.mex'. 37 | 38 | On MATLAB or Octave: 39 | 40 | >> make 41 | 42 | If make.m does not work on MATLAB (especially for Windows), try 'mex 43 | -setup' to choose a suitable compiler for mex. Make sure your compiler 44 | is accessible and workable. Then type 'make' to start the 45 | installation. 46 | 47 | Example: 48 | 49 | matlab>> mex -setup 50 | (ps: MATLAB will show the following messages to setup default compiler.) 51 | Please choose your compiler for building external interface (MEX) files: 52 | Would you like mex to locate installed compilers [y]/n? y 53 | Select a compiler: 54 | [1] Microsoft Visual C/C++ version 7.1 in C:\Program Files\Microsoft Visual Studio 55 | [0] None 56 | Compiler: 1 57 | Please verify your choices: 58 | Compiler: Microsoft Visual C/C++ 7.1 59 | Location: C:\Program Files\Microsoft Visual Studio 60 | Are these correct?([y]/n): y 61 | 62 | matlab>> make 63 | 64 | On Unix systems, if neither make.m nor 'mex -setup' works, please use 65 | Makefile and type 'make' in a command window. Note that we assume 66 | your MATLAB is installed in '/usr/local/matlab'. If not, please change 67 | MATLABDIR in Makefile. 68 | 69 | Example: 70 | linux> make 71 | 72 | To use octave, type 'make octave': 73 | 74 | Example: 75 | linux> make octave 76 | 77 | For a list of supported/compatible compilers for MATLAB, please check 78 | the following page: 79 | 80 | http://www.mathworks.com/support/compilers/current_release/ 81 | 82 | Usage 83 | ===== 84 | 85 | matlab> model = train(training_label_vector, training_instance_matrix [,'liblinear_options', 'col']); 86 | 87 | -training_label_vector: 88 | An m by 1 vector of training labels. (type must be double) 89 | -training_instance_matrix: 90 | An m by n matrix of m training instances with n features. 91 | It must be a sparse matrix. (type must be double) 92 | -liblinear_options: 93 | A string of training options in the same format as that of LIBLINEAR. 94 | -col: 95 | if 'col' is set, each column of training_instance_matrix is a data instance. Otherwise each row is a data instance. 96 | 97 | matlab> [predicted_label, accuracy, decision_values/prob_estimates] = predict(testing_label_vector, testing_instance_matrix, model [, 'liblinear_options', 'col']); 98 | 99 | -testing_label_vector: 100 | An m by 1 vector of prediction labels. If labels of test 101 | data are unknown, simply use any random values. (type must be double) 102 | -testing_instance_matrix: 103 | An m by n matrix of m testing instances with n features. 104 | It must be a sparse matrix. (type must be double) 105 | -model: 106 | The output of train. 107 | -liblinear_options: 108 | A string of testing options in the same format as that of LIBLINEAR. 109 | -col: 110 | if 'col' is set, each column of testing_instance_matrix is a data instance. Otherwise each row is a data instance. 111 | 112 | Returned Model Structure 113 | ======================== 114 | 115 | The 'train' function returns a model which can be used for future 116 | prediction. It is a structure and is organized as [Parameters, nr_class, 117 | nr_feature, bias, Label, w]: 118 | 119 | -Parameters: Parameters 120 | -nr_class: number of classes; = 2 for regression 121 | -nr_feature: number of features in training data (without including the bias term) 122 | -bias: If >= 0, we assume one additional feature is added to the end 123 | of each data instance. 124 | -Label: label of each class; empty for regression 125 | -w: a nr_w-by-n matrix for the weights, where n is nr_feature 126 | or nr_feature+1 depending on the existence of the bias term. 127 | nr_w is 1 if nr_class=2 and -s is not 4 (i.e., not 128 | multi-class svm by Crammer and Singer). It is 129 | nr_class otherwise. 130 | 131 | If the '-v' option is specified, cross validation is conducted and the 132 | returned model is just a scalar: cross-validation accuracy for 133 | classification and mean-squared error for regression. 134 | 135 | Result of Prediction 136 | ==================== 137 | 138 | The function 'predict' has three outputs. The first one, 139 | predicted_label, is a vector of predicted labels. The second output, 140 | accuracy, is a vector including accuracy (for classification), mean 141 | squared error, and squared correlation coefficient (for regression). 142 | The third is a matrix containing decision values or probability 143 | estimates (if '-b 1' is specified). If k is the number of classes 144 | and k' is the number of classifiers (k'=1 if k=2, otherwise k'=k), for decision values, 145 | each row includes results of k' binary linear classifiers. For probabilities, 146 | each row contains k values indicating the probability that the testing instance is in 147 | each class. Note that the order of classes here is the same as 'Label' 148 | field in the model structure. 149 | 150 | Other Utilities 151 | =============== 152 | 153 | A matlab function libsvmread reads files in LIBSVM format: 154 | 155 | [label_vector, instance_matrix] = libsvmread('data.txt'); 156 | 157 | Two outputs are labels and instances, which can then be used as inputs 158 | of svmtrain or svmpredict. 159 | 160 | A matlab function libsvmwrite writes Matlab matrix to a file in LIBSVM format: 161 | 162 | libsvmwrite('data.txt', label_vector, instance_matrix] 163 | 164 | The instance_matrix must be a sparse matrix. (type must be double) 165 | For windows, `libsvmread.mexw64' and `libsvmwrite.mexw64' are ready in 166 | the directory `..\windows'. 167 | 168 | These codes are prepared by Rong-En Fan and Kai-Wei Chang from National 169 | Taiwan University. 170 | 171 | Examples 172 | ======== 173 | 174 | Train and test on the provided data heart_scale: 175 | 176 | matlab> [heart_scale_label, heart_scale_inst] = libsvmread('../heart_scale'); 177 | matlab> model = train(heart_scale_label, heart_scale_inst, '-c 1'); 178 | matlab> [predict_label, accuracy, dec_values] = predict(heart_scale_label, heart_scale_inst, model); % test the training data 179 | 180 | Note that for testing, you can put anything in the testing_label_vector. 181 | 182 | For probability estimates, you need '-b 1' only in the testing phase: 183 | 184 | matlab> [predict_label, accuracy, prob_estimates] = predict(heart_scale_label, heart_scale_inst, model, '-b 1'); 185 | 186 | Additional Information 187 | ====================== 188 | 189 | Please cite LIBLINEAR as follows 190 | 191 | R.-E. Fan, K.-W. Chang, C.-J. Hsieh, X.-R. Wang, and C.-J. Lin. 192 | LIBLINEAR: A Library for Large Linear Classification, Journal of 193 | Machine Learning Research 9(2008), 1871-1874.Software available at 194 | http://www.csie.ntu.edu.tw/~cjlin/liblinear 195 | 196 | For any question, please contact Chih-Jen Lin . 197 | 198 | -------------------------------------------------------------------------------- /Liblinear/predict.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "../linear.h" 5 | 6 | #include "mex.h" 7 | #include "linear_model_matlab.h" 8 | 9 | #ifdef MX_API_VER 10 | #if MX_API_VER < 0x07030000 11 | typedef int mwIndex; 12 | #endif 13 | #endif 14 | 15 | #define CMD_LEN 2048 16 | 17 | #define Malloc(type,n) (type *)malloc((n)*sizeof(type)) 18 | 19 | int print_null(const char *s,...) {} 20 | int (*info)(const char *fmt,...); 21 | 22 | int col_format_flag; 23 | 24 | void read_sparse_instance(const mxArray *prhs, int index, struct feature_node *x, int feature_number, double bias) 25 | { 26 | int i, j, low, high; 27 | mwIndex *ir, *jc; 28 | double *samples; 29 | 30 | ir = mxGetIr(prhs); 31 | jc = mxGetJc(prhs); 32 | samples = mxGetPr(prhs); 33 | 34 | // each column is one instance 35 | j = 0; 36 | low = (int) jc[index], high = (int) jc[index+1]; 37 | for(i=low; i=0) 44 | { 45 | x[j].index = feature_number+1; 46 | x[j].value = bias; 47 | j++; 48 | } 49 | x[j].index = -1; 50 | } 51 | 52 | static void fake_answer(mxArray *plhs[]) 53 | { 54 | plhs[0] = mxCreateDoubleMatrix(0, 0, mxREAL); 55 | plhs[1] = mxCreateDoubleMatrix(0, 0, mxREAL); 56 | plhs[2] = mxCreateDoubleMatrix(0, 0, mxREAL); 57 | } 58 | 59 | void do_predict(mxArray *plhs[], const mxArray *prhs[], struct model *model_, const int predict_probability_flag) 60 | { 61 | int label_vector_row_num, label_vector_col_num; 62 | int feature_number, testing_instance_number; 63 | int instance_index; 64 | double *ptr_label, *ptr_predict_label; 65 | double *ptr_prob_estimates, *ptr_dec_values, *ptr; 66 | struct feature_node *x; 67 | mxArray *pplhs[1]; // instance sparse matrix in row format 68 | 69 | int correct = 0; 70 | int total = 0; 71 | double error = 0; 72 | double sump = 0, sumt = 0, sumpp = 0, sumtt = 0, sumpt = 0; 73 | 74 | int nr_class=get_nr_class(model_); 75 | int nr_w; 76 | double *prob_estimates=NULL; 77 | 78 | if(nr_class==2 && model_->param.solver_type!=MCSVM_CS) 79 | nr_w=1; 80 | else 81 | nr_w=nr_class; 82 | 83 | // prhs[1] = testing instance matrix 84 | feature_number = get_nr_feature(model_); 85 | testing_instance_number = (int) mxGetM(prhs[1]); 86 | if(col_format_flag) 87 | { 88 | feature_number = (int) mxGetM(prhs[1]); 89 | testing_instance_number = (int) mxGetN(prhs[1]); 90 | } 91 | 92 | label_vector_row_num = (int) mxGetM(prhs[0]); 93 | label_vector_col_num = (int) mxGetN(prhs[0]); 94 | 95 | if(label_vector_row_num!=testing_instance_number) 96 | { 97 | mexPrintf("Length of label vector does not match # of instances.\n"); 98 | fake_answer(plhs); 99 | return; 100 | } 101 | if(label_vector_col_num!=1) 102 | { 103 | mexPrintf("label (1st argument) should be a vector (# of column is 1).\n"); 104 | fake_answer(plhs); 105 | return; 106 | } 107 | 108 | ptr_label = mxGetPr(prhs[0]); 109 | 110 | // transpose instance matrix 111 | if(col_format_flag) 112 | pplhs[0] = (mxArray *)prhs[1]; 113 | else 114 | { 115 | mxArray *pprhs[1]; 116 | pprhs[0] = mxDuplicateArray(prhs[1]); 117 | if(mexCallMATLAB(1, pplhs, 1, pprhs, "transpose")) 118 | { 119 | mexPrintf("Error: cannot transpose testing instance matrix\n"); 120 | fake_answer(plhs); 121 | return; 122 | } 123 | } 124 | 125 | 126 | prob_estimates = Malloc(double, nr_class); 127 | 128 | plhs[0] = mxCreateDoubleMatrix(testing_instance_number, 1, mxREAL); 129 | if(predict_probability_flag) 130 | plhs[2] = mxCreateDoubleMatrix(testing_instance_number, nr_class, mxREAL); 131 | else 132 | plhs[2] = mxCreateDoubleMatrix(testing_instance_number, nr_w, mxREAL); 133 | 134 | ptr_predict_label = mxGetPr(plhs[0]); 135 | ptr_prob_estimates = mxGetPr(plhs[2]); 136 | ptr_dec_values = mxGetPr(plhs[2]); 137 | x = Malloc(struct feature_node, feature_number+2); 138 | for(instance_index=0;instance_indexbias); 147 | 148 | if(predict_probability_flag) 149 | { 150 | predict_label = predict_probability(model_, x, prob_estimates); 151 | ptr_predict_label[instance_index] = predict_label; 152 | for(i=0;iparam.solver_type==L2R_L2LOSS_SVR || 179 | model_->param.solver_type==L2R_L1LOSS_SVR_DUAL || 180 | model_->param.solver_type==L2R_L2LOSS_SVR_DUAL) 181 | { 182 | info("Mean squared error = %g (regression)\n",error/total); 183 | info("Squared correlation coefficient = %g (regression)\n", 184 | ((total*sumpt-sump*sumt)*(total*sumpt-sump*sumt))/ 185 | ((total*sumpp-sump*sump)*(total*sumtt-sumt*sumt)) 186 | ); 187 | } 188 | else 189 | info("Accuracy = %g%% (%d/%d)\n", (double) correct/total*100,correct,total); 190 | 191 | // return accuracy, mean squared error, squared correlation coefficient 192 | plhs[1] = mxCreateDoubleMatrix(3, 1, mxREAL); 193 | ptr = mxGetPr(plhs[1]); 194 | ptr[0] = (double)correct/total*100; 195 | ptr[1] = error/total; 196 | ptr[2] = ((total*sumpt-sump*sumt)*(total*sumpt-sump*sumt))/ 197 | ((total*sumpp-sump*sump)*(total*sumtt-sumt*sumt)); 198 | 199 | free(x); 200 | if(prob_estimates != NULL) 201 | free(prob_estimates); 202 | } 203 | 204 | void exit_with_help() 205 | { 206 | mexPrintf( 207 | "Usage: [predicted_label, accuracy, decision_values/prob_estimates] = predict(testing_label_vector, testing_instance_matrix, model, 'liblinear_options','col')\n" 208 | "liblinear_options:\n" 209 | "-b probability_estimates: whether to output probability estimates, 0 or 1 (default 0); currently for logistic regression only\n" 210 | "-q quiet mode (no outputs)\n" 211 | "col: if 'col' is setted testing_instance_matrix is parsed in column format, otherwise is in row format\n" 212 | "Returns:\n" 213 | " predicted_label: prediction output vector.\n" 214 | " accuracy: a vector with accuracy, mean squared error, squared correlation coefficient.\n" 215 | " prob_estimates: If selected, probability estimate vector.\n" 216 | ); 217 | } 218 | 219 | void mexFunction( int nlhs, mxArray *plhs[], 220 | int nrhs, const mxArray *prhs[] ) 221 | { 222 | int prob_estimate_flag = 0; 223 | struct model *model_; 224 | char cmd[CMD_LEN]; 225 | info = &mexPrintf; 226 | col_format_flag = 0; 227 | 228 | if(nrhs > 5 || nrhs < 3) 229 | { 230 | exit_with_help(); 231 | fake_answer(plhs); 232 | return; 233 | } 234 | if(nrhs == 5) 235 | { 236 | mxGetString(prhs[4], cmd, mxGetN(prhs[4])+1); 237 | if(strcmp(cmd, "col") == 0) 238 | { 239 | col_format_flag = 1; 240 | } 241 | } 242 | 243 | if(!mxIsDouble(prhs[0]) || !mxIsDouble(prhs[1])) { 244 | mexPrintf("Error: label vector and instance matrix must be double\n"); 245 | fake_answer(plhs); 246 | return; 247 | } 248 | 249 | if(mxIsStruct(prhs[2])) 250 | { 251 | const char *error_msg; 252 | 253 | // parse options 254 | if(nrhs>=4) 255 | { 256 | int i, argc = 1; 257 | char *argv[CMD_LEN/2]; 258 | 259 | // put options in argv[] 260 | mxGetString(prhs[3], cmd, mxGetN(prhs[3]) + 1); 261 | if((argv[argc] = strtok(cmd, " ")) != NULL) 262 | while((argv[++argc] = strtok(NULL, " ")) != NULL) 263 | ; 264 | 265 | for(i=1;i=argc && argv[i-1][1] != 'q') 270 | { 271 | exit_with_help(); 272 | fake_answer(plhs); 273 | return; 274 | } 275 | switch(argv[i-1][1]) 276 | { 277 | case 'b': 278 | prob_estimate_flag = atoi(argv[i]); 279 | break; 280 | case 'q': 281 | info = &print_null; 282 | i--; 283 | break; 284 | default: 285 | mexPrintf("unknown option\n"); 286 | exit_with_help(); 287 | fake_answer(plhs); 288 | return; 289 | } 290 | } 291 | } 292 | 293 | model_ = Malloc(struct model, 1); 294 | error_msg = matlab_matrix_to_model(model_, prhs[2]); 295 | if(error_msg) 296 | { 297 | mexPrintf("Error: can't read model: %s\n", error_msg); 298 | free_and_destroy_model(&model_); 299 | fake_answer(plhs); 300 | return; 301 | } 302 | 303 | if(prob_estimate_flag) 304 | { 305 | if(!check_probability_model(model_)) 306 | { 307 | mexPrintf("probability output is only supported for logistic regression\n"); 308 | prob_estimate_flag=0; 309 | } 310 | } 311 | 312 | if(mxIsSparse(prhs[1])) 313 | do_predict(plhs, prhs, model_, prob_estimate_flag); 314 | else 315 | { 316 | mexPrintf("Testing_instance_matrix must be sparse; " 317 | "use sparse(Testing_instance_matrix) first\n"); 318 | fake_answer(plhs); 319 | } 320 | 321 | // destroy model_ 322 | free_and_destroy_model(&model_); 323 | } 324 | else 325 | { 326 | mexPrintf("model file should be a struct array\n"); 327 | fake_answer(plhs); 328 | } 329 | 330 | return; 331 | } 332 | -------------------------------------------------------------------------------- /Liblinear/train.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "../linear.h" 7 | 8 | #include "mex.h" 9 | #include "linear_model_matlab.h" 10 | 11 | #ifdef MX_API_VER 12 | #if MX_API_VER < 0x07030000 13 | typedef int mwIndex; 14 | #endif 15 | #endif 16 | 17 | #define CMD_LEN 2048 18 | #define Malloc(type,n) (type *)malloc((n)*sizeof(type)) 19 | #define INF HUGE_VAL 20 | 21 | void print_null(const char *s) {} 22 | void print_string_matlab(const char *s) {mexPrintf(s);} 23 | 24 | void exit_with_help() 25 | { 26 | mexPrintf( 27 | "Usage: model = train(training_label_vector, training_instance_matrix, 'liblinear_options', 'col');\n" 28 | "liblinear_options:\n" 29 | "-s type : set type of solver (default 1)\n" 30 | " for multi-class classification\n" 31 | " 0 -- L2-regularized logistic regression (primal)\n" 32 | " 1 -- L2-regularized L2-loss support vector classification (dual)\n" 33 | " 2 -- L2-regularized L2-loss support vector classification (primal)\n" 34 | " 3 -- L2-regularized L1-loss support vector classification (dual)\n" 35 | " 4 -- support vector classification by Crammer and Singer\n" 36 | " 5 -- L1-regularized L2-loss support vector classification\n" 37 | " 6 -- L1-regularized logistic regression\n" 38 | " 7 -- L2-regularized logistic regression (dual)\n" 39 | " for regression\n" 40 | " 11 -- L2-regularized L2-loss support vector regression (primal)\n" 41 | " 12 -- L2-regularized L2-loss support vector regression (dual)\n" 42 | " 13 -- L2-regularized L1-loss support vector regression (dual)\n" 43 | "-c cost : set the parameter C (default 1)\n" 44 | "-p epsilon : set the epsilon in loss function of SVR (default 0.1)\n" 45 | "-e epsilon : set tolerance of termination criterion\n" 46 | " -s 0 and 2\n" 47 | " |f'(w)|_2 <= eps*min(pos,neg)/l*|f'(w0)|_2,\n" 48 | " where f is the primal function and pos/neg are # of\n" 49 | " positive/negative data (default 0.01)\n" 50 | " -s 11\n" 51 | " |f'(w)|_2 <= eps*|f'(w0)|_2 (default 0.001)\n" 52 | " -s 1, 3, 4 and 7\n" 53 | " Dual maximal violation <= eps; similar to libsvm (default 0.1)\n" 54 | " -s 5 and 6\n" 55 | " |f'(w)|_1 <= eps*min(pos,neg)/l*|f'(w0)|_1,\n" 56 | " where f is the primal function (default 0.01)\n" 57 | " -s 12 and 13\n" 58 | " |f'(alpha)|_1 <= eps |f'(alpha0)|,\n" 59 | " where f is the dual function (default 0.1)\n" 60 | "-B bias : if bias >= 0, instance x becomes [x; bias]; if < 0, no bias term added (default -1)\n" 61 | "-wi weight: weights adjust the parameter C of different classes (see README for details)\n" 62 | "-v n: n-fold cross validation mode\n" 63 | "-q : quiet mode (no outputs)\n" 64 | "col:\n" 65 | " if 'col' is setted, training_instance_matrix is parsed in column format, otherwise is in row format\n" 66 | ); 67 | } 68 | 69 | // liblinear arguments 70 | struct parameter param; // set by parse_command_line 71 | struct problem prob; // set by read_problem 72 | struct model *model_; 73 | struct feature_node *x_space; 74 | int cross_validation_flag; 75 | int col_format_flag; 76 | int nr_fold; 77 | double bias; 78 | 79 | double do_cross_validation() 80 | { 81 | int i; 82 | int total_correct = 0; 83 | double total_error = 0; 84 | double sumv = 0, sumy = 0, sumvv = 0, sumyy = 0, sumvy = 0; 85 | double *target = Malloc(double, prob.l); 86 | double retval = 0.0; 87 | 88 | cross_validation(&prob,¶m,nr_fold,target); 89 | if(param.solver_type == L2R_L2LOSS_SVR || 90 | param.solver_type == L2R_L1LOSS_SVR_DUAL || 91 | param.solver_type == L2R_L2LOSS_SVR_DUAL) 92 | { 93 | for(i=0;i 2) 157 | { 158 | mxGetString(prhs[2], cmd, mxGetN(prhs[2]) + 1); 159 | if((argv[argc] = strtok(cmd, " ")) != NULL) 160 | while((argv[++argc] = strtok(NULL, " ")) != NULL) 161 | ; 162 | } 163 | 164 | // parse options 165 | for(i=1;i=argc && argv[i-1][1] != 'q') // since option -q has no parameter 170 | return 1; 171 | switch(argv[i-1][1]) 172 | { 173 | case 's': 174 | param.solver_type = atoi(argv[i]); 175 | break; 176 | case 'c': 177 | param.C = atof(argv[i]); 178 | break; 179 | case 'p': 180 | param.p = atof(argv[i]); 181 | break; 182 | case 'e': 183 | param.eps = atof(argv[i]); 184 | break; 185 | case 'B': 186 | bias = atof(argv[i]); 187 | break; 188 | case 'v': 189 | cross_validation_flag = 1; 190 | nr_fold = atoi(argv[i]); 191 | if(nr_fold < 2) 192 | { 193 | mexPrintf("n-fold cross validation: n must >= 2\n"); 194 | return 1; 195 | } 196 | break; 197 | case 'w': 198 | ++param.nr_weight; 199 | param.weight_label = (int *) realloc(param.weight_label,sizeof(int)*param.nr_weight); 200 | param.weight = (double *) realloc(param.weight,sizeof(double)*param.nr_weight); 201 | param.weight_label[param.nr_weight-1] = atoi(&argv[i-1][2]); 202 | param.weight[param.nr_weight-1] = atof(argv[i]); 203 | break; 204 | case 'q': 205 | print_func = &print_null; 206 | i--; 207 | break; 208 | default: 209 | mexPrintf("unknown option\n"); 210 | return 1; 211 | } 212 | } 213 | 214 | set_print_string_function(print_func); 215 | 216 | if(param.eps == INF) 217 | { 218 | switch(param.solver_type) 219 | { 220 | case L2R_LR: 221 | case L2R_L2LOSS_SVC: 222 | param.eps = 0.01; 223 | break; 224 | case L2R_L2LOSS_SVR: 225 | param.eps = 0.001; 226 | break; 227 | case L2R_L2LOSS_SVC_DUAL: 228 | case L2R_L1LOSS_SVC_DUAL: 229 | case MCSVM_CS: 230 | case L2R_LR_DUAL: 231 | param.eps = 0.1; 232 | break; 233 | case L1R_L2LOSS_SVC: 234 | case L1R_LR: 235 | param.eps = 0.01; 236 | break; 237 | case L2R_L1LOSS_SVR_DUAL: 238 | case L2R_L2LOSS_SVR_DUAL: 239 | param.eps = 0.1; 240 | break; 241 | } 242 | } 243 | return 0; 244 | } 245 | 246 | static void fake_answer(mxArray *plhs[]) 247 | { 248 | plhs[0] = mxCreateDoubleMatrix(0, 0, mxREAL); 249 | } 250 | 251 | int read_problem_sparse(const mxArray *label_vec, const mxArray *instance_mat) 252 | { 253 | int i, j, k, low, high; 254 | mwIndex *ir, *jc; 255 | int elements, max_index, num_samples, label_vector_row_num; 256 | double *samples, *labels; 257 | mxArray *instance_mat_col; // instance sparse matrix in column format 258 | 259 | prob.x = NULL; 260 | prob.y = NULL; 261 | x_space = NULL; 262 | 263 | if(col_format_flag) 264 | instance_mat_col = (mxArray *)instance_mat; 265 | else 266 | { 267 | // transpose instance matrix 268 | mxArray *prhs[1], *plhs[1]; 269 | prhs[0] = mxDuplicateArray(instance_mat); 270 | if(mexCallMATLAB(1, plhs, 1, prhs, "transpose")) 271 | { 272 | mexPrintf("Error: cannot transpose training instance matrix\n"); 273 | return -1; 274 | } 275 | instance_mat_col = plhs[0]; 276 | mxDestroyArray(prhs[0]); 277 | } 278 | 279 | // the number of instance 280 | prob.l = (int) mxGetN(instance_mat_col); 281 | label_vector_row_num = (int) mxGetM(label_vec); 282 | 283 | if(label_vector_row_num!=prob.l) 284 | { 285 | mexPrintf("Length of label vector does not match # of instances.\n"); 286 | return -1; 287 | } 288 | 289 | // each column is one instance 290 | labels = mxGetPr(label_vec); 291 | samples = mxGetPr(instance_mat_col); 292 | ir = mxGetIr(instance_mat_col); 293 | jc = mxGetJc(instance_mat_col); 294 | 295 | num_samples = (int) mxGetNzmax(instance_mat_col); 296 | 297 | elements = num_samples + prob.l*2; 298 | max_index = (int) mxGetM(instance_mat_col); 299 | 300 | prob.y = Malloc(double, prob.l); 301 | prob.x = Malloc(struct feature_node*, prob.l); 302 | x_space = Malloc(struct feature_node, elements); 303 | 304 | prob.bias=bias; 305 | 306 | j = 0; 307 | for(i=0;i=0) 319 | { 320 | x_space[j].index = max_index+1; 321 | x_space[j].value = prob.bias; 322 | j++; 323 | } 324 | x_space[j++].index = -1; 325 | } 326 | 327 | if(prob.bias>=0) 328 | prob.n = max_index+1; 329 | else 330 | prob.n = max_index; 331 | 332 | return 0; 333 | } 334 | 335 | // Interface function of matlab 336 | // now assume prhs[0]: label prhs[1]: features 337 | void mexFunction( int nlhs, mxArray *plhs[], 338 | int nrhs, const mxArray *prhs[] ) 339 | { 340 | const char *error_msg; 341 | // fix random seed to have same results for each run 342 | // (for cross validation) 343 | srand(1); 344 | 345 | // Transform the input Matrix to libsvm format 346 | if(nrhs > 1 && nrhs < 5) 347 | { 348 | int err=0; 349 | 350 | if(!mxIsDouble(prhs[0]) || !mxIsDouble(prhs[1])) { 351 | mexPrintf("Error: label vector and instance matrix must be double\n"); 352 | fake_answer(plhs); 353 | return; 354 | } 355 | 356 | if(parse_command_line(nrhs, prhs, NULL)) 357 | { 358 | exit_with_help(); 359 | destroy_param(¶m); 360 | fake_answer(plhs); 361 | return; 362 | } 363 | 364 | if(mxIsSparse(prhs[1])) 365 | err = read_problem_sparse(prhs[0], prhs[1]); 366 | else 367 | { 368 | mexPrintf("Training_instance_matrix must be sparse; " 369 | "use sparse(Training_instance_matrix) first\n"); 370 | destroy_param(¶m); 371 | fake_answer(plhs); 372 | return; 373 | } 374 | 375 | // train's original code 376 | error_msg = check_parameter(&prob, ¶m); 377 | 378 | if(err || error_msg) 379 | { 380 | if (error_msg != NULL) 381 | mexPrintf("Error: %s\n", error_msg); 382 | destroy_param(¶m); 383 | free(prob.y); 384 | free(prob.x); 385 | free(x_space); 386 | fake_answer(plhs); 387 | return; 388 | } 389 | 390 | if(cross_validation_flag) 391 | { 392 | double *ptr; 393 | plhs[0] = mxCreateDoubleMatrix(1, 1, mxREAL); 394 | ptr = mxGetPr(plhs[0]); 395 | ptr[0] = do_cross_validation(); 396 | } 397 | else 398 | { 399 | const char *error_msg; 400 | 401 | model_ = train(&prob, ¶m); 402 | error_msg = model_to_matlab_structure(plhs, model_); 403 | if(error_msg) 404 | mexPrintf("Error: can't convert libsvm model to matrix structure: %s\n", error_msg); 405 | free_and_destroy_model(&model_); 406 | } 407 | destroy_param(¶m); 408 | free(prob.y); 409 | free(prob.x); 410 | free(x_space); 411 | } 412 | else 413 | { 414 | exit_with_help(); 415 | fake_answer(plhs); 416 | return; 417 | } 418 | } 419 | -------------------------------------------------------------------------------- /prototxt_files/test_ice.prototxt: -------------------------------------------------------------------------------- 1 | name: "Transferred Deep Learning" 2 | layer { 3 | name: "test_data" 4 | type: "Data" 5 | top: "data" 6 | top: "label" 7 | include { 8 | phase: TEST 9 | } 10 | data_param { 11 | source: "./examples/Transfer/data/test_lmdb" 12 | batch_size: 32 13 | backend: LMDB 14 | } 15 | } 16 | layer { 17 | name: "Convolution1" 18 | type: "Convolution" 19 | bottom: "data" 20 | top: "Convolution1" 21 | param { 22 | lr_mult: 0 23 | decay_mult: 1 24 | } 25 | param { 26 | lr_mult: 0 27 | decay_mult: 0 28 | } 29 | convolution_param { 30 | num_output: 16 31 | pad: 1 32 | kernel_size: 3 33 | stride: 1 34 | weight_filler { 35 | type: "xavier" 36 | } 37 | bias_filler { 38 | type: "constant" 39 | value: 0 40 | } 41 | } 42 | } 43 | layer { 44 | name: "BatchNorm1" 45 | type: "BatchNorm" 46 | bottom: "Convolution1" 47 | top: "Convolution1" 48 | param { 49 | lr_mult: 0 50 | decay_mult: 0 51 | } 52 | param { 53 | lr_mult: 0 54 | decay_mult: 0 55 | } 56 | param { 57 | lr_mult: 0 58 | decay_mult: 0 59 | } 60 | } 61 | layer { 62 | name: "Scale1" 63 | type: "Scale" 64 | bottom: "Convolution1" 65 | top: "Convolution1" 66 | scale_param { 67 | bias_term: true 68 | } 69 | } 70 | layer { 71 | name: "ReLU1" 72 | type: "ReLU" 73 | bottom: "Convolution1" 74 | top: "Convolution1" 75 | } 76 | layer { 77 | name: "Convolution2" 78 | type: "Convolution" 79 | bottom: "Convolution1" 80 | top: "Convolution2" 81 | param { 82 | lr_mult: 0 83 | decay_mult: 1 84 | } 85 | param { 86 | lr_mult: 0 87 | decay_mult: 0 88 | } 89 | convolution_param { 90 | num_output: 16 91 | pad: 1 92 | kernel_size: 3 93 | stride: 1 94 | weight_filler { 95 | type: "xavier" 96 | } 97 | bias_filler { 98 | type: "constant" 99 | value: 0 100 | } 101 | } 102 | } 103 | layer { 104 | name: "BatchNorm2" 105 | type: "BatchNorm" 106 | bottom: "Convolution2" 107 | top: "Convolution2" 108 | param { 109 | lr_mult: 0 110 | decay_mult: 0 111 | } 112 | param { 113 | lr_mult: 0 114 | decay_mult: 0 115 | } 116 | param { 117 | lr_mult: 0 118 | decay_mult: 0 119 | } 120 | } 121 | layer { 122 | name: "Scale2" 123 | type: "Scale" 124 | bottom: "Convolution2" 125 | top: "Convolution2" 126 | scale_param { 127 | bias_term: true 128 | } 129 | } 130 | layer { 131 | name: "Eltwise1" 132 | type: "Eltwise" 133 | bottom: "Convolution1" 134 | bottom: "Convolution2" 135 | top: "Eltwise1" 136 | eltwise_param { 137 | operation: SUM 138 | } 139 | } 140 | layer { 141 | name: "ReLU2" 142 | type: "ReLU" 143 | bottom: "Eltwise1" 144 | top: "Eltwise1" 145 | } 146 | layer { 147 | name: "Convolution3" 148 | type: "Convolution" 149 | bottom: "Eltwise1" 150 | top: "Convolution3" 151 | param { 152 | lr_mult: 0 153 | decay_mult: 1 154 | } 155 | param { 156 | lr_mult: 0 157 | decay_mult: 0 158 | } 159 | convolution_param { 160 | num_output: 16 161 | pad: 1 162 | kernel_size: 3 163 | stride: 1 164 | weight_filler { 165 | type: "xavier" 166 | } 167 | bias_filler { 168 | type: "constant" 169 | value: 0 170 | } 171 | } 172 | } 173 | layer { 174 | name: "BatchNorm3" 175 | type: "BatchNorm" 176 | bottom: "Convolution3" 177 | top: "Convolution3" 178 | param { 179 | lr_mult: 0 180 | decay_mult: 0 181 | } 182 | param { 183 | lr_mult: 0 184 | decay_mult: 0 185 | } 186 | param { 187 | lr_mult: 0 188 | decay_mult: 0 189 | } 190 | } 191 | layer { 192 | name: "Scale3" 193 | type: "Scale" 194 | bottom: "Convolution3" 195 | top: "Convolution3" 196 | scale_param { 197 | bias_term: true 198 | } 199 | } 200 | 201 | layer { 202 | name: "Eltwise2" 203 | type: "Eltwise" 204 | bottom: "Eltwise1" 205 | bottom: "Convolution3" 206 | top: "Eltwise2" 207 | eltwise_param { 208 | operation: SUM 209 | } 210 | } 211 | layer { 212 | name: "ReLU3" 213 | type: "ReLU" 214 | bottom: "Eltwise2" 215 | top: "Eltwise2" 216 | } 217 | layer { 218 | name: "Convolution4" 219 | type: "Convolution" 220 | bottom: "Eltwise2" 221 | top: "Convolution4" 222 | param { 223 | lr_mult: 0 224 | decay_mult: 1 225 | } 226 | param { 227 | lr_mult: 0 228 | decay_mult: 0 229 | } 230 | convolution_param { 231 | num_output: 16 232 | pad: 1 233 | kernel_size: 3 234 | stride: 1 235 | weight_filler { 236 | type: "xavier" 237 | } 238 | bias_filler { 239 | type: "constant" 240 | value: 0 241 | } 242 | } 243 | } 244 | layer { 245 | name: "BatchNorm4" 246 | type: "BatchNorm" 247 | bottom: "Convolution4" 248 | top: "Convolution4" 249 | param { 250 | lr_mult: 0 251 | decay_mult: 0 252 | } 253 | param { 254 | lr_mult: 0 255 | decay_mult: 0 256 | } 257 | param { 258 | lr_mult: 0 259 | decay_mult: 0 260 | } 261 | } 262 | layer { 263 | name: "Scale4" 264 | type: "Scale" 265 | bottom: "Convolution4" 266 | top: "Convolution4" 267 | scale_param { 268 | bias_term: true 269 | } 270 | } 271 | layer { 272 | name: "Eltwise3" 273 | type: "Eltwise" 274 | bottom: "Eltwise2" 275 | bottom: "Convolution4" 276 | top: "Eltwise3" 277 | eltwise_param { 278 | operation: SUM 279 | } 280 | } 281 | layer { 282 | name: "ReLU4" 283 | type: "ReLU" 284 | bottom: "Eltwise3" 285 | top: "Eltwise3" 286 | } 287 | layer { 288 | name: "Convolution5" 289 | type: "Convolution" 290 | bottom: "Eltwise3" 291 | top: "Convolution5" 292 | param { 293 | lr_mult: 0 294 | decay_mult: 1 295 | } 296 | param { 297 | lr_mult: 0 298 | decay_mult: 0 299 | } 300 | convolution_param { 301 | num_output: 16 302 | pad: 1 303 | kernel_size: 3 304 | stride: 1 305 | weight_filler { 306 | type: "xavier" 307 | } 308 | bias_filler { 309 | type: "constant" 310 | value: 0 311 | } 312 | } 313 | } 314 | layer { 315 | name: "BatchNorm5" 316 | type: "BatchNorm" 317 | bottom: "Convolution5" 318 | top: "Convolution5" 319 | param { 320 | lr_mult: 0 321 | decay_mult: 0 322 | } 323 | param { 324 | lr_mult: 0 325 | decay_mult: 0 326 | } 327 | param { 328 | lr_mult: 0 329 | decay_mult: 0 330 | } 331 | } 332 | layer { 333 | name: "Scale5" 334 | type: "Scale" 335 | bottom: "Convolution5" 336 | top: "Convolution5" 337 | scale_param { 338 | bias_term: true 339 | } 340 | } 341 | layer { 342 | name: "Eltwise4" 343 | type: "Eltwise" 344 | bottom: "Eltwise3" 345 | bottom: "Convolution5" 346 | top: "Eltwise4" 347 | eltwise_param { 348 | operation: SUM 349 | } 350 | } 351 | layer { 352 | name: "ReLU5" 353 | type: "ReLU" 354 | bottom: "Eltwise4" 355 | top: "Eltwise4" 356 | } 357 | 358 | ##################################### 359 | layer { 360 | name: "Convolution6" 361 | type: "Convolution" 362 | bottom: "Eltwise4" 363 | top: "Convolution6" 364 | param { 365 | lr_mult: 1 366 | decay_mult: 1 367 | } 368 | param { 369 | lr_mult: 2 370 | decay_mult: 0 371 | } 372 | convolution_param { 373 | num_output: 32 374 | pad: 0 375 | kernel_size: 1 376 | stride: 2 377 | weight_filler { 378 | type: "xavier" 379 | } 380 | bias_filler { 381 | type: "constant" 382 | value: 0 383 | } 384 | } 385 | } 386 | layer { 387 | name: "BatchNorm6" 388 | type: "BatchNorm" 389 | bottom: "Convolution6" 390 | top: "Convolution6" 391 | param { 392 | lr_mult: 0 393 | decay_mult: 0 394 | } 395 | param { 396 | lr_mult: 0 397 | decay_mult: 0 398 | } 399 | param { 400 | lr_mult: 0 401 | decay_mult: 0 402 | } 403 | } 404 | layer { 405 | name: "Scale6" 406 | type: "Scale" 407 | bottom: "Convolution6" 408 | top: "Convolution6" 409 | scale_param { 410 | bias_term: true 411 | } 412 | } 413 | layer { 414 | name: "Convolution7" 415 | type: "Convolution" 416 | bottom: "Eltwise4" 417 | top: "Convolution7" 418 | param { 419 | lr_mult: 1 420 | decay_mult: 1 421 | } 422 | param { 423 | lr_mult: 2 424 | decay_mult: 0 425 | } 426 | convolution_param { 427 | num_output: 32 428 | pad: 1 429 | kernel_size: 3 430 | stride: 2 431 | weight_filler { 432 | type: "xavier" 433 | } 434 | bias_filler { 435 | type: "constant" 436 | value: 0 437 | } 438 | } 439 | } 440 | layer { 441 | name: "BatchNorm7" 442 | type: "BatchNorm" 443 | bottom: "Convolution7" 444 | top: "Convolution7" 445 | param { 446 | lr_mult: 0 447 | decay_mult: 0 448 | } 449 | param { 450 | lr_mult: 0 451 | decay_mult: 0 452 | } 453 | param { 454 | lr_mult: 0 455 | decay_mult: 0 456 | } 457 | } 458 | layer { 459 | name: "Scale7" 460 | type: "Scale" 461 | bottom: "Convolution7" 462 | top: "Convolution7" 463 | scale_param { 464 | bias_term: true 465 | } 466 | } 467 | layer { 468 | name: "Eltwise5" 469 | type: "Eltwise" 470 | bottom: "Convolution6" 471 | bottom: "Convolution7" 472 | top: "Eltwise5" 473 | eltwise_param { 474 | operation: SUM 475 | } 476 | } 477 | layer { 478 | name: "ReLU6" 479 | type: "ReLU" 480 | bottom: "Eltwise5" 481 | top: "Eltwise5" 482 | } 483 | layer { 484 | name: "Convolution8" 485 | type: "Convolution" 486 | bottom: "Eltwise5" 487 | top: "Convolution8" 488 | param { 489 | lr_mult: 1 490 | decay_mult: 1 491 | } 492 | param { 493 | lr_mult: 2 494 | decay_mult: 0 495 | } 496 | convolution_param { 497 | num_output: 32 498 | pad: 1 499 | kernel_size: 3 500 | stride: 1 501 | weight_filler { 502 | type: "xavier" 503 | } 504 | bias_filler { 505 | type: "constant" 506 | value: 0 507 | } 508 | } 509 | } 510 | layer { 511 | name: "BatchNorm8" 512 | type: "BatchNorm" 513 | bottom: "Convolution8" 514 | top: "Convolution8" 515 | param { 516 | lr_mult: 0 517 | decay_mult: 0 518 | } 519 | param { 520 | lr_mult: 0 521 | decay_mult: 0 522 | } 523 | param { 524 | lr_mult: 0 525 | decay_mult: 0 526 | } 527 | } 528 | layer { 529 | name: "Scale8" 530 | type: "Scale" 531 | bottom: "Convolution8" 532 | top: "Convolution8" 533 | scale_param { 534 | bias_term: true 535 | } 536 | } 537 | layer { 538 | name: "Eltwise6" 539 | type: "Eltwise" 540 | bottom: "Eltwise5" 541 | bottom: "Convolution8" 542 | top: "Eltwise6" 543 | eltwise_param { 544 | operation: SUM 545 | } 546 | } 547 | layer { 548 | name: "ReLU7" 549 | type: "ReLU" 550 | bottom: "Eltwise6" 551 | top: "Eltwise6" 552 | } 553 | layer { 554 | name: "Convolution9" 555 | type: "Convolution" 556 | bottom: "Eltwise6" 557 | top: "Convolution9" 558 | param { 559 | lr_mult: 1 560 | decay_mult: 1 561 | } 562 | param { 563 | lr_mult: 2 564 | decay_mult: 0 565 | } 566 | convolution_param { 567 | num_output: 32 568 | pad: 1 569 | kernel_size: 3 570 | stride: 1 571 | weight_filler { 572 | type: "xavier" 573 | } 574 | bias_filler { 575 | type: "constant" 576 | value: 0 577 | } 578 | } 579 | } 580 | layer { 581 | name: "BatchNorm9" 582 | type: "BatchNorm" 583 | bottom: "Convolution9" 584 | top: "Convolution9" 585 | param { 586 | lr_mult: 0 587 | decay_mult: 0 588 | } 589 | param { 590 | lr_mult: 0 591 | decay_mult: 0 592 | } 593 | param { 594 | lr_mult: 0 595 | decay_mult: 0 596 | } 597 | } 598 | layer { 599 | name: "Scale9" 600 | type: "Scale" 601 | bottom: "Convolution9" 602 | top: "Convolution9" 603 | scale_param { 604 | bias_term: true 605 | } 606 | } 607 | layer { 608 | name: "Eltwise7" 609 | type: "Eltwise" 610 | bottom: "Eltwise6" 611 | bottom: "Convolution9" 612 | top: "Eltwise7" 613 | eltwise_param { 614 | operation: SUM 615 | } 616 | } 617 | layer { 618 | name: "ReLU8" 619 | type: "ReLU" 620 | bottom: "Eltwise7" 621 | top: "Eltwise7" 622 | } 623 | layer { 624 | name: "Convolution10" 625 | type: "Convolution" 626 | bottom: "Eltwise7" 627 | top: "Convolution10" 628 | param { 629 | lr_mult: 1 630 | decay_mult: 1 631 | } 632 | param { 633 | lr_mult: 2 634 | decay_mult: 0 635 | } 636 | convolution_param { 637 | num_output: 32 638 | pad: 1 639 | kernel_size: 3 640 | stride: 1 641 | weight_filler { 642 | type: "xavier" 643 | } 644 | bias_filler { 645 | type: "constant" 646 | value: 0 647 | } 648 | } 649 | } 650 | layer { 651 | name: "BatchNorm10" 652 | type: "BatchNorm" 653 | bottom: "Convolution10" 654 | top: "Convolution10" 655 | param { 656 | lr_mult: 0 657 | decay_mult: 0 658 | } 659 | param { 660 | lr_mult: 0 661 | decay_mult: 0 662 | } 663 | param { 664 | lr_mult: 0 665 | decay_mult: 0 666 | } 667 | } 668 | layer { 669 | name: "Scale10" 670 | type: "Scale" 671 | bottom: "Convolution10" 672 | top: "Convolution10" 673 | scale_param { 674 | bias_term: true 675 | } 676 | } 677 | layer { 678 | name: "Eltwise8" 679 | type: "Eltwise" 680 | bottom: "Eltwise7" 681 | bottom: "Convolution10" 682 | top: "Eltwise8" 683 | eltwise_param { 684 | operation: SUM 685 | } 686 | } 687 | layer { 688 | name: "ReLU9" 689 | type: "ReLU" 690 | bottom: "Eltwise8" 691 | top: "Eltwise8" 692 | } 693 | 694 | layer { 695 | name: "Convolution11" 696 | type: "Convolution" 697 | bottom: "Eltwise8" 698 | top: "Convolution11" 699 | param { 700 | lr_mult: 1 701 | decay_mult: 1 702 | } 703 | param { 704 | lr_mult: 2 705 | decay_mult: 0 706 | } 707 | convolution_param { 708 | num_output: 64 709 | pad: 0 710 | kernel_size: 1 711 | stride: 2 712 | weight_filler { 713 | type: "xavier" 714 | } 715 | bias_filler { 716 | type: "constant" 717 | value: 0 718 | } 719 | } 720 | } 721 | layer { 722 | name: "BatchNorm11" 723 | type: "BatchNorm" 724 | bottom: "Convolution11" 725 | top: "Convolution11" 726 | param { 727 | lr_mult: 0 728 | decay_mult: 0 729 | } 730 | param { 731 | lr_mult: 0 732 | decay_mult: 0 733 | } 734 | param { 735 | lr_mult: 0 736 | decay_mult: 0 737 | } 738 | } 739 | layer { 740 | name: "Scale11" 741 | type: "Scale" 742 | bottom: "Convolution11" 743 | top: "Convolution11" 744 | scale_param { 745 | bias_term: true 746 | } 747 | } 748 | layer { 749 | name: "Convolution12" 750 | type: "Convolution" 751 | bottom: "Eltwise8" 752 | top: "Convolution12" 753 | param { 754 | lr_mult: 1 755 | decay_mult: 1 756 | } 757 | param { 758 | lr_mult: 2 759 | decay_mult: 0 760 | } 761 | convolution_param { 762 | num_output: 64 763 | pad: 1 764 | kernel_size: 3 765 | stride: 2 766 | weight_filler { 767 | type: "xavier" 768 | } 769 | bias_filler { 770 | type: "constant" 771 | value: 0 772 | } 773 | } 774 | } 775 | layer { 776 | name: "BatchNorm12" 777 | type: "BatchNorm" 778 | bottom: "Convolution12" 779 | top: "Convolution12" 780 | param { 781 | lr_mult: 0 782 | decay_mult: 0 783 | } 784 | param { 785 | lr_mult: 0 786 | decay_mult: 0 787 | } 788 | param { 789 | lr_mult: 0 790 | decay_mult: 0 791 | } 792 | } 793 | layer { 794 | name: "Scale12" 795 | type: "Scale" 796 | bottom: "Convolution12" 797 | top: "Convolution12" 798 | scale_param { 799 | bias_term: true 800 | } 801 | } 802 | layer { 803 | name: "Eltwise9" 804 | type: "Eltwise" 805 | bottom: "Convolution11" 806 | bottom: "Convolution12" 807 | top: "Eltwise9" 808 | eltwise_param { 809 | operation: SUM 810 | } 811 | } 812 | layer { 813 | name: "ReLU10" 814 | type: "ReLU" 815 | bottom: "Eltwise9" 816 | top: "Eltwise9" 817 | } 818 | layer { 819 | name: "Convolution13" 820 | type: "Convolution" 821 | bottom: "Eltwise9" 822 | top: "Convolution13" 823 | param { 824 | lr_mult: 1 825 | decay_mult: 1 826 | } 827 | param { 828 | lr_mult: 2 829 | decay_mult: 0 830 | } 831 | convolution_param { 832 | num_output: 64 833 | pad: 1 834 | kernel_size: 3 835 | stride: 1 836 | weight_filler { 837 | type: "xavier" 838 | } 839 | bias_filler { 840 | type: "constant" 841 | value: 0 842 | } 843 | } 844 | } 845 | layer { 846 | name: "BatchNorm13" 847 | type: "BatchNorm" 848 | bottom: "Convolution13" 849 | top: "Convolution13" 850 | param { 851 | lr_mult: 0 852 | decay_mult: 0 853 | } 854 | param { 855 | lr_mult: 0 856 | decay_mult: 0 857 | } 858 | param { 859 | lr_mult: 0 860 | decay_mult: 0 861 | } 862 | } 863 | layer { 864 | name: "Scale13" 865 | type: "Scale" 866 | bottom: "Convolution13" 867 | top: "Convolution13" 868 | scale_param { 869 | bias_term: true 870 | } 871 | } 872 | layer { 873 | name: "Eltwise10" 874 | type: "Eltwise" 875 | bottom: "Eltwise9" 876 | bottom: "Convolution13" 877 | top: "Eltwise10" 878 | eltwise_param { 879 | operation: SUM 880 | } 881 | } 882 | layer { 883 | name: "ReLU11" 884 | type: "ReLU" 885 | bottom: "Eltwise10" 886 | top: "Eltwise10" 887 | } 888 | layer { 889 | name: "Convolution14" 890 | type: "Convolution" 891 | bottom: "Eltwise10" 892 | top: "Convolution14" 893 | param { 894 | lr_mult: 1 895 | decay_mult: 1 896 | } 897 | param { 898 | lr_mult: 2 899 | decay_mult: 0 900 | } 901 | convolution_param { 902 | num_output: 64 903 | pad: 1 904 | kernel_size: 3 905 | stride: 1 906 | weight_filler { 907 | type: "xavier" 908 | } 909 | bias_filler { 910 | type: "constant" 911 | value: 0 912 | } 913 | } 914 | } 915 | layer { 916 | name: "BatchNorm14" 917 | type: "BatchNorm" 918 | bottom: "Convolution14" 919 | top: "Convolution14" 920 | param { 921 | lr_mult: 0 922 | decay_mult: 0 923 | } 924 | param { 925 | lr_mult: 0 926 | decay_mult: 0 927 | } 928 | param { 929 | lr_mult: 0 930 | decay_mult: 0 931 | } 932 | } 933 | layer { 934 | name: "Scale14" 935 | type: "Scale" 936 | bottom: "Convolution14" 937 | top: "Convolution14" 938 | scale_param { 939 | bias_term: true 940 | } 941 | } 942 | layer { 943 | name: "Eltwise11" 944 | type: "Eltwise" 945 | bottom: "Eltwise10" 946 | bottom: "Convolution14" 947 | top: "Eltwise11" 948 | eltwise_param { 949 | operation: SUM 950 | } 951 | } 952 | layer { 953 | name: "ReLU12" 954 | type: "ReLU" 955 | bottom: "Eltwise11" 956 | top: "Eltwise11" 957 | } 958 | layer { 959 | name: "Convolution15" 960 | type: "Convolution" 961 | bottom: "Eltwise11" 962 | top: "Convolution15" 963 | param { 964 | lr_mult: 1 965 | decay_mult: 1 966 | } 967 | param { 968 | lr_mult: 2 969 | decay_mult: 0 970 | } 971 | convolution_param { 972 | num_output: 64 973 | pad: 1 974 | kernel_size: 3 975 | stride: 1 976 | weight_filler { 977 | type: "xavier" 978 | } 979 | bias_filler { 980 | type: "constant" 981 | value: 0 982 | } 983 | } 984 | } 985 | layer { 986 | name: "BatchNorm15" 987 | type: "BatchNorm" 988 | bottom: "Convolution15" 989 | top: "Convolution15" 990 | param { 991 | lr_mult: 0 992 | decay_mult: 0 993 | } 994 | param { 995 | lr_mult: 0 996 | decay_mult: 0 997 | } 998 | param { 999 | lr_mult: 0 1000 | decay_mult: 0 1001 | } 1002 | } 1003 | layer { 1004 | name: "Scale15" 1005 | type: "Scale" 1006 | bottom: "Convolution15" 1007 | top: "Convolution15" 1008 | scale_param { 1009 | bias_term: true 1010 | } 1011 | } 1012 | layer { 1013 | name: "Eltwise12" 1014 | type: "Eltwise" 1015 | bottom: "Eltwise11" 1016 | bottom: "Convolution15" 1017 | top: "Eltwise12" 1018 | eltwise_param { 1019 | operation: SUM 1020 | } 1021 | } 1022 | layer { 1023 | name: "ReLU13" 1024 | type: "ReLU" 1025 | bottom: "Eltwise12" 1026 | top: "Eltwise12" 1027 | } 1028 | 1029 | layer { 1030 | name: "Convolution_eltwise4" 1031 | type: "Convolution" 1032 | bottom: "Eltwise4" 1033 | top: "Convolution_eltwise4" 1034 | param { 1035 | lr_mult: 1 1036 | decay_mult: 1 1037 | } 1038 | param { 1039 | lr_mult: 2 1040 | decay_mult: 0 1041 | } 1042 | convolution_param { 1043 | num_output: 64 1044 | pad: 1 1045 | kernel_size: 3 1046 | stride: 4 1047 | weight_filler { 1048 | type: "xavier" 1049 | } 1050 | bias_filler { 1051 | type: "constant" 1052 | value: 0 1053 | } 1054 | } 1055 | } 1056 | layer { 1057 | name: "BatchNorm_Convolution_eltwise4" 1058 | type: "BatchNorm" 1059 | bottom: "Convolution_eltwise4" 1060 | top: "Convolution_eltwise4" 1061 | } 1062 | layer { 1063 | name: "Scale_Convolution_eltwise4" 1064 | type: "Scale" 1065 | bottom: "Convolution_eltwise4" 1066 | top: "Convolution_eltwise4" 1067 | scale_param { 1068 | bias_term: true 1069 | } 1070 | } 1071 | 1072 | 1073 | layer { 1074 | name: "Convolution_eltwise8" 1075 | type: "Convolution" 1076 | bottom: "Eltwise8" 1077 | top: "Convolution_eltwise8" 1078 | param { 1079 | lr_mult: 1 1080 | decay_mult: 1 1081 | } 1082 | param { 1083 | lr_mult: 2 1084 | decay_mult: 0 1085 | } 1086 | convolution_param { 1087 | num_output: 64 1088 | pad: 1 1089 | kernel_size: 3 1090 | stride: 2 1091 | weight_filler { 1092 | type: "xavier" 1093 | } 1094 | bias_filler { 1095 | type: "constant" 1096 | value: 0 1097 | } 1098 | } 1099 | } 1100 | layer { 1101 | name: "BatchNorm_Convolution_eltwise8" 1102 | type: "BatchNorm" 1103 | bottom: "Convolution_eltwise8" 1104 | top: "Convolution_eltwise8" 1105 | } 1106 | layer { 1107 | name: "Scale_Convolution_eltwise8" 1108 | type: "Scale" 1109 | bottom: "Convolution_eltwise8" 1110 | top: "Convolution_eltwise8" 1111 | scale_param { 1112 | bias_term: true 1113 | } 1114 | } 1115 | 1116 | layer { 1117 | name: "fuse1" 1118 | type: "Eltwise" 1119 | bottom: "Convolution_eltwise4" 1120 | bottom: "Convolution_eltwise8" 1121 | top: "fuse1" 1122 | eltwise_param { 1123 | operation: SUM 1124 | } 1125 | } 1126 | layer { 1127 | name: "fuse2" 1128 | type: "Eltwise" 1129 | bottom: "fuse1" 1130 | bottom: "Eltwise12" 1131 | top: "fuse2" 1132 | eltwise_param { 1133 | operation: SUM 1134 | } 1135 | } 1136 | 1137 | layer { 1138 | name: "ReLU14" 1139 | type: "ReLU" 1140 | bottom: "fuse2" 1141 | top: "fuse2" 1142 | } 1143 | 1144 | layer { 1145 | name: "Pooling1" 1146 | type: "Pooling" 1147 | bottom: "fuse2" 1148 | top: "Pooling1" 1149 | pooling_param { 1150 | pool: AVE 1151 | global_pooling: true 1152 | } 1153 | } 1154 | 1155 | 1156 | layer { 1157 | name: "InnerProduct" 1158 | type: "InnerProduct" 1159 | bottom: "Pooling1" 1160 | top: "InnerProduct1" 1161 | param { 1162 | lr_mult: 1 1163 | decay_mult: 1 1164 | } 1165 | param { 1166 | lr_mult: 2 1167 | decay_mult: 1 1168 | } 1169 | inner_product_param { 1170 | num_output: 2 1171 | weight_filler { 1172 | type: "xavier" 1173 | } 1174 | bias_filler { 1175 | type: "constant" 1176 | value: 0 1177 | } 1178 | } 1179 | } 1180 | layer { 1181 | name: "SoftmaxWithLoss1" 1182 | type: "SoftmaxWithLoss" 1183 | bottom: "InnerProduct1" 1184 | bottom: "label" 1185 | top: "SoftmaxWithLoss1" 1186 | } 1187 | layer { 1188 | name: "prob" 1189 | type: "Softmax" 1190 | bottom: "InnerProduct1" 1191 | top: "prob" 1192 | include { 1193 | phase: TEST 1194 | } 1195 | } 1196 | layer { 1197 | name: "Accuracy1" 1198 | type: "Accuracy" 1199 | bottom: "InnerProduct1" 1200 | bottom: "label" 1201 | top: "Accuracy1" 1202 | include { 1203 | phase: TEST 1204 | } 1205 | } 1206 | -------------------------------------------------------------------------------- /prototxt_files/train_ice.prototxt: -------------------------------------------------------------------------------- 1 | name: "Transferred Deep Learning" 2 | layer { 3 | name: "train_data" 4 | type: "Data" 5 | top: "data" 6 | top: "label" 7 | include { 8 | phase: TRAIN 9 | } 10 | data_param { 11 | source: "./examples/Transfer/data/train_lmdb" 12 | batch_size: 32 13 | backend: LMDB 14 | } 15 | } 16 | layer { 17 | name: "test_data" 18 | type: "Data" 19 | top: "data" 20 | top: "label" 21 | include { 22 | phase: TEST 23 | } 24 | data_param { 25 | source: "./examples/Transfer/data/test_lmdb" 26 | batch_size: 32 27 | backend: LMDB 28 | } 29 | } 30 | layer { 31 | name: "Convolution1" 32 | type: "Convolution" 33 | bottom: "data" 34 | top: "Convolution1" 35 | param { 36 | lr_mult: 0 37 | decay_mult: 1 38 | } 39 | param { 40 | lr_mult: 0 41 | decay_mult: 0 42 | } 43 | convolution_param { 44 | num_output: 16 45 | pad: 1 46 | kernel_size: 3 47 | stride: 1 48 | weight_filler { 49 | type: "xavier" 50 | } 51 | bias_filler { 52 | type: "constant" 53 | value: 0 54 | } 55 | } 56 | } 57 | layer { 58 | name: "BatchNorm1" 59 | type: "BatchNorm" 60 | bottom: "Convolution1" 61 | top: "Convolution1" 62 | param { 63 | lr_mult: 0 64 | decay_mult: 0 65 | } 66 | param { 67 | lr_mult: 0 68 | decay_mult: 0 69 | } 70 | param { 71 | lr_mult: 0 72 | decay_mult: 0 73 | } 74 | } 75 | layer { 76 | name: "Scale1" 77 | type: "Scale" 78 | bottom: "Convolution1" 79 | top: "Convolution1" 80 | scale_param { 81 | bias_term: true 82 | } 83 | } 84 | layer { 85 | name: "ReLU1" 86 | type: "ReLU" 87 | bottom: "Convolution1" 88 | top: "Convolution1" 89 | } 90 | layer { 91 | name: "Convolution2" 92 | type: "Convolution" 93 | bottom: "Convolution1" 94 | top: "Convolution2" 95 | param { 96 | lr_mult: 0 97 | decay_mult: 1 98 | } 99 | param { 100 | lr_mult: 0 101 | decay_mult: 0 102 | } 103 | convolution_param { 104 | num_output: 16 105 | pad: 1 106 | kernel_size: 3 107 | stride: 1 108 | weight_filler { 109 | type: "xavier" 110 | } 111 | bias_filler { 112 | type: "constant" 113 | value: 0 114 | } 115 | } 116 | } 117 | layer { 118 | name: "BatchNorm2" 119 | type: "BatchNorm" 120 | bottom: "Convolution2" 121 | top: "Convolution2" 122 | param { 123 | lr_mult: 0 124 | decay_mult: 0 125 | } 126 | param { 127 | lr_mult: 0 128 | decay_mult: 0 129 | } 130 | param { 131 | lr_mult: 0 132 | decay_mult: 0 133 | } 134 | } 135 | layer { 136 | name: "Scale2" 137 | type: "Scale" 138 | bottom: "Convolution2" 139 | top: "Convolution2" 140 | scale_param { 141 | bias_term: true 142 | } 143 | } 144 | layer { 145 | name: "Eltwise1" 146 | type: "Eltwise" 147 | bottom: "Convolution1" 148 | bottom: "Convolution2" 149 | top: "Eltwise1" 150 | eltwise_param { 151 | operation: SUM 152 | } 153 | } 154 | layer { 155 | name: "ReLU2" 156 | type: "ReLU" 157 | bottom: "Eltwise1" 158 | top: "Eltwise1" 159 | } 160 | layer { 161 | name: "Convolution3" 162 | type: "Convolution" 163 | bottom: "Eltwise1" 164 | top: "Convolution3" 165 | param { 166 | lr_mult: 0 167 | decay_mult: 1 168 | } 169 | param { 170 | lr_mult: 0 171 | decay_mult: 0 172 | } 173 | convolution_param { 174 | num_output: 16 175 | pad: 1 176 | kernel_size: 3 177 | stride: 1 178 | weight_filler { 179 | type: "xavier" 180 | } 181 | bias_filler { 182 | type: "constant" 183 | value: 0 184 | } 185 | } 186 | } 187 | layer { 188 | name: "BatchNorm3" 189 | type: "BatchNorm" 190 | bottom: "Convolution3" 191 | top: "Convolution3" 192 | param { 193 | lr_mult: 0 194 | decay_mult: 0 195 | } 196 | param { 197 | lr_mult: 0 198 | decay_mult: 0 199 | } 200 | param { 201 | lr_mult: 0 202 | decay_mult: 0 203 | } 204 | } 205 | layer { 206 | name: "Scale3" 207 | type: "Scale" 208 | bottom: "Convolution3" 209 | top: "Convolution3" 210 | scale_param { 211 | bias_term: true 212 | } 213 | } 214 | 215 | layer { 216 | name: "Eltwise2" 217 | type: "Eltwise" 218 | bottom: "Eltwise1" 219 | bottom: "Convolution3" 220 | top: "Eltwise2" 221 | eltwise_param { 222 | operation: SUM 223 | } 224 | } 225 | layer { 226 | name: "ReLU3" 227 | type: "ReLU" 228 | bottom: "Eltwise2" 229 | top: "Eltwise2" 230 | } 231 | layer { 232 | name: "Convolution4" 233 | type: "Convolution" 234 | bottom: "Eltwise2" 235 | top: "Convolution4" 236 | param { 237 | lr_mult: 0 238 | decay_mult: 1 239 | } 240 | param { 241 | lr_mult: 0 242 | decay_mult: 0 243 | } 244 | convolution_param { 245 | num_output: 16 246 | pad: 1 247 | kernel_size: 3 248 | stride: 1 249 | weight_filler { 250 | type: "xavier" 251 | } 252 | bias_filler { 253 | type: "constant" 254 | value: 0 255 | } 256 | } 257 | } 258 | layer { 259 | name: "BatchNorm4" 260 | type: "BatchNorm" 261 | bottom: "Convolution4" 262 | top: "Convolution4" 263 | param { 264 | lr_mult: 0 265 | decay_mult: 0 266 | } 267 | param { 268 | lr_mult: 0 269 | decay_mult: 0 270 | } 271 | param { 272 | lr_mult: 0 273 | decay_mult: 0 274 | } 275 | } 276 | layer { 277 | name: "Scale4" 278 | type: "Scale" 279 | bottom: "Convolution4" 280 | top: "Convolution4" 281 | scale_param { 282 | bias_term: true 283 | } 284 | } 285 | layer { 286 | name: "Eltwise3" 287 | type: "Eltwise" 288 | bottom: "Eltwise2" 289 | bottom: "Convolution4" 290 | top: "Eltwise3" 291 | eltwise_param { 292 | operation: SUM 293 | } 294 | } 295 | layer { 296 | name: "ReLU4" 297 | type: "ReLU" 298 | bottom: "Eltwise3" 299 | top: "Eltwise3" 300 | } 301 | layer { 302 | name: "Convolution5" 303 | type: "Convolution" 304 | bottom: "Eltwise3" 305 | top: "Convolution5" 306 | param { 307 | lr_mult: 0 308 | decay_mult: 1 309 | } 310 | param { 311 | lr_mult: 0 312 | decay_mult: 0 313 | } 314 | convolution_param { 315 | num_output: 16 316 | pad: 1 317 | kernel_size: 3 318 | stride: 1 319 | weight_filler { 320 | type: "xavier" 321 | } 322 | bias_filler { 323 | type: "constant" 324 | value: 0 325 | } 326 | } 327 | } 328 | layer { 329 | name: "BatchNorm5" 330 | type: "BatchNorm" 331 | bottom: "Convolution5" 332 | top: "Convolution5" 333 | param { 334 | lr_mult: 0 335 | decay_mult: 0 336 | } 337 | param { 338 | lr_mult: 0 339 | decay_mult: 0 340 | } 341 | param { 342 | lr_mult: 0 343 | decay_mult: 0 344 | } 345 | } 346 | layer { 347 | name: "Scale5" 348 | type: "Scale" 349 | bottom: "Convolution5" 350 | top: "Convolution5" 351 | scale_param { 352 | bias_term: true 353 | } 354 | } 355 | layer { 356 | name: "Eltwise4" 357 | type: "Eltwise" 358 | bottom: "Eltwise3" 359 | bottom: "Convolution5" 360 | top: "Eltwise4" 361 | eltwise_param { 362 | operation: SUM 363 | } 364 | } 365 | layer { 366 | name: "ReLU5" 367 | type: "ReLU" 368 | bottom: "Eltwise4" 369 | top: "Eltwise4" 370 | } 371 | 372 | ##################################### 373 | layer { 374 | name: "Convolution6" 375 | type: "Convolution" 376 | bottom: "Eltwise4" 377 | top: "Convolution6" 378 | param { 379 | lr_mult: 1 380 | decay_mult: 1 381 | } 382 | param { 383 | lr_mult: 2 384 | decay_mult: 0 385 | } 386 | convolution_param { 387 | num_output: 32 388 | pad: 0 389 | kernel_size: 1 390 | stride: 2 391 | weight_filler { 392 | type: "xavier" 393 | } 394 | bias_filler { 395 | type: "constant" 396 | value: 0 397 | } 398 | } 399 | } 400 | layer { 401 | name: "BatchNorm6" 402 | type: "BatchNorm" 403 | bottom: "Convolution6" 404 | top: "Convolution6" 405 | param { 406 | lr_mult: 0 407 | decay_mult: 0 408 | } 409 | param { 410 | lr_mult: 0 411 | decay_mult: 0 412 | } 413 | param { 414 | lr_mult: 0 415 | decay_mult: 0 416 | } 417 | } 418 | layer { 419 | name: "Scale6" 420 | type: "Scale" 421 | bottom: "Convolution6" 422 | top: "Convolution6" 423 | scale_param { 424 | bias_term: true 425 | } 426 | } 427 | layer { 428 | name: "Convolution7" 429 | type: "Convolution" 430 | bottom: "Eltwise4" 431 | top: "Convolution7" 432 | param { 433 | lr_mult: 1 434 | decay_mult: 1 435 | } 436 | param { 437 | lr_mult: 2 438 | decay_mult: 0 439 | } 440 | convolution_param { 441 | num_output: 32 442 | pad: 1 443 | kernel_size: 3 444 | stride: 2 445 | weight_filler { 446 | type: "xavier" 447 | } 448 | bias_filler { 449 | type: "constant" 450 | value: 0 451 | } 452 | } 453 | } 454 | layer { 455 | name: "BatchNorm7" 456 | type: "BatchNorm" 457 | bottom: "Convolution7" 458 | top: "Convolution7" 459 | param { 460 | lr_mult: 0 461 | decay_mult: 0 462 | } 463 | param { 464 | lr_mult: 0 465 | decay_mult: 0 466 | } 467 | param { 468 | lr_mult: 0 469 | decay_mult: 0 470 | } 471 | } 472 | layer { 473 | name: "Scale7" 474 | type: "Scale" 475 | bottom: "Convolution7" 476 | top: "Convolution7" 477 | scale_param { 478 | bias_term: true 479 | } 480 | } 481 | layer { 482 | name: "Eltwise5" 483 | type: "Eltwise" 484 | bottom: "Convolution6" 485 | bottom: "Convolution7" 486 | top: "Eltwise5" 487 | eltwise_param { 488 | operation: SUM 489 | } 490 | } 491 | layer { 492 | name: "ReLU6" 493 | type: "ReLU" 494 | bottom: "Eltwise5" 495 | top: "Eltwise5" 496 | } 497 | layer { 498 | name: "Convolution8" 499 | type: "Convolution" 500 | bottom: "Eltwise5" 501 | top: "Convolution8" 502 | param { 503 | lr_mult: 1 504 | decay_mult: 1 505 | } 506 | param { 507 | lr_mult: 2 508 | decay_mult: 0 509 | } 510 | convolution_param { 511 | num_output: 32 512 | pad: 1 513 | kernel_size: 3 514 | stride: 1 515 | weight_filler { 516 | type: "xavier" 517 | } 518 | bias_filler { 519 | type: "constant" 520 | value: 0 521 | } 522 | } 523 | } 524 | layer { 525 | name: "BatchNorm8" 526 | type: "BatchNorm" 527 | bottom: "Convolution8" 528 | top: "Convolution8" 529 | param { 530 | lr_mult: 0 531 | decay_mult: 0 532 | } 533 | param { 534 | lr_mult: 0 535 | decay_mult: 0 536 | } 537 | param { 538 | lr_mult: 0 539 | decay_mult: 0 540 | } 541 | } 542 | layer { 543 | name: "Scale8" 544 | type: "Scale" 545 | bottom: "Convolution8" 546 | top: "Convolution8" 547 | scale_param { 548 | bias_term: true 549 | } 550 | } 551 | layer { 552 | name: "Eltwise6" 553 | type: "Eltwise" 554 | bottom: "Eltwise5" 555 | bottom: "Convolution8" 556 | top: "Eltwise6" 557 | eltwise_param { 558 | operation: SUM 559 | } 560 | } 561 | layer { 562 | name: "ReLU7" 563 | type: "ReLU" 564 | bottom: "Eltwise6" 565 | top: "Eltwise6" 566 | } 567 | layer { 568 | name: "Convolution9" 569 | type: "Convolution" 570 | bottom: "Eltwise6" 571 | top: "Convolution9" 572 | param { 573 | lr_mult: 1 574 | decay_mult: 1 575 | } 576 | param { 577 | lr_mult: 2 578 | decay_mult: 0 579 | } 580 | convolution_param { 581 | num_output: 32 582 | pad: 1 583 | kernel_size: 3 584 | stride: 1 585 | weight_filler { 586 | type: "xavier" 587 | } 588 | bias_filler { 589 | type: "constant" 590 | value: 0 591 | } 592 | } 593 | } 594 | layer { 595 | name: "BatchNorm9" 596 | type: "BatchNorm" 597 | bottom: "Convolution9" 598 | top: "Convolution9" 599 | param { 600 | lr_mult: 0 601 | decay_mult: 0 602 | } 603 | param { 604 | lr_mult: 0 605 | decay_mult: 0 606 | } 607 | param { 608 | lr_mult: 0 609 | decay_mult: 0 610 | } 611 | } 612 | layer { 613 | name: "Scale9" 614 | type: "Scale" 615 | bottom: "Convolution9" 616 | top: "Convolution9" 617 | scale_param { 618 | bias_term: true 619 | } 620 | } 621 | layer { 622 | name: "Eltwise7" 623 | type: "Eltwise" 624 | bottom: "Eltwise6" 625 | bottom: "Convolution9" 626 | top: "Eltwise7" 627 | eltwise_param { 628 | operation: SUM 629 | } 630 | } 631 | layer { 632 | name: "ReLU8" 633 | type: "ReLU" 634 | bottom: "Eltwise7" 635 | top: "Eltwise7" 636 | } 637 | layer { 638 | name: "Convolution10" 639 | type: "Convolution" 640 | bottom: "Eltwise7" 641 | top: "Convolution10" 642 | param { 643 | lr_mult: 1 644 | decay_mult: 1 645 | } 646 | param { 647 | lr_mult: 2 648 | decay_mult: 0 649 | } 650 | convolution_param { 651 | num_output: 32 652 | pad: 1 653 | kernel_size: 3 654 | stride: 1 655 | weight_filler { 656 | type: "xavier" 657 | } 658 | bias_filler { 659 | type: "constant" 660 | value: 0 661 | } 662 | } 663 | } 664 | layer { 665 | name: "BatchNorm10" 666 | type: "BatchNorm" 667 | bottom: "Convolution10" 668 | top: "Convolution10" 669 | param { 670 | lr_mult: 0 671 | decay_mult: 0 672 | } 673 | param { 674 | lr_mult: 0 675 | decay_mult: 0 676 | } 677 | param { 678 | lr_mult: 0 679 | decay_mult: 0 680 | } 681 | } 682 | layer { 683 | name: "Scale10" 684 | type: "Scale" 685 | bottom: "Convolution10" 686 | top: "Convolution10" 687 | scale_param { 688 | bias_term: true 689 | } 690 | } 691 | layer { 692 | name: "Eltwise8" 693 | type: "Eltwise" 694 | bottom: "Eltwise7" 695 | bottom: "Convolution10" 696 | top: "Eltwise8" 697 | eltwise_param { 698 | operation: SUM 699 | } 700 | } 701 | layer { 702 | name: "ReLU9" 703 | type: "ReLU" 704 | bottom: "Eltwise8" 705 | top: "Eltwise8" 706 | } 707 | 708 | layer { 709 | name: "Convolution11" 710 | type: "Convolution" 711 | bottom: "Eltwise8" 712 | top: "Convolution11" 713 | param { 714 | lr_mult: 1 715 | decay_mult: 1 716 | } 717 | param { 718 | lr_mult: 2 719 | decay_mult: 0 720 | } 721 | convolution_param { 722 | num_output: 64 723 | pad: 0 724 | kernel_size: 1 725 | stride: 2 726 | weight_filler { 727 | type: "xavier" 728 | } 729 | bias_filler { 730 | type: "constant" 731 | value: 0 732 | } 733 | } 734 | } 735 | layer { 736 | name: "BatchNorm11" 737 | type: "BatchNorm" 738 | bottom: "Convolution11" 739 | top: "Convolution11" 740 | param { 741 | lr_mult: 0 742 | decay_mult: 0 743 | } 744 | param { 745 | lr_mult: 0 746 | decay_mult: 0 747 | } 748 | param { 749 | lr_mult: 0 750 | decay_mult: 0 751 | } 752 | } 753 | layer { 754 | name: "Scale11" 755 | type: "Scale" 756 | bottom: "Convolution11" 757 | top: "Convolution11" 758 | scale_param { 759 | bias_term: true 760 | } 761 | } 762 | layer { 763 | name: "Convolution12" 764 | type: "Convolution" 765 | bottom: "Eltwise8" 766 | top: "Convolution12" 767 | param { 768 | lr_mult: 1 769 | decay_mult: 1 770 | } 771 | param { 772 | lr_mult: 2 773 | decay_mult: 0 774 | } 775 | convolution_param { 776 | num_output: 64 777 | pad: 1 778 | kernel_size: 3 779 | stride: 2 780 | weight_filler { 781 | type: "xavier" 782 | } 783 | bias_filler { 784 | type: "constant" 785 | value: 0 786 | } 787 | } 788 | } 789 | layer { 790 | name: "BatchNorm12" 791 | type: "BatchNorm" 792 | bottom: "Convolution12" 793 | top: "Convolution12" 794 | param { 795 | lr_mult: 0 796 | decay_mult: 0 797 | } 798 | param { 799 | lr_mult: 0 800 | decay_mult: 0 801 | } 802 | param { 803 | lr_mult: 0 804 | decay_mult: 0 805 | } 806 | } 807 | layer { 808 | name: "Scale12" 809 | type: "Scale" 810 | bottom: "Convolution12" 811 | top: "Convolution12" 812 | scale_param { 813 | bias_term: true 814 | } 815 | } 816 | layer { 817 | name: "Eltwise9" 818 | type: "Eltwise" 819 | bottom: "Convolution11" 820 | bottom: "Convolution12" 821 | top: "Eltwise9" 822 | eltwise_param { 823 | operation: SUM 824 | } 825 | } 826 | layer { 827 | name: "ReLU10" 828 | type: "ReLU" 829 | bottom: "Eltwise9" 830 | top: "Eltwise9" 831 | } 832 | layer { 833 | name: "Convolution13" 834 | type: "Convolution" 835 | bottom: "Eltwise9" 836 | top: "Convolution13" 837 | param { 838 | lr_mult: 1 839 | decay_mult: 1 840 | } 841 | param { 842 | lr_mult: 2 843 | decay_mult: 0 844 | } 845 | convolution_param { 846 | num_output: 64 847 | pad: 1 848 | kernel_size: 3 849 | stride: 1 850 | weight_filler { 851 | type: "xavier" 852 | } 853 | bias_filler { 854 | type: "constant" 855 | value: 0 856 | } 857 | } 858 | } 859 | layer { 860 | name: "BatchNorm13" 861 | type: "BatchNorm" 862 | bottom: "Convolution13" 863 | top: "Convolution13" 864 | param { 865 | lr_mult: 0 866 | decay_mult: 0 867 | } 868 | param { 869 | lr_mult: 0 870 | decay_mult: 0 871 | } 872 | param { 873 | lr_mult: 0 874 | decay_mult: 0 875 | } 876 | } 877 | layer { 878 | name: "Scale13" 879 | type: "Scale" 880 | bottom: "Convolution13" 881 | top: "Convolution13" 882 | scale_param { 883 | bias_term: true 884 | } 885 | } 886 | layer { 887 | name: "Eltwise10" 888 | type: "Eltwise" 889 | bottom: "Eltwise9" 890 | bottom: "Convolution13" 891 | top: "Eltwise10" 892 | eltwise_param { 893 | operation: SUM 894 | } 895 | } 896 | layer { 897 | name: "ReLU11" 898 | type: "ReLU" 899 | bottom: "Eltwise10" 900 | top: "Eltwise10" 901 | } 902 | layer { 903 | name: "Convolution14" 904 | type: "Convolution" 905 | bottom: "Eltwise10" 906 | top: "Convolution14" 907 | param { 908 | lr_mult: 1 909 | decay_mult: 1 910 | } 911 | param { 912 | lr_mult: 2 913 | decay_mult: 0 914 | } 915 | convolution_param { 916 | num_output: 64 917 | pad: 1 918 | kernel_size: 3 919 | stride: 1 920 | weight_filler { 921 | type: "xavier" 922 | } 923 | bias_filler { 924 | type: "constant" 925 | value: 0 926 | } 927 | } 928 | } 929 | layer { 930 | name: "BatchNorm14" 931 | type: "BatchNorm" 932 | bottom: "Convolution14" 933 | top: "Convolution14" 934 | param { 935 | lr_mult: 0 936 | decay_mult: 0 937 | } 938 | param { 939 | lr_mult: 0 940 | decay_mult: 0 941 | } 942 | param { 943 | lr_mult: 0 944 | decay_mult: 0 945 | } 946 | } 947 | layer { 948 | name: "Scale14" 949 | type: "Scale" 950 | bottom: "Convolution14" 951 | top: "Convolution14" 952 | scale_param { 953 | bias_term: true 954 | } 955 | } 956 | layer { 957 | name: "Eltwise11" 958 | type: "Eltwise" 959 | bottom: "Eltwise10" 960 | bottom: "Convolution14" 961 | top: "Eltwise11" 962 | eltwise_param { 963 | operation: SUM 964 | } 965 | } 966 | layer { 967 | name: "ReLU12" 968 | type: "ReLU" 969 | bottom: "Eltwise11" 970 | top: "Eltwise11" 971 | } 972 | layer { 973 | name: "Convolution15" 974 | type: "Convolution" 975 | bottom: "Eltwise11" 976 | top: "Convolution15" 977 | param { 978 | lr_mult: 1 979 | decay_mult: 1 980 | } 981 | param { 982 | lr_mult: 2 983 | decay_mult: 0 984 | } 985 | convolution_param { 986 | num_output: 64 987 | pad: 1 988 | kernel_size: 3 989 | stride: 1 990 | weight_filler { 991 | type: "xavier" 992 | } 993 | bias_filler { 994 | type: "constant" 995 | value: 0 996 | } 997 | } 998 | } 999 | layer { 1000 | name: "BatchNorm15" 1001 | type: "BatchNorm" 1002 | bottom: "Convolution15" 1003 | top: "Convolution15" 1004 | param { 1005 | lr_mult: 0 1006 | decay_mult: 0 1007 | } 1008 | param { 1009 | lr_mult: 0 1010 | decay_mult: 0 1011 | } 1012 | param { 1013 | lr_mult: 0 1014 | decay_mult: 0 1015 | } 1016 | } 1017 | layer { 1018 | name: "Scale15" 1019 | type: "Scale" 1020 | bottom: "Convolution15" 1021 | top: "Convolution15" 1022 | scale_param { 1023 | bias_term: true 1024 | } 1025 | } 1026 | layer { 1027 | name: "Eltwise12" 1028 | type: "Eltwise" 1029 | bottom: "Eltwise11" 1030 | bottom: "Convolution15" 1031 | top: "Eltwise12" 1032 | eltwise_param { 1033 | operation: SUM 1034 | } 1035 | } 1036 | layer { 1037 | name: "ReLU13" 1038 | type: "ReLU" 1039 | bottom: "Eltwise12" 1040 | top: "Eltwise12" 1041 | } 1042 | 1043 | layer { 1044 | name: "Convolution_eltwise4" 1045 | type: "Convolution" 1046 | bottom: "Eltwise4" 1047 | top: "Convolution_eltwise4" 1048 | param { 1049 | lr_mult: 1 1050 | decay_mult: 1 1051 | } 1052 | param { 1053 | lr_mult: 2 1054 | decay_mult: 0 1055 | } 1056 | convolution_param { 1057 | num_output: 64 1058 | pad: 1 1059 | kernel_size: 3 1060 | stride: 4 1061 | weight_filler { 1062 | type: "xavier" 1063 | } 1064 | bias_filler { 1065 | type: "constant" 1066 | value: 0 1067 | } 1068 | } 1069 | } 1070 | layer { 1071 | name: "BatchNorm_Convolution_eltwise4" 1072 | type: "BatchNorm" 1073 | bottom: "Convolution_eltwise4" 1074 | top: "Convolution_eltwise4" 1075 | } 1076 | layer { 1077 | name: "Scale_Convolution_eltwise4" 1078 | type: "Scale" 1079 | bottom: "Convolution_eltwise4" 1080 | top: "Convolution_eltwise4" 1081 | scale_param { 1082 | bias_term: true 1083 | } 1084 | } 1085 | 1086 | 1087 | layer { 1088 | name: "Convolution_eltwise8" 1089 | type: "Convolution" 1090 | bottom: "Eltwise8" 1091 | top: "Convolution_eltwise8" 1092 | param { 1093 | lr_mult: 1 1094 | decay_mult: 1 1095 | } 1096 | param { 1097 | lr_mult: 2 1098 | decay_mult: 0 1099 | } 1100 | convolution_param { 1101 | num_output: 64 1102 | pad: 1 1103 | kernel_size: 3 1104 | stride: 2 1105 | weight_filler { 1106 | type: "xavier" 1107 | } 1108 | bias_filler { 1109 | type: "constant" 1110 | value: 0 1111 | } 1112 | } 1113 | } 1114 | layer { 1115 | name: "BatchNorm_Convolution_eltwise8" 1116 | type: "BatchNorm" 1117 | bottom: "Convolution_eltwise8" 1118 | top: "Convolution_eltwise8" 1119 | } 1120 | layer { 1121 | name: "Scale_Convolution_eltwise8" 1122 | type: "Scale" 1123 | bottom: "Convolution_eltwise8" 1124 | top: "Convolution_eltwise8" 1125 | scale_param { 1126 | bias_term: true 1127 | } 1128 | } 1129 | 1130 | layer { 1131 | name: "fuse1" 1132 | type: "Eltwise" 1133 | bottom: "Convolution_eltwise4" 1134 | bottom: "Convolution_eltwise8" 1135 | top: "fuse1" 1136 | eltwise_param { 1137 | operation: SUM 1138 | } 1139 | } 1140 | layer { 1141 | name: "fuse2" 1142 | type: "Eltwise" 1143 | bottom: "fuse1" 1144 | bottom: "Eltwise12" 1145 | top: "fuse2" 1146 | eltwise_param { 1147 | operation: SUM 1148 | } 1149 | } 1150 | 1151 | layer { 1152 | name: "ReLU14" 1153 | type: "ReLU" 1154 | bottom: "fuse2" 1155 | top: "fuse2" 1156 | } 1157 | 1158 | layer { 1159 | name: "Pooling1" 1160 | type: "Pooling" 1161 | bottom: "fuse2" 1162 | top: "Pooling1" 1163 | pooling_param { 1164 | pool: AVE 1165 | global_pooling: true 1166 | } 1167 | } 1168 | 1169 | 1170 | layer { 1171 | name: "InnerProduct" 1172 | type: "InnerProduct" 1173 | bottom: "Pooling1" 1174 | top: "InnerProduct1" 1175 | param { 1176 | lr_mult: 1 1177 | decay_mult: 1 1178 | } 1179 | param { 1180 | lr_mult: 2 1181 | decay_mult: 1 1182 | } 1183 | inner_product_param { 1184 | num_output: 2 1185 | weight_filler { 1186 | type: "xavier" 1187 | } 1188 | bias_filler { 1189 | type: "constant" 1190 | value: 0 1191 | } 1192 | } 1193 | } 1194 | layer { 1195 | name: "SoftmaxWithLoss1" 1196 | type: "SoftmaxWithLoss" 1197 | bottom: "InnerProduct1" 1198 | bottom: "label" 1199 | top: "SoftmaxWithLoss1" 1200 | } 1201 | #layer { 1202 | # name: "prob" 1203 | # type: "Softmax" 1204 | # bottom: "InnerProduct1" 1205 | # top: "prob" 1206 | # include { 1207 | # phase: TEST 1208 | # } 1209 | #} 1210 | layer { 1211 | name: "Accuracy1" 1212 | type: "Accuracy" 1213 | bottom: "InnerProduct1" 1214 | bottom: "label" 1215 | top: "Accuracy1" 1216 | include { 1217 | phase: TEST 1218 | } 1219 | } 1220 | --------------------------------------------------------------------------------