Giter Club home page Giter Club logo

audioclassification-paddlepaddle's Introduction

基于PaddlePaddle实现的声音分类系统

python version GitHub forks GitHub Repo stars GitHub 支持系统

前言

本项目是基于PaddlePaddle的声音分类项目,旨在实现对各种环境声音、动物叫声和语种的识别。项目提供了多种声音分类模型,如EcapaTdnn、PANNS、ResNetSE、CAMPPlus和ERes2Net,以支持不同的应用场景。此外,项目还提供了常用的Urbansound8K数据集测试报告和一些方言数据集的下载和使用例子。用户可以根据自己的需求选择适合的模型和数据集,以实现更准确的声音分类。项目的应用场景广泛,可以用于室外的环境监测、野生动物保护、语音识别等领域。同时,项目也鼓励用户探索更多的使用场景,以推动声音分类技术的发展和应用。

欢迎大家扫码入知识星球或者QQ群讨论,知识星球里面提供项目的模型文件和博主其他相关项目的模型文件,也包括其他一些资源。

知识星球 QQ群

使用准备

  • Anaconda 3
  • Python 3.8
  • PaddlePaddle 2.4.0
  • Windows 10 or Ubuntu 18.04

项目特性

  1. 支持模型:EcapaTdnn、PANNS、TDNN、Res2Net、ResNetSE
  2. 支持池化层:AttentiveStatisticsPooling(ASP)、SelfAttentivePooling(SAP)、TemporalStatisticsPooling(TSP)、TemporalAveragePooling(TAP)
  3. 支持预处理方法:MelSpectrogram、LogMelSpectrogram、Spectrogram、MFCC、Fbank

模型论文:

模型测试表

模型 Params(M) 预处理方法 数据集 类别数量 准确率 获取模型
CAMPPlus 7.2 Flank UrbanSound8K 10 0.96590 加入知识星球获取
PANNS(CNN10) 4.9 Flank UrbanSound8K 10 0.95454 加入知识星球获取
ERes2NetV2 5.4 Flank UrbanSound8K 10 0.93295 加入知识星球获取
ResNetSE 9.1 Flank UrbanSound8K 10 0.92219 加入知识星球获取
TDNN 2.7 Flank UrbanSound8K 10 0.92045 加入知识星球获取
ERes2Net 6.6 Flank UrbanSound8K 10 0.90909 加入知识星球获取
EcapaTdnn 6.2 Flank UrbanSound8K 10 0.90503 加入知识星球获取
Res2Net 5.6 Flank UrbanSound8K 10 0.85812 加入知识星球获取
CAMPPlus 6.1 Flank CN-Celeb和VoxCeleb 2(中英文语种) 0.99254 加入知识星球获取
ResNetSE 9.8 Flank CN-Celeb和VoxCeleb 2(中英文语种) 0.99545 加入知识星球获取

安装环境

  • 首先安装的是PaddlePaddle的GPU版本,如果已经安装过了,请跳过。
conda install paddlepaddle-gpu==2.4.0 cudatoolkit=10.2 --channel https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/Paddle/
  • 安装ppacls库。

使用pip安装,命令如下:

python -m pip install ppacls -U -i https://pypi.tuna.tsinghua.edu.cn/simple

建议源码安装,源码安装能保证使用最新代码。

git clone https://github.com/yeyupiaoling/AudioClassification_PaddlePaddle.git
cd AudioClassification_PaddlePaddle
pip install .

数据数据

生成数据列表,用于下一步的读取需要,audio_path为音频文件路径,用户需要提前把音频数据集存放在dataset/audio目录下,每个文件夹存放一个类别的音频数据,每条音频数据长度在3秒以上,如 dataset/audio/鸟叫声/······audio是数据列表存放的位置,生成的数据类别的格式为 音频路径\t音频对应的类别标签,音频路径和标签用制表符 \t分开。读者也可以根据自己存放数据的方式修改以下函数。

以Urbansound8K为例,Urbansound8K是目前应用较为广泛的用于自动城市环境声分类研究的公共数据集,包含10个分类:空调声、汽车鸣笛声、儿童玩耍声、狗叫声、钻孔声、引擎空转声、枪声、手提钻、警笛声和街道音乐声。数据集下载地址:UrbanSound8K.tar.gz。以下是针对Urbansound8K生成数据列表的函数。如果读者想使用该数据集,请下载并解压到 dataset目录下,把生成数据列表代码改为以下代码。

执行create_data.py即可生成数据列表,里面提供了两种生成列表方式,第一种是自定义的数据,第二种是生成Urbansound8K的数据列表,具体看代码。

python create_data.py

生成的列表是长这样的,前面是音频的路径,后面是该音频对应的标签,从0开始,路径和标签之间用Tab隔开。

dataset/UrbanSound8K/audio/fold2/104817-4-0-2.wav	4
dataset/UrbanSound8K/audio/fold9/105029-7-2-5.wav	7
dataset/UrbanSound8K/audio/fold3/107228-5-0-0.wav	5
dataset/UrbanSound8K/audio/fold4/109711-3-2-4.wav	3

修改预处理方法(可选)

配置文件中默认使用的是MelSpectrogram预处理方法,如果要使用其他预处理方法,可以修改配置文件中的安装下面方式修改,具体的值可以根据自己情况修改。如果不清楚如何设置参数,可以直接删除该部分,直接使用默认值。

preprocess_conf:
  # 音频预处理方法,支持:MelSpectrogram、Spectrogram、MFCC、Fbank
  feature_method: 'MelSpectrogram'
  # 设置API参数,更参数查看对应API,不清楚的可以直接删除该部分,直接使用默认值
  method_args:
    sample_rate: 16000
    n_fft: 1024
    hop_length: 320
    win_length: 1024
    f_min: 50.0
    f_max: 14000.0
    n_mels: 64

提取特征(可选)

在训练过程中,首先是要读取音频数据,然后提取特征,最后再进行训练。其中读取音频数据、提取特征也是比较消耗时间的,所以我们可以选择提前提取好取特征,训练模型的是就可以直接加载提取好的特征,这样训练速度会更快。这个提取特征是可选择,如果没有提取好的特征,训练模型的时候就会从读取音频数据,然后提取特征开始。提取特征步骤如下:

  1. 执行extract_features.py,提取特征,特征会保存在dataset/features目录下,并生成新的数据列表train_list_features.txttest_list_features.txt
python extract_features.py --configs=configs/cam++.yml --save_dir=dataset/features
  1. 修改配置文件,将dataset_conf.train_listdataset_conf.test_list修改为train_list_features.txttest_list_features.txt

训练

接着就可以开始训练模型了,创建 train.py。配置文件里面的参数一般不需要修改,但是这几个是需要根据自己实际的数据集进行调整的,首先最重要的就是分类大小dataset_conf.num_class,这个每个数据集的分类大小可能不一样,根据自己的实际情况设定。然后是dataset_conf.batch_size,如果是显存不够的话,可以减小这个参数。

# 单卡训练
CUDA_VISIBLE_DEVICES=0 python train.py
# 多卡训练
python -m paddle.distributed.launch --gpus '0,1' train.py

训练输出日志:

[2023-08-07 23:02:08.807036 INFO   ] utils:print_arguments:14 - ----------- 额外配置参数 -----------
[2023-08-07 23:02:08.807036 INFO   ] utils:print_arguments:16 - configs: configs/ecapa_tdnn.yml
[2023-08-07 23:02:08.807036 INFO   ] utils:print_arguments:16 - pretrained_model: None
[2023-08-07 23:02:08.807036 INFO   ] utils:print_arguments:16 - resume_model: None
[2023-08-07 23:02:08.807036 INFO   ] utils:print_arguments:16 - save_model_path: models/
[2023-08-07 23:02:08.807036 INFO   ] utils:print_arguments:16 - use_gpu: True
[2023-08-07 23:02:08.807036 INFO   ] utils:print_arguments:17 - ------------------------------------------------
[2023-08-07 23:02:08.811036 INFO   ] utils:print_arguments:19 - ----------- 配置文件参数 -----------
[2023-08-07 23:02:08.812035 INFO   ] utils:print_arguments:22 - dataset_conf:
[2023-08-07 23:02:08.812035 INFO   ] utils:print_arguments:25 - 	aug_conf:
[2023-08-07 23:02:08.812035 INFO   ] utils:print_arguments:27 - 		noise_aug_prob: 0.2
[2023-08-07 23:02:08.812035 INFO   ] utils:print_arguments:27 - 		noise_dir: dataset/noise
[2023-08-07 23:02:08.812035 INFO   ] utils:print_arguments:27 - 		speed_perturb: True
[2023-08-07 23:02:08.812035 INFO   ] utils:print_arguments:27 - 		volume_aug_prob: 0.2
[2023-08-07 23:02:08.812035 INFO   ] utils:print_arguments:27 - 		volume_perturb: False
[2023-08-07 23:02:08.812035 INFO   ] utils:print_arguments:25 - 	dataLoader:
[2023-08-07 23:02:08.812035 INFO   ] utils:print_arguments:27 - 		batch_size: 64
[2023-08-07 23:02:08.812035 INFO   ] utils:print_arguments:27 - 		num_workers: 4
[2023-08-07 23:02:08.812035 INFO   ] utils:print_arguments:29 - 	do_vad: False
[2023-08-07 23:02:08.812035 INFO   ] utils:print_arguments:25 - 	eval_conf:
[2023-08-07 23:02:08.812035 INFO   ] utils:print_arguments:27 - 		batch_size: 1
[2023-08-07 23:02:08.812035 INFO   ] utils:print_arguments:27 - 		max_duration: 20
[2023-08-07 23:02:08.812035 INFO   ] utils:print_arguments:29 - 	label_list_path: dataset/label_list.txt
[2023-08-07 23:02:08.812035 INFO   ] utils:print_arguments:29 - 	max_duration: 3
[2023-08-07 23:02:08.812035 INFO   ] utils:print_arguments:29 - 	min_duration: 0.5
[2023-08-07 23:02:08.812035 INFO   ] utils:print_arguments:29 - 	sample_rate: 16000
[2023-08-07 23:02:08.812035 INFO   ] utils:print_arguments:25 - 	spec_aug_args:
[2023-08-07 23:02:08.812035 INFO   ] utils:print_arguments:27 - 		freq_mask_width: [0, 8]
[2023-08-07 23:02:08.812035 INFO   ] utils:print_arguments:27 - 		time_mask_width: [0, 10]
[2023-08-07 23:02:08.812035 INFO   ] utils:print_arguments:29 - 	target_dB: -20
[2023-08-07 23:02:08.812035 INFO   ] utils:print_arguments:29 - 	test_list: dataset/test_list.txt
[2023-08-07 23:02:08.812035 INFO   ] utils:print_arguments:29 - 	train_list: dataset/train_list.txt
[2023-08-07 23:02:08.812035 INFO   ] utils:print_arguments:29 - 	use_dB_normalization: True
[2023-08-07 23:02:08.812035 INFO   ] utils:print_arguments:29 - 	use_spec_aug: True
[2023-08-07 23:02:08.812035 INFO   ] utils:print_arguments:22 - model_conf:
[2023-08-07 23:02:08.816062 INFO   ] utils:print_arguments:29 - 	num_class: 10
[2023-08-07 23:02:08.816062 INFO   ] utils:print_arguments:29 - 	pooling_type: ASP
[2023-08-07 23:02:08.816062 INFO   ] utils:print_arguments:22 - optimizer_conf:
[2023-08-07 23:02:08.816062 INFO   ] utils:print_arguments:29 - 	optimizer: Adam
[2023-08-07 23:02:08.816062 INFO   ] utils:print_arguments:29 - 	scheduler: WarmupCosineSchedulerLR
[2023-08-07 23:02:08.816062 INFO   ] utils:print_arguments:25 - 	scheduler_args:
[2023-08-07 23:02:08.816062 INFO   ] utils:print_arguments:27 - 		learning_rate: 0.001
[2023-08-07 23:02:08.816062 INFO   ] utils:print_arguments:27 - 		min_lr: 1e-05
[2023-08-07 23:02:08.816062 INFO   ] utils:print_arguments:27 - 		warmup_epoch: 5
[2023-08-07 23:02:08.816062 INFO   ] utils:print_arguments:29 - 	weight_decay: 1e-06
[2023-08-07 23:02:08.816062 INFO   ] utils:print_arguments:22 - preprocess_conf:
[2023-08-07 23:02:08.816062 INFO   ] utils:print_arguments:29 - 	feature_method: Fbank
[2023-08-07 23:02:08.816062 INFO   ] utils:print_arguments:25 - 	method_args:
[2023-08-07 23:02:08.816062 INFO   ] utils:print_arguments:27 - 		n_mels: 80
[2023-08-07 23:02:08.816062 INFO   ] utils:print_arguments:27 - 		sr: 16000
[2023-08-07 23:02:08.816062 INFO   ] utils:print_arguments:22 - train_conf:
[2023-08-07 23:02:08.816062 INFO   ] utils:print_arguments:29 - 	log_interval: 10
[2023-08-07 23:02:08.816062 INFO   ] utils:print_arguments:29 - 	max_epoch: 60
[2023-08-07 23:02:08.816062 INFO   ] utils:print_arguments:31 - use_model: EcapaTdnn
[2023-08-07 23:02:08.816062 INFO   ] utils:print_arguments:32 - ------------------------------------------------
[2023-08-07 23:02:08.817077 WARNING] trainer:__init__:69 - Windows系统不支持多线程读取数据,已自动关闭!
W0807 23:02:08.822477  3192 gpu_resources.cc:61] Please NOTE: device: 0, GPU Compute Capability: 7.5, Driver API Version: 11.7, Runtime API Version: 11.6
W0807 23:02:08.826478  3192 gpu_resources.cc:91] device: 0, cuDNN Version: 8.4.
----------------------------------------------------------------------------------------
        Layer (type)             Input Shape          Output Shape         Param #    
========================================================================================
          Conv1D-2              [[1, 80, 102]]        [1, 512, 98]         205,312    
          Conv1d-1              [[1, 80, 98]]         [1, 512, 98]            0       
           ReLU-1               [[1, 512, 98]]        [1, 512, 98]            0       
       BatchNorm1D-2            [[1, 512, 98]]        [1, 512, 98]          2,048     
       BatchNorm1d-1            [[1, 512, 98]]        [1, 512, 98]            0       
        TDNNBlock-1             [[1, 80, 98]]         [1, 512, 98]            0       
          Conv1D-4              [[1, 512, 98]]        [1, 512, 98]         262,656    
          Conv1d-3              [[1, 512, 98]]        [1, 512, 98]            0       
           ReLU-2               [[1, 512, 98]]        [1, 512, 98]            0       
       BatchNorm1D-4            [[1, 512, 98]]        [1, 512, 98]          2,048     
       BatchNorm1d-3            [[1, 512, 98]]        [1, 512, 98]            0       
        TDNNBlock-2             [[1, 512, 98]]        [1, 512, 98]            0       
          Conv1D-6              [[1, 64, 102]]        [1, 64, 98]          12,352     
          Conv1d-5              [[1, 64, 98]]         [1, 64, 98]             0       
           ReLU-3               [[1, 64, 98]]         [1, 64, 98]             0       
       BatchNorm1D-6            [[1, 64, 98]]         [1, 64, 98]            256      
       BatchNorm1d-5            [[1, 64, 98]]         [1, 64, 98]             0       
        TDNNBlock-3             [[1, 64, 98]]         [1, 64, 98]             0       
          Conv1D-8              [[1, 64, 102]]        [1, 64, 98]          12,352     
          Conv1d-7              [[1, 64, 98]]         [1, 64, 98]             0       
           ReLU-4               [[1, 64, 98]]         [1, 64, 98]             0       
       BatchNorm1D-8            [[1, 64, 98]]         [1, 64, 98]            256      
       BatchNorm1d-7            [[1, 64, 98]]         [1, 64, 98]             0       
        TDNNBlock-4             [[1, 64, 98]]         [1, 64, 98]             0       
         Conv1D-10              [[1, 64, 102]]        [1, 64, 98]          12,352     
          Conv1d-9              [[1, 64, 98]]         [1, 64, 98]             0       
           ReLU-5               [[1, 64, 98]]         [1, 64, 98]             0       
       BatchNorm1D-10           [[1, 64, 98]]         [1, 64, 98]            256      
       BatchNorm1d-9            [[1, 64, 98]]         [1, 64, 98]             0       
        TDNNBlock-5             [[1, 64, 98]]         [1, 64, 98]             0       
         Conv1D-12              [[1, 64, 102]]        [1, 64, 98]          12,352     
         Conv1d-11              [[1, 64, 98]]         [1, 64, 98]             0       
           ReLU-6               [[1, 64, 98]]         [1, 64, 98]             0       
       BatchNorm1D-12           [[1, 64, 98]]         [1, 64, 98]            256      
       BatchNorm1d-11           [[1, 64, 98]]         [1, 64, 98]             0       
        TDNNBlock-6             [[1, 64, 98]]         [1, 64, 98]             0      
······················································  
       BatchNorm1d-59           [[1, 128, 98]]        [1, 128, 98]            0       
        TDNNBlock-30           [[1, 4608, 98]]        [1, 128, 98]            0       
           Tanh-1               [[1, 128, 98]]        [1, 128, 98]            0       
         Conv1D-74              [[1, 128, 98]]       [1, 1536, 98]         198,144    
         Conv1d-73              [[1, 128, 98]]       [1, 1536, 98]            0       
AttentiveStatisticsPooling-1   [[1, 1536, 98]]        [1, 3072, 1]            0       
       BatchNorm1D-62           [[1, 3072, 1]]        [1, 3072, 1]         12,288     
       BatchNorm1d-61           [[1, 3072, 1]]        [1, 3072, 1]            0       
         Conv1D-76              [[1, 3072, 1]]        [1, 192, 1]          590,016    
         Conv1d-75              [[1, 3072, 1]]        [1, 192, 1]             0       
          Linear-1                [[1, 192]]            [1, 10]             1,930     
========================================================================================
Total params: 6,215,306
Trainable params: 6,195,978
Non-trainable params: 19,328
----------------------------------------------------------------------------------------
Input size (MB): 0.03
Forward/backward pass size (MB): 35.53
Params size (MB): 23.71
Estimated Total Size (MB): 59.27
----------------------------------------------------------------------------------------

[2023-08-07 23:02:11.081835 INFO   ] trainer:train:317 - 训练数据:8644
[2023-08-07 23:02:15.428326 INFO   ] trainer:__train_epoch:269 - Train epoch: [1/60], batch: [0/136], loss: 2.99582, accuracy: 0.04688, learning rate: 0.00000000, speed: 14.72 data/sec, eta: 9:51:07

评估

执行下面命令执行评估。

python eval.py --configs=configs/bi_lstm.yml

评估输出如下:

[2024-02-03 15:13:25.469242 INFO   ] trainer:evaluate:461 - 成功加载模型:models/CAMPPlus_Fbank/best_model/model.pth
100%|██████████████████████████████| 150/150 [00:00<00:00, 1281.96it/s]
评估消耗时间:1s,loss:0.61840,accuracy:0.87333

评估会出来输出准确率,还保存了混淆矩阵图片,保存路径output/images/,如下。


混淆矩阵

注意:如果类别标签是中文的,需要设置安装字体才能正常显示,一般情况下Windows无需安装,Ubuntu需要安装。如果Windows确实是确实字体,只需要字体文件这里下载.ttf格式的文件,复制到C:\Windows\Fonts即可。Ubuntu系统操作如下。

  1. 安装字体
git clone https://github.com/tracyone/program_font && cd program_font && ./install.sh
  1. 执行下面Python代码
import matplotlib
import shutil
import os

path = matplotlib.matplotlib_fname()
path = path.replace('matplotlibrc', 'fonts/ttf/')
print(path)
shutil.copy('/usr/share/fonts/MyFonts/simhei.ttf', path)
user_dir = os.path.expanduser('~')
shutil.rmtree(f'{user_dir}/.cache/matplotlib', ignore_errors=True)

预测

在训练结束之后,我们得到了一个模型参数文件,我们使用这个模型预测音频。

python infer.py --audio_path=dataset/UrbanSound8K/audio/fold5/156634-5-2-5.wav

其他功能

  • 为了方便读取录制数据和制作数据集,这里提供了录音程序record_audio.py,这个用于录制音频,录制的音频采样率为16000,单通道,16bit。
python record_audio.py
  • infer_record.py这个程序是用来不断进行录音识别,我们可以大致理解为这个程序在实时录音识别。通过这个应该我们可以做一些比较有趣的事情,比如把麦克风放在小鸟经常来的地方,通过实时录音识别,一旦识别到有鸟叫的声音,如果你的数据集足够强大,有每种鸟叫的声音数据集,这样你还能准确识别是那种鸟叫。如果识别到目标鸟类,就启动程序,例如拍照等等。
python infer_record.py --record_seconds=3

打赏作者


打赏一块钱支持一下作者

打赏作者

参考资料

  1. https://github.com/PaddlePaddle/PaddleSpeech
  2. https://github.com/yeyupiaoling/PaddlePaddle-MobileFaceNets
  3. https://github.com/yeyupiaoling/PPASR
  4. https://github.com/alibaba-damo-academy/3D-Speaker

audioclassification-paddlepaddle's People

Contributors

gt-acerzhang avatar yeyupiaoling avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

audioclassification-paddlepaddle's Issues

训练时报错

输出如下

-----------  Configuration Arguments -----------
batch_size: 32
gpus: 0
input_shape: (None, 1, 128, 128)
learning_rate: 0.001
num_classes: 10
num_epoch: 50
num_workers: 4
save_model: models/
test_list_path: dataset/test_list.txt
train_list_path: dataset/train_list.txt
------------------------------------------------
W1230 03:44:49.589563  1696 device_context.cc:404] Please NOTE: device: 0, GPU Compute Capability: 6.0, Driver API Version: 11.2, Runtime API Version: 10.2
W1230 03:44:49.593922  1696 device_context.cc:422] device: 0, cuDNN Version: 7.6.
-------------------------------------------------------------------------------
   Layer (type)         Input Shape          Output Shape         Param #    
===============================================================================
     Conv2D-1        [[1, 1, 128, 128]]    [1, 64, 64, 64]         3,136     
   BatchNorm2D-1     [[1, 64, 64, 64]]     [1, 64, 64, 64]          256      
      ReLU-1         [[1, 64, 64, 64]]     [1, 64, 64, 64]           0       
    MaxPool2D-1      [[1, 64, 64, 64]]     [1, 64, 32, 32]           0       
     Conv2D-2        [[1, 64, 32, 32]]     [1, 64, 32, 32]        36,864     
   BatchNorm2D-2     [[1, 64, 32, 32]]     [1, 64, 32, 32]          256      
      ReLU-2         [[1, 64, 32, 32]]     [1, 64, 32, 32]           0       
     Conv2D-3        [[1, 64, 32, 32]]     [1, 64, 32, 32]        36,864     
   BatchNorm2D-3     [[1, 64, 32, 32]]     [1, 64, 32, 32]          256      
   BasicBlock-1      [[1, 64, 32, 32]]     [1, 64, 32, 32]           0       
     Conv2D-4        [[1, 64, 32, 32]]     [1, 64, 32, 32]        36,864     
   BatchNorm2D-4     [[1, 64, 32, 32]]     [1, 64, 32, 32]          256      
      ReLU-3         [[1, 64, 32, 32]]     [1, 64, 32, 32]           0       
     Conv2D-5        [[1, 64, 32, 32]]     [1, 64, 32, 32]        36,864     
   BatchNorm2D-5     [[1, 64, 32, 32]]     [1, 64, 32, 32]          256      
   BasicBlock-2      [[1, 64, 32, 32]]     [1, 64, 32, 32]           0       
     Conv2D-6        [[1, 64, 32, 32]]     [1, 64, 32, 32]        36,864     
   BatchNorm2D-6     [[1, 64, 32, 32]]     [1, 64, 32, 32]          256      
      ReLU-4         [[1, 64, 32, 32]]     [1, 64, 32, 32]           0       
     Conv2D-7        [[1, 64, 32, 32]]     [1, 64, 32, 32]        36,864     
   BatchNorm2D-7     [[1, 64, 32, 32]]     [1, 64, 32, 32]          256      
   BasicBlock-3      [[1, 64, 32, 32]]     [1, 64, 32, 32]           0       
     Conv2D-9        [[1, 64, 32, 32]]     [1, 128, 16, 16]       73,728     
   BatchNorm2D-9     [[1, 128, 16, 16]]    [1, 128, 16, 16]         512      
      ReLU-5         [[1, 128, 16, 16]]    [1, 128, 16, 16]          0       
     Conv2D-10       [[1, 128, 16, 16]]    [1, 128, 16, 16]       147,456    
  BatchNorm2D-10     [[1, 128, 16, 16]]    [1, 128, 16, 16]         512      
     Conv2D-8        [[1, 64, 32, 32]]     [1, 128, 16, 16]        8,192     
   BatchNorm2D-8     [[1, 128, 16, 16]]    [1, 128, 16, 16]         512      
   BasicBlock-4      [[1, 64, 32, 32]]     [1, 128, 16, 16]          0       
     Conv2D-11       [[1, 128, 16, 16]]    [1, 128, 16, 16]       147,456    
  BatchNorm2D-11     [[1, 128, 16, 16]]    [1, 128, 16, 16]         512      
      ReLU-6         [[1, 128, 16, 16]]    [1, 128, 16, 16]          0       
     Conv2D-12       [[1, 128, 16, 16]]    [1, 128, 16, 16]       147,456    
  BatchNorm2D-12     [[1, 128, 16, 16]]    [1, 128, 16, 16]         512      
   BasicBlock-5      [[1, 128, 16, 16]]    [1, 128, 16, 16]          0       
     Conv2D-13       [[1, 128, 16, 16]]    [1, 128, 16, 16]       147,456    
  BatchNorm2D-13     [[1, 128, 16, 16]]    [1, 128, 16, 16]         512      
      ReLU-7         [[1, 128, 16, 16]]    [1, 128, 16, 16]          0       
     Conv2D-14       [[1, 128, 16, 16]]    [1, 128, 16, 16]       147,456    
  BatchNorm2D-14     [[1, 128, 16, 16]]    [1, 128, 16, 16]         512      
   BasicBlock-6      [[1, 128, 16, 16]]    [1, 128, 16, 16]          0       
     Conv2D-15       [[1, 128, 16, 16]]    [1, 128, 16, 16]       147,456    
  BatchNorm2D-15     [[1, 128, 16, 16]]    [1, 128, 16, 16]         512      
      ReLU-8         [[1, 128, 16, 16]]    [1, 128, 16, 16]          0       
     Conv2D-16       [[1, 128, 16, 16]]    [1, 128, 16, 16]       147,456    
  BatchNorm2D-16     [[1, 128, 16, 16]]    [1, 128, 16, 16]         512      
   BasicBlock-7      [[1, 128, 16, 16]]    [1, 128, 16, 16]          0       
     Conv2D-18       [[1, 128, 16, 16]]     [1, 256, 8, 8]        294,912    
  BatchNorm2D-18      [[1, 256, 8, 8]]      [1, 256, 8, 8]         1,024     
      ReLU-9          [[1, 256, 8, 8]]      [1, 256, 8, 8]           0       
     Conv2D-19        [[1, 256, 8, 8]]      [1, 256, 8, 8]        589,824    
  BatchNorm2D-19      [[1, 256, 8, 8]]      [1, 256, 8, 8]         1,024     
     Conv2D-17       [[1, 128, 16, 16]]     [1, 256, 8, 8]        32,768     
  BatchNorm2D-17      [[1, 256, 8, 8]]      [1, 256, 8, 8]         1,024     
   BasicBlock-8      [[1, 128, 16, 16]]     [1, 256, 8, 8]           0       
     Conv2D-20        [[1, 256, 8, 8]]      [1, 256, 8, 8]        589,824    
  BatchNorm2D-20      [[1, 256, 8, 8]]      [1, 256, 8, 8]         1,024     
      ReLU-10         [[1, 256, 8, 8]]      [1, 256, 8, 8]           0       
     Conv2D-21        [[1, 256, 8, 8]]      [1, 256, 8, 8]        589,824    
  BatchNorm2D-21      [[1, 256, 8, 8]]      [1, 256, 8, 8]         1,024     
   BasicBlock-9       [[1, 256, 8, 8]]      [1, 256, 8, 8]           0       
     Conv2D-22        [[1, 256, 8, 8]]      [1, 256, 8, 8]        589,824    
  BatchNorm2D-22      [[1, 256, 8, 8]]      [1, 256, 8, 8]         1,024     
      ReLU-11         [[1, 256, 8, 8]]      [1, 256, 8, 8]           0       
     Conv2D-23        [[1, 256, 8, 8]]      [1, 256, 8, 8]        589,824    
  BatchNorm2D-23      [[1, 256, 8, 8]]      [1, 256, 8, 8]         1,024     
   BasicBlock-10      [[1, 256, 8, 8]]      [1, 256, 8, 8]           0       
     Conv2D-24        [[1, 256, 8, 8]]      [1, 256, 8, 8]        589,824    
  BatchNorm2D-24      [[1, 256, 8, 8]]      [1, 256, 8, 8]         1,024     
      ReLU-12         [[1, 256, 8, 8]]      [1, 256, 8, 8]           0       
     Conv2D-25        [[1, 256, 8, 8]]      [1, 256, 8, 8]        589,824    
  BatchNorm2D-25      [[1, 256, 8, 8]]      [1, 256, 8, 8]         1,024     
   BasicBlock-11      [[1, 256, 8, 8]]      [1, 256, 8, 8]           0       
     Conv2D-26        [[1, 256, 8, 8]]      [1, 256, 8, 8]        589,824    
  BatchNorm2D-26      [[1, 256, 8, 8]]      [1, 256, 8, 8]         1,024     
      ReLU-13         [[1, 256, 8, 8]]      [1, 256, 8, 8]           0       
     Conv2D-27        [[1, 256, 8, 8]]      [1, 256, 8, 8]        589,824    
  BatchNorm2D-27      [[1, 256, 8, 8]]      [1, 256, 8, 8]         1,024     
   BasicBlock-12      [[1, 256, 8, 8]]      [1, 256, 8, 8]           0       
     Conv2D-28        [[1, 256, 8, 8]]      [1, 256, 8, 8]        589,824    
  BatchNorm2D-28      [[1, 256, 8, 8]]      [1, 256, 8, 8]         1,024     
      ReLU-14         [[1, 256, 8, 8]]      [1, 256, 8, 8]           0       
     Conv2D-29        [[1, 256, 8, 8]]      [1, 256, 8, 8]        589,824    
  BatchNorm2D-29      [[1, 256, 8, 8]]      [1, 256, 8, 8]         1,024     
   BasicBlock-13      [[1, 256, 8, 8]]      [1, 256, 8, 8]           0       
     Conv2D-31        [[1, 256, 8, 8]]      [1, 512, 4, 4]       1,179,648   
  BatchNorm2D-31      [[1, 512, 4, 4]]      [1, 512, 4, 4]         2,048     
      ReLU-15         [[1, 512, 4, 4]]      [1, 512, 4, 4]           0       
     Conv2D-32        [[1, 512, 4, 4]]      [1, 512, 4, 4]       2,359,296   
  BatchNorm2D-32      [[1, 512, 4, 4]]      [1, 512, 4, 4]         2,048     
     Conv2D-30        [[1, 256, 8, 8]]      [1, 512, 4, 4]        131,072    
  BatchNorm2D-30      [[1, 512, 4, 4]]      [1, 512, 4, 4]         2,048     
   BasicBlock-14      [[1, 256, 8, 8]]      [1, 512, 4, 4]           0       
     Conv2D-33        [[1, 512, 4, 4]]      [1, 512, 4, 4]       2,359,296   
  BatchNorm2D-33      [[1, 512, 4, 4]]      [1, 512, 4, 4]         2,048     
      ReLU-16         [[1, 512, 4, 4]]      [1, 512, 4, 4]           0       
     Conv2D-34        [[1, 512, 4, 4]]      [1, 512, 4, 4]       2,359,296   
  BatchNorm2D-34      [[1, 512, 4, 4]]      [1, 512, 4, 4]         2,048     
   BasicBlock-15      [[1, 512, 4, 4]]      [1, 512, 4, 4]           0       
     Conv2D-35        [[1, 512, 4, 4]]      [1, 512, 4, 4]       2,359,296   
  BatchNorm2D-35      [[1, 512, 4, 4]]      [1, 512, 4, 4]         2,048     
      ReLU-17         [[1, 512, 4, 4]]      [1, 512, 4, 4]           0       
     Conv2D-36        [[1, 512, 4, 4]]      [1, 512, 4, 4]       2,359,296   
  BatchNorm2D-36      [[1, 512, 4, 4]]      [1, 512, 4, 4]         2,048     
   BasicBlock-16      [[1, 512, 4, 4]]      [1, 512, 4, 4]           0       
AdaptiveAvgPool2D-1   [[1, 512, 4, 4]]      [1, 512, 1, 1]           0       
     Linear-1            [[1, 512]]            [1, 10]             5,130     
===============================================================================
Total params: 21,300,554
Trainable params: 21,266,506
Non-trainable params: 34,048
-------------------------------------------------------------------------------
Input size (MB): 0.06
Forward/backward pass size (MB): 28.00
Params size (MB): 81.26
Estimated Total Size (MB): 109.32
-------------------------------------------------------------------------------

Epoch 0: StepDecay set learning rate to 0.001.
/usr/local/lib/python3.7/dist-packages/librosa/core/audio.py:165: UserWarning: PySoundFile failed. Trying audioread instead.
  warnings.warn("PySoundFile failed. Trying audioread instead.")
/usr/local/lib/python3.7/dist-packages/librosa/core/audio.py:165: UserWarning: PySoundFile failed. Trying audioread instead.
  warnings.warn("PySoundFile failed. Trying audioread instead.")
ERROR:root:DataLoader reader thread raised an exception!
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python3.7/threading.py", line 926, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.7/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.7/dist-packages/paddle/fluid/dataloader/dataloader_iter.py", line 411, in _thread_loop
    batch = self._get_data()
  File "/usr/local/lib/python3.7/dist-packages/paddle/fluid/dataloader/dataloader_iter.py", line 525, in _get_data
    batch.reraise()
  File "/usr/local/lib/python3.7/dist-packages/paddle/fluid/dataloader/worker.py", line 168, in reraise
    raise self.exc_type(msg)
ValueError: DataLoader worker(2) caught ValueError with message:
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/paddle/fluid/dataloader/worker.py", line 320, in _worker_loop
    batch = fetcher.fetch(indices)
  File "/usr/local/lib/python3.7/dist-packages/paddle/fluid/dataloader/fetcher.py", line 99, in fetch
    data = [self.dataset[idx] for idx in batch_indices]
  File "/usr/local/lib/python3.7/dist-packages/paddle/fluid/dataloader/fetcher.py", line 99, in <listcomp>
    data = [self.dataset[idx] for idx in batch_indices]
  File "/content/AudioClassification-PaddlePaddle/reader.py", line 36, in __getitem__
    spec_mag = load_audio(audio_path, mode=self.model, spec_len=self.spec_len)
  File "/content/AudioClassification-PaddlePaddle/reader.py", line 14, in load_audio
    crop_start = random.randint(0, spec_mag.shape[1] - spec_len)
  File "/usr/lib/python3.7/random.py", line 222, in randint
    return self.randrange(a, b+1)
  File "/usr/lib/python3.7/random.py", line 200, in randrange
    raise ValueError("empty range for randrange() (%d,%d, %d)" % (istart, istop, width))
ValueError: empty range for randrange() (0,-15, -15)


Traceback (most recent call last):
  File "train.py", line 125, in <module>
    train(args)
  File "train.py", line 85, in train
    for batch_id, (spec_mag, label) in enumerate(train_loader()):
  File "/usr/local/lib/python3.7/dist-packages/paddle/fluid/dataloader/dataloader_iter.py", line 585, in __next__
    data = self._reader.read_next_var_list()
SystemError: (Fatal) Blocking queue is killed because the data reader raises an exception.
  [Hint: Expected killed_ != true, but received killed_:1 == true:1.] (at /paddle/paddle/fluid/operators/reader/blocking_queue.h:166)

/usr/local/lib/python3.7/dist-packages/librosa/core/audio.py:165: UserWarning: PySoundFile failed. Trying audioread instead.
  warnings.warn("PySoundFile failed. Trying audioread instead.")
/usr/local/lib/python3.7/dist-packages/librosa/core/audio.py:165: UserWarning: PySoundFile failed. Trying audioread instead.
  warnings.warn("PySoundFile failed. Trying audioread instead.")
/usr/local/lib/python3.7/dist-packages/librosa/core/audio.py:165: UserWarning: PySoundFile failed. Trying audioread instead.
  warnings.warn("PySoundFile failed. Trying audioread instead.")
/usr/local/lib/python3.7/dist-packages/librosa/core/audio.py:165: UserWarning: PySoundFile failed. Trying audioread instead.
  warnings.warn("PySoundFile failed. Trying audioread instead.")
/usr/local/lib/python3.7/dist-packages/librosa/core/audio.py:165: UserWarning: PySoundFile failed. Trying audioread instead.
  warnings.warn("PySoundFile failed. Trying audioread instead.")

声音异常检测

如果我想添加一个声音异常检测功能该怎么做呢,比如我划分了十个类别,当检测到声音不在这十个类别中,就输出其他类别,类似这样的怎么实现呢,我的想法是检测声音对比后返回一个和各类别相似度的分数,低于阈值的就是其他类别。问题是如何用你的代码得到这个分数呢。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.