在 eval 的时候运行一遍网络,发现显存增加特别快

应该是变量的 梯度没有 关闭,导致在运行网络的时候,梯度也被储存在了 CUDA 里面。

解决方法是: 在被调用的网络 函数 前面加一个装饰器,(这个函数可以是专门用来eval 的时候用的),

@torch.no_grad()  ## 在运行这个函数的时候,不会计算梯度
def get_pos_density(self, positions):
      """Computes and returns the densities."""
      assert self.spatial_distortion is not None
      positions = self.spatial_distortion(positions)
      positions = (positions + 2.0) / 4.0
      self._sample_locations = positions
      if not self._sample_locations.requires_grad:
          self._sample_locations.requires_grad = True
      positions_flat = positions.view(-1, 3)
      h = self.mlp_base(positions_flat)
      density_before_activation, base_mlp_out = torch.split(h, [1, self.geo_feat_dim], dim=-1)
      self._density_before_activation = density_before_activation

      # Rectifying the density with an exponential is much more stable than a ReLU or
      # softplus, because it enables high post-activation (float32) density outputs
      # from smaller internal (float16) parameters.
      density = trunc_exp(density_before_activation.to(positions))[:, 0]
      # print(base_mlp_out)
      return density, base_mlp_out
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值