声明:该本文代码与官方代码有差距,仅作个人练习之用。
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还不太了解,
但是论文中提到:
- this process is naturally differentiable
- 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