[NeRF]部分代码实现

23 篇文章 0 订阅
12 篇文章 1 订阅

声明:该本文代码与官方代码有差距,仅作个人练习之用。

part 1. viewing direction转3D Cartesian unit vector

在这里插入图片描述
In paper:In practice, we express direction as a 3D Cartesian unit vector d.
暂时没有了解过OpenGL等库,因此暂且参考数学上的正方向。(曲线曲面积分中的那种正方向)
根据论文,viewing direction 只有theta,psi,要将其变成三维地卡尔系,应该还差一个维度。
但论文中将数据进行了标准化,根据此推出第三维度默认长度。此点与论文可能有出入。
保留从底部观看的可能。
约定0度起点为x轴正方向。

仔细研究了一下三角函数的定义,这样写应该没问题,比我最初构思的版本简单得多。

def dir2Cartesian_unit(theta,psi):

    x = torch.cos(torch.tensor(theta))
    y = torch.sin(torch.tensor(theta))
    z = torch.sin(torch.tensor(psi))
    
    return [x,y,z]
    

part2. Positional encoding

在这里插入图片描述
对论文中描述的volume rendering techniques还不太了解,
但是论文中提到:

  1. this process is naturally differentiable
  2. the RGB color c to be predicted as a function of both location and viewing direction.

直觉上主观猜测将来需要对Positional code进行反向传播,故暂且写成nn.model的子类,后面看情况,如果在这个类里写不了,可能会通过二次继承或者把这个功能摘出来。

part1放在一起比较合适,编都编辑好了,就不改了吧。

假设输入数据已由part1 处理好,形如((x,y,z),(x1,y1,z1) )

# Psitional Encoding
class posEncode(nn.Module):
    def mapping(self,x,in_list,L):
        for i in range(L):
            in_list.append(torch.sin(torch.tensor((2**i)*np.pi*x)))
            in_list.append(torch.cos(torch.tensor((2**i)*np.pi*x)))
        
    
    def __init__(self, in_postion, L=10):
        #假设输入数据 in_postion 已由part1 处理好,形如((x,y,z),(x1,y1,z1) )
        #L就是论文里的L
        super(posEncode, self).__init__()
        self.L=10
         # In paper: In our experiments, we set L = 10 for γ(x) and L = 4 for γ(d).     
        self.pos=[]
        for i in in_postion:
            for j in i:
                self.mapping(j,self.pos,self.L)           
            self.L=4
        self.pos = torch.FloatTensor(self.pos)

   
    def forward(self, x):
        pass

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值