caffe学习笔记11-deploy.prototxt学习

本文详细介绍了CaffeNet深度学习网络的结构配置文件deploy.prototxt的具体内容,包括输入层、卷积层、池化层、全连接层等各层的参数设置,并解释了这些配置如何构成整个网络。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

deploy.prototxt:

name: "CaffeNet"

layer {
  name: "data"
  type: "Input"
  top: "data"
  input_param { shape: { dim: 10 dim: 3 dim: 227 dim: 227 } } #剪裁后10个,实际输入的是单张
}
layer {
  name: "conv1"
  type: "Convolution"
  bottom: "data"
  top: "conv1"
  convolution_param {
    num_output: 96
    kernel_size: 11
    stride: 4
  }
}
layer {
  name: "relu1"
  type: "ReLU"
  bottom: "conv1"
  top: "conv1"
}
layer {
  name: "pool1"
  type: "Pooling"
  bottom: "conv1"
  top: "pool1"
  pooling_param {
    pool: MAX
    kernel_size: 3
    stride: 2
  }
}
layer {
  name: "norm1"
  type: "LRN"
  bottom: "pool1"
  top: "norm1"
  lrn_param {
    local_size: 5
    alpha: 0.0001
    beta: 0.75
  }
}
layer {
  name: "conv2"
  type: "Convolution"
  bottom: "norm1"
  top: "conv2"
  convolution_param {
    num_output: 256
    pad: 2
    kernel_size: 5
    group: 2
  }
}
layer {
  name: "relu2"
  type: "ReLU"
  bottom: "conv2"
  top: "conv2"
}
layer {
  name: "pool2"
  type: "Pooling"
  bottom: "conv2"
  top: "pool2"
  pooling_param {
    pool: MAX
    kernel_size: 3
    stride: 2
  }
}
layer {
  name: "norm2"
  type: "LRN"
  bottom: "pool2"
  top: "norm2"
  lrn_param {
    local_size: 5
    alpha: 0.0001
    beta: 0.75
  }
}
layer {
  name: "conv3"
  type: "Convolution"
  bottom: "norm2"
  top: "conv3"
  convolution_param {
    num_output: 384
    pad: 1
    kernel_size: 3
  }
}
layer {
  name: "relu3"
  type: "ReLU"
  bottom: "conv3"
  top: "conv3"
}
layer {
  name: "conv4"
  type: "Convolution"
  bottom: "conv3"
  top: "conv4"
  convolution_param {
    num_output: 384
    pad: 1
    kernel_size: 3
    group: 2
  }
}
layer {
  name: "relu4"
  type: "ReLU"
  bottom: "conv4"
  top: "conv4"
}
layer {
  name: "conv5"
  type: "Convolution"
  bottom: "conv4"
  top: "conv5"
  convolution_param {
    num_output: 256
    pad: 1
    kernel_size: 3
    group: 2
  }
}
layer {
  name: "relu5"
  type: "ReLU"
  bottom: "conv5"
  top: "conv5"
}
layer {
  name: "pool5"
  type: "Pooling"
  bottom: "conv5"
  top: "pool5"
  pooling_param {
    pool: MAX
    kernel_size: 3
    stride: 2
  }
}
layer {
  name: "fc6"
  type: "InnerProduct"
  bottom: "pool5"
  top: "fc6"
  inner_product_param {
    num_output: 4096
  }
}
layer {
  name: "relu6"
  type: "ReLU"
  bottom: "fc6"
  top: "fc6"
}
layer {
  name: "drop6"
  type: "Dropout"
  bottom: "fc6"
  top: "fc6"
  dropout_param {
    dropout_ratio: 0.5
  }
}
layer {
  name: "fc7"
  type: "InnerProduct"
  bottom: "fc6"
  top: "fc7"
  inner_product_param {
    num_output: 4096
  }
}
layer {
  name: "relu7"
  type: "ReLU"
  bottom: "fc7"
  top: "fc7"
}
layer {
  name: "drop7"
  type: "Dropout"
  bottom: "fc7"
  top: "fc7"
  dropout_param {
    dropout_ratio: 0.5
  }
}
layer {
  name: "fc8"
  type: "InnerProduct"
  bottom: "fc7"
  top: "fc8"
  inner_product_param {
    num_output: 1000
  }
}
layer {
  name: "prob"
  type: "Softmax"
  bottom: "fc8"
  top: "prob"
}
#去掉了损失函数层以及上述层的学习速率参数,留下分类层预测层
### Caffedeploy.prototxt与train_val.prototxt的区别及用途 在Caffe框架中,`deploy.prototxt`和`train_val.prototxt`是两种不同的网络配置文件,它们分别用于不同的场景。以下是两者的详细区别及用途: #### 1. **train_val.prototxt** - `train_val.prototxt`主要用于定义模型的训练和验证阶段的网络结构。 - 它包含了完整的网络层定义,包括输入数据层(如`Data`层)、损失函数层(如`SoftmaxWithLoss`层)以及准确性评估层(如`Accuracy`层)。这些层在训练和验证过程中是必需的[^2]。 - 此外,`train_val.prototxt`还可能包含一些与训练相关的参数,例如学习率调整、正则化等设置。 - 文件中通常会有多个`phase`属性,用于区分训练阶段(`TRAIN`)和验证阶段(`TEST`)的网络配置。 示例代码: ```protobuf layer { name: "data" type: "Data" top: "data" top: "label" include { phase: TRAIN } transform_param { mirror: true crop_size: 227 mean_file: "data/ilsvrc12/mean.binaryproto" } data_param { source: "examples/imagenet/train_lmdb" batch_size: 256 backend: LMDB } } ``` #### 2. **deploy.prototxt** - `deploy.prototxt`主要用于模型部署阶段,即在测试或实际应用中使用训练好的模型进行预测时的网络结构定义。 - 它通常是从`train_val.prototxt`简化而来的,去掉了与训练相关的内容,例如数据输入层、损失函数层和准确性评估层[^3]。 - 在`deploy.prototxt`中,输入数据层被替换为`Input`层,用户需要手动指定输入数据的形状。 - 此外,`deploy.prototxt`中不包含任何与训练过程相关的参数,例如学习率、动量等。 示例代码: ```protobuf layer { name: "data" type: "Input" top: "data" input_param { shape: { dim: 1 dim: 3 dim: 227 dim: 227 } } } ``` #### 3. **主要区别** | 特性 | train_val.prototxt | deploy.prototxt | |--------------------|-----------------------------------------------------|--------------------------------------------------| | **用途** | 训练和验证阶段 | 测试和部署阶段 | | **输入层类型** | Data层或其他数据输入层 | Input层 | | **是否包含损失层** | 包含(如SoftmaxWithLoss) | 不包含 | | **是否包含评估层** | 包含(如Accuracy) | 不包含 | | **是否包含训练参数** | 包含(如学习率、动量等) | 不包含 | #### 4. **生成关系** - `deploy.prototxt`通常可以通过从`train_val.prototxt`中删除与训练无关的部分生成[^2]。 - 具体操作包括:移除`Data`层,添加`Input`层,删除损失函数层和评估层等。 --- ### 示例对比 #### train_val.prototxt片段 ```protobuf layer { name: "loss" type: "SoftmaxWithLoss" bottom: "fc8" bottom: "label" top: "loss" } layer { name: "accuracy" type: "Accuracy" bottom: "fc8" bottom: "label" top: "accuracy" include { phase: TEST } } ``` #### deploy.prototxt片段 ```protobuf layer { name: "fc8" type: "InnerProduct" bottom: "fc7" top: "fc8" param { lr_mult: 1 decay_mult: 1 } param { lr_mult: 2 decay_mult: 0 } inner_product_param { num_output: 1000 weight_filler { type: "xavier" } bias_filler { type: "constant" value: 0 } } } ``` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值