<s> '''<STR_LIT>''' <EOL> import pyvision as pv <EOL> import os <EOL> from pyvision . analysis . FaceAnalysis . EyesFile import EyesFile <EOL> import csv <EOL> import numpy as np <EOL> SCRAPS_EYES = EyesFile ( os . path . join ( pv . __path__ [ <NUM_LIT:0> ] , '<STR_LIT:data>' , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> '''<STR_LIT>''' <EOL> AIRPLANE = os . path . join ( pv . __path__ [ <NUM_LIT:0> ] , '<STR_LIT:data>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> '''<STR_LIT>''' <EOL> BABOON = os . path . join ( pv . __path__ [ <NUM_LIT:0> ] , '<STR_LIT:data>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> '''<STR_LIT>''' <EOL> FRUITS = os . path . join ( pv . __path__ [ <NUM_LIT:0> ] , '<STR_LIT:data>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> '''<STR_LIT>''' <EOL> LENA = os . path . join ( pv . __path__ [ <NUM_LIT:0> ] , '<STR_LIT:data>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> '''<STR_LIT>''' <EOL> LOGO = os . path . join ( pv . __path__ [ <NUM_LIT:0> ] , '<STR_LIT:data>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> '''<STR_LIT>''' <EOL> TAZ_IMAGE = os . path . join ( pv . __path__ [ <NUM_LIT:0> ] , '<STR_LIT:data>' , '<STR_LIT:test>' , '<STR_LIT>' ) <EOL> '''<STR_LIT>''' <EOL> TAZ_VIDEO = os . path . join ( pv . __path__ [ <NUM_LIT:0> ] , '<STR_LIT:data>' , '<STR_LIT:test>' , '<STR_LIT>' ) <EOL> '''<STR_LIT>''' <EOL> CAR_VIDEO = os . path . join ( pv . __path__ [ <NUM_LIT:0> ] , '<STR_LIT:data>' , '<STR_LIT:test>' , '<STR_LIT>' ) <EOL> '''<STR_LIT>''' <EOL> BUGS_VIDEO = os . path . join ( pv . __path__ [ <NUM_LIT:0> ] , '<STR_LIT:data>' , '<STR_LIT:test>' , '<STR_LIT>' ) <EOL> '''<STR_LIT>''' <EOL> FONT_ARIAL = os . path . join ( pv . __path__ [ <NUM_LIT:0> ] , '<STR_LIT>' , '<STR_LIT>' ) <EOL> '''<STR_LIT>''' <EOL> IRIS_PATH = os . path . join ( pv . __path__ [ <NUM_LIT:0> ] , '<STR_LIT:data>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> IRIS_DATA = np . array ( list ( csv . reader ( open ( IRIS_PATH , '<STR_LIT:rb>' ) ) ) ) <EOL> IRIS_LABELS = IRIS_DATA [ <NUM_LIT:1> : , <NUM_LIT:5> ] <EOL> IRIS_DATA = np . array ( IRIS_DATA [ <NUM_LIT:1> : , <NUM_LIT:1> : <NUM_LIT:5> ] , dtype = np . float32 ) <EOL> def genderClassifier ( clsfy , ilog = None ) : <EOL> '''<STR_LIT>''' <EOL> filename = os . path . join ( pv . __path__ [ <NUM_LIT:0> ] , '<STR_LIT:data>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> f = open ( filename , '<STR_LIT:r>' ) <EOL> image_cache = [ ] <EOL> examples = [ ] <EOL> for line in f : <EOL> im_name , class_name = line . split ( ) <EOL> if class_name == '<STR_LIT:F>' : <EOL> class_name = <NUM_LIT:0> <EOL> else : <EOL> class_name = <NUM_LIT:1> <EOL> long_name = os . path . join ( pv . __path__ [ <NUM_LIT:0> ] , '<STR_LIT:data>' , '<STR_LIT>' , im_name ) <EOL> leye , reye = SCRAPS_EYES . getEyes ( im_name ) [ <NUM_LIT:0> ] <EOL> im = pv . Image ( long_name ) <EOL> image_cache . append ( im ) <EOL> im = pv . AffineFromPoints ( leye , reye , pv . Point ( <NUM_LIT> , <NUM_LIT> ) , pv . Point ( <NUM_LIT> , <NUM_LIT> ) , ( <NUM_LIT:64> , <NUM_LIT:64> ) ) . transformImage ( im ) <EOL> examples . append ( [ class_name , im , im_name ] ) <EOL> training = examples [ : <NUM_LIT> ] <EOL> testing = examples [ <NUM_LIT> : ] <EOL> for each in training [ : <NUM_LIT> ] : <EOL> clsfy . addTraining ( each [ <NUM_LIT:0> ] , each [ <NUM_LIT:1> ] , ilog = ilog ) <EOL> clsfy . train ( ilog = ilog ) <EOL> table = pv . Table ( ) <EOL> correct = <NUM_LIT:0> <EOL> total = <NUM_LIT:0> <EOL> for each in testing : <EOL> label = clsfy . predict ( each [ <NUM_LIT:1> ] , ilog = ilog ) <EOL> total += <NUM_LIT:1> <EOL> if label == each [ <NUM_LIT:0> ] : <EOL> correct += <NUM_LIT:1> <EOL> rate = float ( correct ) / total <EOL> if ilog : ilog . table ( table ) <EOL> return rate <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> from pyvision . vector . SVM import SVM <EOL> svm = SVM ( kernel = '<STR_LIT>' , random_seed = <NUM_LIT:30> ) <EOL> ilog = pv . ImageLog ( ) <EOL> print "<STR_LIT>" , genderClassifier ( svm , ilog = None ) <EOL> svm = SVM ( kernel = '<STR_LIT>' , random_seed = <NUM_LIT:30> ) <EOL> ilog = pv . ImageLog ( ) <EOL> print "<STR_LIT>" , genderClassifier ( svm , ilog = None ) <EOL> ilog . show ( ) </s>
