caffe生成deploy.prototxt文件

参考:

http://blog.csdn.net/cham_3/article/details/52682479

以caffe工程自带的mnist数据集,lenet网络为例:

将lenet_train_test.prototxt文件进行一些修改即可得到lenet.prototxt文件

头部:

去除训练用的输入数据层,

layer {
  name: "mnist"
  type: "Data"
  top: "data"
  top: "label"
  include {
    phase: TRAIN
  }
  transform_param {
        mean_file: "mean.binaryproto"
    scale: 0.00390625
  }
  data_param {
    source: "examples/mnist/mnist_train_lmdb"
    batch_size: 64
    backend: LMDB
  }
}
layer {
  name: "mnist"
  type: "Data"
  top: "data"
  top: "label"
  include {
    phase: TEST
  }
  transform_param {
        mean_file: "mean.binaryproto"
    scale: 0.00390625
  }
  data_param {
    source: "examples/mnist/mnist_test_lmdb"
    batch_size: 100
    backend: LMDB
  }
}

添加数据,

layer {
  name: "data"
  type: "Input"
  top: "data"
  input_param { shape: { dim: 64 dim: 1 dim: 28 dim: 28 } }
}

中间的部分:

conv1-pool1-conv2-pool2-ip1-relu1-ip2中间的这些层是相同的

尾部:

lenet_train_test.prototxt去除,

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

添加,

layer {
  name: "prob"
  type: "Softmax"
  bottom: "ip2"
  top: "prob"
}

即可得到lenet.prototxt文件

以siftflow-fcn32s为例,说明:

打开trainval.prototxt文件,删除,

layer {
  name: "data"
  type: "Python"
  top: "data"
  top: "sem"
  top: "geo"
  python_param {
    module: "siftflow_layers"
    layer: "SIFTFlowSegDataLayer"
    param_str: "{\'siftflow_dir\': \'../data/sift-flow\', \'seed\': 1337, \'split\': \'trainval\'}"
  }
}

添加,

layer {
  name: "input"
  type: "Input"
  top: "data"
  input_param {
    # These dimensions are purely for sake of example;
    # see infer.py for how to reshape the net to the given input size.
    shape { dim: 1 dim: 3 dim: 256 dim: 256 }
  }
}

中间的网络层都是相同的,

尾部,删除两个网络的loss层,

layer {
  name: "loss"
  type: "SoftmaxWithLoss"
  bottom: "score_sem"
  bottom: "sem"
  top: "loss"
  loss_param {
    ignore_label: 255
    normalize: false
  }
}
layer {
  name: "loss_geo"
  type: "SoftmaxWithLoss"
  bottom: "score_geo"
  bottom: "geo"
  top: "loss_geo"
  loss_param {
    ignore_label: 255
    normalize: false
  }
}

即可得到deploy.prototxt文件