def setUpClass(cls):
     cls.url = 'https://www.dropbox.com/s/tcem6metr3ejp6y/2015_07_13-10h38m15s101111ms_Juliette__full_test_calm.wav?dl=0'
     cls.filename = 'test_huge_sound.wav'
     cls.wav_file = wget_file(cls.url)
     cls.dataset_path = _get_training_data()
     cls.file_regexp = os.path.join(cls.dataset_path, '*.wav')
     cls.file_regexp_bis = os.path.join(cls.dataset_path, '*/*.wav')
     cls.files = glob.glob(cls.file_regexp) + glob.glob(cls.file_regexp_bis)
     cls.sound_classification_obj = classification_service.SoundClassification(
         wav_file_list=cls.files, calibrate_score=True)
     cls.sound_classification_obj.learn()
     cls.wav_duration = io_sound.duration(cls.wav_file)
Ejemplo n.º 2
0
def test_bell_detection(enable_calibration_of_score):
    dataset_path = _get_training_data()
    file_regexp = os.path.join(dataset_path, '*.wav')
    files = glob.glob(file_regexp)
    sound_classification_obj = classification_service.SoundClassification(wav_file_list=files, calibrate_score=enable_calibration_of_score)
    sound_classification_obj.learn()
    test_file_url = "https://www.dropbox.com/s/8dlr28s9gby46h1/bell_test.wav?dl=0"
    test_file = wget_file(test_file_url)
    test_file = os.path.abspath(test_file)

    res = sound_classification_obj.processed_wav(test_file)
    ## TODO assert deskbell is better than doorbell
    assert('DeskBell' in set([x.class_predicted for x in res]))
 def setUpClass(cls):
     cls.url = (
         "https://www.dropbox.com/s/tcem6metr3ejp6y/2015_07_13-10h38m15s101111ms_Juliette__full_test_calm.wav?dl=0"
     )
     cls.filename = "test_huge_sound.wav"
     cls.wav_file = wget_file(cls.url)
     cls.dataset_path = _get_training_data()
     cls.file_regexp = os.path.join(cls.dataset_path, "*.wav")
     cls.file_regexp_bis = os.path.join(cls.dataset_path, "*/*.wav")
     cls.files = glob.glob(cls.file_regexp) + glob.glob(cls.file_regexp_bis)
     cls.sound_classification_obj = classification_service.SoundClassification(
         wav_file_list=cls.files, calibrate_score=True
     )
     cls.sound_classification_obj.learn()
     cls.wav_duration = io_sound.duration(cls.wav_file)
    def setUpClass(cls, dataset_url=None, wav_file_url=None, csv_url=None):
        cls.min_precision = 0.7
        cls.min_recall = 0.7
        cls.enable_calibration_of_score = True
        cls.dataset_url = dataset_url
        cls.dataset_path = _get_training_data(cls.dataset_url)
        cls.file_regexp = os.path.join(cls.dataset_path, '*.wav')
        cls.file_regexp_bis = os.path.join(cls.dataset_path, '*/*.wav')
        cls.files = glob.glob(cls.file_regexp) + glob.glob(cls.file_regexp_bis)
        cls.sound_classification_obj = classification_service.SoundClassification(wav_file_list=cls.files, calibrate_score=cls.enable_calibration_of_score)
        cls.test_file = "test.wav"
        if wav_file_url is None:
            wav_file_url = 'https://www.dropbox.com/s/tcem6metr3ejp6y/2015_07_13-10h38m15s101111ms_Juliette__full_test_calm.wav?dl=0'
        cls.wav_file_url = wav_file_url
        cls.test_file = wget_file(cls.wav_file_url)
        cls.test_file = os.path.abspath(cls.test_file)
        #cls.test_file = '/home/lgeorge/tests/2015_07_13-10h38m15s101111ms_Juliette__full_test_calm.wav'

        if csv_url is None:
            csv_url = 'https://www.dropbox.com/s/umohtewtn6l5275/2015_07_13-10h38m15s101111ms_Juliette__full_test_calm.csv?dl=0'
        cls.csv_url = csv_url
        cls.csv_file = wget_file(cls.csv_url)
        cls.df_expected = load_csv_annotation(cls.csv_file)

        cls.csv_file = os.path.abspath(cls.csv_file)

        cls.sound_classification_obj.learn()
        cls.res = cls.sound_classification_obj.processed_wav(cls.test_file)

        cls.df = pandas.DataFrame([rec.__dict__ for rec in cls.res])
        if cls.enable_calibration_of_score:
            #df.class_predicted[df.score <= 0.9] = 'NOTHING'
            cls.df = cls.df[cls.df.score >= 2.5] #we drop low score
            cls.df = cls.df.reset_index(drop=True)
        cls.df.to_csv('output.csv')  # just for later check if needed

        cls.labels_present_in_wavfile = set(cls.df_expected.class_expected)

        detection_dict = compute_tp_fp(cls.df, cls.df_expected)

        #print("True positive count: {}".format(len(detection_dict['true_positives'])))
        #print("False positive count: {}".format(len(detection_dict['false_positives'])))
        #print("Silence detected as something: {}".format(len(detection_dict['silence_not_detected'])))
        #print("Not detected count: {}".format(len(detection_dict['not_detected'])))

        cls.expected, cls.predicted, cls.labels = convert_tp_fp_to_confusion_matrix(detection_dict['true_positives'], detection_dict['false_positives'], detection_dict['not_detected'], detection_dict['silence_not_detected'])
        report = sklearn.metrics.classification_report(cls.expected, cls.predicted, labels=cls.labels, target_names=None, sample_weight=None, digits=2)
        matrix = sklearn.metrics.confusion_matrix(cls.expected, cls.predicted, cls.labels)
        print("Confusion Matrix")
        pprint.pprint(matrix)

        #res.savefig('confusion_mat.png')
        print(report)


        cls.precisions = sklearn.metrics.precision_score(cls.expected, cls.predicted, labels=cls.labels, average=None)
        cls.recalls = sklearn.metrics.recall_score(cls.expected, cls.predicted, labels=cls.labels, average=None)

        cls.labels_to_consider = [l for l in cls.labels if l in cls.sound_classification_obj.clf.classes_]
        cls.labels_to_ignore = [l for l in cls.labels if l not in cls.sound_classification_obj.clf.classes_]
        cls.labels_to_consider_index = [num for (num, val) in enumerate(cls.labels) if val in cls.labels_to_consider]
Ejemplo n.º 5
0
    def setUpClass(cls, dataset_url=None, wav_file_url=None, csv_url=None):
        cls.min_precision = 0.7
        cls.min_recall = 0.7
        cls.enable_calibration_of_score = True
        cls.dataset_url = dataset_url
        cls.dataset_path = _get_training_data(cls.dataset_url)
        cls.file_regexp = os.path.join(cls.dataset_path, '*.wav')
        cls.file_regexp_bis = os.path.join(cls.dataset_path, '*/*.wav')
        cls.files = glob.glob(cls.file_regexp) + glob.glob(cls.file_regexp_bis)
        cls.sound_classification_obj = classification_service.SoundClassification(
            wav_file_list=cls.files,
            calibrate_score=cls.enable_calibration_of_score)
        cls.test_file = "test.wav"
        if wav_file_url is None:
            wav_file_url = 'https://www.dropbox.com/s/tcem6metr3ejp6y/2015_07_13-10h38m15s101111ms_Juliette__full_test_calm.wav?dl=0'
        cls.wav_file_url = wav_file_url
        cls.test_file = wget_file(cls.wav_file_url)
        cls.test_file = os.path.abspath(cls.test_file)
        #cls.test_file = '/home/lgeorge/tests/2015_07_13-10h38m15s101111ms_Juliette__full_test_calm.wav'

        if csv_url is None:
            csv_url = 'https://www.dropbox.com/s/umohtewtn6l5275/2015_07_13-10h38m15s101111ms_Juliette__full_test_calm.csv?dl=0'
        cls.csv_url = csv_url
        cls.csv_file = wget_file(cls.csv_url)
        cls.df_expected = load_csv_annotation(cls.csv_file)

        cls.csv_file = os.path.abspath(cls.csv_file)

        cls.sound_classification_obj.learn()
        cls.res = cls.sound_classification_obj.processed_wav(cls.test_file)

        cls.df = pandas.DataFrame([rec.__dict__ for rec in cls.res])
        if cls.enable_calibration_of_score:
            #df.class_predicted[df.score <= 0.9] = 'NOTHING'
            cls.df = cls.df[cls.df.score >= 2.5]  #we drop low score
            cls.df = cls.df.reset_index(drop=True)
        cls.df.to_csv('output.csv')  # just for later check if needed

        cls.labels_present_in_wavfile = set(cls.df_expected.class_expected)

        detection_dict = compute_tp_fp(cls.df, cls.df_expected)

        #print("True positive count: {}".format(len(detection_dict['true_positives'])))
        #print("False positive count: {}".format(len(detection_dict['false_positives'])))
        #print("Silence detected as something: {}".format(len(detection_dict['silence_not_detected'])))
        #print("Not detected count: {}".format(len(detection_dict['not_detected'])))

        cls.expected, cls.predicted, cls.labels = convert_tp_fp_to_confusion_matrix(
            detection_dict['true_positives'],
            detection_dict['false_positives'], detection_dict['not_detected'],
            detection_dict['silence_not_detected'])
        report = sklearn.metrics.classification_report(cls.expected,
                                                       cls.predicted,
                                                       labels=cls.labels,
                                                       target_names=None,
                                                       sample_weight=None,
                                                       digits=2)
        matrix = sklearn.metrics.confusion_matrix(cls.expected, cls.predicted,
                                                  cls.labels)
        print("Confusion Matrix")
        pprint.pprint(matrix)

        #res.savefig('confusion_mat.png')
        print(report)

        cls.precisions = sklearn.metrics.precision_score(cls.expected,
                                                         cls.predicted,
                                                         labels=cls.labels,
                                                         average=None)
        cls.recalls = sklearn.metrics.recall_score(cls.expected,
                                                   cls.predicted,
                                                   labels=cls.labels,
                                                   average=None)

        cls.labels_to_consider = [
            l for l in cls.labels
            if l in cls.sound_classification_obj.clf.classes_
        ]
        cls.labels_to_ignore = [
            l for l in cls.labels
            if l not in cls.sound_classification_obj.clf.classes_
        ]
        cls.labels_to_consider_index = [
            num for (num, val) in enumerate(cls.labels)
            if val in cls.labels_to_consider
        ]