Skip to content
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

ImportError: cannot import name 'sequence_mask' from 'paddle.fluid.layers' #3520

Closed
openersoft opened this issue Sep 14, 2023 · 6 comments
Closed

Comments

@openersoft
Copy link

系统:windows
Python 3.11.5

安装的CPU版本
python -m pip install paddlepaddle==2.5.1 -i https://mirror.baidu.com/pypi/simple

然后
pip install paddlespeech -i https://pypi.tuna.tsinghua.edu.cn/simple

此时numpy 版本为numpy-1.24.4

运行 paddlespeech cls --input zh.wav

PS D:\work\mgsdk\doc> paddlespeech cls --input zh.wav
Traceback (most recent call last):
File "", line 198, in run_module_as_main
File "", line 88, in run_code
File "C:\Users\mghua\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\Scripts\paddlespeech.exe_main
.py", line 4, in
File "C:\Users\mghua\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\paddlespeech\cli_init
.py", line 16, in
from .asr import ASRExecutor
File "C:\Users\mghua\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\paddlespeech\cli\asr_init_.py", line 14, in
from .infer import ASRExecutor
File "C:\Users\mghua\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\paddlespeech\cli\asr\infer.py", line 22, in
import librosa
File "C:\Users\mghua\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\librosa_init_.py", line 211, in
from . import core
File "C:\Users\mghua\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\librosa\core_init_.py", line 9, in
from .constantq import * # pylint: disable=wildcard-import
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\mghua\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\librosa\core\constantq.py", line 1059, in
dtype=np.complex,
^^^^^^^^^^
File "C:\Users\mghua\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\numpy_init_.py", line 305, in getattr
raise AttributeError(former_attrs[attr])
AttributeError: module 'numpy' has no attribute 'complex'.
np.complex was a deprecated alias for the builtin complex. To avoid this error in existing code, use complex by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use np.complex128 here.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations. Did you mean: 'complex_'?

**将constantq.py中的np.complex, 改为 complex后,就又显示

ImportError: cannot import name 'sequence_mask' from 'paddle.fluid.layers'**

@BoredWait
Copy link

怎么样搞定了吗

@yaleimeng
Copy link

yaleimeng commented Oct 11, 2023

采用paddlepaddle 2.5.1 加 github源码直接pip install . 方式安装;
或者使用 paddlepaddle 2.4.2 加 paddlespeech 1.4.1 ;
这样组合比较稳。注意paddlenlp == 2.5.2,
@BoredWait

@secext2022
Copy link

git 源码安装 paddlespeech 需要 python 3.10 版本.
如果用 python 3.11 安装会报错.

参考安装命令:

> pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
> python3.10 --version
Python 3.10.13
> python3.10 -m venv ./py310
> ./py310/bin/python --version
Python 3.10.13
> ./py310/bin/pip install paddlepaddle==2.5.2

> git clone https://github.com/PaddlePaddle/PaddleSpeech.git --single-branch --depth=1
> ./py310/bin/pip install ./PaddleSpeech/

测试安装:

./py310/bin/paddlespeech tts --input "测试百度飞桨" --output 1.wav

@sunqinbo
Copy link

安装版本 +问题处理
(speech_env) dongao@deepin207:/data/works/html/data/source$ pip list|grep paddle
paddle-bfloat 0.1.7
paddle2onnx 1.1.0
paddleaudio 1.1.0
paddlefsl 1.1.0
paddlenlp 2.5.2
paddlepaddle 2.5.2
paddlesde 0.2.5
paddleslim 2.4.1
paddlespeech 1.4.1
paddlespeech-ctcdecoders 0.2.0
paddlespeech-feat 0.1.0

问题处理:
1 AttributeError: module 'numpy' has no attribute 'complex'.
np.complex was a deprecated alias for the builtin complex. To avoid this error in existing code, use complex by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use np.complex128 here.
The aliases was originally deprecated in NumPy 1.20;
由于 paddlespeech 依赖中要求 librosa 版本0.8.1,而且 librosa库使用个了NumPy1.20之前的API导致的

pip install librosa==0.10.1

2 报错信息提示:ModuleNotFoundError: No module named 'paddle.nn.layer.layers'
报错信息:IndexError: list index out of range
由于 paddlepaddle 2.6.1版本 ,降级 paddlenlp 版本到 2.5.2问题得到解决
pip install paddlenlp==2.5.2

运行例子
paddlespeech text --task punc -v --input "你知道吗大部分时候你都在假装学习你在年初提出了一整面墙的todo list到了九月还没打上几个钩你的书架上陈列着全网最畅销的专业书籍"
[2023-12-20 17:56:18,543] [ INFO] - loading configuration file /home/dongao/.paddlespeech/models/ernie_linear_p7_wudao-punc-zh/1.0/ernie_linear_p7_wudao-punc-zh.tar/ckpt/config.json
[2023-12-20 17:56:18,545] [ INFO] - Model config ErnieConfig {
"architectures": [
"ErnieForTokenClassification"
],
"attention_probs_dropout_prob": 0.1,
"enable_recompute": false,
"fuse": false,
"hidden_act": "relu",
"hidden_dropout_prob": 0.1,
"hidden_size": 768,
"id2label": {
"0": "LABEL_0",
"1": "LABEL_1",
"2": "LABEL_2",
"3": "LABEL_3",
"4": "LABEL_4",
"5": "LABEL_5",
"6": "LABEL_6",
"7": "LABEL_7"
},
"initializer_range": 0.02,
"intermediate_size": 3072,
"label2id": {
"LABEL_0": 0,
"LABEL_1": 1,
"LABEL_2": 2,
"LABEL_3": 3,
"LABEL_4": 4,
"LABEL_5": 5,
"LABEL_6": 6,
"LABEL_7": 7
},
"layer_norm_eps": 1e-12,
"max_position_embeddings": 513,
"model_type": "ernie",
"num_attention_heads": 12,
"num_hidden_layers": 12,
"pad_token_id": 0,
"paddlenlp_version": null,
"pool_act": "tanh",
"task_id": 0,
"task_type_vocab_size": 3,
"type_vocab_size": 2,
"use_task_id": false,
"vocab_size": 18000
}

[2023-12-20 17:56:33,740] [ INFO] - All model checkpoint weights were used when initializing ErnieForTokenClassification.

[2023-12-20 17:56:33,740] [ INFO] - All the weights of ErnieForTokenClassification were initialized from the model checkpoint at /home/dongao/.paddlespeech/models/ernie_linear_p7_wudao-punc-zh/1.0/ernie_linear_p7_wudao-punc-zh.tar/ckpt.
If your task is similar to the task the model of the checkpoint was trained on, you can already use ErnieForTokenClassification for predictions without further training.
[2023-12-20 17:56:33,761] [ INFO] - Already cached /home/dongao/.paddlenlp/models/ernie-1.0/vocab.txt
[2023-12-20 17:56:33,776] [ INFO] - tokenizer config file saved in /home/dongao/.paddlenlp/models/ernie-1.0/tokenizer_config.json
[2023-12-20 17:56:33,777] [ INFO] - Special tokens file saved in /home/dongao/.paddlenlp/models/ernie-1.0/special_tokens_map.json
你知道吗?大部分时候,你都在假装学习。你在年初提出了一整面墙的todolist,到了九月,还没打上几个钩。你的书架上,陈列着全网最畅销的专业书籍。

@happywch
Copy link

happywch commented Jan 4, 2024

一定要使用gcc5吗,使用的是paddlepaddle=2.5.0我在安装develop版本的时候即使已经有其他版本的gcc还是要求安装gcc5,我添加gcc-11-test-results的apt源后,再次安装出现下面错误

libsndfile1 : 依赖: libflac12 (>= 1.3.0) 但无法安装它
sox : 依赖: libsox-fmt-base (= 14.4.2+git20190427-3.4ubuntu1.1) 但是 14.4.2+git20190427-2+deb11u2ubuntu0.22.04.1 正要被安装
依赖: libsox3 (= 14.4.2+git20190427-3.4ubuntu1.1) 但是 14.4.2+git20190427-2+deb11u2ubuntu0.22.04.1 正要被安装
但是sox依赖的这些包是ubantu23.04的版本,我尝试安装后,在此跳回到无法定位gcc需要gcc5的错误

@openersoft
Copy link
Author

一定要使用gcc5吗,使用的是paddlepaddle=2.5.0我在安装develop版本的时候即使已经有其他版本的gcc还是要求安装gcc5,我添加gcc-11-test-results的apt源后,再次安装出现下面错误

libsndfile1 : 依赖: libflac12 (>= 1.3.0) 但无法安装它 sox : 依赖: libsox-fmt-base (= 14.4.2+git20190427-3.4ubuntu1.1) 但是 14.4.2+git20190427-2+deb11u2ubuntu0.22.04.1 正要被安装 依赖: libsox3 (= 14.4.2+git20190427-3.4ubuntu1.1) 但是 14.4.2+git20190427-2+deb11u2ubuntu0.22.04.1 正要被安装 但是sox依赖的这些包是ubantu23.04的版本,我尝试安装后,在此跳回到无法定位gcc需要gcc5的错误

不用飞桨了...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants