@@ -28,6 +28,28 @@ class TestMusicnn extends EssentiaModel.TensorflowMusiCNN {
2828 } ) ;
2929 this . isReady = true ;
3030 }
31+
32+ async predict ( inputFeature , zeroPadding ) {
33+
34+ let featureTensor = this . arrayToTensorAsBatches (
35+ inputFeature . melSpectrum ,
36+ [ inputFeature . frameSize , inputFeature . melBandsSize ] ,
37+ inputFeature . patchSize ,
38+ zeroPadding
39+ ) ;
40+ // Get default model input variables
41+ let modelInputs = this . disambiguateExtraInputs ( ) ;
42+ // add the input feature tensor to the model inputs
43+ modelInputs . push ( featureTensor ) ;
44+ // Run inference
45+ let results = this . model . execute ( modelInputs ) ;
46+ // free tensors
47+ featureTensor . dispose ( ) ;
48+ // decode the output activations as array with a promise
49+ let resultsArray = await results . array ( ) ;
50+ results . dispose ( ) ;
51+ return resultsArray ;
52+ }
3153}
3254const musiCNN = new TestMusicnn ( tf , modelURL ) ;
3355
@@ -37,6 +59,7 @@ musiCNN.initialize()
3759console . log ( `Using TF ${ tf . getBackend ( ) } backend` ) ;
3860
3961self . onmessage = e => {
62+ console . log ( 'received data: ' , e . data )
4063 musiCNN . predict ( e . data , true )
4164 . then ( ( predictions ) => self . postMessage ( predictions ) ) ;
4265 // post the predictions as message to the main thread
0 commit comments