Skip to content

Training

daw3rd edited this page Aug 27, 2022 · 3 revisions

Training Models

Once you have an initial set of labeled data and decided on the desired model (see Evaluation), you are ready to train the model. Training is similar to model evaluation, but trains on all the data (not K-1 folds) and allows you to store the trained model in the file system for later use by the classify tool.

Example

Starting with our sample data set,

sound-info -sounds metadata.csv -clipLen 250 -pad duplicate -clipShift 125
Loading aisp properties from file:/c:/dev/aisp/aisp.properties


Loading sounds from [.]
Sounds will be clipped every 125 msec into 250 msec clips (padding=DuplicatePad)
Total: 736 samples, 1 label(s), 00:03:4.000 hr:min:sec
Label: class, 736 samples, 3 value(s), 00:03:4.000 hr:min:sec
  Value: ambient, 549 samples, 00:02:17.250 hr:min:sec
  Value: click, 28 samples, 00:00:7.000 hr:min:sec
  Value: voice, 159 samples, 00:00:39.750 hr:min:sec

When training, it is generally desirable to balance the data (that is, the same number of samples for each label value). We can use the -balance-with option to balance the data for training our customized JavaScript-defined model in mylpknn.js,

% train -model mylpknn.js -sounds . -clipLen 250 -pad duplicate -clipShift 125 -label class \
        -output mylpknn.cfr -balance-with up
Loading aisp properties from file:/c:/dev/aisp/aisp.properties
Warning: Nashorn engine is planned to be removed from a future JDK release
Loading sounds from [.]
Sounds will be clipped every 125 msec into 250 msec clips (padding=DuplicatePad)
Balancing training data using up sampling.
Aug 27, 2022 2:09:47 PM org.eng.aisp.util.BalancedLabeledWindowShuffleIterable$LevelingMutator.computeItemCounts(BalancedLabeledWindowShuffleIterable.java:65)
INFO: Enter: Total: 736 samples, 1 label(s), 00:03:4.000 hr:min:sec
Label: class, 736 samples, 3 value(s), 00:03:4.000 hr:min:sec
  Value: ambient, 549 samples, 00:02:17.250 hr:min:sec
  Value: click, 28 samples, 00:00:7.000 hr:min:sec
  Value: voice, 159 samples, 00:00:39.750 hr:min:sec
Training local model on label class
Training using classifier LpDistanceMergeKNNClassifier[primaryTrainingLabel=null, trainingWindowTransform=null, featureGramDescriptors=[FeatureGramDescriptor [windowSizeMsec=40, windowShiftMsec=20, extractor=LogMelFeatureExtractor [numBands=128, minFreq=20, maxFreq=20000, normalize=false, useLog=true, targetSamplingRate=44100.0, maxFinalCoefficients=0], processor=null]], classifier=null, nnFunc=LpDistanceMergeKNNFunc [p=0.5, normalizeWhenMerging=false], stdDevFactor=3.0, maxDistAmplifyFactor=1.0, lowerBoundDelta=0.0, dataSummary=BaseKNNDataSummary [distFunc=LpDistanceMergeKNNFunc [p=0.5, normalizeWhenMerging=false], lowerBoundDelta=0.0, maxDistBetweenSameLabel=0.0]]
Training sounds: Total: 1647 samples, 1 label(s), 00:06:51.750 hr:min:sec
Label: class, 1647 samples, 3 value(s), 00:06:51.750 hr:min:sec
  Value: ambient, 549 samples, 00:02:17.250 hr:min:sec
  Value: click, 549 samples, 00:02:17.250 hr:min:sec
  Value: voice, 549 samples, 00:02:17.250 hr:min:sec
Trained classifier: LpDistanceMergeKNNClassifier
Completed model training in 1.95 seconds, 0.47358834244080145% of training data
Wrote trained classifier to file mylpknn.cfr

We have trained the model on balanced data and placed into the file mylpknn.cfr.

Clone this wiki locally