zoukankan      html  css  js  c++  java
  • Torch笔记

    Torch笔记

    • 初始化很重要 切记 !不同的初始化产生的结果完全不同
    • relu函数可以解决sigmod函数梯度弥散的问题
    • tanh函数在卷积用的比较多
    • Leaky Relu 泄露的relu函数 使x<0时仍然具有梯度
    • SELU函数时两个函数的concat(不常用)
    • softplus同样是relu函数平滑的版本 在0处平滑(不常用)

    如何防止Over fitting

    • 使用更多的数据

    • 控制模型复杂度

      • 使用更浅的模型

      • 正则化

        • L1 L2正则 lambda参数
        • 使用正则的前提是模型已经over fitting了
        optimizer = optim.SGD(net.parameters(),lr = learning_rate,weight_decay = 0.01)
        
    • Dropout

      torch.nn.Dropout(0.5) 将上一层数据减少一半传播
      
    • Data argumentation 数据增强

    • Early Stopping

    优化器

    • momentum 动量 使用只需在优化器中添加momentum参数即可

      Adam优化器不需要添加动量 因为他自带

    • learnning rate decay 动态LR ReduceLROnPlateau(optimzer,'min')

    代码笔记

    device = torch.device('cuda:0')
    
    net = MLP().to(device)  # 将网络切换到GPU上  原地更新
    
    

    底层实现全连接

    import torch
    import troch.nn.Function as F
    w1,b1 = torch.randn(200,784,requires_grad=True),torch.zeros(200,requires_grad=True)
    w2,b2 = torch.randn(200,200,requires_grad=True),torch.zeros(200,requires_grad=True)
    w3,b3 = torch.randn(200,784,requires_grad=True),torch.zeros(200,requires_grad=True)
    def forward(x):
        x = x@w1.t()+b1
        x = F.relu(x)
        x = x@w2.t()+b2
        x = F.relu(x)
        x = x@w3.t()+b3
        x = F.relu(x)
        return x
    
        
    
  • 相关阅读:
    数据库高并发
    Syslog+Fluentd+InfluxDB日志收集系统搭建
    EFK Stack容器部署
    Logstash过滤插件
    Collectd+InfluxDB+Grafana监控系统搭建
    Collectd基本使用
    Haproxy配置详解
    Kafka基本使用
    HDU-2087 剪花布条 字符串问题 KMP算法 查匹配子串
    POJ-2752 Seek the Name, Seek the Fame 字符串问题 KMP算法 求前后缀串相同数木
  • 原文地址:https://www.cnblogs.com/rise0111/p/11360982.html
Copyright © 2011-2022 走看看