-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Hackathon 7th] 修复 panns
中 predict.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
Conversation
Thanks for your contribution! |
Update 20241127模型推理的问题已经解决, |
@@ -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): |
There was a problem hiding this comment.
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行来
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done~
There was a problem hiding this 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")): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment with #3923
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done~
@zxcd 关于 PR 里面去掉 另外,这里貌似也不需要判断 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]) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
PR types
Bug fixes
PR changes
Others
Describe
修复
panns
中predict.py
对于 pir 的 json 模型路径这里修复了两个问题:
paddle
(这个文件当时运行过吗???)注意:
PaddleSpeech/examples/esc50
测试$ CUDA_VISIBLE_DEVICES=0 ./run.sh 4 cpu ./export ~/datasets/5-9032-A-0.wav
过程中发现此问题,但是,修改了这里的两个问题之后,模型仍然不能进行推理,仍需定位问题 ~
@zxcd @Liyulingyue