如何使用 Caffe 进行多任务学习?

数据挖掘 深度学习 多任务学习
2021-10-07 07:45:51

我想知道如何使用Caffe进行多任务学习。我是否应该简单地使用输出层SigmoidCrossEntropyLossEuclideanLoss并定义多个输出?


例如,以下架构是否有效(3 个输出,即同时学习 3 个任务)?

在此处输入图像描述

对应的prototxt文件:

name: "IrisNet"
layer {
  name: "iris"
  type: "HDF5Data"
  top: "data"
  top: "label"
  include {
    phase: TRAIN
  }
  hdf5_data_param {
    source: "iris_train_data.txt"
    batch_size: 1

  }
}

layer {
  name: "iris"
  type: "HDF5Data"
  top: "data"
  top: "label"
  include {
    phase: TEST
  }
  hdf5_data_param {
    source: "iris_test_data.txt"
    batch_size: 1

  }
}

layer {
  name: "ip1"
  type: "InnerProduct"
  bottom: "data"
  top: "ip1"
  param {
    lr_mult: 1
  }
  param {
    lr_mult: 2
  }
  inner_product_param {
    num_output: 50
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
    }
  }
}


layer {
  name: "ip2"
  type: "InnerProduct"
  bottom: "ip1"
  top: "ip2"
  param {
    lr_mult: 1
  }
  param {
    lr_mult: 2
  }
  inner_product_param {
    num_output: 3
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
    }
  }
}




layer {
  name: "loss"
  type: "SigmoidCrossEntropyLoss" 
  # type: "EuclideanLoss" 
  # type: "HingeLoss"  
  bottom: "ip2"
  bottom: "label"
  top: "loss"
}
1个回答

caffe 中的每个 Blob 都可以分配一个非零损失权重。

你可以有任意数量的输出。

这意味着您可以在具有不同目标的相同数据上学习 n 个不同的网络,并为每个损失函数分配它自己的权重。Caffe 负责将所有损失加起来。