Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anlaysis unit testing #64

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,473 changes: 736 additions & 737 deletions snaw-backend/acousticIndices.py → snaw-backend/analysis/acousticIndices.py

Large diffs are not rendered by default.

Large diffs are not rendered by default.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
def classify_file( audio_file, all_models ) :
# load the models


all_labels = [ ["AAT", "AHV", "AMA", "ART", "ASI", "AVH", "AVT"],
["BRA", "BAM", "BBI", "BMA", "BIN"],
["GOC", "GRA", "GST","GWG", "GWC"] ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import sys
import os
import base64
from classification_cnn import runScript as get_result
import traceback

DEBUG_FLAG = False
Expand Down
6 changes: 3 additions & 3 deletions snaw-backend/analysis_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
import traceback
import os
import json
from classification_cnn import runScript as run_classification
from get_spectrogram import runScript as run_spectrogram
from acousticIndices import getAcousticIndices as run_indices
from analysis.classification_cnn import runScript as run_classification
from analysis.get_spectrogram import runScript as run_spectrogram
from analysis.acousticIndices import getAcousticIndices as run_indices

DEBUG_FLAG = True

Expand Down
8 changes: 4 additions & 4 deletions snaw-backend/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import os
import sys
import subprocess
from get_spectrogram import runScript as get_spectrogram
from classification import runScript as get_svm_classification
from classification_cnn import runScript as get_cnn_classification
from acousticIndices import getAcousticIndices as get_acoustic_indices
from analysis.get_spectrogram import runScript as get_spectrogram
from analysis.classification import runScript as get_svm_classification
from analysis.classification_cnn import runScript as get_cnn_classification
from analysis.acousticIndices import getAcousticIndices as get_acoustic_indices
from analysis_driver import run_driver
import traceback
import random
Expand Down
39 changes: 39 additions & 0 deletions snaw-backend/bad.wav
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Open your eyes and exalt
In this fragile world, in this knowing flesh
In this very moment

We have forsaken the delusions
Of comprehension as we are born
Into the certainty of the sensual

We are the stone that starts the avalanche
We are the cough that spreads the plague
We are the spark that lights the inferno

Relinquish those wretched controls
Of knowledge and experience
Those conditions which hinder
Desire’s progress

Cut away esoteric corruption
Seek out unfettered fulfillment
In defiance of the sages
In defiance of the intelligentsia

Useless philosophy
And theory and poetry
Must be heaped upon the cairn

See them consumed
In action, sweet, reckless action

Join our sad tears
And dance on the blackened bones of gods
Beyond the shadow of the citadel
There is no such thing as time
There is no such thing as negation

There is only this tangible
Only this perceptible world
There is only this moment
There is only this very moment
Binary file added snaw-backend/good.wav
Binary file not shown.
Binary file added snaw-backend/spectrogram/SpectroedImage0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions snaw-backend/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import random
import unittest
from analysis.classification_cnn import classify_file as class_run
from analysis.classification_cnn import classify_file as class_driver
from analysis.get_spectrogram import runScript as spectro_driver
from analysis.acousticIndices import getAcousticIndices as indices_driver
from keras.models import load_model
import audioread

class TestSequenceFunctions(unittest.TestCase):

def setUp(self):
self.seq = range(10)
self.good = "./good.wav"
self.bad = "./bad.wav"
self.models = [ load_model('model\\anthro\\ant_cnn_model.h5'),
load_model('model\\bio\\bio_cnn_model.h5'),
load_model('model\\geo\\geo_cnn_model.h5') ]

def testclassification(self):
self.assertTrue( class_driver(self.good, self.models) )
self.assertTrue( class_run(self.good, self.models ) )
with self.assertRaises(audioread.exceptions.NoBackendError) :
class_run( self.bad, self.models )
with self.assertRaises(audioread.exceptions.NoBackendError) :
class_driver( self.bad, self.models )

def testspectrogram(self):
self.assertTrue( spectro_driver(self.good, 0, self.good, class_driver(self.good, self.models) ) )
with self.assertRaises(KeyError):
spectro_driver(self.good, 0, self.good, {} )

def testindices(self):
self.assertTrue( indices_driver( self.good ) )
with self.assertRaises(RuntimeError) :
indices_driver( self.bad )

suite = unittest.TestLoader().loadTestsFromTestCase(TestSequenceFunctions)
unittest.TextTestRunner(verbosity=2).run(suite)