name | about | labels |
---|---|---|
Bug Report | Use this template for reporting a bug | kind/bug |
在gcd值(orig_freq和new_freq的最小公约数)偏小的情况下,MindData算子resample的性能比不过对标框架
Ascend
/GPU
/CPU
) / 硬件环境:Please delete the backend not involved / 请删除不涉及的后端:
/device ascend/GPU/CPU/kirin/等其他芯片
Software Environment / 软件环境 (Mandatory / 必填):
-- MindSpore version (e.g., 1.7.0.Bxxx) :commit_id = '[sha1]:e2c89157,[branch]:(HEAD,origin/master,origin/HEAD,master)'
-- Python version (e.g., Python 3.7.5) :Python 3.7.5
-- OS platform and distribution (e.g., Linux Ubuntu 16.04):Ubuntu 18.04.6 LTS
-- GCC/Compiler version (if compiled from source): gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
Excute Mode / 执行模式 (Mandatory / 必填)(PyNative
/Graph
):
Please delete the mode not involved / 请删除不涉及的模式:
import numpy as np
from mindspore import log as logger
import mindspore.dataset as ds
import mindspore.dataset.audio.transforms as audio
from mindspore.dataset.audio.utils import ResampleMethod
import librosa
import time
import torch
import torchaudio.functional
import math
from torch.utils.data import Dataset
def testEagerTorchAudio(input_shape, orig_freq, new_freq):
waveform = np.random.rand(*input_shape) * 100
orig_freq = orig_freq
sleep_time = 10
new_freq = new_freq
times2 = 100
print("waveform.shape", waveform.shape)
print("orig_freq:", orig_freq)
print("new_freq:", new_freq)
print("gcd:", math.gcd(orig_freq, new_freq))
time.sleep(sleep_time)
start_time = time.time()
for i in range(times2):
audio.Resample(orig_freq=orig_freq, new_freq=new_freq)(waveform)
end_time = time.time()
output1 = audio.Resample(orig_freq=orig_freq, new_freq=new_freq)(waveform)
print("minddata time over ", times2, " runs is ", (end_time - start_time) / times2 * 1000 ** 2, "µs")
time.sleep(sleep_time)
times = 100
start_time = time.time()
for i in range(times):
librosa.core.resample(waveform, orig_sr=orig_freq, target_sr=new_freq)
end_time = time.time()
print("librosa resample average time over", times, "runs is ", (end_time - start_time) / times * 1000 ** 2, "µs")
time.sleep(sleep_time)
waveform2 = torch.from_numpy(waveform)
start_time = time.time()
times3 = 1
for i in range(times3):
torchaudio.functional.resample(waveform2, orig_freq=orig_freq, new_freq=new_freq)
end_time = time.time()
output3 = torchaudio.functional.resample(waveform2, orig_freq=orig_freq, new_freq=new_freq)
output3 = output3.detach().numpy()
print("pytorch time over ", times3, "runs is ", (end_time - start_time) / times3 * 1000 ** 2, "µs")
print(abs(output3 - output1))
assert (np.all(output1 - output3 < 1e-5))
if __name__ == '__main__':
if __name__ == '__main__':
test_data = [{"waveform": (1000, 1000), "orig_freq": 16000, "new_freq": 160000},
{"waveform": (1000, 1000), "orig_freq": 16000, "new_freq": 48000},
{"waveform": (1000, 1000), "orig_freq": 16000, "new_freq": 8000},
{"waveform": (1000, 1000), "orig_freq": 16000, "new_freq": 11000},
{"waveform": (1000, 1000), "orig_freq": 16000, "new_freq": 500},
{"waveform": (1000, 1000), "orig_freq": 16000, "new_freq": 11025},
{"waveform": (1000, 1000), "orig_freq": 16000, "new_freq": 11005},
{"waveform": (1000, 1000), "orig_freq": 22050, "new_freq": 44100},
{"waveform": (1000, 1000), "orig_freq": 22050, "new_freq": 11025},
{"waveform": (1000, 1000), "orig_freq": 22050, "new_freq": 500},
{"waveform": (1000, 1000), "orig_freq": 22050, "new_freq": 11005},
{"waveform": (17, 12345), "orig_freq": 16000, "new_freq": 160000},
{"waveform": (17, 12345), "orig_freq": 16000, "new_freq": 48000},
{"waveform": (17, 12345), "orig_freq": 16000, "new_freq": 8000},
{"waveform": (17, 12345), "orig_freq": 16000, "new_freq": 11000},
{"waveform": (17, 12345), "orig_freq": 16000, "new_freq": 500},
{"waveform": (17, 12345), "orig_freq": 16000, "new_freq": 11025},
{"waveform": (17, 12345), "orig_freq": 16000, "new_freq": 11005},
{"waveform": (16560,), "orig_freq": 24000, "new_freq": 48000},
{"waveform": (16560,), "orig_freq": 24000, "new_freq": 16000},
{"waveform": (16560,), "orig_freq": 24000, "new_freq": 1600},
{"waveform": (16560,), "orig_freq": 24000, "new_freq": 11025},
{"waveform": (16560,), "orig_freq": 24000, "new_freq": 11005},
{"waveform": (7432986,), "orig_freq": 16000, "new_freq": 48000},
{"waveform": (7432986,), "orig_freq": 16000, "new_freq": 24000},
{"waveform": (7432986,), "orig_freq": 16000, "new_freq": 1600},
{"waveform": (7432986,), "orig_freq": 16000, "new_freq": 11025},
{"waveform": (241840,), "orig_freq": 16000, "new_freq": 48000},
{"waveform": (241840,), "orig_freq": 16000, "new_freq": 24000},
{"waveform": (241840,), "orig_freq": 16000, "new_freq": 1600},
{"waveform": (241840,), "orig_freq": 16000, "new_freq": 11025},
{"waveform": (241840,), "orig_freq": 16000, "new_freq": 11005},
{"waveform": (2, 125800), "orig_freq": 22050, "new_freq": 11025},
{"waveform": (2, 125800), "orig_freq": 22050, "new_freq": 44100},
]
for data in test_data:
testEagerTorchAudio(input_shape=data["waveform"], orig_freq=data["orig_freq"], new_freq=data["new_freq"])
修改参数值,执行脚本
minddata time < librose time
见附件
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
Please add labels (comp or sig), also you can visit https://gitee.com/mindspore/community/blob/master/sigs/dx/docs/labels.md to find more.
为了让代码尽快被审核,请您为Pull Request打上 组件(comp)或兴趣组(sig) 标签,打上标签的PR可直接推送给责任人进行审核。
更多的标签可以查看https://gitee.com/mindspore/community/blob/master/sigs/dx/docs/labels.md
以组件相关代码提交为例,如果你提交的是data组件代码,你可以这样评论:
//comp/data
当然你也可以邀请data SIG组来审核代码,可以这样写:
//sig/data
另外你还可以给这个PR标记类型,例如是bugfix或者是特性需求:
//kind/bug or //kind/feature
恭喜你,你已经学会了使用命令来打标签,接下来就在下面的评论里打上标签吧!
@xiaotianci 后续回归转给hanshunping
此需求为媒体院提出,现有优化能够满足他们的网络运行场景,gcd较小的场景不常见,暂不做处理。
该场景下性能对比情况如下
回归时间:2023.0103
回归版本:mindspore-2.0.0-0102
回归步骤:按照问题单中步骤回归检查
回归结果:执行用例,mindspore性能优于librosa
回归结论:回归通过
登录 后才可以发表评论