-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsceneTrain.m
28 lines (24 loc) · 1.02 KB
/
sceneTrain.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
%% Train KNN model for pitching scene classification
pitchingFiles = dir('pitching/*.jpg');
pitchingNumFiles = length(pitchingFiles);
pitchingFeatures = zeros(pitchingNumFiles, 12);
pitchingResponses = ones(pitchingNumFiles, 1);
for k = 1:pitchingNumFiles
im = imread(strcat('pitching/', pitchingFiles(k).name));
feature = sceneFeature(im);
pitchingFeatures(k, :) = feature;
end
nonPitchingFiles = dir('nonpitching/*.jpg');
nonPitchingNumFiles = length(nonPitchingFiles);
nonPitchingFeatures = zeros(nonPitchingNumFiles, 12);
nonPitchingResponses = zeros(nonPitchingNumFiles, 1);
for k = 1:nonPitchingNumFiles
im = imread(strcat('nonpitching/', nonPitchingFiles(k).name));
feature = sceneFeature(im);
nonPitchingFeatures(k, :) = feature;
end
features = vertcat(pitchingFeatures, nonPitchingFeatures);
responses = vertcat(pitchingResponses, nonPitchingResponses);
sceneModel = fitcknn(features,responses,'NumNeighbors',3,'DistanceWeight','squaredinverse');
% save trained model
save('sceneModel.mat', 'sceneModel');