import os
import json
import torch
from PIL import Image
from torchvision import transforms
import matplotlib.pyplot as plt
#导入对应的模型
from model import swin_tiny_patch4_window7_224 as create_modeldevice = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
model = create_model(num_classes=5).to(device)
modules = list(model.children())
for i in modules:print(i)print('==' * 50)
print('modules内的数量:',len(modules))

输出

PatchEmbed((proj): Conv2d(3, 96, kernel_size=(4, 4), stride=(4, 4))(norm): LayerNorm((96,), eps=1e-05, elementwise_affine=True)
)
====================================================================================================
Dropout(p=0.0, inplace=False)
====================================================================================================
ModuleList((0): BasicLayer((blocks): ModuleList((0): SwinTransformerBlock((norm1): LayerNorm((96,), eps=1e-05, elementwise_affine=True)(attn): WindowAttention((qkv): Linear(in_features=96, out_features=288, bias=True)(attn_drop): Dropout(p=0.0, inplace=False)(proj): Linear(in_features=96, out_features=96, bias=True)(proj_drop): Dropout(p=0.0, inplace=False)(softmax): Softmax(dim=-1))(drop_path): Identity()(norm2): LayerNorm((96,), eps=1e-05, elementwise_affine=True)(mlp): Mlp((fc1): Linear(in_features=96, out_features=384, bias=True)(act): GELU()(drop1): Dropout(p=0.0, inplace=False)(fc2): Linear(in_features=384, out_features=96, bias=True)(drop2): Dropout(p=0.0, inplace=False)))(1): SwinTransformerBlock((norm1): LayerNorm((96,), eps=1e-05, elementwise_affine=True)(attn): WindowAttention((qkv): Linear(in_features=96, out_features=288, bias=True)(attn_drop): Dropout(p=0.0, inplace=False)(proj): Linear(in_features=96, out_features=96, bias=True)(proj_drop): Dropout(p=0.0, inplace=False)(softmax): Softmax(dim=-1))(drop_path): DropPath()(norm2): LayerNorm((96,), eps=1e-05, elementwise_affine=True)(mlp): Mlp((fc1): Linear(in_features=96, out_features=384, bias=True)(act): GELU()(drop1): Dropout(p=0.0, inplace=False)(fc2): Linear(in_features=384, out_features=96, bias=True)(drop2): Dropout(p=0.0, inplace=False))))(downsample): PatchMerging((reduction): Linear(in_features=384, out_features=192, bias=False)(norm): LayerNorm((384,), eps=1e-05, elementwise_affine=True)))(1): BasicLayer((blocks): ModuleList((0): SwinTransformerBlock((norm1): LayerNorm((192,), eps=1e-05, elementwise_affine=True)(attn): WindowAttention((qkv): Linear(in_features=192, out_features=576, bias=True)(attn_drop): Dropout(p=0.0, inplace=False)(proj): Linear(in_features=192, out_features=192, bias=True)(proj_drop): Dropout(p=0.0, inplace=False)(softmax): Softmax(dim=-1))(drop_path): DropPath()(norm2): LayerNorm((192,), eps=1e-05, elementwise_affine=True)(mlp): Mlp((fc1): Linear(in_features=192, out_features=768, bias=True)(act): GELU()(drop1): Dropout(p=0.0, inplace=False)(fc2): Linear(in_features=768, out_features=192, bias=True)(drop2): Dropout(p=0.0, inplace=False)))(1): SwinTransformerBlock((norm1): LayerNorm((192,), eps=1e-05, elementwise_affine=True)(attn): WindowAttention((qkv): Linear(in_features=192, out_features=576, bias=True)(attn_drop): Dropout(p=0.0, inplace=False)(proj): Linear(in_features=192, out_features=192, bias=True)(proj_drop): Dropout(p=0.0, inplace=False)(softmax): Softmax(dim=-1))(drop_path): DropPath()(norm2): LayerNorm((192,), eps=1e-05, elementwise_affine=True)(mlp): Mlp((fc1): Linear(in_features=192, out_features=768, bias=True)(act): GELU()(drop1): Dropout(p=0.0, inplace=False)(fc2): Linear(in_features=768, out_features=192, bias=True)(drop2): Dropout(p=0.0, inplace=False))))(downsample): PatchMerging((reduction): Linear(in_features=768, out_features=384, bias=False)(norm): LayerNorm((768,), eps=1e-05, elementwise_affine=True)))(2): BasicLayer((blocks): ModuleList((0): SwinTransformerBlock((norm1): LayerNorm((384,), eps=1e-05, elementwise_affine=True)(attn): WindowAttention((qkv): Linear(in_features=384, out_features=1152, bias=True)(attn_drop): Dropout(p=0.0, inplace=False)(proj): Linear(in_features=384, out_features=384, bias=True)(proj_drop): Dropout(p=0.0, inplace=False)(softmax): Softmax(dim=-1))(drop_path): DropPath()(norm2): LayerNorm((384,), eps=1e-05, elementwise_affine=True)(mlp): Mlp((fc1): Linear(in_features=384, out_features=1536, bias=True)(act): GELU()(drop1): Dropout(p=0.0, inplace=False)(fc2): Linear(in_features=1536, out_features=384, bias=True)(drop2): Dropout(p=0.0, inplace=False)))(1): SwinTransformerBlock((norm1): LayerNorm((384,), eps=1e-05, elementwise_affine=True)(attn): WindowAttention((qkv): Linear(in_features=384, out_features=1152, bias=True)(attn_drop): Dropout(p=0.0, inplace=False)(proj): Linear(in_features=384, out_features=384, bias=True)(proj_drop): Dropout(p=0.0, inplace=False)(softmax): Softmax(dim=-1))(drop_path): DropPath()(norm2): LayerNorm((384,), eps=1e-05, elementwise_affine=True)(mlp): Mlp((fc1): Linear(in_features=384, out_features=1536, bias=True)(act): GELU()(drop1): Dropout(p=0.0, inplace=False)(fc2): Linear(in_features=1536, out_features=384, bias=True)(drop2): Dropout(p=0.0, inplace=False)))(2): SwinTransformerBlock((norm1): LayerNorm((384,), eps=1e-05, elementwise_affine=True)(attn): WindowAttention((qkv): Linear(in_features=384, out_features=1152, bias=True)(attn_drop): Dropout(p=0.0, inplace=False)(proj): Linear(in_features=384, out_features=384, bias=True)(proj_drop): Dropout(p=0.0, inplace=False)(softmax): Softmax(dim=-1))(drop_path): DropPath()(norm2): LayerNorm((384,), eps=1e-05, elementwise_affine=True)(mlp): Mlp((fc1): Linear(in_features=384, out_features=1536, bias=True)(act): GELU()(drop1): Dropout(p=0.0, inplace=False)(fc2): Linear(in_features=1536, out_features=384, bias=True)(drop2): Dropout(p=0.0, inplace=False)))(3): SwinTransformerBlock((norm1): LayerNorm((384,), eps=1e-05, elementwise_affine=True)(attn): WindowAttention((qkv): Linear(in_features=384, out_features=1152, bias=True)(attn_drop): Dropout(p=0.0, inplace=False)(proj): Linear(in_features=384, out_features=384, bias=True)(proj_drop): Dropout(p=0.0, inplace=False)(softmax): Softmax(dim=-1))(drop_path): DropPath()(norm2): LayerNorm((384,), eps=1e-05, elementwise_affine=True)(mlp): Mlp((fc1): Linear(in_features=384, out_features=1536, bias=True)(act): GELU()(drop1): Dropout(p=0.0, inplace=False)(fc2): Linear(in_features=1536, out_features=384, bias=True)(drop2): Dropout(p=0.0, inplace=False)))(4): SwinTransformerBlock((norm1): LayerNorm((384,), eps=1e-05, elementwise_affine=True)(attn): WindowAttention((qkv): Linear(in_features=384, out_features=1152, bias=True)(attn_drop): Dropout(p=0.0, inplace=False)(proj): Linear(in_features=384, out_features=384, bias=True)(proj_drop): Dropout(p=0.0, inplace=False)(softmax): Softmax(dim=-1))(drop_path): DropPath()(norm2): LayerNorm((384,), eps=1e-05, elementwise_affine=True)(mlp): Mlp((fc1): Linear(in_features=384, out_features=1536, bias=True)(act): GELU()(drop1): Dropout(p=0.0, inplace=False)(fc2): Linear(in_features=1536, out_features=384, bias=True)(drop2): Dropout(p=0.0, inplace=False)))(5): SwinTransformerBlock((norm1): LayerNorm((384,), eps=1e-05, elementwise_affine=True)(attn): WindowAttention((qkv): Linear(in_features=384, out_features=1152, bias=True)(attn_drop): Dropout(p=0.0, inplace=False)(proj): Linear(in_features=384, out_features=384, bias=True)(proj_drop): Dropout(p=0.0, inplace=False)(softmax): Softmax(dim=-1))(drop_path): DropPath()(norm2): LayerNorm((384,), eps=1e-05, elementwise_affine=True)(mlp): Mlp((fc1): Linear(in_features=384, out_features=1536, bias=True)(act): GELU()(drop1): Dropout(p=0.0, inplace=False)(fc2): Linear(in_features=1536, out_features=384, bias=True)(drop2): Dropout(p=0.0, inplace=False))))(downsample): PatchMerging((reduction): Linear(in_features=1536, out_features=768, bias=False)(norm): LayerNorm((1536,), eps=1e-05, elementwise_affine=True)))(3): BasicLayer((blocks): ModuleList((0): SwinTransformerBlock((norm1): LayerNorm((768,), eps=1e-05, elementwise_affine=True)(attn): WindowAttention((qkv): Linear(in_features=768, out_features=2304, bias=True)(attn_drop): Dropout(p=0.0, inplace=False)(proj): Linear(in_features=768, out_features=768, bias=True)(proj_drop): Dropout(p=0.0, inplace=False)(softmax): Softmax(dim=-1))(drop_path): DropPath()(norm2): LayerNorm((768,), eps=1e-05, elementwise_affine=True)(mlp): Mlp((fc1): Linear(in_features=768, out_features=3072, bias=True)(act): GELU()(drop1): Dropout(p=0.0, inplace=False)(fc2): Linear(in_features=3072, out_features=768, bias=True)(drop2): Dropout(p=0.0, inplace=False)))(1): SwinTransformerBlock((norm1): LayerNorm((768,), eps=1e-05, elementwise_affine=True)(attn): WindowAttention((qkv): Linear(in_features=768, out_features=2304, bias=True)(attn_drop): Dropout(p=0.0, inplace=False)(proj): Linear(in_features=768, out_features=768, bias=True)(proj_drop): Dropout(p=0.0, inplace=False)(softmax): Softmax(dim=-1))(drop_path): DropPath()(norm2): LayerNorm((768,), eps=1e-05, elementwise_affine=True)(mlp): Mlp((fc1): Linear(in_features=768, out_features=3072, bias=True)(act): GELU()(drop1): Dropout(p=0.0, inplace=False)(fc2): Linear(in_features=3072, out_features=768, bias=True)(drop2): Dropout(p=0.0, inplace=False)))))
)
====================================================================================================
LayerNorm((768,), eps=1e-05, elementwise_affine=True)
====================================================================================================
AdaptiveAvgPool1d(output_size=1)
====================================================================================================
Linear(in_features=768, out_features=5, bias=True)
====================================================================================================
modules内的数量: 6

查看swintransformer模型的参数是否需要计算梯度

参考:
1、requires_grad,grad_fn,grad的含义及使用
2、Pytorch之requires_grad

for p in model.parameters():print(p.requires_grad)print('==' * 50)

输出

True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================
True
====================================================================================================

全是True,显然是需要求梯度

查看swintransformer的网络结构.children()相关推荐

  1. 查看swintransformer的网络结构

    import torch #导入对应的模型 from model import swin_tiny_patch4_window7_224 as create_model device = torch. ...

  2. 查看resnet101的网络结构

    代码 import torch from torch import nn import torchvision device = torch.device("cuda" if to ...

  3. html获取孩子节点,JS实现JQuery children()方法,获取某个元素下所有子元素节点或者某个元素下指定标签元素 – Fakin's Blog...

    想必大家都知道jquery中有个children()是一个遍历的方法,作用是获取某个指定元素下所有子元素,那么今天我们来用原生JS实现一个这个children(),其实很简单,只不过需要处理一下IE6 ...

  4. 【神经网络】(7) 迁移学习(CNN-MobileNetV2),案例:乳腺癌二分类

    各位同学好,今天和大家分享一下Tensorflow2.0中如何使用迁移学习的方法构造神经网络.需要数据集的在评论区留个言. 1. 迁移学习 官方文档:Module: tf.keras.applicat ...

  5. python 标签树的遍历

    下行遍历: .contents:字节点列表,将<tag>所有儿子节点存入列表 他的儿子,就是title. body的儿子还有\n,对呀.这个也算是一个节点! (比例不对就用放大镜查看!嘿嘿 ...

  6. 李宗纯:图机器学习在度小满风控中的应用

    来源:DataFunTalk 本文约6900字,建议阅读10+分钟 本文主要介绍度小满的超大规模图平台,以及它在真实金融风控业务中的应用.其中会包括一些应用方法和案例,希望能为大家在图机器学习落地产品 ...

  7. 创建 VXLAN - 每天5分钟玩转 OpenStack(111)

    前面我们讨论了 VXLAN 的理论知识,并且在 ML2 中完成了相关配置. 今天将通过 Web UI 创建 vxlan100_net 并观察节点网络结构的变化. 打开菜单 Admin -> Ne ...

  8. 创建 OVS 外部网络 ext_net - 每天5分钟玩转 OpenStack(144)

    上一节完成连接外网的配置准备工作,今天就来创建 OVS 外部网络 ext_net. 进入 Admin -> Networks 菜单,点击 "Create Network" 按 ...

  9. Caffe-windows入门学习,编译、训练、测试详细教程

    ####目录结构 一. 准备工作 二. 编译 2.1.开启相关caffe版本的编译开关配置内容 2.2.手动更改或者指定版本对应编译器目录 2.3.下载依赖文件dependencies文件到指定目录 ...

最新文章

  1. c++ 结构体构造函数使用总结 附一道经典模拟题
  2. HDU 4685 Prince and Princess(二分匹配加点建图+强连通分量)
  3. 计算机本地网络如何共享,本地网络共享怎么实现
  4. 音频断句Matlab,一步一步教你实现iOS音频频谱动画(二)
  5. c语言数组与指针编程源码,C语言编程(练习9:数组与指针)
  6. 算法设计与分析复习——第四章:贪心算法
  7. 专题开发十三:JEECG微云高速开发平台-附录
  8. 光伏窗性能研究(2)——光伏窗性能研究方法和过程
  9. word转html制作操作手册,Word文档转换为HTML帮助文档操作手册范本.pdf
  10. 选手投票html,选手投票网页制作
  11. 用机器学习来提升你的用户增长:第八步,Uplift模型
  12. python语音验证码识别_python语音验证码接口_python语音接口_python语音验证码_语音验证码代码示例_互亿无线...
  13. 从Watson看AI平台的架构设计
  14. 清华大学张亚勤对话朱民:颠覆认知的AI时代及产业机遇
  15. win10桌面管理文件收纳_win10系统关闭桌面文件收纳盒的方法
  16. python reset_index()_python 问题 reset_index(drop=True
  17. Nginx启动成功但页面访问不到的解决方法
  18. Linux系统调用详解(实现机制分析)--linux内核剖析(六)
  19. 数字化转型,你也可以品
  20. Nature重磅:软硬分离、图灵完备,清华首次提出“类脑计算完备性”

热门文章

  1. hibernate缓存机制
  2. 前端工程师面试题JavaScript部分(第二季)
  3. 【翻译自mos文章】job 不能自己主动运行的解决方法
  4. 让Vs2013 完美支持EF6.1 Code First with Oracle 2015年12月24日更新
  5. 贪吃蛇游戏(附源码)
  6. TurboShop应用特性(2009V3.6)
  7. python 调用另一个py_跟我自学python 第9章 类(9.4.6 在一个模块中导入另一个模块)...
  8. python播放音乐同步歌词_python终端播放音乐同定制步显示本地或网络歌词
  9. dicom文件_DICOM数据转成NIfTI数据
  10. mysql 临时表 汉字_转MySQL临时表的简单用法