Home > @RealAdaBooster > saveToFid.m

saveToFid

PURPOSE ^

SAVETOFID Saves RealAdaBoost classifier to a binary file

SYNOPSIS ^

function saveToFid(cl, fid)

DESCRIPTION ^

SAVETOFID Saves RealAdaBoost classifier to a binary file
   Inputs:
       cl : svm classifier
       fid : file descriptor

   Note : weak classifier must support saveToFild method

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function saveToFid(cl, fid)
0002 %SAVETOFID Saves RealAdaBoost classifier to a binary file
0003 %   Inputs:
0004 %       cl : svm classifier
0005 %       fid : file descriptor
0006 %
0007 %   Note : weak classifier must support saveToFild method
0008 
0009 %% write weak classifier name
0010 data = serialize(class(cl.weakCl));
0011 dataSize = size(data, 1);
0012 
0013 %write weak classifier name length
0014 if fwrite(fid, uint16(dataSize), 'uint16') ~= 1
0015     error('Error writing to file\n');
0016 end
0017 
0018 % write weights
0019 if fwrite(fid, data, 'uint8') ~= dataSize
0020      error('Error writing to file\n');
0021 end
0022 
0023 %% write err bound
0024 if fwrite(fid, cl.errBound, 'double') ~= 1
0025     error('Error writing to file\n');
0026 end
0027 %% write untrained weak classifier
0028 saveToFid(cl.weakCl, fid);
0029 %% write trained weak classifiers
0030 % write length of trained classifiers
0031 if fwrite(fid, length(cl.trndCls), 'uint16') ~= 1
0032     error('Error writing to file\n');
0033 end
0034 
0035 % write classifier data
0036 for i = 1:length(cl.trndCls)
0037     saveToFid(cl.trndCls{i}, fid)
0038 end
0039 
0040 %% write number of stages
0041 if fwrite(fid, cl.nStages, 'uint16') ~= 1
0042     error('Error writing to file\n');
0043 end
0044 
0045 %% write last instances weights
0046 data = serialize(cl.lastExWeights);
0047 dataSize = size(data, 1);
0048 
0049 % write length of weights
0050 if fwrite(fid, uint16(dataSize), 'uint16') ~= 1
0051     error('Error writing to file\n');
0052 end
0053 
0054 % write weights
0055 if fwrite(fid, data, 'uint8') ~= dataSize
0056      error('Error writing to file\n');
0057 end
0058 %% write cls weights
0059 data = serialize(cl.clsWeights);
0060 dataSize = size(data, 1);
0061 
0062 % write length of weights
0063 if fwrite(fid, uint16(dataSize), 'uint16') ~= 1
0064     error('Error writing to file\n');
0065 end
0066 
0067 % write weights
0068 if fwrite(fid, data, 'uint8') ~= dataSize
0069      error('Error writing to file\n');
0070 end
0071 %% write threshold
0072 if fwrite(fid, cl.thresh, 'double') ~= 1,
0073     error('Error writing to file\n');
0074 end
0075 %% write detection rate
0076 if fwrite(fid, cl.detectionRate, 'double') ~= 1,
0077     error('Error writing to file\n');
0078 end

Generated on Sun 29-Sep-2013 01:25:24 by m2html © 2005