Deep learning caffe:当用VGG16替换AlexNet时,Net不会收敛,但其他一切都是一样的

Deep learning caffe:当用VGG16替换AlexNet时,Net不会收敛,但其他一切都是一样的,deep-learning,caffe,vgg-net,Deep Learning,Caffe,Vgg Net,我一直在使用AlexNet进行像素回归任务(深度估计)。现在我想用VGG网络替换AlexNet,因为它应该更好 这是我使用的AlexNet: layer { name: "train-data" type: "Data" top: "data" include { phase: TRAIN } data_param { source: "../data/.." batch_size: 4 backend: LMDB } transf

我一直在使用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
}
学习率为:0.0005


训练AlexNet时,损失收敛到大约5,使用VGG时,网络根本不收敛。它始终保持在30,尽管我一直在降低学习率,甚至降低mult lr。有人知道还有什么不对劲吗?我100%确信,只有.prototxt文件不同,其他所有文件都完全相同。

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


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

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


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

尝试移除顶部完全连接的层。他们有太多的参数,我已经删除了VGG的一个顶层。你是说我应该删除“fc6”一个,这样我只有一个num_output=1369的完全连接层,还是应该将num output fc6减少到1024@第二个问题,你是怎么知道这些的?这仅仅是因为你有比较,或者你会说,无论如何,因为我的最后一层有1369个num_输出,但我的第二层有4096个,很明显是1369的3倍大@Shaiyour的输出形状是37x37,我想它与输入形状密切相关。为什么不让你的网络完全卷积呢?为什么要坚持在上面有一个完全连接的层呢?因为我试图复制一篇论文。我的输入是128x128或298x298我已经尝试了这两种方法。因此,如果我改变输出的形状,例如60x60。问题是,为什么AlexNet工作得很好,而VGG16却不是,即使报纸上这么说。请看@Shaitry中的图1,移除顶部完全连接的层。他们有太多的参数,我已经删除了VGG的一个顶层。你是说我应该删除“fc6”一个,这样我只有一个num_output=1369的完全连接层,还是应该将num output fc6减少到1024@第二个问题,你是怎么知道这些的?这仅仅是因为你有比较,或者你会说,无论如何,因为我的最后一层有1369个num_输出,但我的第二层有4096个,很明显是1369的3倍大@Shaiyour的输出形状是37x37,我想它与输入形状密切相关。为什么不让你的网络完全卷积呢?为什么要坚持在上面有一个完全连接的层呢?因为我试图复制一篇论文。我的输入是128x128或298x298我已经尝试了这两种方法。因此,如果我改变输出的形状,例如60x60。问题是,为什么AlexNet工作得很好,而VGG16却不是,即使报纸上这么说。看看@ShaiOh谢谢你的图1,这是一个有趣的答案。我一直试图做的是训练100张图片,我认为这些图片应该足够小,可以通过网络背诵。Hm微调可能不可能,因为我想使用128x128的输入。但我可能会尝试更大的数据集。或者我会试试谷歌网。你有caffe的googlenet的链接吗?因为我认为googlenet是一个真正的深网而不是一个“轻”网。如果你是指那个网,那么在我看来它不是很轻:D至少与VGG网相比不是。但是谢谢你的回答!就向前传球所需的操作次数以及重量而言,我认为它更轻:例如,见。哦,谢谢你,这是一个有趣的答案。我一直试图做的是训练100张图片,我认为这些图片应该足够小,可以通过网络背诵。Hm微调可能不可能,因为我想使用128x128的输入。但我可能会尝试更大的数据集。或者我会试试谷歌网。你有caffe的googlenet的链接吗?因为我认为googlenet是一个真正的深网而不是一个“轻”网。如果你是指那个网,那么在我看来它不是很轻:D至少与VGG网相比不是。但是谢谢你的回答!就向前传球所需的操作次数以及重量而言,我认为它更轻:例如。