• 大小: 61.62MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2022-05-18
  • 语言: Python
  • 标签:

资源简介

简单、快速、实时、可定制的机器学习音频分类器

资源截图

代码片段和文件信息

# Common functions and definitions
#
# This file defines commonly used parts for ease of programming.
# Import as follows:
#
# > from common import *
#
# Private notation(s):
# - mels = melspectrogram
#

# # Basic definitions
import warnings
warnings.simplefilter(‘ignore‘)
import numpy as np
np.warnings.filterwarnings(‘ignore‘)
np.random.seed(1001)

import sys
import shutil
from pathlib import Path
import pandas as pd
import matplotlib.pyplot as plt
sys.path.insert(0 str(Path.cwd()))

# # Configration
def is_handling_audio(conf):
    return ‘sampling_rate‘ in conf

def test_conf(conf):
    if conf.model not in [‘mobilenetv2‘ ‘alexnet‘]:
        raise Exception(‘conf.model not recognized: {}‘.format(conf.model))
    if conf.data_balancing not in [‘over_sampling‘ ‘under_sampling‘
                                        ‘by_generator‘ ‘dont_balance‘]:
        raise Exception(‘conf.data_balancing not recognized: {}‘.format(conf.data_balancing))

def auto_complete_conf(conf):
    if ‘folder‘ in conf:
        conf.folder = Path(conf.folder)
    conf.label2int = {l:i for i l in enumerate(conf.labels)}
    conf.num_classes = len(conf.labels)
    # audio auto configurations
    if is_handling_audio(conf):
        conf.samples = conf.sampling_rate * conf.duration
        conf.rt_chunk_samples = conf.sampling_rate // conf.rt_oversamples
        conf.mels_onestep_samples = conf.rt_chunk_samples * conf.rt_process_count
        conf.mels_convert_samples = conf.samples + conf.mels_onestep_samples
        conf.dims = (conf.n_mels 1 + int(np.floor(conf.samples/conf.hop_length)) 1)
    # optional configurations
    if ‘model‘ not in conf:
        conf.model = ‘mobilenetv2‘
    if ‘metric_save_ckpt‘ not in conf:
        conf.metric_save_ckpt = ‘val_loss‘
    if ‘metric_save_mode‘ not in conf:
        conf.metric_save_mode=‘auto‘
    if ‘logdir‘ not in conf:
        conf.logdir = ‘logs‘
    if ‘data_balancing‘ not in conf:
        conf.data_balancing = ‘over_sampling‘
    if ‘X_train‘ not in conf:
        conf.X_train = ‘X_train.npy‘
        conf.y_train = ‘y_train.npy‘
        conf.X_test  = ‘X_test.npy‘
        conf.y_test  = ‘y_test.npy‘
    if ‘steps_per_epoch_limit‘ not in conf:
        conf.steps_per_epoch_limit = None
    if ‘aug_mixup_alpha‘ not in conf:
        conf.aug_mixup_alpha = 1.0
    if ‘samples_per_file‘ not in conf:
        conf.samples_per_file = 1
    if ‘eval_ensemble‘ not in conf:
        conf.eval_ensemble = True # Set False if samples_per_file > 1 but ensemble is not available
    if ‘what_is_sample‘ not in conf:
        conf.what_is_sample = ‘log mel-spectrogram‘
    if ‘use_audio_training_model‘ not in conf:
        conf.use_audio_training_model = True

from config import *
auto_complete_conf(conf)
print(conf)

# # Data utilities
def load_labels(conf):
    conf.labels = load_npy(conf ‘labels.npy‘)
    auto_complete_conf(conf)
    print(‘Labels are‘ conf.labels)

def datapath(conf filename):
    return conf.folder / filename

def

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-11-19 23:58  ml-sound-classifier-master\
     文件        1214  2018-11-19 23:58  ml-sound-classifier-master\.gitignore
     文件        2920  2018-11-19 23:58  ml-sound-classifier-master\EXAMPLE_APPS.md
     文件        1072  2018-11-19 23:58  ml-sound-classifier-master\LICENSE
     文件       12207  2018-11-19 23:58  ml-sound-classifier-master\README.md
     文件        1506  2018-11-19 23:58  ml-sound-classifier-master\RaspberryPi.md
     目录           0  2018-11-19 23:58  ml-sound-classifier-master\apps\
     目录           0  2018-11-19 23:58  ml-sound-classifier-master\apps\IF201812\
     文件        7089  2018-11-19 23:58  ml-sound-classifier-master\apps\IF201812\IF201812-Preprocess.ipynb
     文件      194914  2018-11-19 23:58  ml-sound-classifier-master\apps\IF201812\IF201812-Train-Eval-All.ipynb
     文件         982  2018-11-19 23:58  ml-sound-classifier-master\apps\IF201812\config.py
     目录           0  2018-11-19 23:58  ml-sound-classifier-master\apps\cnn-laser-machine-listener\
     文件      537452  2018-11-19 23:58  ml-sound-classifier-master\apps\cnn-laser-machine-listener\CNN-LML-Another-Attempt-AlexNetbased.ipynb
     文件       80754  2018-11-19 23:58  ml-sound-classifier-master\apps\cnn-laser-machine-listener\CNN-LML-Preprocess-Data.ipynb
     文件     5012432  2018-11-19 23:58  ml-sound-classifier-master\apps\cnn-laser-machine-listener\CNN-LML-TF-Model-Conversion.ipynb
     文件      123245  2018-11-19 23:58  ml-sound-classifier-master\apps\cnn-laser-machine-listener\CNN-LML-Train.ipynb
     文件      916187  2018-11-19 23:58  ml-sound-classifier-master\apps\cnn-laser-machine-listener\CNN-LML-Visualize.ipynb
     文件         589  2018-11-19 23:58  ml-sound-classifier-master\apps\cnn-laser-machine-listener\README.md
     文件     4164068  2018-11-19 23:58  ml-sound-classifier-master\apps\cnn-laser-machine-listener\cnn-alexbased-laser-machine-listener.pb
     文件     7100700  2018-11-19 23:58  ml-sound-classifier-master\apps\cnn-laser-machine-listener\cnn-model-laser-machine-listener.pb
     文件        1027  2018-11-19 23:58  ml-sound-classifier-master\apps\cnn-laser-machine-listener\config.py
     文件          66  2018-11-19 23:58  ml-sound-classifier-master\apps\cnn-laser-machine-listener\download.sh
     文件     7296600  2018-11-19 23:58  ml-sound-classifier-master\apps\cnn-laser-machine-listener\model_based_on_fsd.h5
     目录           0  2018-11-19 23:58  ml-sound-classifier-master\apps\fsdkaggle2018\
     文件     5073767  2018-11-19 23:58  ml-sound-classifier-master\apps\fsdkaggle2018\FSDKaggle2018-TF-Model-Coversion.ipynb
     文件     9985888  2018-11-19 23:58  ml-sound-classifier-master\apps\fsdkaggle2018\FSDKaggle2018-Visualize.ipynb
     文件        1476  2018-11-19 23:58  ml-sound-classifier-master\apps\fsdkaggle2018\config.py
     文件        1919  2018-11-19 23:58  ml-sound-classifier-master\apps\fsdkaggle2018\train_alexbased.py
     文件        1950  2018-11-19 23:58  ml-sound-classifier-master\apps\fsdkaggle2018\train_mobilenetv2.py
     目录           0  2018-11-19 23:58  ml-sound-classifier-master\apps\fsdkaggle2018small\
     文件        1477  2018-11-19 23:58  ml-sound-classifier-master\apps\fsdkaggle2018small\config.py
............此处省略32个文件信息

评论

共有 条评论