NER学习过程中的报错记录(小白纯粹自己录,误点)

报错内容:UnicodeDecodeError:  gbk  codec can t decode byte 0xa1 in position 444: illegal multibyte sequence

解决方法:open(filename)改为open(filename,encoding=‘utf-8’)

报错内容:

解决方法:pip install pytorch-crf

 

报错内容:

RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu! (when checking argument for argument index in method wrapper__index_select) 

解决方法:

说明:

pytorch中模型的保存方法有两种:

1.torch.save(model,PATH)  # 保存整个模型

2.torch.save(model.state_dict(), PATH)  # 保存模型参数

pytorch中模型加载有以下几种方式:

1.只加载模型的参数(先创建模型、并加载参数,再恢复得到模型)

model = MyModel().to(device)
checkpoint = torch.load(config['save_path'])  # 先加载参数
model.load_state_dict(checkpoint)  # 再让模型加载参数, 恢复得到模型

2.加载整个模型

model = torch.load(PATH)

torch.load()中,常常会使用map_location进行cpu和gpu的转化。
(1)【GPU->CPU】
比如模型训练的时候是在GPU上进行并保存的,测试的时候却想在CPU上进行训练:

model = torch.load(PATH, map_location='cpu')

(2)【CPU->GPU】
转为GPU需要指明在哪块GPU上,例如转到第0块GPU:

model = torch.load(PATH, map_location=lambda storage, loc: storage.cuda(0))

(3)【GPU->GPU】
不同块GPU的转换,例如第1块转到第0块:

torch.load(PATH, map_location={'cuda:1':'cuda:0'})

暂时觉得可以一试的方法:

RuntimeError: Expected all tensors to be on the same device, but found at least two devices_德国Viviane的博客-CSDN博客

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值