栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

错误记录帖(持续更新)

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

错误记录帖(持续更新)

1 错误:RuntimeError: All input tensors must be on the same device. Received cpu and cuda:0

代码来源:detectron2中的GeneralizedRCNNWithTTA

分析:输入all_boxes变量的tensor来自不同设备,所以从出错行往上找输入all_boxes的tensor有哪些

for output, tfm in zip(outputs, tfms):
    # Need to inverse the transforms on boxes, to obtain results on original image
    pred_boxes = output.pred_boxes.tensor
    original_pred_boxes = tfm.inverse().apply_rotated_box(pred_boxes.cpu().numpy())
    all_boxes.append(torch.from_numpy(original_pred_boxes).to(pred_boxes.device))
    all_scores.extend(output.scores)
    all_classes.extend(output.pred_classes)

可以看到第四行代码中all_boxes中插入了转为pred_boxes.device的变量,而上一句pred_boxes转为了cpu上,所以更改这里的设备

更改后的代码为:

for output, tfm in zip(outputs, tfms):
    # Need to inverse the transforms on boxes, to obtain results on original image
    pred_boxes = output.pred_boxes.tensor
    device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
    original_pred_boxes = tfm.inverse().apply_rotated_box(pred_boxes.cpu().numpy())
    all_boxes.append(torch.from_numpy(original_pred_boxes).to(device))
    all_scores.extend(output.scores)
    all_classes.extend(output.pred_classes)
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/339347.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号