代碼下載
這是一個(gè)音頻提取、分離的項(xiàng)目
一、環(huán)境搭建
(1)新建虛擬環(huán)境,并進(jìn)入
conda create -n demucs python=3.8
activate demucs
(2)安裝pyTorch
到pyTorch官網(wǎng)選擇對(duì)應(yīng)配置
這個(gè)是我的配置
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
(3)進(jìn)入代碼文件夾,批量安裝包
d:
cd D:\data\cqZhang\demucs-3
pip install -r requirements.txt
(4)安裝其他需要的包
pip install librosa
二、數(shù)據(jù)集準(zhǔn)備
(1)下載數(shù)據(jù)集
使用Musdb HQ 數(shù)據(jù)集
獲取路徑有:
https://zenodo.org/record/3338373
https://www.kaggle.com/datasets/ayu055/musdb18hq
數(shù)據(jù)集可以放在“\checkpoint\defossez\datasets\musdbhq”路徑下,
這與代碼原來的位置應(yīng)該是一致的
(2)修改配置參數(shù)
- The
dset.musdb
key insideconf/config.yaml
. - The variable
MUSDB_PATH
insidetools/automix.py
.
我本來使用的是相對(duì)路徑,但是他貌似找不到,后來改成絕對(duì)路徑
其他的路徑也一樣,如果找不到,就要改成絕對(duì)路徑
(3)創(chuàng)建微調(diào)數(shù)據(jù)集
原來的命令是export NUMBA_NUM_THREADS=1; python3 -m tools.automix
,但它是linux上的命令,
將其改為set NUMBA_NUM_THREADS=1 && python -m tools.automix
運(yùn)行結(jié)束會(huì)在項(xiàng)目目錄下產(chǎn)生tmp文件夾,里面有新的數(shù)據(jù)集
修改 conf/config.yaml
.中的 dset.musdb
修改 conf/dset/auto_mus.yaml
中的 dset.wav
( OUTPATH
)
(4)解壓outputs.tar.gz
tar xvf outputs.tar.gz
三、訓(xùn)練
訓(xùn)練有三種命令
我只嘗試了第二種
(1)默認(rèn),cpu
dora info -f 81de367c
this will show the hyper-parameter used by a specific XP.
Be careful some overrides might present twice, and the right most one will give you the right value for it.
這將顯示特定XP使用的超參數(shù)。
請(qǐng)注意,有些覆蓋可能會(huì)出現(xiàn)兩次,最正確的一次將為您提供正確的值。
(2)默認(rèn),gpu
dora run -d -f 81de367c
注意:
如果修改了數(shù)據(jù)集,要在目錄下刪除metadata文件夾,否則會(huì)出錯(cuò)。
run an XP with the hyper-parameters from XP 81de367c.
-d
is for distributed, it will use all available GPUs.
使用XP 81de367c中的超參數(shù)運(yùn)行XP。-d
是分布式的,它將使用所有可用的GPU。
(3)修改參數(shù),gpu
dora run -d -f 81de367c hdemucs.channels=32
start from the config of XP 81de367c but change some hyper-params.
This will give you a new XP with a new signature (here 3fe9c332).
從XP 81de367c的配置開始,但更改了一些超參數(shù)。
這將為您提供一個(gè)帶有新簽名的新XP(此處為3fe9c332)。
四、推理
(1)模型導(dǎo)出
python -m tools.export 81de367c
(2)模型評(píng)估
python -m tools.test_pretrained --repo ./release_models -n 81de367c
(3)推理
python -m demucs --repo ./release_models -n 81de367c --mp3 D:\data\cqZhang\001.mp3
保存位置./separated
報(bào)錯(cuò)
(1)soundfile.LibsndfileError: Error opening ‘C:\Users\Lenovo\AppData\Local\Temp\tmps0ogpyqy.wav’: System error.
在linux上運(yùn)行會(huì)創(chuàng)建一個(gè)臨時(shí)文件,且程序退出后該臨時(shí)文件會(huì)自動(dòng)刪除,
但是在windows上運(yùn)行時(shí),不能打開創(chuàng)建的臨時(shí)文件,
Whether the name can be used to open the file a second time, while the named temporary file is still open, varies across platforms (it can be so used on Unix; it cannot on Windows NT or later).
在命名的臨時(shí)文件仍然打開的情況下,該名稱是否可以用于第二次打開文件,因平臺(tái)而異(它可以在Unix上使用;不能在Windows NT或更高版本上使用)。
處理:
方法1. 更改臨時(shí)文件保存方式(不保存到系統(tǒng)的臨時(shí)文件夾里)
方法2. 增加參數(shù):delete=False,手動(dòng)刪除
我采用方法2
執(zhí)行后會(huì)報(bào)其他錯(cuò)誤,這是另一個(gè)問題了
(2)FileNotFoundError: [WinError 2] 系統(tǒng)找不到指定的文件。
出現(xiàn)這個(gè)錯(cuò)誤,原因大概有三種:
1、先查看路徑是否正確
2、再查看該文件是否存在
3、如果還沒解決問題,最后很可能就是該命令在dos環(huán)境內(nèi)無法使用
處理:
根據(jù)實(shí)際情況,我判斷是第三種問題
到這里下載一個(gè)程序,
解壓后放在項(xiàng)目目錄下
已經(jīng)成功執(zhí)行了
(3)TypeError: beat_track() takes 0 positional arguments but 1 positional argument (and 2 keyword-only arguments) were given
說是參數(shù)個(gè)數(shù)不匹配的問題,其實(shí)并不是
處理:
# 將下列代碼
tempo, events = beat_track(drums.numpy(), units='time', sr=SR)
# 改為
tempo, events = beat_track(y=drums.numpy(), units='time', sr=SR)
(4)TypeError: chroma_cqt() takes 0 positional arguments but 1 positional argument (and 1 keyword-only argument) were given
這個(gè)問題與上面那個(gè)問題一樣
說是參數(shù)個(gè)數(shù)不匹配的問題,其實(shí)并不是
處理:
# 將下列代碼
kr = torch.from_numpy(chroma_cqt(bass.numpy(), sr=SR))
# 改為
kr = torch.from_numpy(chroma_cqt(y = bass.numpy(), sr=SR))
(5)numpy.core._exceptions._ArrayMemoryError: Unable to allocate 1.11 GiB for an array with shape (54134, 1377) and data type complex128
內(nèi)存不足
這個(gè)我沒有去思考如何減少內(nèi)存的使用
也許減小數(shù)據(jù)集有效
我的處理方式是:換一臺(tái)大內(nèi)存的機(jī)器
它的內(nèi)存需求不超過40g
(6)UserWarning:The version_base parameter is not specified.
這是一個(gè)版本警告,其實(shí)無關(guān)緊要
完整的警告如下:
D:\app\anaconda\envs\demucs\lib\site-packages\dora\hydra.py:279: UserWarning:
The version_base parameter is not specified.
Please specify a compatability version level, or None.
Will assume defaults for version 1.1
with initialize_config_dir(str(self.full_config_path), job_name=self._job_name,
處理:
加上參數(shù)version_base='1.1'
(7)FileNotFoundError: Caught FileNotFoundError in DataLoader worker process 0.
處理:
首先我在demucs/repitch
的sp.run()
中加入?yún)?shù)shell=True
再次運(yùn)行dora run -d -f 81de367c
,報(bào)錯(cuò)信息出現(xiàn)變化
我運(yùn)行命令soundstretch C:\\Users\\Lenovo\\AppData\\Local\\Temp\\tmps9ifi1_z.wav C:\\Users\\Lenovo\\AppData\\Local\\Temp\\tmp44v82njg.wav -pitch=2 -tempo=-3.226039
,執(zhí)行成功
說明文件其實(shí)是存在的,但是不知道為啥不能執(zhí)行成功
第二處應(yīng)該是編碼格式的問題,我將raise RuntimeError(f"Could not change bpm because {error.stderr.decode('utf-8')}")
修改為raise RuntimeError(f"Could not change bpm because {error.stderr.decode('gbk')}")
解決
這可能就是報(bào)錯(cuò)的主要原因了
將soundstretch放到下面目錄
運(yùn)行出現(xiàn)一下結(jié)果,應(yīng)該是沒問題了。(內(nèi)存不足修改batch_size)
(8)torch.cuda.OutOfMemoryError: CUDA out of memory. Tried to allocate 562.00 MiB (GPU 0; 15.99 GiB total capacity; 14.06 GiB already allocated; 0 bytes free; 14.72 GiB reserved in total by PyTorch) If reserved memory is >> allocated memory try setting max_split_size_mb to avoid fragmentation. See documentation for Memory Management and PYTORCH_CUDA_ALLOC_CONF
處理:
修改conf/config.yaml
里的batch_size
默認(rèn)64,但是我只有16G的顯存,設(shè)置成4,目前恰好運(yùn)行,不知道能不能運(yùn)行到結(jié)束。
##(9)FileExistsError: [WinError 183] 當(dāng)文件已存在時(shí),無法創(chuàng)建該文件。
處理:
方法1:修改重命名方式,改成強(qiáng)制覆蓋
方法2:在重命名前刪除已有文件
方法3:修改命名方式,比如加上日期時(shí)間
(9)WARNING:main:Model 81de367c has less epoch than expected (8 / 360)
模型沒有訓(xùn)練夠就想導(dǎo)出。
處理:
只是一個(gè)警告,不理會(huì)也沒關(guān)系。
介意的話,把這里改小即可。文章來源:http://www.zghlxwxcb.cn/news/detail-621591.html
寫在最后
寫一半的時(shí)候有其他的事,停了大半個(gè)月
現(xiàn)在又有事了,匆匆忙忙把推理部分寫上
后面有機(jī)會(huì)再補(bǔ)充
有機(jī)會(huì)嘗試自己構(gòu)造數(shù)據(jù)集訓(xùn)練文章來源地址http://www.zghlxwxcb.cn/news/detail-621591.html
到了這里,關(guān)于【音頻分離】demucs V3的環(huán)境搭建及訓(xùn)練(window)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!