• xavier,kaiming初始化中的fan_in,fan_out在卷积神经网络是什么意思


    xavier

    xavier初始化出自论文Understanding the difficulty of training deep feedforward neural network,论文讨论的是全连接神经网络,fan_in指第i层神经元个数,fan_out指第i+1层神经元个数,但是我们的卷积神经网路是局部连接的,此时的fan_in,fan_out是什么意思呢。
    在pytorch中,fan_in指kernel_height x kernel_width x in_channel. fan_out指kernel_height x kernel_width x out_channel,从局部连接的过程来看似乎并不十分合理,卷积神经网络的局部连接在感受野内仍然是全连接。fan_in=kh x kw x in_channel没什么疑问,但是fan_out应该等于out_channel更合理啊。待解答。

    code,来自pytorch实现

    def _calculate_fan_in_and_fan_out(tensor):
        dimensions = tensor.ndimension()
        if dimensions < 2:
            raise ValueError("Fan in and fan out can not be computed for tensor with fewer than 2 dimensions")
    
        if dimensions == 2:  # Linear
            fan_in = tensor.size(1)
            fan_out = tensor.size(0)
        else:
            num_input_fmaps = tensor.size(1)
            num_output_fmaps = tensor.size(0)
            receptive_field_size = 1
            if tensor.dim() > 2:
                receptive_field_size = tensor[0][0].numel()
            fan_in = num_input_fmaps * receptive_field_size
            fan_out = num_output_fmaps * receptive_field_size
    
        return fan_in, fan_out
    
    
  • 相关阅读:
    动态规划_树形DP
    动态规划_区间DP
    Git
    动态规划_状态机与状态压缩DP
    Mybatis
    3.UIViewController详解
    Flutter boost实现原理简介
    FFmpeg笔记(四)
    Xcode-FFmpeg环境搭建
    FFmpeg(一)
  • 原文地址:https://www.cnblogs.com/liuzhan709/p/10092679.html
Copyright © 2020-2023  润新知