Caffe:LSTM使用

name: "BasicLstm"

layer {
  name: "data"
  type: "HDF5Data"
  top: "data" //输入数据
  top: "cont" //数据切分(不是1就是0)
  top: "label"//对应的标签
  include {
    phase: TRAIN
  }
  hdf5_data_param {
    source: "./path_to_txt.txt"
    batch_size: 2000
  }
}


layer {
  name: "lstm1"
  type: "LSTM"
  bottom: "data"
  bottom: "cont"
  top: "lstm1"
  recurrent_param {
    num_output: 5 //LSTM1输出的对应维度
    weight_filler {
      type: "uniform"
      min: -0.08
      max: 0.08
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
}

layer {
  name: "lstm2"
  type: "LSTM"
  bottom: "lstm1" 
  bottom: "cont"
  top: "lstm2"
  recurrent_param {
    num_output: 4    //LSTM2输出对应的维度
    weight_filler {
      type: "uniform"
      min: -0.08
      max: 0.08
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
}


layer {
  name: "predict"
  type: "InnerProduct"
  bottom: "lstm2"
  top: "predict"
  param {
    lr_mult: 1
    decay_mult: 1
  }
  param {
    lr_mult: 2
    decay_mult: 0
  }
  inner_product_param {
    num_output: 39    //对应的输出维度用于分类
    weight_filler {
      type: "gaussian"
      std: 0.01
    }
    bias_filler {
      type: "constant"
      value: 0
    }
    axis: 2
  }
}



layer {
  name: "softmax_loss"
  type: "SoftmaxWithLoss" //softmax分类
  bottom: "predict"
  bottom: "label"
  top: "loss"
  loss_weight: 20
  softmax_param {
    axis: 2
  }
  loss_param {
    ignore_label: -1 //忽略标签为-1的数据
  }
}

                                                            

值得注意的是:这里的数据会被直接分成三个数据流方向



猜你喜欢

转载自blog.csdn.net/liyaohhh/article/details/53894797