SEGAN: Speech Enhancement Generative Adversarial Network 项目部署(Tensorflow)

Segan项目部署(Tensorflow)

原文:https://arxiv.org/abs/1703.09452
项目地址:https://github.com/santi-pdp/segan

虽然官方的README表示Python是2.7版本,但其实已经更新到3.x版本了,本篇用的环境是Python3.5。

这个是我组用的服务器配置:Python 3.5.6, CUDA 10.0, cudNN 7.6.5, Tensorflow-gpu 1.10.0, Keras 2.1.6, Pytorch 1.3.1, Caffe 1.0.0, Chainer 7.0.0, Mxnet-cu100 1.5.1.post0,Ubuntu 18.04

Tensorflow版本需要是1.x,不然会有很多版本问题。

数据集准备

两种做法:

  1. 直接去数据集地址下载,再使用作者提供的脚本./prepare_data.sh

  2. (推荐)直接使用作者提供的脚本./prepare_data.sh,脚本内容大致就是:

    1. 创建data目录作为存放数据集的目录。
    2. 下载clean_trainset_wav和noisy_trainset_wav,并分别转化为16k形式。
    3. 这里可能需要安装一下sox,用来音频处理的包,安装方法:Ubuntu【已解决】 sox: command not found

这里我还额外下载了测试集的数据。

请添加图片描述

训练

为了方便,作者提供了train_segan.sh脚本文件,稍微修改一下参数:比如 CUDA_VISIBLE_DEVICES=“xxxx”,按照自己机器的配置来改。

# Place the CUDA_VISIBLE_DEVICES="xxxx" required before the python call
# e.g. to specify the first two GPUs in your system: CUDA_VISIBLE_DEVICES="0,1" python ...

直接运行就行,如果有提示需要安装包,那就安装一下。接着会出现很多问题,如下:

  1. AttributeError: ‘dict’ object has no attribute ‘iteritems’,python3中iteritems()被items()代替了。

  2. TypeError: Expected int32, got list containing Tensors of type ‘_Message’ instead. 这主要是因为tf.concat函数出错,需要将两个参数的位置调换一下,这个过程中,控制台会提示你在哪个文件的第几行出错,分别修改即可。

    vim可以通过:行数快速定位。

  3. AttributeError: module ‘tensorflow’ has no attribute ‘sub’,将sub改为subtract

  4. AttributeError: ‘dict_values’ object has no attribute ‘op’, 需要将self.d_vars的地方用list()强制转换为list,如下图。

    请添加图片描述

    请添加图片描述

  5. ValueError: Variable d_model/d_block_5/downconv/W/RMSProp/ does not exist, Did you mean to set reuse=tf.AUTO_REUSE in VarScope?model.py的144行处,改为下面的。

    请添加图片描述

预测

加载模型

作者提供了训练好的模型参数,下载地址

解压:tar -zxvf segan_v1.1.tar.gz

运行脚本

./clean.wav 【噪声文件名16k】【去噪后保存的目录】

可能会遇到的问题:

# main.py
wavfile.write(os.path.join(FLAGS.save_clean_path, wavname), 16e3, c_wave)

这里会报错,因为wavfile.write的第二个参数需要传入int类型,将16e3改为16000即可。

猜你喜欢

转载自blog.csdn.net/Sky_QiaoBa_Sum/article/details/130050383