void TestForward() {
   LayerParameter layer_param;
   const Dtype kLossWeight = 3.7;
   layer_param.add_loss_weight(kLossWeight);
   FillerParameter data_filler_param;
   data_filler_param.set_std(1);
   GaussianFiller<Dtype> data_filler(data_filler_param);
   FillerParameter targets_filler_param;
   targets_filler_param.set_min(0.0);
   targets_filler_param.set_max(1.0);
   UniformFiller<Dtype> targets_filler(targets_filler_param);
   Dtype eps = tol<Dtype>(2e-2, 5e-2);
   for (int i = 0; i < 100; ++i) {
     // Fill the data vector
     data_filler.Fill(this->blob_bottom_data_);
     // Fill the targets vector
     targets_filler.Fill(this->blob_bottom_targets_);
     SigmoidCrossEntropyLossLayer<Dtype, Dtype> layer(layer_param);
     layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);
     Dtype layer_loss =
         layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);
     const int count = this->blob_bottom_data_->count();
     const int num = this->blob_bottom_data_->num();
     const Dtype* blob_bottom_data = this->blob_bottom_data_->cpu_data();
     const Dtype* blob_bottom_targets =
         this->blob_bottom_targets_->cpu_data();
     Dtype reference_loss = kLossWeight * SigmoidCrossEntropyLossReference(
         count, num, blob_bottom_data, blob_bottom_targets);
     EXPECT_NEAR(reference_loss, layer_loss, eps) << "debug: trial #" << i;
   }
 }
 void TestForward() {
   LayerParameter layer_param;
   FillerParameter data_filler_param;
   data_filler_param.set_std(1);
   GaussianFiller<Dtype> data_filler(data_filler_param);
   FillerParameter targets_filler_param;
   targets_filler_param.set_min(-1);
   targets_filler_param.set_max(1);
   UniformFiller<Dtype> targets_filler(targets_filler_param);
   const int count = this->blob_bottom_data_->count();
   Dtype eps = 2e-2;
   for (int i = 0; i < 10; ++i) {
     // Fill the data vector
     data_filler.Fill(this->blob_bottom_data_);
     // Fill the targets vector
     targets_filler.Fill(this->blob_bottom_targets_);
     // Make negatives into -1 and positives into 1
     Dtype* targets = this->blob_bottom_targets_->mutable_cpu_data();
     caffe_cpu_sign(count, targets, targets);
     MultiLabelLossLayer<Dtype> layer(layer_param);
     layer.SetUp(this->blob_bottom_vec_, &(this->blob_top_vec_));
     Dtype layer_loss =
         layer.Forward(this->blob_bottom_vec_, &(this->blob_top_vec_));
     const int num = this->blob_bottom_data_->num();
     const Dtype* blob_bottom_data = this->blob_bottom_data_->cpu_data();
     const Dtype* blob_bottom_targets =
         this->blob_bottom_targets_->cpu_data();
     Dtype reference_loss = this->SigmoidMultiLabelLossReference(
         count, num, blob_bottom_data, blob_bottom_targets);
     EXPECT_NEAR(reference_loss, layer_loss, eps) << "debug: trial #" << i;
   }
 }
 SigmoidCrossEntropyLossLayerTest()
     : blob_bottom_data_(new Blob<Dtype>(10, 5, 1, 1)),
       blob_bottom_targets_(new Blob<Dtype>(10, 5, 1, 1)) {
   // Fill the data vector
   FillerParameter data_filler_param;
   data_filler_param.set_std(1);
   GaussianFiller<Dtype> data_filler(data_filler_param);
   data_filler.Fill(blob_bottom_data_);
   blob_bottom_vec_.push_back(blob_bottom_data_);
   // Fill the targets vector
   FillerParameter targets_filler_param;
   targets_filler_param.set_min(0);
   targets_filler_param.set_max(1);
   UniformFiller<Dtype> targets_filler(targets_filler_param);
   targets_filler.Fill(blob_bottom_targets_);
   blob_bottom_vec_.push_back(blob_bottom_targets_);
 }
 MultiLabelLossLayerTest()
     : blob_bottom_data_(new Blob<Dtype>(10, 5, 1, 1)),
       blob_bottom_targets_(new Blob<Dtype>(10, 5, 1, 1)) {
   // Fill the data vector
   FillerParameter data_filler_param;
   data_filler_param.set_std(1);
   GaussianFiller<Dtype> data_filler(data_filler_param);
   data_filler.Fill(blob_bottom_data_);
   blob_bottom_vec_.push_back(blob_bottom_data_);
   // Fill the targets vector
   FillerParameter targets_filler_param;
   targets_filler_param.set_min(-1);
   targets_filler_param.set_max(1);
   UniformFiller<Dtype> targets_filler(targets_filler_param);
   targets_filler.Fill(blob_bottom_targets_);
   int count = blob_bottom_targets_->count();
   caffe_cpu_sign(count, this->blob_bottom_targets_->cpu_data(),
     this->blob_bottom_targets_->mutable_cpu_data());
   blob_bottom_vec_.push_back(blob_bottom_targets_);
 }
 MilLossLayerTest()
     : blob_bottom_data_(new Blob<Dtype>(1, 5, 1, 1)),
       blob_bottom_targets_(new Blob<Dtype>(1, 5, 1, 1)),
       blob_top_loss_(new Blob<Dtype>()) {
   // Fill the data vector
   FillerParameter data_filler_param;
   data_filler_param.set_min(0);
   data_filler_param.set_max(1);
   UniformFiller<Dtype> data_filler(data_filler_param);
   data_filler.Fill(blob_bottom_data_);
   blob_bottom_vec_.push_back(blob_bottom_data_);
   // Fill the targets vector
   FillerParameter targets_filler_param;
   targets_filler_param.set_min(0);
   targets_filler_param.set_max(1);
   UniformFiller<Dtype> targets_filler(targets_filler_param);
   targets_filler.Fill(blob_bottom_targets_);
   blob_bottom_vec_.push_back(blob_bottom_targets_);
   blob_top_vec_.push_back(blob_top_loss_);
   propogate_down_.push_back(true);
 }