Skip to content

[Hackathon 7th] 修复 pannspredict.py 对于 pir 的 json 模型路径 #3914

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Dec 5, 2024

Conversation

megemini
Copy link
Collaborator

PR types

Bug fixes

PR changes

Others

Describe

修复 pannspredict.py 对于 pir 的 json 模型路径

这里修复了两个问题:

  • 没有导入 paddle (这个文件当时运行过吗???)
  • 修复对于 pir 的 json 模型路径问题

注意:PaddleSpeech/examples/esc50 测试

$ CUDA_VISIBLE_DEVICES=0 ./run.sh 4 cpu ./export ~/datasets/5-9032-A-0.wav

过程中发现此问题,但是,修改了这里的两个问题之后,模型仍然不能进行推理,仍需定位问题 ~

@zxcd @Liyulingyue

Copy link

paddle-bot bot commented Nov 26, 2024

Thanks for your contribution!

@megemini
Copy link
Collaborator Author

Update 20241127

模型推理的问题已经解决,paddlespeech/cls/exps/panns/deploy/predict.py 中的 feat 的 dimension 问题,以及不能使用 mkldnn

@@ -74,12 +75,18 @@ def __init__(self,
self.batch_size = batch_size

model_file = os.path.join(model_dir, "inference.pdmodel")
if not os.path.exists(model_file):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议直接判断是否有.json文件,如果有model_file=.json,没有model_file=.pdmodel,报错统一由85行来

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done~

@megemini megemini requested a review from zxcd November 28, 2024 09:50
zxcd
zxcd previously approved these changes Dec 2, 2024
Copy link
Collaborator

@zxcd zxcd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -73,13 +74,18 @@ def __init__(self,
enable_mkldnn=False):
self.batch_size = batch_size

model_file = os.path.join(model_dir, "inference.pdmodel")
if os.path.exists(os.path.join(model_dir, "inference.json")):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment with #3923

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done~

@megemini
Copy link
Collaborator Author

megemini commented Dec 3, 2024

@zxcd 关于 PR 里面去掉 unsqueeze 的问题,测了一下,2.6.2/2.5.1版本也不需要 unsqueeze

image

image

另外,这里貌似也不需要判断 feat.dim() == 1,比如下面这样:

        feat = paddle.transpose(feat, perm=[1, 0])
        if feat.dim() == 1:
            feat = feat.unsqueeze(0)

如果 feat 可以 transpose 的话,那么 dim 不可能为 1,所以加这个判断也没啥用 ... ...

@@ -55,8 +58,7 @@ def extract_features(files: str, **kwargs):

feature_extractor = LogMelSpectrogram(sr, **kwargs)
feat = feature_extractor(paddle.to_tensor(waveforms[i]))
feat = paddle.transpose(feat, perm=[1, 0]).unsqueeze(0)

feat = paddle.transpose(feat, perm=[1, 0])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

single audio still need unsqueeze, suggest adding an if judgment.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里应该不需要 unsqueeze ~ 后面代码用的是 np.stack ,而 np.stack 会自动在 axis=0 加一个维度,也就是咱们需要的 batch ~ 如果这里加了 unsqueeze ,那后面就需要用 np.vstack ,不然会多出来一个维度 ~

>>> import numpy as np
>>> a = np.random.rand(2, 3)
>>> b = [a]
>>> np.stack(b, axis=0)
array([[[0.67850623, 0.57210335, 0.21218978],
        [0.10639948, 0.49831181, 0.45858706]]])
>>> np.stack(b, axis=0).shape
(1, 2, 3)
>>> b = [a, a]
>>> np.stack(b, axis=0).shape
(2, 2, 3)
>>> np.vstack(b)
array([[0.67850623, 0.57210335, 0.21218978],
       [0.10639948, 0.49831181, 0.45858706],
       [0.67850623, 0.57210335, 0.21218978],
       [0.10639948, 0.49831181, 0.45858706]])
>>> np.vstack(b).shape
(4, 3)

@megemini megemini requested a review from zxcd December 4, 2024 05:24
Copy link
Collaborator

@zxcd zxcd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zxcd zxcd merged commit f582cb6 into PaddlePaddle:develop Dec 5, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants