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

RuntimeError: a view of a leaf Variable that requires grad is being used in an in-place operation.

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

RuntimeError: a view of a leaf Variable that requires grad is being used in an in-place operation.

跑yolov5的代码时,pytorch遇到<>RuntimeError: a view of a leaf Variable that requires grad is being used in an in-place operation.的报错

在报错的这一块增加 with torch.no_grad():

  def _initialize_biases(self, cf=None):  # initialize biases into Detect(), cf is class frequency
      # https://arxiv.org/abs/1708.02002 section 3.3
      # cf = torch.bincount(torch.tensor(np.concatenate(dataset.labels, 0)[:, 0]).long(), minlength=nc) + 1.
      m = self.model[-1]  # Detect() module
      for mi, s in zip(m.m, m.stride):  # from
          b = mi.bias.view(m.na, -1)  # conv.bias(255) to (3,85)
          with torch.no_grad():
              b[:, 4] += math.log(8 / (640 / s) ** 2)  # obj (8 objects per 640 image)
              b[:, 5:] += math.log(0.6 / (m.nc - 0.99)) if cf is None else torch.log(cf / cf.sum())  # cls
          mi.bias = torch.nn.Parameter(b.view(-1), requires_grad=True)
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/488498.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

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

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