STN3D函数注解:
# Tnet generates a 3 * 3 correction matrix
class STN3d(nn.Module):
def __init__(self):
super(STN3d, self).__init__()
self.conv1 = torch.nn.Conv1d(3, 64, 1)
#Conv1d的三个参数分别代表输入通道、输出通道以及卷积核的一维大小,另一维大小为输入通道大小;
#将32*3*2500的数据进行上述卷积,会得到32*64*1*2500的数据;
#具体参考 https://blog.csdn.net/dujuancao11/article/details/114679134
self.conv2 = torch.nn.Conv1d(64, 128, 1)
self.conv3 = torch.nn.Conv1d(128, 1024, 1)
self.fc1 = nn.Linear(1024, 512)
self.fc2 = nn.Linear(512, 256)
self.fc3 = nn.Linear(256, 9)
self.relu = nn.ReLU()
self.bn1 = nn.BatchNorm1d(64)
self.bn2 = nn.BatchNorm1d(128)
self.bn3 = nn.BatchNorm1d(1024)
self.bn4 = nn.BatchNorm1d(512)
self.bn5 = nn.BatchNorm1d(256)
def forward(self, x):
#此时代入的x的数据为32*3*2500,
batchsize = x.size()[0]
# batchsize为32?(大概)
x = F.relu(self.bn1(self.conv1(x)))
x = F.relu(self.bn2(self.conv2(x)))
x = F.relu(self.bn3(self.conv3(x)))
#通过上述三次卷积,可以得到数据32*1024*1*2500(还是32*1024*2500)
x = torch.max(x, 2, keepdim=True)[0]
# 可参考 https://blog.csdn.net/zylooooooooong/article/details/112576268
# 得到一个32*1024*1*1(或者32*1024*1)的矩阵
x = x.view(-1, 1024)
# 得到一个32*1024的矩阵;
x = F.relu(self.bn4(self.fc1(x)))
x = F.relu(self.bn5(self.fc2(x)))
x = self.fc3(x)
#以下操作分别进行了数组生成,类型转变,形状重新定义view以及重复repeat;
iden = Variable(torch.from_numpy(np.array([1,0,0,0,1,0,0,0,1]).astype(np.float32))).view(1,9).repeat(batchsize,1)
if x.is_cuda:
iden = iden.cuda()
x = x + iden
x = x.view(-1, 3, 3)
return x
后续待补充。。。