-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:jervisfm/Digit-Recognizer
- Loading branch information
Showing
9 changed files
with
194 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,45 @@ | ||
Jervis Muindi | ||
Varun Ravishankar | ||
Biometric Project | ||
28th November 2011 | ||
|
||
Jervis Muindi (jjm2190) | ||
Varun Ravishankar (vr2263) | ||
Biometric Final Project | ||
12th December 2011 | ||
--------------------------- | ||
About | ||
======= | ||
This is a handwritten digit recognizer that uses a nearest neighbor classifier to recognize handwritten single digits. | ||
This is a handwritten digit recognizer that uses a nearest neighbor classifier to recognize handwritten single digits. | ||
|
||
|
||
Files: | ||
======= | ||
readDATA.m -> reads in the MNIST dataset. The data should be in a subdirectory called 'MNIST' | ||
loadHndDATA.m -> reads in the manually collected images. These images should in a subdirectory called 'img' | ||
procTD.m -> Processes the MNIST training set and bounds the images to 28x28 bounding box. | ||
proc.m -> Processes a test image and bounds it in a 28x28 bounding box. | ||
approach1.m -> Does classification using raw features | ||
approach2.m -> Binds digits to a bounding box and then applies nearest neighbor classifer | ||
approach3.m -> Does nearest neighbor classification with K = 3. | ||
extract.m -> Finds the bounding box in an image with a digit and returns that bounding box. | ||
binarze.m -> Converts an image to a binary image of 0s and 1s. | ||
pca.m -> Implements PCA | ||
dopca.m -> Tests PCA apporach to see how well it does. | ||
darken.m -> Converts white background in a image to a black background. | ||
|
||
|
||
|
||
Before Running | ||
============== | ||
Make sure that the directory structure is as follows: | ||
|
||
1) MNIST : This directory should contain all of the MNIST raw data set and it should be in extracted form. You can download the dataset from http://yann.lecun.com/exdb/mnist/ | ||
2) img : This should contain the 200 scanned images. | ||
|
||
If you do not have this structure, you will get a file not found error as the scripts expects the data to be in these locations. | ||
|
||
|
||
Independent Dataset | ||
=================== | ||
For the classification of the independently gathered dataset, the relevant files are : | ||
approach1.m ; approach2.m and approach3.m and dopca.m. | ||
|
||
When you run these you scripts you will get a current estimate of how well the classifier is doing on test data. Also note that | ||
the scripts output estimated time of completion when carrying out computationally intensive task that can take a while to run. | ||
Refers to the files description above to infer what each file does and for more details please see the report of Jervis Muindi. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
function [r,pc] = dopca() | ||
%UNTITLED9 Summary of this function goes here | ||
% Detailed explanation goes here | ||
|
||
|
||
|
||
% with 60,000 samples , its too much. don't have enough memory | ||
% on hand to compute (need 24gb). | ||
% | ||
% so just look at 10,000 samples -> this needs 0.8Gb which we have. | ||
% | ||
|
||
[train_data, train_labels, test_data, test_labels] = readDATA(); | ||
%train_data = procTD(train_data); | ||
[test_data, test_labels] = loadHndDATA(); | ||
|
||
|
||
length = size(train_data,2); | ||
length = 2000; | ||
data = zeros(784,length); | ||
|
||
|
||
for i =1:length | ||
if(mod(i,1000) == 0) | ||
disp(i); | ||
end | ||
|
||
img = train_data{i}; | ||
img = img(:); | ||
data(:,i) = img; | ||
|
||
|
||
end | ||
|
||
disp('doing pca...'); | ||
|
||
[r, pc] = pca(data); | ||
%[r, pc] = pca2(data'); | ||
disp('pca done'); | ||
disp('proj data'); | ||
size(r) | ||
disp('principal comp') | ||
size(pc) | ||
|
||
%error('s'); | ||
disp('doiing testing of pca results...'); | ||
|
||
train_size = length; | ||
train_data = r; | ||
errors=0; | ||
|
||
for i = 1:200 | ||
|
||
|
||
tv = test_data{i}; | ||
%tv = proc(tv); | ||
tv = tv(:); | ||
%tv = tv' | ||
ptv = pc' * tv; | ||
tv = ptv; | ||
|
||
minIdx = 0; | ||
minDist = Inf; | ||
for k = 1:train_size | ||
j=k; | ||
av = train_data(j); | ||
av = av(:); | ||
diff = tv - av; | ||
dist = norm(diff,2); | ||
|
||
if(dist < minDist) | ||
minDist = dist; | ||
%disp(j); | ||
minIdx = j; | ||
end | ||
|
||
end | ||
|
||
|
||
result(i) = train_labels{minIdx}; | ||
|
||
|
||
%do accuracy checking in line | ||
if( test_labels(i) ~= result(i) ) | ||
errors = errors + 1; | ||
|
||
end | ||
tot = i; | ||
curr_acc = (tot - errors) / tot; | ||
|
||
|
||
if( test_labels(i) ~= result(i) ) | ||
|
||
fprintf('Curr Accuracy: %f | %d,%d.\n', curr_acc, test_labels(i),result(i) ); | ||
%figure; | ||
%im = [test_data{i} train_data{minIdx} ]; | ||
%imshow(im); | ||
continue; | ||
end | ||
|
||
fprintf('Curr Accuracy: %f.\n', curr_acc); | ||
|
||
|
||
end | ||
|
||
|
||
|
||
|
||
|
||
|
||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.