解读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:沿着哪个维度进行索引
  • index:用来 scatter 的元素索引
  • src:用来 scatter 的源元素,可以是一个标量或一个张量

这个 scatter  可以理解成放置元素或者修改元素

5.y_onehot = y_onehot.unsqueeze(0).unsqueeze(0)-》对数据的维度进行压缩
6. y_onehot = y_onehot.repeat(bs, tem, 1, 1)-》计算矩阵

7.return y_onehot-》返回处理后矩阵

解读embed类:

1.if norm:
            self.cnn = nn.Sequential(
                norm_data(dim),-》创建一个norm_data模块(resize-》正则化-》resize)
                cnn1x1(dim, 64, bias=bias),-》1x1卷积核,输入通道为dim,输出通道(卷积核数量)64
                nn.ReLU(),-》Relu激活
                cnn1x1(64, dim1, bias=bias),-》1x1卷积核,输入通道为64,输出通道(卷积核数量)dim1
                nn.ReLU(),-》Relu激活
            )
        else:
            self.cnn = nn.Sequential(
                cnn1x1(dim, 64, bias=bias),-》1x1卷积核,输入通道为dim,输出通道(卷积核数量)64
                nn.ReLU(),-》Relu激活
                cnn1x1(64, dim1, bias=bias),-》1x1卷积核,输入通道为64,输出通道(卷积核数量)dim1
                nn.ReLU(),-》Relu激活
            )

解读local方法:

1.self.maxpool = nn.AdaptiveMaxPool2d((1, 20))-》最大池化
        self.cnn1 = nn.Conv2d(dim1, dim1, kernel_size=(1, 3), padding=(0, 1), bias=bias)-》卷积,输入输出均为dim1,卷积核大小为1x3,左右加上一圈0
        self.bn1 = nn.BatchNorm2d(dim1)-》正则化
        self.relu = nn.ReLU()-》Relu激活
        self.cnn2 = nn.Conv2d(dim1, dim2, kernel_size=1, bias=bias)-》卷积,输入均为dim1,输出为dim2,卷积核大小为1x1.
        self.bn2 = nn.BatchNorm2d(dim2)-》正则化
        self.dropout = nn.Dropout2d(0.2) ->Dropout随机失活

解读compute_g_spa方法:

1.x = x1.permute(0, 3, 2, 1).contiguous()-》将张量的维度换位
        x = g.matmul(x)-》返回两个数组的矩阵乘积
        x = x.permute(0, 3, 2, 1).contiguous()-》将张量的维度换位
        x = self.w(x) + self.w1(x1)-》计算矩阵的和
        x = self.relu(self.bn(x))-》Relu激活

解读gcn_spa方法:

1.x = x1.permute(0, 3, 2, 1).contiguous()-》将张量的维度换位
   x = g.matmul(x)-》返回两个数组的矩阵乘积
   x = x.permute(0, 3, 2, 1).contiguous()-》将张量的维度换位
  x = self.w(x) + self.w1(x1)-》计算矩阵的和
 x = self.relu(self.bn(x)) -》Relu激活

解读norm_data方法

1. bs, c, num_joints, step = x.size()-》获得矩阵x的规格大小
        x = x.view(bs, -1, step)-》相当于numpy中resize()的功能
        x = self.bn(x)-》批归一化

x = x.view(bs, -1, num_joints, step).contiguous()-》相当于numpy中resize()的功能

# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
from torch import nn
import torch
import mathclass SGN(nn.Module):def __init__(self, num_classes, dataset, seg, args, bias = True):super(SGN, self).__init__()self.dim1 = 256self.dataset = datasetself.seg = segnum_joint = 25bs = args.batch_sizeif 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()else:self.spa = self.one_hot(32 * 5, num_joint, self.seg)self.spa = self.spa.permute(0, 3, 2, 1).cuda()self.tem = self.one_hot(32 * 5, self.seg, num_joint)self.tem = self.tem.permute(0, 3, 1, 2).cuda()self.tem_embed = embed(self.seg, 64*4, norm=False, bias=bias)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)self.maxpool = nn.AdaptiveMaxPool2d((1, 1))self.cnn = local(self.dim1, self.dim1 * 2, bias=bias)self.compute_g1 = compute_g_spa(self.dim1 // 2, self.dim1, bias=bias)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)self.fc = nn.Linear(self.dim1 * 2, num_classes)for m in self.modules():if isinstance(m, nn.Conv2d):n = m.kernel_size[0] * m.kernel_size[1] * m.out_channelsm.weight.data.normal_(0, math.sqrt(2. / n))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)def forward(self, input):# Dynamic Representationbs, step, dim = input.size()num_joints = dim //3input = input.view((bs, step, num_joints, 3))input = input.permute(0, 3, 2, 1).contiguous()dif = input[:, :, :, 1:] - input[:, :, :, 0:-1]dif = torch.cat([dif.new(bs, dif.size(1), num_joints, 1).zero_(), dif], dim=-1)pos = self.joint_embed(input)tem1 = self.tem_embed(self.tem)spa1 = self.spa_embed(self.spa)dif = self.dif_embed(dif)dy = pos + dif# Joint-level Moduleinput= torch.cat([dy, spa1], 1)g = self.compute_g1(input)input = self.gcn1(input, g)input = self.gcn2(input, g)input = self.gcn3(input, g)# Frame-level Moduleinput = input + tem1input = self.cnn(input)# Classificationoutput = self.maxpool(input)output = torch.flatten(output, 1)output = self.fc(output)return outputdef one_hot(self, bs, spa, tem):y = torch.arange(spa).unsqueeze(-1)y_onehot = torch.FloatTensor(spa, spa)y_onehot.zero_()y_onehot.scatter_(1, y, 1)y_onehot = y_onehot.unsqueeze(0).unsqueeze(0)y_onehot = y_onehot.repeat(bs, tem, 1, 1)return y_onehotclass norm_data(nn.Module):def __init__(self, dim= 64):super(norm_data, self).__init__()self.bn = nn.BatchNorm1d(dim* 25)def forward(self, x):bs, c, num_joints, step = x.size()x = x.view(bs, -1, step)x = self.bn(x)x = x.view(bs, -1, num_joints, step).contiguous()return xclass embed(nn.Module):def __init__(self, dim = 3, dim1 = 128, norm = True, bias = False):super(embed, self).__init__()if norm:self.cnn = nn.Sequential(norm_data(dim),cnn1x1(dim, 64, bias=bias),nn.ReLU(),cnn1x1(64, dim1, bias=bias),nn.ReLU(),)else:self.cnn = nn.Sequential(cnn1x1(dim, 64, bias=bias),nn.ReLU(),cnn1x1(64, dim1, bias=bias),nn.ReLU(),)def forward(self, x):x = self.cnn(x)return xclass cnn1x1(nn.Module):def __init__(self, dim1 = 3, dim2 =3, bias = True):super(cnn1x1, self).__init__()self.cnn = nn.Conv2d(dim1, dim2, kernel_size=1, bias=bias)def forward(self, x):x = self.cnn(x)return xclass local(nn.Module):def __init__(self, dim1 = 3, dim2 = 3, bias = False):super(local, self).__init__()self.maxpool = nn.AdaptiveMaxPool2d((1, 20))self.cnn1 = nn.Conv2d(dim1, dim1, kernel_size=(1, 3), padding=(0, 1), bias=bias)self.bn1 = nn.BatchNorm2d(dim1)self.relu = nn.ReLU()self.cnn2 = nn.Conv2d(dim1, dim2, kernel_size=1, bias=bias)self.bn2 = nn.BatchNorm2d(dim2)self.dropout = nn.Dropout2d(0.2)def forward(self, x1):x1 = self.maxpool(x1)x = self.cnn1(x1)x = self.bn1(x)x = self.relu(x)x = self.dropout(x)x = self.cnn2(x)x = self.bn2(x)x = self.relu(x)return xclass gcn_spa(nn.Module):def __init__(self, in_feature, out_feature, bias = False):super(gcn_spa, self).__init__()self.bn = nn.BatchNorm2d(out_feature)self.relu = nn.ReLU()self.w = cnn1x1(in_feature, out_feature, bias=False)self.w1 = cnn1x1(in_feature, out_feature, bias=bias)def forward(self, x1, g):x = x1.permute(0, 3, 2, 1).contiguous()x = g.matmul(x)x = x.permute(0, 3, 2, 1).contiguous()x = self.w(x) + self.w1(x1)x = self.relu(self.bn(x))return xclass compute_g_spa(nn.Module):def __init__(self, dim1 = 64 *3, dim2 = 64*3, bias = False):super(compute_g_spa, self).__init__()self.dim1 = dim1self.dim2 = dim2self.g1 = cnn1x1(self.dim1, self.dim2, bias=bias)self.g2 = cnn1x1(self.dim1, self.dim2, bias=bias)self.softmax = nn.Softmax(dim=-1)def forward(self, x1):g1 = self.g1(x1).permute(0, 3, 2, 1).contiguous()g2 = self.g2(x1).permute(0, 3, 1, 2).contiguous()g3 = g1.matmul(g2)g = self.softmax(g3)return g

https://github.com/microsoft/SGN

智能数字图像处理:图卷积SGN代码(pytorch)之model.py解读相关推荐

  1. 数字图像处理-python基于opencv代码实现 反转变换、对数变换和幂律(伽马)变换

    本文主要介绍对<数字图像处理>第三章书中示例图片实现 反转变换.对数变换以及伽马变换的代码 若要获取更多数字图像处理,python,深度学习,机器学习,计算机视觉等高清PDF以及 更多有意 ...

  2. 图卷积神经网络代码讲解,cnn卷积神经网络伪代码

    1.卷积神经网络通俗理解 卷积神经网络(Convolutional Neural Networks, CNN)是一类包含卷积计算且具有深度结构的前馈神经网络(Feedforward Neural Ne ...

  3. 数字图像处理-常考算法代码-详细注释

    文章目录 求一幅图像的灰度直方图 对一幅图像的直方图均衡化 使用各种模板的中值滤波对图像进行处理 对图像进行傅里叶变换 使用巴特沃斯低通滤波器对图像进行处理 使用迭代阈值分割图像 使用区域生长法分割图 ...

  4. python 图像分析自然纹理方向与粗细代码_数字图像处理与Python实现笔记之基础知识...

    数字图像处理与Python实现笔记之基础知识 摘要 绪论 1 数字图像处理基础知识 1.1 数字图像简介 1.1.1 数字图像处理的目的 1.1.2 数字图像处理的应用 1.1.3 数字图像处理的特点 ...

  5. 基于AlexNet卷积神经网络的手写体数字识别系统研究-附Matlab代码

    ⭕⭕ 目 录 ⭕⭕ ✳️ 一.引言 ✳️ 二.手写体数字识别系统 ✳️ 2.1 MNIST 数据集 ✳️ 2.2 CNN ✳️ 2.3 网络训练 ✳️ 三.手写体数字识别结果 ✳️ 四.参考文献 ✳️ ...

  6. 最值得收藏的 数字图像处理 全部知识点思维导图整理(武汉大学慕课课程)(持续更新中)

    本文的思维导图根据慕课上的武汉大学数字图像处理国家精品课程整理而来并标记出重点内容 思维导图就整理了这么多,之后应该也不会更新此内容了, 有需要的可以去 我的主页 了解更多学科的精品思维导图整理 本文 ...

  7. 数字图像处理Matlab-图像的滤波处理与图像空间变换(附代码)

    目录 1.Objectives: 2.Experiment Content: 3.Experiment Principle: 4.Experiment Steps Result and Conlusi ...

  8. 数字图像处理期末大作业-美图秀秀

    本项目是以matlab为主语言并设计GUI界面的一款简易美图秀秀,包含基础的图像处理和一些常见美颜算法 对于一些matlab较难实现的算法采用C++或python来实现 ⭐️ github地址:htt ...

  9. 数字图像处理-3.7混合空间增强法-骨骼图 基于opencv3.4.3的实现

    引子 刚开始看冈萨雷斯的<数字图像处理>时,3.7节 混合空间增强法中图3.4.3中的全身骨骼图的印象非常深刻.牛XX啊,这么模糊,都能变得这么清楚.虽然书中也给出了大段大段的解释,但是能 ...

最新文章

  1. oa 中会议推送 实现_揭秘“OA与ERP高端融合方案”三大亮点
  2. Linux字符设备驱动剖析
  3. Windows XP下Service的编程入门[2]
  4. oracle logfile sync,oracle等待事件3构造一个DirectPathwrite等待事件和构造一个LogFileSync等待事件...
  5. 50行python代码写个计算器教程
  6. Jenkins的定时构建与轮询SCM
  7. 系统服务器更换技术方案,通道设备监控服务器更换 专项工程施工组织方案
  8. 计算机中学期末考试,[探析我国中学计算机教育]计算机基础大一考试题
  9. 【WIN10更改鼠标指针默认图标】
  10. 布谷技术月刊 1608
  11. c语言 函数拟合,曲线拟合成Y=a*(X^b)+c*(X^d)函数 - 数学 - 小木虫 - 学术 科研 互动社区...
  12. 如何解决电脑任务栏无故不见了的问题 ?
  13. linux 6新扩分区识别,虚拟机中CentOS 6.5 添加扩展分区
  14. ubuntu18.04无法找到wifi适配器解决方案
  15. Java学习(58)Java单例模式——单例模式的特点及适用场景
  16. openwrt用WEB刷固件型号不对问题强行处理
  17. 计算机中的换行符、回车符、\n、\r、\n\r 怎么区分
  18. 黄梅戏 名家 名段 下载
  19. 转:Unicode汉字编码表
  20. (转)求质数算法的N种境界[1] - 试除法和初级筛法

热门文章

  1. oracle vba 数组_Excel VBA 连接各种数据库(二) VBA连接Oracle数据库
  2. 大数据时代的Serverless工作负载预测赛后总结
  3. matlab处理afm图片,基于MATLAB的增大页岩AFM灰度图分辨率的方法与流程
  4. 精品微信小程序源码丨基于微信小程序的美容预约+后台管理系统|前后分离VUE[包运行成功]
  5. Redis学习之srem命令
  6. Altium Designer--如何将底层视图进行翻转
  7. oracle读写速率,Oracle、PostgreSQL与Mysql数据写入性能对比
  8. stm32复位引脚NRST
  9. 计算机休眠唤醒后分辨率变小了,WIN10休眠唤醒后,所有的窗口都跑到了左上角,如何解决?...
  10. Excel导出(浏览器下载器下载导出Excel)