whisper执行报错

573 阅读2分钟

SSLCertVerificationError错误

问题

执行python whisper_demo.py报错,报错如下:

ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed:
self signed certificate in certificate chain (_ssl.c:997)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

  File "/Library/Frameworks/Python.framework/Versions/3.10/bin/whisper", line 8, in <module>

    sys.exit(cli())

  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/whisper/transcribe.py", line 577, in cli

    model = load_model(model_name, device=device, download_root=model_dir)

  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/whisper/__init__.py", line 133, in load_model

    checkpoint_file = _download(_MODELS[name], download_root, in_memory)

  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/whisper/__init__.py", line 69, in _download

    with urllib.request.urlopen(url) as source, open(download_target, "wb") as output:

  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 216, in urlopen

    return opener.open(url, data, timeout)

  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 519, in open

    response = self._open(req, data)

  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 536, in _open

    result = self._call_chain(self.handle_open, protocol, protocol +

  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 496, in _call_chain

    result = func(*args)

  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 1391, in https_open

    return self.do_open(http.client.HTTPSConnection, req,

  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 1351, in do_open

    raise URLError(err)

urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify
failed: self signed certificate in certificate chain (_ssl.c:997)>

解决方案

全局取消证书验证,不推荐在正式环境使用,在py代码中引入:

import ssl

ssl._create_default_https_context = ssl._create_unverified_context

完整的代码如下:

import whisper
import ssl

ssl._create_default_https_context = ssl._create_unverified_context
model = whisper.load_model(name="tiny", download_root="./model")

# load audio and pad/trim it to fit 30 seconds
audio = whisper.load_audio("./data/zh.wav")
audio = whisper.pad_or_trim(audio)

# make log-Mel spectrogram and move to the same device as the model
mel = whisper.log_mel_spectrogram(audio).to(model.device)

# detect the spoken language
_, probs = model.detect_language(mel)
print(f"Detected language: {max(probs, key=probs.get)}")

# decode the audio
# options = whisper.DecodingOptions()
options = whisper.DecodingOptions(fp16 = False)
result = whisper.decode(model, mel, options)

# print the recognized text
print(result.text)

RuntimeError: "slow_conv2d_cpu" not implemented for 'Half'

问题

修复上面的问题后,继续执行whisper demo.py,报错如下:

result = whisper.decode(model, mel, options)

  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context

    return func(*args, **kwargs)

  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/whisper/decoding.py", line 824, in decode

    result = DecodingTask(model, options).run(mel)

  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context

    return func(*args, **kwargs)

  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/whisper/decoding.py", line 718, in run

    audio_features: Tensor = self._get_audio_features(mel)  # encoder forward pass

  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/whisper/decoding.py", line 655, in _get_audio_features

    audio_features = self.model.encoder(mel)

  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl

    return forward_call(*args, **kwargs)

  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/whisper/model.py", line 162, in forward

    x = F.gelu(self.conv1(x))

  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl

    return forward_call(*args, **kwargs)

  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/torch/nn/modules/conv.py", line 313, in forward

    return self._conv_forward(input, self.weight, self.bias)

  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/whisper/model.py", line 48, in _conv_forward

    return super()._conv_forward(

  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/torch/nn/modules/conv.py", line 309, in _conv_forward

    return F.conv1d(input, weight, bias, self.stride,

RuntimeError: "slow_conv2d_cpu" not implemented for 'Half'

解决方案

因为默认是用的GPU模式,如果用CPU模式,是不支持float16的,需要设置为false。

I ran into the same error. I was able to resolve it after changing this line:  
`options = whisper.DecodingOptions()`

to  
`options = whisper.DecodingOptions(fp16 = False)`

其他

查看所有的python安装模块版本

pip list --outdated