史上最透彻的lenet.prototxt解析

// 输入层的定义:
name: "LeNet" (网络的名字)
  layer { (定义一个网络层)
  name: "data" (网络层的名字为 data)
  type: "Input" (网络层的类型,输入)
  top: "data" (该网络层的输出叫 data )
  input_param { shape: { dim: 64 dim: 1 dim: 28 dim: 28 } } }(64张图像为一批,28*28大小)
}
////读取这批数据维度:64 1 28 28
 
// 第一卷积层的定义:
layer {
  name: "conv1" (网络层的名字为 conv1)
  type: "Convolution" (网络层类型是 卷积层)
  bottom: "data" (该层的输入层是 data 层)
  top: "conv1" (该层的输出层叫 conv1 feature maps)
  param {
    lr_mult: 1 (weights的学习率与全局相同)
  }
  param {
    lr_mult: 2 (biases的学习率是全局的2倍)
  }
  convolution_param { {(卷积操作参数设置)
    num_output: 20 (卷积输出数量20,由20个特征图Feature Map构成)
    kernel_size: 5 (卷积核的大小是5*5)
    stride: 1 (卷积操作步长)
    weight_filler {
      type: "xavier" (卷积滤波器的参数使用 xavier 方法来初始化)
    }
    bias_filler {
      type: "constant" (bias使用0初始化)
    }
  }
}
////卷积之后这批数据维度:64 20 24 24
 
// 第一池化层定义:
layer {
  name: "pool1" (网络层的名字是 pool1 )
  type: "Pooling" (网络层的类型是 池化操作)
  bottom: "conv1" (网络层的输入是 conv1 feature maps)
  top: "pool1" (网络层的输出是 pool1)
  pooling_param { (池化参数设置)
    pool: MAX (最大池化操作)
    kernel_size: 2 (池化核尺寸,2*2 区域池化)
    stride: 2 (池化步长)
  }
}
////池化之后这批数据维度:64 20 12 12
 
// 第二卷积层的定义:
layer {
  name: "conv2" (该网络层的名字)
  type: "Convolution" (该网络层的类型,卷积)
  bottom: "pool1" (该网络层的输入是 pool1)
  top: "conv2" (该网络层的输出是 conv2, feature maps)
  param {
    lr_mult: 1 (weights的学习率与全局相同)
  }
  param {
    lr_mult: 2 (biases的学习率是全局的2倍)
  }
  convolution_param { (卷积参数设置)
    num_output: 50 (卷积的输出个数,由50个特征图Feature Map构成)
    kernel_size: 5 (卷积核尺寸 5*5)
    stride: 1 (卷积步长)
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
    }
  }
}
////卷积之后这批数据维度:64 50 8 8
 
// 第二池化层的定义:
layer {
  name: "pool2"
  type: "Pooling"
  bottom: "conv2"
  top: "pool2"
  pooling_param {
    pool: MAX
    kernel_size: 2
    stride: 2
  }
}
////池化之后这批数据维度:64 50 4 4
 
// 第一层全链接层的定义:
layer {
  name: "ip1" (该网络层的名字 ip1)
  type: "InnerProduct" (该网络层的类型是 全链接层)
  bottom: "pool2" (该层的输入是 pool2)
  top: "ip1" (该层的输出是 ip1)
  param {
    lr_mult: 1
  }
  param {
    lr_mult: 2
  }
  inner_product_param { (全链接层的 参数设置)
    num_output: 500 (500个输出神经元)
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
    }
  }
}
////500 个神经元
 
// 激活函数层的定义:
layer {
  name: "relu1" (该网络层的名字 relu1)
  type: "ReLU" (该网络层的类型, ReLU 激活函数)
  bottom: "ip1" (该层的输入是 ip1)
  top: "ip1" (该层的输出还是 ip1,底层与顶层相同是为了减少开支)
}
 
// 第二全链接层的定义:(数据的分类判断在这一层中完成)
layer {
  name: "ip2"
  type: "InnerProduct"
  bottom: "ip1"
  top: "ip2"
  param {
    lr_mult: 1
  }
  param {
    lr_mult: 2
  }
  inner_product_param {
    num_output: 10 (直接输出结果,0-9,十个数字所以维度是10)
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
    }
  }
}
 
// 输出层的定义:
layer {
  name: "prob"
  type: "Softmax" (损失函数)
  bottom: "ip2"
  top: "prob"
}

 

 

 

在使用 Caffe 进行人脸识别模型训练和测试时,`train.prototxt` 和 `test.prototxt` 是两个非常关键的配置文件。它们分别用于定义模型在训练和测试阶段的网络结构以及数据输入方式。 ### train.prototxt `train.prototxt` 文件用于描述训练过程中使用的网络结构。它包括输入数据的来源、数据增强参数、网络各层的定义、损失函数的类型以及优化策略等。例如,输入数据可以来自 LMDB 或者 LevelDB 数据库,也可以直接从图像文件中读取。数据增强参数通常包括随机裁剪、镜像翻转等操作,以增加模型的泛化能力。 以下是一个简化的 `train.prototxt` 文件示例片段,展示了数据层和卷积层的基本定义: ```protobuf name: "FaceNet" layer { name: "data" type: "Data" top: "data" top: "label" include { phase: TRAIN } transform_param { scale: 0.00390625 mirror: true crop_size: 128 } data_param { source: "/path/to/train_lmdb" batch_size: 64 backend: LMDB } } layer { name: "conv1" type: "Convolution" bottom: "data" top: "conv1" convolution_param { num_output: 64 kernel_size: 3 stride: 1 weight_filler { type: "xavier" } bias_filler { type: "constant" } } } ``` ### test.prototxt `test.prototxt` 文件则用于定义测试阶段的网络结构。与 `train.prototxt` 类似,但它通常不包含数据增强操作,并且可能包括额外的层如 `Accuracy` 层来评估模型性能。此外,在测试阶段,通常会使用更大的 `batch_size` 来加速推理过程。 下面是一个简化的 `test.prototxt` 文件示例片段: ```protobuf name: "FaceNet" layer { name: "data" type: "Data" top: "data" top: "label" include { phase: TEST } transform_param { scale: 0.00390625 mirror: false crop_size: 128 } data_param { source: "/path/to/test_lmdb" batch_size: 100 backend: LMDB } } layer { name: "conv1" type: "Convolution" bottom: "data" top: "conv1" convolution_param { num_output: 64 kernel_size: 3 stride: 1 weight_filler { type: "xavier" } bias_filler { type: "constant" } } } ``` 为了获取适用于特定人脸识别任务的 `train.prototxt` 和 `test.prototxt` 文件,通常需要参考具体的开源项目或者论文中的实现细节。这些文件可以根据所使用的模型架构(如 AlexNet、VGG、ResNet 等)进行相应的调整。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值