Home > @SVMClassifier > loadFromFid.m

loadFromFid

PURPOSE ^

LOADFROMFID loads svm classifier from binary file

SYNOPSIS ^

function [ cl ] = loadFromFid( dummy, fid )

DESCRIPTION ^

LOADFROMFID loads svm classifier from binary file
   Inputs:
       dummy : svm classifier dummy object (SVMClassifier)
       fid : file descriptor
   Outputs:
       cl : loaded svm classifier object

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [ cl ] = loadFromFid( dummy, fid )
0002 %LOADFROMFID loads svm classifier from binary file
0003 %   Inputs:
0004 %       dummy : svm classifier dummy object (SVMClassifier)
0005 %       fid : file descriptor
0006 %   Outputs:
0007 %       cl : loaded svm classifier object
0008 
0009 % read number of classes
0010 [numClasses, count] = fread(fid, 1, 'uint16');
0011 if count <= 0
0012     error('Error reading from file\n');
0013 end
0014 
0015 %% Read Classifier object
0016 
0017 % read length of classifier object
0018 [clSize, count] = fread(fid, 1, 'uint16');
0019 
0020 if count <= 0
0021     error('Error reading from file\n');
0022 end
0023 
0024 % read classifier data
0025 [clobj, count] = fread(fid, clSize, '*uint8');
0026 
0027 if count <= 0
0028     error('Error reading from file\n');
0029 end
0030 
0031 cl.trainedSVM = deserialize(clobj);
0032 
0033 if isstruct(cl.trainedSVM)
0034     %return any sparse values to its original state
0035     cl.trainedSVM.SVs = sparse(cl.trainedSVM.SVs);
0036 end
0037 
0038 %% Read libsvm training Classifier parameters
0039 
0040 % read length of training parameters
0041 [datasize, count] = fread(fid, 1, 'uint16');
0042 
0043 if count <= 0
0044     error('Error reading from file\n');
0045 end
0046 
0047 % read classifier data
0048 [data, count] = fread(fid, datasize, '*uint8');
0049 
0050 if count <= 0
0051     error('Error reading from file\n');
0052 end
0053 
0054 cl.libSvmTrnOpts = deserialize(data);
0055 
0056 %% Read libsvm training Classifier parameters
0057 % read length of training parameters
0058 [datasize, count] = fread(fid, 1, 'uint16');
0059 
0060 if count <= 0
0061     error('Error reading from file\n');
0062 end
0063 
0064 % read classifier data
0065 [data, count] = fread(fid, datasize, '*uint8');
0066 
0067 if count <= 0
0068     error('Error reading from file\n');
0069 end
0070 
0071 cl.libSvmPrdOpts = deserialize(data);
0072 
0073 %% Create new Object
0074 cl = class(cl, 'SVMClassifier', Classifier(numClasses));
0075 end

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