解读SGN类
1.self.dim1 = 256
self.dataset = dataset
self.seg = seg
num_joint = 25-》关节数为25
2.if args.train:
self.spa = self.one_hot(bs, num_joint, self.seg)-》独热编码
self.spa = self.spa.permute(0, 3, 2, 1).cuda()-》转置
self.tem = self.one_hot(bs, self.seg, num_joint)-》独热编码
self.tem = self.tem.permute(0, 3, 1, 2).cuda()-》转置
3.self.tem_embed = embed(self.seg, 64*4, norm=False, bias=bias)-》传入embed类创建embed模块
self.spa_embed = embed(num_joint, 64, norm=False, bias=bias)
self.joint_embed = embed(3, 64, norm=True, bias=bias)
self.dif_embed = embed(3, 64, norm=True, bias=bias)
embed组成:正则化-》1x1卷积-》Relu激活-》1x1卷积-》Relu激活
4.self.maxpool = nn.AdaptiveMaxPool2d((1, 1))-》最大池化
5.self.cnn = local(self.dim1, self.dim1 * 2, bias=bias)-》创建一个local模块。
local模块组成:最大池化-》卷积-》正则化-》Relu激活-》卷积-》正则化-》Dropout随机损失
6.self.compute_g1 = compute_g_spa(self.dim1 // 2, self.dim1, bias=bias)-》创建compute_g_spa模块
compute_g_spa:卷积-》卷积-》softmax映射为0-1之间的实数,并且归一化保证和为1,因此多分类的概率之和也刚好为1。
7.self.gcn1 = gcn_spa(self.dim1 // 2, self.dim1 // 2, bias=bias)
self.gcn2 = gcn_spa(self.dim1 // 2, self.dim1, bias=bias)
self.gcn3 = gcn_spa(self.dim1, self.dim1, bias=bias)-》创建3个gcn图卷积模块
8.self.fc = nn.Linear(self.dim1 * 2, num_classes)-》全连接分类
9. for m in self.modules():
if isinstance(m, nn.Conv2d):
n = m.kernel_size[0] * m.kernel_size[1] * m.out_channels-》第一个卷积核x第二个卷积核x输出通道
m.weight.data.normal_(0, math.sqrt(2. / n))-》
10.
nn.init.constant_(self.gcn1.w.cnn.weight, 0)
nn.init.constant_(self.gcn2.w.cnn.weight, 0)
nn.init.constant_(self.gcn3.w.cnn.weight, 0)-》初始化各层权重
解读one_hot方法:
1. y = torch.arange(spa).unsqueeze(-1)-》对数据的维度进行压缩,去掉维数为1的的维度,默认是将a中所有为1的维度删掉。也可以通过dim指定位置,删掉指定位置的维数为1的维度。
2.y_onehot = torch.FloatTensor(spa, spa) -》32位浮点型
3.y_onehot.zero_()
4.y_onehot.scatter_(1, y, 1)-》
scatter(dim, index, src) 的参数有 3 个
- dim:沿着哪个维度进行索引
- ind