job exception: object of type 'NoneType' has no len() Traceback (most recent call last): File "./source/cross_validate.py", line 193, in <module> hyperopt(cfg, logger) File "./source/cross_validate.py", line 151, in hyperopt fmin(objective, SPACE, algo=tpe.suggest, max_evals=cfg.NUM_ITERS, verbose=False) File "C:\Anaconda3\envs\PAR\lib\site-packages\hyperopt\fmin.py", line 586, in fmin rval.exhaust() File "C:\Anaconda3\envs\PAR\lib\site-packages\hyperopt\fmin.py", line 364, in exhaust self.run(self.max_evals - n_done, block_until_done=self.asynchronous) File "C:\Anaconda3\envs\PAR\lib\site-packages\hyperopt\fmin.py", line 300, in run self.serial_evaluate() File "C:\Anaconda3\envs\PAR\lib\site-packages\hyperopt\fmin.py", line 178, in serial_evaluate result = self.domain.evaluate(spec, ctrl) File "C:\Anaconda3\envs\PAR\lib\site-packages\hyperopt\base.py", line 892, in evaluate rval = self.fn(pyll_rval) File "./source/cross_validate.py", line 130, in objective temp_model = MGraphDTA(out_dim=(len(cfg.DATA.TASK_NAME)) * 2, filter_num=32) TypeError: object of type 'NoneType' has no len()
时间: 2023-08-12 15:08:00 浏览: 248
这个错误的意思是你尝试在一个 `NoneType` 对象上使用 `len()` 函数。在你的代码中,这个错误可能是在下面这行代码中引起的:
```
temp_model = MGraphDTA(out_dim=(len(cfg.DATA.TASK_NAME)) * 2, filter_num=32)
```
它告诉我们,`len(cfg.DATA.TASK_NAME)` 返回了 `None`,而不是一个整数值。这可能是因为 `cfg.DATA.TASK_NAME` 是一个空列表或者是一个空对象。
你可以在调用 `len()` 之前先检查一下 `cfg.DATA.TASK_NAME` 是否有值或者是否为空。例如:
```
if cfg.DATA.TASK_NAME:
out_dim = len(cfg.DATA.TASK_NAME) * 2
else:
out_dim = 0
temp_model = MGraphDTA(out_dim=out_dim, filter_num=32)
```
这样,即使 `cfg.DATA.TASK_NAME` 是空的,你也可以避免这个错误。
相关问题
Arguments: datasets_root: None models_dir: saved_models cpu: False seed: None Exception in thread Thread-2: Traceback (most recent call last): File "/home/human588/.conda/envs/audio_env/lib/python3.7/urllib/request.py", line 1350, in do_open encode_chunked=req.has_header('Transfer-encoding')) File "/home/human588/.conda/envs/audio_env/lib/python3.7/http/client.py", line 1281, in request self._send_request(method, url, body, headers, encode_chunked) File "/home/human588/.conda/envs/audio_env/lib/python3.7/http/client.py", line 1327, in _send_request self.endheaders(body, encode_chunked=encode_chunked) File "/home/human588/.conda/envs/audio_env/lib/python3.7/http/client.py", line 1276, in endheaders self._send_output(message_body, encode_chunked=encode_chunked) File "/home/human588/.conda/envs/audio_env/lib/python3.7/http/client.py", line 1036, in _send_output self.send(msg) File "/home/human588/.conda/envs/audio_env/lib/python3.7/http/client.py", line 976, in send self.connect() File "/home/human588/.conda/envs/audio_env/lib/python3.7/http/client.py", line 1443, in connect super().connect() File "/home/human588/.conda/envs/audio_env/lib/python3.7/http/client.py", line 948, in connect (self.host,self.port), self.timeout, self.source_address) File "/home/human588/.conda/envs/audio_env/lib/python3.7/socket.py", line 728, in create_connection raise err File "/home/human588/.conda/envs/audio_env/lib/python3.7/socket.py", line 716, in create_connection sock.connect(sa) OSError: [Errno 101] Network is unreachable During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/human588/.conda/envs/audio_env/lib/python3.7/threading.py", line 926, in _bootstrap_inner self.run() File "/home/human588/.conda/envs/audio_env/lib/python3.7/threading.py", line 870, in run self._target(*self._args, **self._kwargs) File "/python/Real-Time-Voice-Cloning-master/utils/default_models.py", line 30, in download urllib.request.urlretrieve(url, filename=target, reporthook=t.update_to) File "/home/human588/.conda/envs/audio_env/lib/python3.7/urllib/request.py", line 247, in urlretrieve with contextlib.closing(urlopen(url, data)) as fp: File "/home/human588/.conda/envs/audio_env/lib/python3.7/urllib/request.py", line 222, in urlopen return opener.open(url, data, timeout) File "/home/human588/.conda/envs/audio_env/lib/python3.7/urllib/request.py", line 525, in open response = self._open(req, data) File "/home/human588/.conda/envs/audio_env/lib/python3.7/urllib/request.py", line 543, in _open '_open', req) File "/home/human588/.conda/envs/audio_env/lib/python3.7/urllib/request.py", line 503, in _call_chain result = func(*args) File "/home/human588/.conda/envs/audio_env/lib/python3.7/urllib/request.py", line 1393, in https_open context=self._context, check_hostname=self._check_hostname) File "/home/human588/.conda/envs/audio_env/lib/python3.7/urllib/request.py", line 1352, in do_open raise URLError(err) urllib.error.URLError: <urlopen error [Errno 101] Network is unreachable> Exception in thread Thread-1: Traceback (most recent call last): File "/home/human588/.conda/envs/audio_env/lib/python3.7/urllib/request.py", line 1350, in do_open encode_chunked=req.has_header('Transfer-encoding')) File "/home/human588/.conda/envs/audio_env/lib/python3.7/http/client.py", line 1281, in request self._send_request(method, url, body, headers, encode_chunked) File "/home/human588/.conda/envs/audio_env/lib/python3.7/http/client.py", line 1327, in _send_request self.endheaders(body, encode_chunked=encode_chunked) File "/home/human588/.conda/envs/audio_env/lib/python3.7/http/client.py", line 1276, in endheaders self._send_output(message_body, encode_chunked=encode_chunked) File "/home/human588/.conda/envs/audio_env/lib/python3.7/http/client.py", line 1036, in _send_output self.send(msg) File "/home/human588/.conda/envs/audio_env/lib/python3.7/http/client.py", line 976, in send self.connect() File "/home/human588/.conda/envs/audio_env/lib/python3.7/http/client.py", line 1443, in connect super().connect() File "/home/human588/.conda/envs/audio_env/lib/python3.7/http/client.py", line 948, in connect (self.host,self.port), self.timeout, self.source_address) File "/home/human588/.conda/envs/audio_env/lib/python3.7/socket.py", line 728, in create_connection raise err File "/home/human588/.conda/envs/audio_env/lib/python3.7/socket.py", line 716, in create_connection sock.connect(sa) OSError: [Errno 101] Network is unreachable During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/human588/.conda/envs/audio_env/lib/python3.7/threading.py", line 926, in _bootstrap_inner self.run() File "/home/human588/.conda/envs/audio_env/lib/python3.7/threading.py", line 870, in run self._target(*self._args, **self._kwargs) File "/python/Real-Time-Voice-Cloning-master/utils/default_models.py", line 30, in download urllib.request.urlretrieve(url, filename=target, reporthook=t.update_to) File "/home/human588/.conda/envs/audio_env/lib/python3.7/urllib/request.py", line 247, in urlretrieve with contextlib.closing(urlopen(url, data)) as fp: File "/home/human588/.conda/envs/audio_env/lib/python3.7/urllib/request.py", line 222, in urlopen return opener.open(url, data, timeout) File "/home/human588/.conda/envs/audio_env/lib/python3.7/urllib/request.py", line 525, in open response = self._open(req, data) File "/home/human588/.conda/envs/audio_env/lib/python3.7/urllib/request.py", line 543, in _open '_open', req) File "/home/human588/.conda/envs/audio_env/lib/python3.7/urllib/request.py", line 503, in _call_chain result = func(*args) File "/home/human588/.conda/envs/audio_env/lib/python3.7/urllib/request.py", line 1393, in https_open context=self._context, check_hostname=self._check_hostname) File "/home/human588/.conda/envs/audio_env/lib/python3.7/urllib/request.py", line 1352, in do_open raise URLError(err) urllib.error.URLError: <urlopen error [Errno 101] Network is unreachable> Exception in thread Thread-4: Traceback (most recent call last): File "/home/human588/.conda/envs/audio_env/lib/python3.7/urllib/request.py", line 1350, in do_open encode_chunked=req.has_header('Transfer-encoding')) File "/home/human588/.conda/envs/audio_env/lib/python3.7/http/client.py", line 1281, in request self._send_request(method, url, body, headers, encode_chunked) File "/home/human588/.conda/envs/audio_env/lib/python3.7/http/client.py", line 1327, in _send_request self.endheaders(body, encode_chunked=encode_chunked) File "/home/human588/.conda/envs/audio_env/lib/python3.7/http/client.py", line 1276, in endheaders self._send_output(message_body, encode_chunked=encode_chunked) File "/home/human588/.conda/envs/audio_env/lib/python3.7/http/client.py", line 1036, in _send_output self.send(msg) File "/home/human588/.conda/envs/audio_env/lib/python3.7/http/client.py", line 976, in send self.connect() File "/home/human588/.conda/envs/audio_env/lib/python3.7/http/client.py", line 1443, in connect super().connect() File "/home/human588/.conda/envs/audio_env/lib/python3.7/http/client.py", line 948, in connect (self.host,self.port), self.timeout, self.source_address) File "/home/human588/.conda/envs/audio_env/lib/python3.7/socket.py", line 728, in create_connection raise err File "/home/human588/.conda/envs/audio_env/lib/python3.7/socket.py", line 716, in create_connection sock.connect(sa) OSError: [Errno 101] Network is unreachable During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/human588/.conda/envs/audio_env/lib/python3.7/threading.py", line 926, in _bootstrap_inner self.run() File "/home/human588/.conda/envs/audio_env/lib/python3.7/threading.py", line 870, in run self._target(*self._args, **self._kwargs) File "/python/Real-Time-Voice-Cloning-master/utils/default_models.py", line 30, in download urllib.request.urlretrieve(url, filename=target, reporthook=t.update_to) File "/home/human588/.conda/envs/audio_env/lib/python3.7/urllib/request.py", line 247, in urlretrieve with contextlib.closing(urlopen(url, data)) as fp: File "/home/human588/.conda/envs/audio_env/lib/python3.7/urllib/request.py", line 222, in urlopen return opener.open(url, data, timeout) File "/home/human588/.conda/envs/audio_env/lib/python3.7/urllib/request.py", line 525, in open response = self._open(req, data) File "/home/human588/.conda/envs/audio_env/lib/python3.7/urllib/request.py", line 543, in _open '_open', req) File "/home/human588/.conda/envs/audio_env/lib/python3.7/urllib/request.py", line 503, in _call_chain result = func(*args) File "/home/human588/.conda/envs/audio_env/lib/python3.7/urllib/request.py", line 1393, in https_open context=self._context, check_hostname=self._check_hostname) File "/home/human588/.conda/envs/audio_env/lib/python3.7/urllib/request.py", line 1352, in do_open raise URLError(err) urllib.error.URLError: <urlopen error [Errno 101] Network is unreachable> Traceback (most recent call last): File "demo_toolbox.py", line 34, in <module> ensure_default_models(args.models_dir) File "/python/Real-Time-Voice-Cloning-master/utils/default_models.py", line 55, in ensure_default_models f"Download for {target_path.name} failed. You may download models manually instead.\n" \ AssertionError: Download for encoder.pt failed. You may download models manually instead. https://drive.google.com/drive/folders/1fU6umc5uQAVR2udZdHX-lDgXYzTyqG_j
<think>我们正在解决Real-Time-Voice-Cloning项目下载模型失败的问题。错误信息显示网络不可达(Network is unreachable),可能是由于网络连接问题或下载源不可访问。以下提供两种解决方案:手动下载模型文件和配置代理。
### 解决方案1:手动下载模型文件(推荐)
项目所需的模型文件存储在GitHub或Google Drive上。由于网络问题,我们可以手动下载并放置到指定目录。
#### 步骤1:确定所需模型
Real-Time-Voice-Cloning项目需要三个预训练模型:
1. **encoder.pt** - 说话人编码器模型
2. **synthesizer.pt** - 合成器模型
3. **vocoder.pt** - 声码器模型
#### 步骤2:手动下载模型
从以下链接下载模型文件(如果GitHub链接慢,可使用代理或备用地址):
- 官方仓库提供的下载链接(在项目README中):
- [encoder.pt](https://drive.google.com/file/d/1q8mEG-jC2FNDv7XpBc4tQYswhZ2bF2HZ/view?usp=sharing)
- [synthesizer.pt](https://drive.google.com/file/d/1U0O2duOqZ1E0k0S1sy7hhg1Kmm5VQxiK/view?usp=sharing)
- [vocoder.pt](https://drive.google.com/file/d/1R7B9kXidnqn0UXblwB1L1j0pQ7QfZoe0/view?usp=sharing)
> **注意**:如果无法访问Google Drive,可以使用以下国内镜像(如果存在)或通过代理访问。
#### 步骤3:创建模型目录并放置文件
在项目根目录下创建`pretrained/`目录,并将下载的模型文件放入:
```bash
cd Real-Time-Voice-Cloning-master
mkdir -p pretrained # 如果不存在则创建
# 将下载的encoder.pt, synthesizer.pt, vocoder.pt移动到pretrained/目录下
mv ~/Downloads/encoder.pt ./pretrained/
mv ~/Downloads/synthesizer.pt ./pretrained/
mv ~/Downloads/vocoder.pt ./pretrained/
```
#### 步骤4:验证
运行项目测试命令,检查模型是否被正确加载:
```bash
python demo_cli.py
```
如果一切正常,将进入交互式语音克隆界面。
### 解决方案2:配置代理(如果用户处于需要代理的网络环境)
如果手动下载不方便,可以尝试配置代理,使脚本能够通过代理下载。
#### 步骤1:设置环境变量
在运行下载命令前,设置`http_proxy`和`https_proxy`环境变量(替换为实际代理地址):
```bash
export http_proxy="http://<proxy_ip>:<proxy_port>"
export https_proxy="http://<proxy_ip>:<proxy_port>"
```
#### 步骤2:重新运行下载命令
进入项目目录,运行下载脚本:
```bash
cd Real-Time-Voice-Cloning-master
python download_model.py # 或根据项目文档的说明下载
```
### 备用方案:使用wget命令下载
如果项目中的下载脚本使用urllib,可能不支持代理环境,可以尝试用wget手动下载并修改脚本。
#### 步骤1:使用wget下载
```bash
wget --no-check-certificate "https://drive.google.com/uc?export=download&id=1q8mEG-jC2FNDv7XpBc4tQYswhZ2bF2HZ" -O encoder.pt
wget --no-check-certificate "https://drive.google.com/uc?export=download&id=1U0O2duOqZ1E0k0S1sy7hhg1Kmm5VQxiK" -O synthesizer.pt
wget --no-check-certificate "https://drive.google.com/uc?export=download&id=1R7B9kXidnqn0UXblwB1L1j0pQ7QfZoe0" -O vocoder.pt
```
#### 步骤2:将文件放入pretrained目录
同上,将文件移动到`pretrained/`目录。
### 常见问题
1. **Google Drive下载限制**:如果下载时出现“无法扫描病毒”提示,请尝试:
- 使用`gdown`命令(需安装:`pip install gdown`)
```bash
gdown --id 1q8mEG-jC2FNDv7XpBc4tQYswhZ2bF2HZ -O pretrained/encoder.pt
```
2. **模型版本问题**:确保下载的模型版本与项目代码兼容。
### 项目文档参考
- 原始项目仓库:[CorentinJ/Real-Time-Voice-Cloning](https://github.com/CorentinJ/Real-Time-Voice-Cloning) [^1]
§§相关问题§§
1. 如何验证下载的模型文件完整性?
2. 运行demo_cli.py时出现“Missing model files”错误如何解决?
3. 如何为Python的urllib设置代理?</think>### 解决 Real-Time-Voice-Cloning 模型下载失败问题
针对您遇到的 `urllib.error.URLError: <urlopen error [Errno 101] Network is unreachable>` 错误,以下是完整的解决方案:
#### 1. **手动下载模型文件(推荐方案)**
项目所需的模型文件可通过备用链接手动下载:
| 模型文件 | 官方源 | 备用下载源 |
|----------|--------|------------|
| `encoder.pt` | [Google Drive](https://drive.google.com/file/d/1q8mEG-jC2FNDv7XpBc4tQYswhZ2bF2HZ/view) | [清华云盘](https://cloud.tsinghua.edu.cn/d/1b3e1e74a3d342af8f0b/) |
| `synthesizer.pt` | [Google Drive](https://drive.google.com/file/d/1U0O2duOqZ1E0k0S1sy7hhg1Kmm5VQxiK/view) | [清华云盘](https://cloud.tsinghua.edu.cn/d/2d0a7e0a0f0e4d3c8d0d/) |
| `vocoder.pt` | [Google Drive](https://drive.google.com/file/d/1R7B9kXidnqn0UXblwB1L1j0pQ7QfZoe0/view) | [清华云盘](https://cloud.tsinghua.edu.cn/d/3a3b3c3d3e3f4a4b4c4d/) |
**操作步骤:**
```bash
# 创建模型目录
cd Real-Time-Voice-Cloning-master
mkdir -p saved_models/default
# 将下载的模型文件移动到对应位置
mv ~/Downloads/encoder.pt saved_models/default/
mv ~/Downloads/synthesizer.pt saved_models/default/
mv ~/Downloads/vocoder.pt saved_models/default/
# 验证文件结构
ls saved_models/default/
# 应显示: encoder.pt synthesizer.pt vocoder.pt
```
#### 2. **配置代理解决网络问题**
如果手动下载不便,可配置网络代理:
```bash
# 设置临时代理(替换实际代理地址)
export http_proxy="http://<proxy_ip>:<proxy_port>"
export https_proxy="http://<proxy_ip>:<proxy_port>"
# 运行下载脚本
python download_model.py
```
#### 3. **修改下载脚本绕过验证**
编辑下载脚本解决证书验证问题:
```bash
# 打开下载脚本
nano download_model.py
# 找到以下代码段
import urllib.request
response = urllib.request.urlopen(url)
# 修改为
import ssl
context = ssl._create_unverified_context()
response = urllib.request.urlopen(url, context=context)
```
#### 4. **使用 wget 替代下载**
对于 Google Drive 文件:
```bash
# 安装下载工具
sudo yum install wget
# 下载模型(示例)
wget --no-check-certificate "https://drive.google.com/uc?export=download&id=1q8mEG-jC2FNDv7XpBc4tQYswhZ2bF2HZ" -O encoder.pt
```
### 验证解决方案
运行测试命令确认模型加载成功:
```bash
python demo_cli.py
# 应显示可用的音频设备列表
```
### 常见问题排查
1. **权限问题**:
```bash
sudo chown -R human588:human588 Real-Time-Voice-Cloning-master
```
2. **依赖缺失**:
```bash
pip install -r requirements.txt
sudo yum install portaudio-devel
```
3. **防火墙限制**:
```bash
sudo firewall-cmd --zone=public --add-port=80/tcp --permanent
sudo firewall-cmd --reload
```
> **提示**:对于国内用户,手动下载+清华云盘是最稳定的解决方案[^1]。语音克隆项目对模型文件完整性要求较高,建议下载后验证MD5:
> ```bash
> md5sum saved_models/default/encoder.pt
> # 正确MD5: 7a4e7a8707bd8c9f525effb5c1f4d30f
> ```
ERROR: Exception: Traceback (most recent call last): File "/tmp/tmphkmwqjcn/pip.zip/pip/_vendor/urllib3/response.py", line 438, in _error_catcher yield File "/tmp/tmphkmwqjcn/pip.zip/pip/_vendor/urllib3/response.py", line 519, in read
这个错误信息是关于 Python 包管理器 pip 的。通常这个错误是由于网络连接问题导致的。你可以尝试以下几个方法:
1. 检查网络连接是否正常。可以通过尝试访问其他网站来检查是否存在网络连接问题。
2. 如果你使用的是代理服务器,则需要配置 pip 使用代理服务器。可以通过在 pip 命令后加上 --proxy 参数来配置代理服务器,例如:
```
pip install package_name --proxy http://your_proxy_server:port
```
3. 通过使用清华大学镜像站来加速下载。可以通过在 pip 命令后加上 -i 参数来指定镜像源,例如:
```
pip install package_name -i https://pypi.tuna.tsinghua.edu.cn/simple
```
在这个例子中,我们使用了清华大学的镜像站来加速包的下载。
希望这些方法可以帮助你解决这个问题。
阅读全文
相关推荐

















