【问题标题】:Caffe - Create deploy.prototxt from train_val.prototxtCaffe - 从 train_val.prototxt 创建 deploy.prototxt
【发布时间】:2016-04-17 11:47:31
【问题描述】:

我已经对我的数据集上的 imagenet 预训练模型进行了微调,以下是在 train_val.prototxt 中所做的相关更改(我也没有进行过采样,只是在准备 hdf5 时进行了中心裁剪)

name: "MyCaffeNet"
layer {
  type: "HDF5Data"
  name: "data"
  top: "X"  
  top: "Meta" 
  top: "Labels"
  hdf5_data_param {
    source: "/path/to/hdf5_train.txt"
    batch_size: 50
  }
  include { phase: TRAIN }
}
layer {
  type: "HDF5Data"
  name: "data"
  top: "X"    
  top: "Meta" 
  top: "Labels"
  hdf5_data_param {
    source: "/path/to/hdf5_test.txt"
    batch_size: 50
 }
  include { phase: TEST }
}
layer {
  name: "conv1"
  type: "Convolution"
  bottom: "X"

其余的都一样,直到

layer {
  name: "concat"
  bottom: "fc7"
  bottom: "Meta"
  top: "combined"
  type: "Concat"
  concat_param {
    concat_dim: 1
  }
}
layer {
  name: "my-fc8"
  type: "InnerProduct"
  bottom: "combined"
  top: "my-fc8"
  # lr_mult is set to higher than for other layers, because this layer is starting from random while the others are already trained
  param {
    lr_mult: 10
    decay_mult: 1
  }
  param {
    lr_mult: 20
    decay_mult: 0
  }
  inner_product_param {
    num_output: 4098
    weight_filler {
      type: "gaussian"
      std: 0.01
    }
    bias_filler {
      type: "constant"
      value: 0
    }
 }
}
layer {
  name: "my-fc9"
  type: "InnerProduct"
  bottom: "my-fc8"
  top: "my-fc9"
  # lr_mult is set to higher than for other layers, because this layer is starting from random while the others are already trained
  param {
    lr_mult: 10
    decay_mult: 1
  }
  param {
    lr_mult: 20
    decay_mult: 0
  }
  inner_product_param {
    num_output: 1
    weight_filler {
      type: "gaussian"
      std: 0.01
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
}
layer {
  name: "loss"
  type: "EuclideanLoss"
  bottom: "my-fc9"
  bottom: "Labels"
}
layer {
  name: "loss"
  type: "EuclideanLoss"
  bottom: "my-fc9"
  bottom: "Labels"
  top: "loss"
  include {
    phase: TEST
  }
}

问题是我不知道如何修改我的 deploy.prototxt 和我的特征提取代码(如下所示)来测试这个模型,现在将额外的元信息作为输入特征

for i=1:n
    im = fgetl(file_list);
    im = imread(im);
    input_data = {prepare_image(im)};
    scores = caffe('forward', input_data);
    scores_original=scores;
    scores = scores{1};
    scores = squeeze(scores);
end

这里 prepare_image 将 rgb 转换为 bgr、置换和居中裁剪内容,基本上是预处理。

所以,归结为我应该如何修改 'caffe('forward', input_data)';并制作一个 deploy.prototxt 以便在测试 caffe 的同时也提供 Meta (n*2) 功能。感谢您的耐心和帮助!

我认为 deploy.prototxt 开头应该是这样的

name: "MyCaffeNet"
input: "X"
input_dim: 1
input_dim: 3
input_dim: 227
input_dim: 227
input: "Meta"
input_dim: 1
input_dim: 1
input_dim: 1
input_dim: 2 # two additional 'features' per image

【问题讨论】:

  • 如果有人也能验证train_val的正确性,我将不胜感激!
  • 基本上,如果我可以将 2 个输入 blob 传递给 caffe forward 函数,例如 caffe('forward',image_data,meta_data) 我的问题就会解决。
  • 对不起,我不能很快确定你的问题。但是如果你想“将train_val.prototxt转换为deploy.prototxt”可以点击HERE

标签: matlab input hdf5 caffe conv-neural-network


【解决方案1】:

变量 input_data 可以是 4-D blob 的向量。函数 prepare_data 提供 4D blob 图像数据,类似地,可以将元数据或任何其他类型的输入充分重塑为 4D blob,然后将其传递给 forward 函数。

input_data = {prepare_data(im),prepare_meta()};

scores = caffe('forward', input_data');

【讨论】:

    猜你喜欢
    • 2015-12-30
    • 2016-08-28
    • 1970-01-01
    • 2023-03-19
    • 2015-11-21
    • 2017-05-22
    • 2015-07-31
    • 2018-12-28
    • 2017-11-15
    相关资源
    最近更新 更多