Caffe(2)--LeNet网络各层参数详解

“LeNet” 1、Data Layer 输入图像为:12828,对应ChannelsHeightWidth

layer {
  name: "mnist"
  type: "ImageData"
  top: "data"
  top: "label"
  include {
    phase: TRAIN
  }
  transform_param {
    scale: 0.00390625
    mirror: false
    crop_size: 0
  }
  image_data_param {
    source: "/caffe/data/mnist_image/train.txt"
    batch_size: 64
    shuffle: true
    new_height: 0 
    new_width : 0
    mean_file: "/caffe/examples/mnist/mean.binaryproto"
    root_folder: "/caffe/data/mnist_image/train/"
  }
}
layer {
  name: "mnist"
  type: "ImageData"
  top: "data"
  top: "label"
  include {
    phase: TEST
  }
  transform_param {
    scale: 0.00390625
    mirror: false
    crop_size: 0
  }
  image_data_param {
    source: "/caffe/data/mnist_image/test.txt"
    batch_size: 100
    shuffle: true
    new_height: 0 
    new_width : 0
    mean_file: "/caffe/examples/mnist/mean.binaryproto"
    root_folder: "/caffe/data/mnist_image/test/"
  }
}

2、C1卷积层 (1)核大小:kernel_size = 55 (2)步长:stride = 1 (3)输入:1个12828的图片 (4)输出:20个2424的特征图(feature map) (5)特征图大小计算方式为: 其中f为卷积核大小,p为zero padding项,s为卷积步长stride (6)训练参数:(5*5+1)*20=520

layer {
  name: "conv1"
  type: "Convolution"
  bottom: "data"
  top: "conv1"
  param {
    lr_mult: 1
  }
  param {
    lr_mult: 2
  }
  convolution_param {
    num_output: 20
    kernel_size: 5
    stride: 1
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
    }
  }
}

3、P1池化层 (1)核大小:kernel_size = 22 (2)步长:stride = 2 (3)输入:20个2424的特征图 (4)输出:20个12*12的特征图 (5)训练参数:0,通过解析caffemodel可知pool层并没有参数。 网上另一种说法:(1+1)*20=40,因为采样方式为4个输入(像素),乘以一个权重参数w,再加上一个偏置项b,结果通过sigmoid,这部分相当于加了激活函数。相互抄来抄去之前都不知道自己去验证一下的么?

layer {
  name: "pool1"
  type: "Pooling"
  bottom: "conv1"
  top: "pool1"
  pooling_param {
    pool: MAX
    kernel_size: 2
    stride: 2
  }
}

4、C2卷积层 (1)核大小:kernel_size = 55 (2)步长:stride = 1 (3)输入:20个1212的特征图 (4)输出:50个88的特征图 (5)训练参数:(5520+1)50=25050,其中55与kernel_size相关,20是输入channel,1是偏置b,50是输出channel。 关于训练参数网上另一种说法:训练参数:查得资料中,这一层输出为16个特征图,特征图组合方式如公式所示,(553+1)6+(554+1)9+(55*6+1)*1=1516,但在本网络中输出50个特征图,组合方式?麻烦去亲自看一下caffe的源码实现好吗?

layer {
  name: "conv2"
  type: "Convolution"
  bottom: "pool1"
  top: "conv2"
  param {
    lr_mult: 1
  }
  param {
    lr_mult: 2
  }
  convolution_param {
    num_output: 50
    kernel_size: 5
    stride: 1
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
    }
  }
}

5、P2池化层 (1)核大小:kernel_size = 22 (2)步长:stride = 2 (3)输入:50个88的特征图 (4)输出:50个4*4的特征图 (5)训练参数:0

layer {
  name: "pool2"
  type: "Pooling"
  bottom: "conv2"
  top: "pool2"
  pooling_param {
    pool: MAX
    kernel_size: 2
    stride: 2
  }
}

6、F1全连接层 (1)输入:50个44的特征图 (2)输出:500个1维的特征向量 (3)训练参数:(504*4+1)500=400500,其中50为输入channel,44为输入特征图,1为偏置b,500为输出channel。

layer {
  name: "ip1"
  type: "InnerProduct"
  bottom: "pool2"
  top: "ip1"
  param {
    lr_mult: 1
  }
  param {
    lr_mult: 2
  }
  inner_product_param {
    num_output: 500
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
    }
  }
}

7、ReLU激活函数 (1)输入:500个1维的特征向量 (2)输出:500个1维的特征向量 (3)对数据进行非线性处理

layer {
  name: "relu1"
  type: "ReLU"
  bottom: "ip1"
  top: "ip1"
}

8、输出层 (1)输入:500个1维的特征向量 (2)输出:10个神经元对应0-9共10个类别,每个神经元分别于500个输入全连接 (3)训练参数:(500*1+1)*10=5010

layer {
  name: "ip2"
  type: "InnerProduct"
  bottom: "ip1"
  top: "ip2"
  param {
    lr_mult: 1
  }
  param {
    lr_mult: 2
  }
  inner_product_param {
    num_output: 10
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
    }
  }
}

9、Accuracy (1)输入:ip2输出层结果和label (2)输出:accuracy

layer {
  name: "accuracy"
  type: "Accuracy"
  bottom: "ip2"
  bottom: "label"
  top: "accuracy"
  include {
    phase: TEST
  }
}

10、loss (1)输入:ip2输出层结果和label (2)输出:loss

layer {
  name: "loss"
  type: "SoftmaxWithLoss"
  bottom: "ip2"
  bottom: "label"
  top: "loss"
}

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

扫码关注云+社区

领取腾讯云代金券