caffe: Net не сходится при замене AlexNet на VGG16, но все остальное то же самое

Я использую AlexNet для задачи попиксельной регрессии (оценка глубины). Теперь я хотел заменить AlexNet сетью VGG, так как она должна быть лучше.

Это 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, хотя я уменьшал Learning_rate и даже уменьшал mult_lr. У кого-нибудь есть идеи, что еще может быть не так? Я на 100% уверен, что отличаются только файлы .prototxt, все остальное точно такое же.


person Community    schedule 07.03.2017    source источник
comment
попробуйте удалить верхние полносвязные слои. у них слишком много параметров   -  person Shai    schedule 07.03.2017
comment
Я уже снял один верхний слой VGG. Вы говорите, что я должен удалить fc6, чтобы у меня был только один полностью подключенный слой с num_output = 1369, или я должен уменьшить num output fc6 до 1024? @Шай   -  person    schedule 08.03.2017
comment
И второй вопрос, откуда вы знаете такие вещи? Это просто потому, что у вас есть сравнение, или вы в любом случае сказали бы, что мой последний слой имеет 1369 num_outputs, а мой второй имеет 4096, что, очевидно, примерно в 3 раза больше, чем 1369. @Shai   -  person    schedule 08.03.2017
comment
ваша выходная форма 37x37, я полагаю, она тесно связана с входной формой. почему бы не оставить свою сеть полностью сверточной? зачем настаивать на полносвязном слое сверху?   -  person Shai    schedule 08.03.2017
comment
Из-за бумаги, которую я пытался скопировать. Мой ввод 128x128 или 298x298, я пробовал оба варианта. Поэтому, если я увеличу форму своего вывода, например, 60x60. Вопрос заключался в том, почему AlexNet работает отлично, а VGG16 — нет, хотя в документе так и написано. Взгляните на рисунок 1 в ссылка @Shai   -  person    schedule 08.03.2017
comment
попробуйте удалить верхние полносвязные слои. у них слишком много параметров, что вы имеете в виду под этим? Я имею в виду, что AlexNet работает нормально. А вот VGG16 нет, хотя они очень похожи. У тебя есть другие идеи? @Шай   -  person    schedule 08.03.2017
comment
Боюсь, я не   -  person Shai    schedule 08.03.2017


Ответы (1)


Известно, что VGG тяжело обучать с нуля для больших сетей: в статье Симоняна и Зиссермана сказано в разделе 3.1. На практике они сначала обучают «маленькую» (A) конфигурацию со случайными весами, а затем используют эти веса для инициализации больших сетей (C-D-E). Более того, вам может понадобиться больше данных для обучения VGG, чем AlexNet.

В вашем случае вы можете подумать о тонкой настройке VGG16, а не изучать его с нуля. Или позвольте использовать googlenet, который намного легче (и проще в обучении) и обеспечивает аналогичную производительность в нескольких тестируемых мной задачах.

person xiawi    schedule 08.03.2017
comment
О, спасибо, интересный ответ. То, что я пытался сделать, это обучить 100 изображений, которых, по моему мнению, должно быть достаточно, чтобы сеть выучила их наизусть. Хм, тонкая настройка может быть невозможна, так как я хочу использовать вход 128x128. Но я мог бы попробовать больший набор данных. Или я попробую GoogleNet. У вас есть ссылка на googlenet для кафе, так как я думал, что GoogleNet - это действительно глубокая сеть, а не легкая сеть? - person ; 08.03.2017
comment
ссылка если вы имеете в виду эту сеть, то она не очень светлая в моем мнение :D По крайней мере, не по сравнению с сетью VGG. Но спасибо за ответ! - person ; 08.03.2017
comment
С точки зрения количества операций, необходимых для прямого прохода, а также с точки зрения количества весов, я думаю, что он легче: см. здесь, например. - person xiawi; 10.03.2017