How can I do a simple binary image classification?
Afficher commentaires plus anciens
Hi,
I'm not really new to MATLAB, just new to this whole Machine Learning thing.
I have to do a simple binary image classification. I don't care if it's a toolbox or just code, I just need to do it. I tried a couple of classification codes I found online on Github or on other sites, but most of them worked randomly and some of them worked for pre-defined images.
Those that worked on pre-defined images were neat (e.g.: http://www.di.ens.fr/willow/events/cvml2011/materials/practical-classification/), but I had issues applying on a new set of images, just because there were some .txt files (vectors of the name of the images, which was easy to replicate) and some .mat files (with both name and histogram).
I had issues creating the name and histogram in the same order, the piece of code that I use is:
for K = 1 : 4
filename = sprintf('image_%04d.jpg', K);
I = imread(filename);
IGray = rgb2gray(I);
H = hist(Igray(:), 32);
end
save('ImageDatabase.mat', 'I', 'H');
But for one reason or another, only the name and path of the last image remains stored (e.g. in this case, only image_0004 is stored in the name slot).
Another code that I found and it seemed easy was: https://github.com/rich-hart/SVM-Classifier , but the output is really random (for me) so if someone could explain to me what is happening I'd be grateful. There are 19 training images and 20 for test. Yet, if I remove one of the test images, 2 entries disappear from the Support Vector Structure?
Anyway, if you have a toolbox, or a more easy to adapt code or some explanations to the above codes, I'd be grateful.
Cheers!
Réponses (1)
Walter Roberson
le 15 Jan 2018
1 vote
9 commentaires
Dorian Diaconu
le 15 Jan 2018
Walter Roberson
le 15 Jan 2018
Use the debugger
dbstop if error
Run the program. When it stops, give the command
dbup
and then check size(Training_Set) and size(train_label) . The first elements of the respective sizes (number of rows) must be the same. Note that train_label must not be a row vector: it would typically be a column vector.
Dorian Diaconu
le 15 Jan 2018
Dorian Diaconu
le 15 Jan 2018
Walter Roberson
le 15 Jan 2018
svmtrain() is defined to use a subset of the training data as the support vectors. See https://www.mathworks.com/help/stats/svmtrain.html#outputarg_SVMStruct
At the moment it is not clear to me how it determines how many support vectors to use.
Looking through the code I see that for SMO and QP, the code runs minimizations to determine which support vectors to use; the minimizer used is quite different for SMO than it is for QP. In other case, the support vectors chosen are the ones with non-zero coefficients after minimizing. For LS (least squared) then all of the points are used.
Dorian Diaconu
le 15 Jan 2018
Walter Roberson
le 15 Jan 2018
Modifié(e) : Walter Roberson
le 15 Jan 2018
Yes, svmtrain decided that 18 of the vectors were important enough to use as support vectors.
The comparison used is to eps rather than exactly 0, to account for round-off error. The ones with small absolute alpha value are discarded.
I would not say "fit identically" for the ones that are discarded: the minimization process involved is a bit complicated. For SMO you can look at the code at toolbox/stats/stats/private/seqminopt.m . For QP, a call to quadprog() is made about 530 lines into svmtrain.m, something related to Hessian.
Dorian Diaconu
le 16 Jan 2018
Walter Roberson
le 16 Jan 2018
- Alpha — Vector of weights for the support vectors. The sign of the weight is positive for support vectors belonging to the first group, and negative for the second group.
- Bias — Intercept of the hyperplane that separates the two groups in the normalized data space (according to the 'AutoScale' argument).
For the support vectors, look at the Alpha values to determine which class it was.
Catégories
En savoir plus sur Deep Learning for Image Processing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
