RetinaFace-pytorch-CPU
视频讲解
BV1yK411K79y(Bubbliiiing)
将CPU版切换为CPU版
1.安装CPU版pytorch
直接运行,根据报错修改
2.RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False. If you are running on a CPU-only machine, please use torch.load with map_location=‘cpu’ to map your storages to the CPU.
出错语句:
torch.load(model_path)
修改为:
torch.load(model_path, map_location='cpu')
3.AssertionError: Torch not compiled with CUDA enabled
出错语句:
image.cuda()
修改为:
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
image.to(device)
训练集中包含无目标图片时报错
训练车牌定位模型时,将CCPD2019-np(没有车牌)纳入训练集时报错
最后还是把np删掉了…ORZ
pytorch报错CUDA out of memory
与图片尺寸无关,模型问题
1.with torch.no_grad():
好像是不参与反向传播,从而节省存储
没用
2.减小batch_size
运行时间会极大增加
不一定有用
3.指定GPU
改变系统变量使得仅目标显卡可见
python xxx.py export CUDA_VISIBLE_DEVICES=0 #GPU编号从0开始
在程序开头设置
os.environ["CUDA_VISIBLE_DEVICES"] = '0,1,2,3'
使用CUDA_VISIBLE_DEVICES=0,1,2,3 python xxx.py
指令来执行
使用torch.cuda接口,在生成网络对象之前执行
torch.cuda.set_device(0)
或者使用pytorch的并行GPU接口
net = torch.nn.DataParallel(model, device_ids=[0])
初始化模型时
net = net.cuda(0)
当有多个GPU时可用
4.释放不需要的显存
torch.cuda.empty_cache()
还是不够
换显卡是最有效的