55#
66# It is made available under the MIT License
77
8+ from __future__ import print_function
89import mahotas as mh
910from sklearn import cross_validation
1011from sklearn .linear_model .logistic import LogisticRegression
11- from mpltools import style
1212from matplotlib import pyplot as plt
1313import numpy as np
1414from glob import glob
1515
1616basedir = 'AnimTransDistr'
17+ print ('This script will test classification of the AnimTransDistr dataset' )
1718
1819
1920def features_for (images ):
@@ -39,6 +40,7 @@ def features_labels(groups):
3940 'Trans' ,
4041]
4142
43+ print ('Computing whole-image texture features...' )
4244features = []
4345labels = []
4446for ci , cl in enumerate (classes ):
@@ -68,12 +70,14 @@ def features_labels(groups):
6870 labels .extend ([ci for _ in curimages ])
6971labels = np .array (labels )
7072
73+ print ('Computing SURF descriptors...' )
7174alldescriptors = []
7275for im in images :
7376 im = mh .imread (im , as_grey = 1 )
7477 im = im .astype (np .uint8 )
7578
76- #alldescriptors.append(surf.dense(im, spacing=max(im.shape)//32))
79+ # To use dense sampling, you can try the following line:
80+ # alldescriptors.append(surf.dense(im, spacing=max(im.shape)//32))
7781 alldescriptors .append (surf .surf (im , descriptor_only = True ))
7882
7983print ('Descriptors done' )
@@ -82,7 +86,7 @@ def features_labels(groups):
8286
8387concatenated = np .concatenate (alldescriptors )
8488concatenated = concatenated [::64 ]
85- print ('k-meaning ...' )
89+ print ('Clustering with K-means ...' )
8690km .fit (concatenated )
8791features = []
8892for d in alldescriptors :
@@ -97,22 +101,21 @@ def features_labels(groups):
97101print ('Accuracy (5 fold x-val) with Log. Reg [SURF features]: %s%%' % (
98102 0.1 * round (1000 * scoreSURFlr .mean ())))
99103
100- print ('combined...' )
104+ print ('Attemping classification with all features combined...' )
101105allfeatures = np .hstack ([features , tfeatures ])
102106scoreSURFplr = cross_validation .cross_val_score (
103107 LogisticRegression (), allfeatures , labels , cv = 5 ).mean ()
104108
105109print ('Accuracy (5 fold x-val) with Log. Reg [All features]: %s%%' % (
106110 0.1 * round (1000 * scoreSURFplr .mean ())))
107111
108- style .use ('ggplot' )
109112plt .plot ([0 , 1 , 2 ], 100 *
110113 np .array ([scores0 .mean (), scoreSURFlr , scoreSURFplr ]), 'k-' , lw = 8 )
111114plt .plot (
112115 [0 , 1 , 2 ], 100 * np .array ([scores0 .mean (), scoreSURFlr , scoreSURFplr ]),
113116 'o' , mec = '#cccccc' , mew = 12 , mfc = 'white' )
114117plt .xlim (- .5 , 2.5 )
115118plt .ylim (scores0 .mean () * 90. , scoreSURFplr * 110 )
116- plt .xticks ([0 , 1 , 2 ], ["baseline " , "SURF" , "combined" ])
119+ plt .xticks ([0 , 1 , 2 ], ["Texture " , "SURF" , "combined" ])
117120plt .ylabel ('Accuracy (%)' )
118121plt .savefig ('../1400OS_10_18+.png' )
0 commit comments