Commit f722baa332cf229461fc653e7b0e85126ec3b58b
1 parent
f2b5f8a3
simplified algorithm by introducing TurkClassifierTransform
Showing
2 changed files
with
88 additions
and
49 deletions
openbr/plugins/turk.cpp
| ... | ... | @@ -57,6 +57,58 @@ BR_REGISTER(Transform, TurkTransform) |
| 57 | 57 | |
| 58 | 58 | /*! |
| 59 | 59 | * \ingroup transforms |
| 60 | + * \brief Convenience class for training turk attribute regressors | |
| 61 | + * \author Josh Klontz \cite jklontz | |
| 62 | + */ | |
| 63 | +class TurkClassifierTransform : public Transform | |
| 64 | +{ | |
| 65 | + Q_OBJECT | |
| 66 | + Q_PROPERTY(QString key READ get_key WRITE set_key RESET reset_key STORED false) | |
| 67 | + Q_PROPERTY(QStringList values READ get_values WRITE set_values RESET reset_values STORED false) | |
| 68 | + Q_PROPERTY(float maxVotes READ get_maxVotes WRITE set_maxVotes RESET reset_maxVotes STORED false) | |
| 69 | + BR_PROPERTY(QString, key, QString()) | |
| 70 | + BR_PROPERTY(QStringList, values, QStringList()) | |
| 71 | + BR_PROPERTY(float, maxVotes, 1) | |
| 72 | + | |
| 73 | + Transform *child; | |
| 74 | + | |
| 75 | + void init() | |
| 76 | + { | |
| 77 | + QString algorithm = QString("Turk(%1, %2)+").arg(key, QString::number(maxVotes)); | |
| 78 | + QStringList classifiers; | |
| 79 | + foreach (const QString &value, values) | |
| 80 | + classifiers.append(QString("SVM(RBF,EPS_SVR,returnDFVal=true,inputVariable=%1,outputVariable=predicted_%1)").arg(value)); | |
| 81 | + algorithm += classifiers.join("/"); | |
| 82 | + if (values.size() > 1) | |
| 83 | + algorithm += "+Cat"; | |
| 84 | + child = Transform::make(algorithm); | |
| 85 | + } | |
| 86 | + | |
| 87 | + void train(const QList<TemplateList> &data) | |
| 88 | + { | |
| 89 | + child->train(data); | |
| 90 | + } | |
| 91 | + | |
| 92 | + void project(const Template &src, Template &dst) const | |
| 93 | + { | |
| 94 | + child->project(src, dst); | |
| 95 | + } | |
| 96 | + | |
| 97 | + void store(QDataStream &stream) const | |
| 98 | + { | |
| 99 | + child->store(stream); | |
| 100 | + } | |
| 101 | + | |
| 102 | + void load(QDataStream &stream) | |
| 103 | + { | |
| 104 | + child->load(stream); | |
| 105 | + } | |
| 106 | +}; | |
| 107 | + | |
| 108 | +BR_REGISTER(Transform, TurkClassifierTransform) | |
| 109 | + | |
| 110 | +/*! | |
| 111 | + * \ingroup transforms | |
| 60 | 112 | * \brief Converts metadata into a map structure |
| 61 | 113 | * \author Scott Klum \cite sklum |
| 62 | 114 | */ | ... | ... |
scripts/attributes.sh
| ... | ... | @@ -18,55 +18,42 @@ mkdir -p $ATTDIR |
| 18 | 18 | DATA=${DATA:-~/data/CUHK-VHDC} |
| 19 | 19 | |
| 20 | 20 | if [ ! -f $ATTDIR/all.model ]; then |
| 21 | - br -gui -crossValidate 2 -algorithm "CrossValidate($BASE+ \ | |
| 22 | -($BROW+ \ | |
| 23 | -(Turk(unibrow,3)+SVM(RBF,EPS_SVR,returnDFVal=true,inputVariable=unibrow,outputVariable=predicted_unibrow)+Cat)/ \ | |
| 24 | -(Turk(eyebroworientation,3)+SVM(RBF,EPS_SVR,returnDFVal=true,inputVariable=eyebrowsdown,outputVariable=predicted_eyebrowsdown)/ \ | |
| 25 | -SVM(RBF,EPS_SVR,returnDFVal=true,inputVariable=eyebrowsuptodown,outputVariable=predicted_eyebrowsuptodown)+Cat)/ \ | |
| 26 | -(Turk(thickeyebrows,3)+SVM(RBF,EPS_SVR,returnDFVal=true,inputVariable=thickeyebrows,outputVariable=predicted_thickeyebrows)/ \ | |
| 27 | -SVM(RBF,EPS_SVR,returnDFVal=true,inputVariable=lighteyebrows,outputVariable=predicted_lighteyebrows)+Cat))/ \ | |
| 28 | -($MOUTH+ \ | |
| 29 | -(Turk(smiling,3)+SVM(RBF,EPS_SVR,returnDFVal=true,inputVariable=smiling,outputVariable=predicted_smiling)+Cat)/ \ | |
| 30 | -(Turk(mouthasymmetry,3)+SVM(RBF,EPS_SVR,returnDFVal=true,inputVariable=asymmetrical,outputVariable=predicted_asymmetrical)+Cat))/ \ | |
| 31 | -($EYES+ \ | |
| 32 | -(Turk(eyecolor,3)+SVM(RBF,EPS_SVR,returnDFVal=true,inputVariable=darkeyes,outputVariable=predicted_darkeyes)/ \ | |
| 33 | -SVM(RBF,EPS_SVR,returnDFVal=true,inputVariable=lighteyes,outputVariable=predicted_lighteyes)+Cat)/ \ | |
| 34 | -(Turk(baggyeyes,3)+SVM(RBF,EPS_SVR,returnDFVal=true,inputVariable=baggy,outputVariable=predicted_baggy)+Cat)/ \ | |
| 35 | -(Turk(almondeyes,3)+SVM(RBF,EPS_SVR,returnDFVal=true,inputVariable=almond,outputVariable=predicted_almond)+Cat)/ \ | |
| 36 | -(Turk(buriedeyes,3)+SVM(RBF,EPS_SVR,returnDFVal=true,inputVariable=buriedeyes,outputVariable=predicted_buriedeyes)+Cat)/ \ | |
| 37 | -(Turk(sleepyeyes,3)+SVM(RBF,EPS_SVR,returnDFVal=true,inputVariable=sleepy,outputVariable=predicted_sleepy)+Cat)/ \ | |
| 38 | -(Turk(lineeyes,3)+SVM(RBF,EPS_SVR,returnDFVal=true,inputVariable=line,outputVariable=predicted_line)+Cat)/ \ | |
| 39 | -(Turk(roundeyes,3)+SVM(RBF,EPS_SVR,returnDFVal=true,inputVariable=round,outputVariable=predicted_round)+Cat)/ \ | |
| 40 | -(Turk(smalleyes,3)+SVM(RBF,EPS_SVR,returnDFVal=true,inputVariable=smalleyes,outputVariable=predicted_smalleyes)+Cat)/ \ | |
| 41 | -(Turk(glasses,3)+SVM(RBF,EPS_SVR,returnDFVal=true,inputVariable=glasses,outputVariable=predicted_glasses)+Cat)/ \ | |
| 42 | -(Turk(eyelashvisibility,3)+SVM(RBF,EPS_SVR,returnDFVal=true,inputVariable=feweyelashes,outputVariable=predicted_feweyelashes)+Cat))/ \ | |
| 43 | -($FACE+ \ | |
| 44 | -(Turk(gender,3)+SVM(RBF,EPS_SVR,returnDFVal=true,inputVariable=male,outputVariable=predicted_male)+Cat)/ \ | |
| 45 | -(Turk(cheekdensity,3)+SVM(RBF,EPS_SVR,returnDFVal=true,inputVariable=puffy,outputVariable=predicted_puffy)/ \ | |
| 46 | -SVM(RBF,EPS_SVR,returnDFVal=true,inputVariable=in,outputVariable=predicted_in)/ \ | |
| 47 | -SVM(RBF,EPS_SVR,returnDFVal=true,inputVariable=normal,outputVariable=predicted_normal)+Cat)/ \ | |
| 48 | -(Turk(facemarks,3)+SVM(RBF,EPS_SVR,returnDFVal=true,inputVariable=scars,outputVariable=predicted_scars)/ \ | |
| 49 | -SVM(RBF,EPS_SVR,returnDFVal=true,inputVariable=moles,outputVariable=predicted_moles)/ \ | |
| 50 | -SVM(RBF,EPS_SVR,returnDFVal=true,inputVariable=normal,outputVariable=predicted_normal)+Cat)/ \ | |
| 51 | -(Turk(facelength,3)+SVM(RBF,EPS_SVR,returnDFVal=true,inputVariable=long,outputVariable=predicted_long)+Cat)/ \ | |
| 52 | -(Turk(nosetomouthdist,3)+SVM(RBF,EPS_SVR,returnDFVal=true,inputVariable=long,outputVariable=predicted_long)/ \ | |
| 53 | -SVM(RBF,EPS_SVR,returnDFVal=true,inputVariable=small,outputVariable=predicted_small)+Cat))/ \ | |
| 54 | -($HAIR+ \ | |
| 55 | -(Turk(foreheadwrinkles,3)+SVM(RBF,EPS_SVR,returnDFVal=true,inputVariable=wrinkled,outputVariable=predicted_wrinkled)+Cat)/ \ | |
| 56 | -(Turk(haircolor,3)+SVM(RBF,EPS_SVR,returnDFVal=true,inputVariable=darkhair,outputVariable=predicted_darkhair)/ \ | |
| 57 | -SVM(RBF,EPS_SVR,returnDFVal=true,inputVariable=lighthair,outputVariable=predicted_lighthair)/ \ | |
| 58 | -SVM(RBF,EPS_SVR,returnDFVal=true,inputVariable=greyhair,outputVariable=predicted_greyhair)+Cat)/ \ | |
| 59 | -(Turk(hairstyle,3)+SVM(RBF,EPS_SVR,returnDFVal=true,inputVariable=curlyhair,outputVariable=predicted_curlyhair)+Cat))/ \ | |
| 60 | -($NOSE+ \ | |
| 61 | -(Turk(noseorientation,3)+SVM(RBF,EPS_SVR,returnDFVal=true,inputVariable=upnose,outputVariable=predicted_upnose)/ \ | |
| 62 | -SVM(RBF,EPS_SVR,returnDFVal=true,inputVariable=downnose,outputVariable=predicted_downnose)+Cat)/ \ | |
| 63 | -(Turk(nosewidth,3)+SVM(RBF,EPS_SVR,returnDFVal=true,inputVariable=small,outputVariable=predicted_small)/ \ | |
| 64 | -SVM(RBF,EPS_SVR,returnDFVal=true,inputVariable=thick,outputVariable=predicted_thick)+Cat)/ \ | |
| 65 | -(Turk(nosesize,3)+SVM(RBF,EPS_SVR,returnDFVal=true,inputVariable=smallnose,outputVariable=predicted_smallnose)/ \ | |
| 66 | -SVM(RBF,EPS_SVR,returnDFVal=true,inputVariable=bignose,outputVariable=predicted_bignose)+Cat))/ \ | |
| 67 | -($JAW+ \ | |
| 68 | -(Turk(chinsize,3)+SVM(RBF,EPS_SVR,returnDFVal=true,inputVariable=shortchin,outputVariable=predicted_shortchin)/ \ | |
| 69 | -SVM(RBF,EPS_SVR,returnDFVal=true,inputVariable=longchin,outputVariable=predicted_longchin))+Cat)): \ | |
| 21 | + br -crossValidate 2 -algorithm "CrossValidate($BASE+ \ | |
| 22 | + ($BROW+ \ | |
| 23 | + TurkClassifier(unibrow,[unibrow],3)/ \ | |
| 24 | + TurkClassifier(eyebroworientation,[eyebrowsdown,eyebrowsuptodown],3)/ \ | |
| 25 | + TurkClassifier(thickeyebrows,[thickeyebrows,lighteyebrows],3))/ \ | |
| 26 | + ($MOUTH+ \ | |
| 27 | + TurkClassifier(smiling,[smiling],3)/ \ | |
| 28 | + TurkClassifier(mouthasymmetry,[asymmetrical],3))/ \ | |
| 29 | + ($EYES+ \ | |
| 30 | + TurkClassifier(eyecolor,[darkeyes,lighteyes],3)/ \ | |
| 31 | + TurkClassifier(baggyeyes,[baggy],3)/ \ | |
| 32 | + TurkClassifier(almondeyes,[almond],3)/ \ | |
| 33 | + TurkClassifier(buriedeyes,[buriedeyes],3)/ \ | |
| 34 | + TurkClassifier(sleepyeyes,[sleepy],3)/ \ | |
| 35 | + TurkClassifier(lineeyes,[line],3)/ \ | |
| 36 | + TurkClassifier(roundeyes,[round],3)/ \ | |
| 37 | + TurkClassifier(smalleyes,[smalleyes],3)/ \ | |
| 38 | + TurkClassifier(glasses,[glasses],3)/ \ | |
| 39 | + TurkClassifier(eyelashvisibility,[feweyelashes],3))/ \ | |
| 40 | + ($FACE+ \ | |
| 41 | + TurkClassifier(gender,[male],3)/ \ | |
| 42 | + TurkClassifier(cheekdensity,[puffy,in,normal],3)/ \ | |
| 43 | + TurkClassifier(facemarks,[scars,moles,normal],3)/ \ | |
| 44 | + TurkClassifier(facelength,[long],3)/ \ | |
| 45 | + TurkClassifier(nosetomouthdist,[long,small],3))/ \ | |
| 46 | + ($HAIR+ \ | |
| 47 | + TurkClassifier(foreheadwrinkles,[wrinkled],3)/ \ | |
| 48 | + TurkClassifier(haircolor,[darkhair,lighthair,greyhair],3)/ \ | |
| 49 | + TurkClassifier(hairstyle,[curlyhair],3))/ \ | |
| 50 | + ($NOSE+ \ | |
| 51 | + TurkClassifier(noseorientation,[upnose,downnose],3)/ \ | |
| 52 | + TurkClassifier(nosewidth,[small,thick],3)/ \ | |
| 53 | + TurkClassifier(nosesize,[smallnose,bignose],3))/ \ | |
| 54 | + ($JAW+ \ | |
| 55 | + TurkClassifier(chinsize,[shortchin,longchin],3)) \ | |
| 56 | + ): \ | |
| 70 | 57 | CrossValidate+Fuse([ \ |
| 71 | 58 | Turk(unibrow,[unibrow],3), \ |
| 72 | 59 | Turk(eyebroworientation,[eyebrowsdown,eyebrowsuptodown],3), \ | ... | ... |