【问题标题】:caffe: Net not converging when replacing AlexNet with VGG16 but everything else is the samecaffe:用 VGG16 替换 AlexNet 时网络不收敛,但其他一切都一样
【发布时间】:2017-07-27 22:23:33
【问题描述】:

我一直在使用 AlexNet 进行逐像素回归任务(深度估计)。现在我想用 VGG 网络替换 AlexNet,因为它应该会更好。

这是我使用的 AlexNet:

layer {
  name: "train-data"
  type: "Data"
  top: "data"
  include {
    phase: TRAIN
  }
  data_param {
    source: "../data/.."
    batch_size: 4
    backend: LMDB
  }
  transform_param {
     mean_value: 127
  }
}
layer {
  name: "train-depth"
  type: "Data"
  top: "gt"
  include {
    phase: TRAIN
  }
  transform_param {
    # feature scaling coefficient: this maps [0, 255] to [0, 1]
    scale: 0.00390625
  }
  data_param {
    source: "../data/.."
    batch_size: 4
    backend: LMDB
  }
}
layer {
  name: "val-data"
  type: "Data"
  top: "data"
  include {
    phase: TEST
  }
  data_param {
    source: "../data/.."
    batch_size: 4
    backend: LMDB
  }
  transform_param {
     mean_value: 127
  }
}
layer {
  name: "val-depth"
  type: "Data"
  top: "gt"
  include {
    phase: TEST
  }
  transform_param {
    # feature scaling coefficient: this maps [0, 255] to [0, 1]
    scale: 0.00390625
  }
  data_param {
    source: "../data/.."
    batch_size: 4
    backend: LMDB
  }
}

# CONVOLUTIONAL
layer {
  name: "conv1"
  type: "Convolution"
  bottom: "data"
  top: "conv1"
  param {
    lr_mult: 0.02
    decay_mult: 1
  }
  param {
    lr_mult:  0.02
    decay_mult: 0
  }
  convolution_param {
    num_output: 96
    kernel_size: 11
    stride: 4
    weight_filler {
      type: "gaussian"
      std: 0.01
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
}
layer {
  name: "relu1"
  type: "ReLU"
  bottom: "conv1"
  top: "conv1"
}
layer {
  name: "norm1"
  type: "LRN"
  bottom: "conv1"
  top: "norm1"
  lrn_param {
    local_size: 5
    alpha: 0.0001
    beta: 0.75
  }
}
layer {
  name: "pool1"
  type: "Pooling"
  bottom: "norm1"
  top: "pool1"
  pooling_param {
    pool: MAX
    kernel_size: 3
    stride: 2
  }
}
layer {
  name: "conv2"
  type: "Convolution"
  bottom: "pool1"
  top: "conv2"
  param {
    lr_mult:  0.02
    decay_mult: 1
  }
  param {
    lr_mult:  0.02
    decay_mult: 0
  }
  convolution_param {
    engine: CAFFE
    num_output: 256
    pad: 2
    kernel_size: 5
    group: 2
    weight_filler {
      type: "gaussian"
      std: 0.01
    }
    bias_filler {
      type: "constant"
      value: 0.1
    }
  }
}
layer {
  name: "relu2"
  type: "ReLU"
  bottom: "conv2"
  top: "conv2"
}
layer {
  name: "norm2"
  type: "LRN"
  bottom: "conv2"
  top: "norm2"
  lrn_param {
    local_size: 5
    alpha: 0.0001
    beta: 0.75
  }
}
layer {
  name: "conv3"
  type: "Convolution"
  bottom: "norm2"
  top: "conv3"
  param {
    lr_mult:  0.02
    decay_mult: 1
  }
  param {
    lr_mult:  0.02
    decay_mult: 0
  }
  convolution_param {
    num_output: 384
    pad: 1
    kernel_size: 3
    weight_filler {
      type: "gaussian"
      std: 0.01
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
}
layer {
  name: "relu3"
  type: "ReLU"
  bottom: "conv3"
  top: "conv3"
}
layer {
  name: "conv4"
  type: "Convolution"
  bottom: "conv3"
  top: "conv4"
  param {
    lr_mult:  0.02
    decay_mult: 1
  }
  param {
    lr_mult:  0.02
    decay_mult: 0
  }
  convolution_param {
    num_output: 384
    pad: 1
    kernel_size: 3
    group: 2
    weight_filler {
      type: "gaussian"
      std: 0.01
    }
    bias_filler {
      type: "constant"
      value: 0.1
    }
  }
}
layer {
  name: "relu4"
  type: "ReLU"
  bottom: "conv4"
  top: "conv4"
}
layer {
  name: "conv5"
  type: "Convolution"
  bottom: "conv4"
  top: "conv5"
  param {
    lr_mult:  0.02
    decay_mult: 1
  }
  param {
    lr_mult:  0.02
    decay_mult: 0
  }
  convolution_param {
    num_output: 256
    pad: 1
    kernel_size: 3
    group: 2
    weight_filler {
      type: "gaussian"
      std: 0.01
    }
    bias_filler {
      type: "constant"
      value: 0.1
    }
  }
}
layer {
  name: "relu5"
  type: "ReLU"
  bottom: "conv5"
  top: "conv5"
}
layer {
  name: "pool5"
  type: "Pooling"
  bottom: "conv5"
  top: "pool5"
  pooling_param {
    pool: MAX
    kernel_size: 3
    stride: 2
  }
}

# MAIN

layer {
  name: "fc-main"
  type: "InnerProduct"
  bottom: "pool5"
  top: "fc-main"
  param {
    decay_mult: 1
  }
  param {
    decay_mult: 0
  }
  inner_product_param {
    num_output: 1024
    weight_filler {
      type: "xavier"
      std: 0.005
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
}
layer {
  name: "relu6"
  type: "ReLU"
  bottom: "fc-main"
  top: "fc-main"
  relu_param {
    engine: CAFFE
  }
}
layer {
  name: "drop6"
 type: "Dropout"
  bottom: "fc-main"
  top: "fc-main"
  dropout_param {
    dropout_ratio: 0.5
  }
}
layer {
  name: "fc-depth"
  type: "InnerProduct"
  bottom: "fc-main"
  top: "fc-depth"
  param {
    decay_mult: 1
    lr_mult:  0.2
  }
  param {
    lr_mult:  0.2
    decay_mult: 0
  }
  inner_product_param {
    num_output: 1369
    weight_filler {
      type: "gaussian"
      std: 0.001
    }
    bias_filler {
      type: "constant"
      value: 0.5
    }
  }
}
layer {
    name: "reshape"
    type: "Reshape"
    bottom: "fc-depth"
    top: "depth"
    reshape_param {
      shape {
        dim: 0  # copy the dimension from below
        dim: 1
        dim: 37
        dim: 37 # infer it from the other dimensions
      }
    }
  }



layer {
  name: "loss"
  type: "EuclideanLoss"
  bottom: "depth"
  bottom: "gt"
  top: "loss"
  loss_weight: 1
}

这是我正在使用的 VGG:

layer {
  bottom: "data"
  top: "conv1_1"
  name: "conv1_1"
  type: "Convolution"
  param {
      lr_mult: 0.001
      decay_mult: 1
    }
    param {
      lr_mult: 0.001
      decay_mult: 0
  }
  convolution_param {
    num_output: 64
    pad: 1
    kernel_size: 3
    weight_filler {
      type: "gaussian"
      std: 0.01
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
}
layer {
  bottom: "conv1_1"
  top: "conv1_1"
  name: "relu1_1"
  type: "ReLU"
}
layer {
  bottom: "conv1_1"
  top: "conv1_2"
  name: "conv1_2"
  type: "Convolution"
  param {
      lr_mult: 0.001
      decay_mult: 1
    }
    param {
      lr_mult: 0.001
      decay_mult: 0
  }
  convolution_param {
    num_output: 64
    pad: 1
    kernel_size: 3
    weight_filler {
      type: "gaussian"
      std: 0.01
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
}
layer {
  bottom: "conv1_2"
  top: "conv1_2"
  name: "relu1_2"
  type: "ReLU"
}
layer {
  bottom: "conv1_2"
  top: "pool1"
  name: "pool1"
  type: "Pooling"
  pooling_param {
    pool: MAX
    kernel_size: 2
    stride: 2
  }
}
layer {
  bottom: "pool1"
  top: "conv2_1"
  name: "conv2_1"
  type: "Convolution"
  param {
      lr_mult: 0.001
      decay_mult: 1
    }
    param {
      lr_mult: 0.001
      decay_mult: 0
  }
  convolution_param {
    num_output: 128
    pad: 1
    kernel_size: 3
    weight_filler {
      type: "gaussian"
      std: 0.01
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
}
layer {
  bottom: "conv2_1"
  top: "conv2_1"
  name: "relu2_1"
  type: "ReLU"
}
layer {
  bottom: "conv2_1"
  top: "conv2_2"
  name: "conv2_2"
  type: "Convolution"
  param {
      lr_mult: 0.001
      decay_mult: 1
    }
    param {
      lr_mult: 0.001
      decay_mult: 0
  }
  convolution_param {
    num_output: 128
    pad: 1
    kernel_size: 3
    weight_filler {
      type: "gaussian"
      std: 0.01
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
}
layer {
  bottom: "conv2_2"
  top: "conv2_2"
  name: "relu2_2"
  type: "ReLU"
}
layer {
  bottom: "conv2_2"
  top: "pool2"
  name: "pool2"
  type: "Pooling"
  pooling_param {
    pool: MAX
    kernel_size: 2
    stride: 2
  }
}
layer {
  bottom: "pool2"
  top: "conv3_1"
  name: "conv3_1"
  type: "Convolution"
  param {
      lr_mult: 0.001
      decay_mult: 1
    }
    param {
      lr_mult: 0.001
      decay_mult: 0
  }
  convolution_param {
    num_output: 256
    pad: 1
    kernel_size: 3
    weight_filler {
      type: "gaussian"
      std: 0.01
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
}
layer {
  bottom: "conv3_1"
  top: "conv3_1"
  name: "relu3_1"
  type: "ReLU"
}
layer {
  bottom: "conv3_1"
  top: "conv3_2"
  name: "conv3_2"
  type: "Convolution"
  param {
      lr_mult: 0.001
      decay_mult: 1
    }
    param {
      lr_mult: 0.001
      decay_mult: 0
  }
  convolution_param {
    num_output: 256
    pad: 1
    kernel_size: 3
    weight_filler {
      type: "gaussian"
      std: 0.01
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
}
layer {
  bottom: "conv3_2"
  top: "conv3_2"
  name: "relu3_2"
  type: "ReLU"
}
layer {
  bottom: "conv3_2"
  top: "conv3_3"
  name: "conv3_3"
  type: "Convolution"
  param {
      lr_mult: 0.001
      decay_mult: 1
    }
    param {
      lr_mult: 0.001
      decay_mult: 0
  }
  convolution_param {
    num_output: 256
    pad: 1
    kernel_size: 3
    weight_filler {
      type: "gaussian"
      std: 0.01
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
}
layer {
  bottom: "conv3_3"
  top: "conv3_3"
  name: "relu3_3"
  type: "ReLU"
}
layer {
  bottom: "conv3_3"
  top: "pool3"
  name: "pool3"
  type: "Pooling"
  pooling_param {
    pool: MAX
    kernel_size: 2
    stride: 2
  }
}
layer {
  bottom: "pool3"
  top: "conv4_1"
  name: "conv4_1"
  type: "Convolution"
  param {
      lr_mult: 0.001
      decay_mult: 1
    }
    param {
      lr_mult: 0.001
      decay_mult: 0
  }
  convolution_param {
    num_output: 512
    pad: 1
    kernel_size: 3
    weight_filler {
      type: "gaussian"
      std: 0.01
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
}
layer {
  bottom: "conv4_1"
  top: "conv4_1"
  name: "relu4_1"
  type: "ReLU"
}
layer {
  bottom: "conv4_1"
  top: "conv4_2"
  name: "conv4_2"
  type: "Convolution"
  param {
      lr_mult: 0.001
      decay_mult: 1
    }
    param {
      lr_mult: 0.001
      decay_mult: 0
  }
  convolution_param {
    num_output: 512
    pad: 1
    kernel_size: 3
    weight_filler {
      type: "gaussian"
      std: 0.01
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
}
layer {
  bottom: "conv4_2"
  top: "conv4_2"
  name: "relu4_2"
  type: "ReLU"
}
layer {
  bottom: "conv4_2"
  top: "conv4_3"
  name: "conv4_3"
  type: "Convolution"
  param {
      lr_mult: 0.001
      decay_mult: 1
    }
    param {
      lr_mult: 0.001
      decay_mult: 0
  }
  convolution_param {
    num_output: 512
    pad: 1
    kernel_size: 3
    weight_filler {
      type: "gaussian"
      std: 0.01
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
}
layer {
  bottom: "conv4_3"
  top: "conv4_3"
  name: "relu4_3"
  type: "ReLU"
}
layer {
  bottom: "conv4_3"
  top: "pool4"
  name: "pool4"
  type: "Pooling"
  pooling_param {
    pool: MAX
    kernel_size: 2
    stride: 2
  }
}
layer {
  bottom: "pool4"
  top: "conv5_1"
  name: "conv5_1"
  type: "Convolution"
  param {
      lr_mult: 0.001
      decay_mult: 1
    }
    param {
      lr_mult: 0.001
      decay_mult: 0
  }
  convolution_param {
    num_output: 512
    pad: 1
    kernel_size: 3
    weight_filler {
      type: "gaussian"
      std: 0.01
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
}
layer {
  bottom: "conv5_1"
  top: "conv5_1"
  name: "relu5_1"
  type: "ReLU"
}
layer {
  bottom: "conv5_1"
  top: "conv5_2"
  name: "conv5_2"
  type: "Convolution"
  param {
      lr_mult: 0.001
      decay_mult: 1
    }
    param {
      lr_mult: 0.001
      decay_mult: 0
  }
  convolution_param {
    num_output: 512
    pad: 1
    kernel_size: 3
    weight_filler {
      type: "gaussian"
      std: 0.01
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
}
layer {
  bottom: "conv5_2"
  top: "conv5_2"
  name: "relu5_2"
  type: "ReLU"
}
layer {
  bottom: "conv5_2"
  top: "conv5_3"
  name: "conv5_3"
  type: "Convolution"
  param {
      lr_mult: 0.001
      decay_mult: 1
    }
    param {
      lr_mult: 0.001
      decay_mult: 0
  }
  convolution_param {
    num_output: 512
    pad: 1
    kernel_size: 3
    weight_filler {
      type: "gaussian"
      std: 0.01
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
}
layer {
  bottom: "conv5_3"
  top: "conv5_3"
  name: "relu5_3"
  type: "ReLU"
}
layer {
  bottom: "conv5_3"
  top: "pool5"
  name: "pool5"
  type: "Pooling"
  pooling_param {
    pool: MAX
    kernel_size: 2
    stride: 2
  }
}
layer {
  bottom: "pool5"
  top: "fc6"
  name: "fc6"
  type: "InnerProduct"
  param {
      lr_mult: 0.1
      decay_mult: 1
    }
    param {
      lr_mult: 0.1
      decay_mult: 0
  }
  inner_product_param {
    num_output: 4096
    weight_filler {
      type: "gaussian"
      std: 0.001
    }
    bias_filler {
      type: "constant"
      value: 0.5
    }
  }
}
layer {
  bottom: "fc6"
  top: "fc6"
  name: "relu6"
  type: "ReLU"
  relu_param {
    engine: CAFFE
  }
}

layer {
  name: "drop6"
  type: "Dropout"
  bottom: "fc6"
  top: "fc6"
  dropout_param {
    dropout_ratio: 0.5
  }
}

layer {
  bottom: "fc6"
  top: "fc7"
  name: "fc7"
  type: "InnerProduct"
  param {
      lr_mult: 0.1
      decay_mult: 1
    }
    param {
      lr_mult: 0.1
      decay_mult: 0
  }
  inner_product_param {
    num_output: 1369
    weight_filler {
      type: "gaussian"
      std: 0.001
    }
    bias_filler {
      type: "constant"
      value: 0.5
    }
  }
}

layer {
    name: "reshape"
    type: "Reshape"
    bottom: "fc7"
    top: "depth"
    reshape_param {
      shape {
        dim: 0  # copy the dimension from below
        dim: 1
        dim: 37
        dim: 37 # infer it from the other dimensions
      }
    }
  }

layer {
  name: "loss"
  type: "EuclideanLoss"
  bottom: "depth"
  bottom: "gt"
  top: "loss"
  loss_weight: 1
}

learning_rate 为:0.0005

在训练 AlexNet 时,损失收敛到大约 5,而在使用 VGG 时,网络根本不收敛。它始终保持在 30,即使我一直在降低 learning_rate 甚至降低 mult_lr。有谁知道还有什么问题?我 100% 确定只有 .prototxt 文件不同,其他一切都完全相同。

【问题讨论】:

  • 尝试移除顶部的全连接层。参数太多
  • 我已经移除了 VGG 的顶层。你是说我应该删除“fc6”,这样我就只有一个 num_output=1369 的全连接层,还是应该将 num 输出 fc6 减少到 1024? @Shai
  • 第二个问题你怎么知道那种东西?是因为你有比较还是你会说反正我的最后一层有 1369 num_outputs 但我的第二层有 4096 显然是 1369 的 3 倍。@Shai
  • 您的输出形状是 37x37 我想它与输入形状密切相关。为什么不把你的网络作为一个完全卷积的网络呢?为什么要坚持在顶部使用全连接层?
  • 因为我试图复印的一篇论文。我的输入是 128x128 或 298x298 我都试过了。因此,如果我增加输出的形状,例如 60x60。问题是为什么 AlexNet 工作得很好,而 VGG16 却没有,尽管论文这么说。看看link@Shai中的图1

标签: deep-learning caffe vgg-net


【解决方案1】:

众所周知,VGG 很难从头开始训练大型网络:在 Simonyan 和 Zisserman 的论文中,在第 3.1 节中说过。在实践中,他们首先训练具有随机权重的“小”(A)配置,然后使用这些权重来初始化更大的网络(C-D-E)。此外,您可能需要比 AlexNet 更多的数据来训练 VGG。

在您的情况下,您可以考虑微调 VGG16,而不是从头开始学习。或者让我们使用更轻量(并且更容易训练)的 googlenet,并在我测试的几个问题上获得类似的性能。

【讨论】:

  • 哦,谢谢,这是一个有趣的答案。我一直在尝试做的是训练 100 张图像,我认为这些图像应该足够少,可以通过网络记住。嗯微调可能是不可能的,因为我想使用 128x128 的输入。但我可能会尝试更大的数据集。或者我会试试 GoogleNet。你有 googlenet for caffe 的链接吗,因为我认为 GoogleNet 是一个非常深的网络,而不是一个“轻”网络
  • link 如果您的意思是网络,那么在我看来它不是很轻:D 至少与 VGG 网络相比不是。不过谢谢你的回答!
  • 就前向传球所需的操作数量以及权重数量而言,我认为它更轻:例如参见here
猜你喜欢
  • 1970-01-01
  • 2012-03-03
  • 2020-04-26
  • 2016-05-13
  • 1970-01-01
  • 2014-06-24
  • 2017-02-08
  • 1970-01-01
  • 2011-12-10
相关资源
最近更新 更多