深度学习碰见的报错信息汇总
1. 第一个AttributeError: module 'torchtext.data' has no attribute 'Field'原文代码如下import mathimport timeimport numpy as npimport torchimport torch.nn.functional as Ffrom torchtext import data# 两个Field对象定义字段
·
1. AttributeError: module 'torchtext.data' has no attribute 'Field'
原文代码如下
import math
import time
import numpy as np
import torch
import torch.nn.functional as F
from torchtext import data
# 两个Field对象定义字段的处理方法(文本字段、标签字段)
TEXT = data.Field(tokenize=lambda x: x.split(), lower=True)
LABEL = data.LabelField(dtype=torch.float)
更改成如下引用即可
import math
import time
import numpy as np
import torch
import torchtext
import torch.nn.functional as F
from torchtext.legacy import data
from torchtext.legacy.data import Field, TabularDataset, Iterator, BucketIterator
2. TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.
问题描述
如果想把CUDA tensor格式的数据改成numpy时,需要先将其转换成cpu float-tensor随后再转到numpy格式。 numpy不能读取CUDA tensor 需要将它转化为 CPU tensor
解决办法:
self.cpu().numpy()
torch.tensor(self, device='cpu')
3. 在导入torch的时候报错
报错内容:TqdmWarning: IProgress not found. Please update jupyter and ipywidgets.
解决办法:
1. 卸载jupyter:pip uninstall jupyter
2. 卸载ipywidgets:pip uninstall ipywidgets
3. 安装jupyter:pip install jupyter
4. 安装ipywidgets:pip install ipywidgets
5. 关联:jupyter nbextension enable --py widgetsnbextension
更多推荐
所有评论(0)