首页 > 其他分享 >【调参实战】如何开始你的第一个深度学习调参任务?不妨从图像分类中的学习率入手。...

【调参实战】如何开始你的第一个深度学习调参任务?不妨从图像分类中的学习率入手。...

时间:2022-10-12 17:06:30浏览次数:41  
标签:... name bottom 调参 top param 学习 type mult


大家好,欢迎来到专栏《调参实战》,虽然当前自动化调参研究越来越火,但那其实只是换了一些参数来调,对参数的理解和调试在机器学习相关任务中是最基本的素质,在这个专栏中我们会带领大家一步一步理解和学习调参。

本次主要讲述图像分类项目中的学习率的调参实践。

作者&编辑 | 言有三

【调参实战】如何开始你的第一个深度学习调参任务?不妨从图像分类中的学习率入手。..._ide

本文资源与结果展示

【调参实战】如何开始你的第一个深度学习调参任务?不妨从图像分类中的学习率入手。..._ide_02

本文篇幅:3500字

背景要求:会使用Python和任一深度学习开源框架

附带资料:Caffe代码和数据集一份

同步平台:有三AI知识星球(一周内)

1 项目背景与准备工作

对于很多初入机器学习/深度学习领域的朋友来说,往往只会套用公开的模型,对参数的理解和调试非常欠缺经验,很多经验丰富的老鸟则往往自称“炼丹师”,这就是因为参数的调试对于模型性能的影响确实非常大,轻则损害模型性能,重则甚至使得模型无法正常收敛。

图像分类是整个计算机视觉领域中最基础的任务,实验起来比较简单,在学术界也常用于新模型的比较,因此我们选择图像分类任务来进行调参的学习

本次项目开发需要以下环境:

(1) Linux系统,推荐ubuntu16.04或者ubuntu18.04。使用windows系统也可以完成,但是使用Linux效率更高。

(2) 最好拥有一块显存不低于6G的GPU显卡,如果没有使用CPU进行训练速度较慢。

(3) 安装好的Caffe开源框架。

2 数据集和基准模型

下面我们首先介绍一下数据集和基准模型。

2.1 数据集

在计算机视觉领域中,MNIST,CIFAR,ImageNet常常被用于任务比较,但是它们都有各自的问题。MNIST和CIFAR数据集图像太小,与真实的计算机视觉任务相去甚远。ImageNet数据集超过100G,对于大部分个人研究者来说,不适合拿来快速进行学习验证。

基于此,我们选择了GHIM-10k数据集,这是一个图像检索数据集,包含20个类别,分别是日落,船舶,花卉,建筑物,汽车,山脉,昆虫等自然图像,各个类别拥有较好的多样性,而类别之间也有比较好的区分度。数据集共10000张图像,每个类别包含500张JPEG格式的大小为400×300或300×400的图像。

【调参实战】如何开始你的第一个深度学习调参任务?不妨从图像分类中的学习率入手。..._ide_03

这个数据集有以下几个比较重要的优点。

(1) 数据集规模不大,获取也很容易,所有的读者都可以轻易验证我们的实验结果。

(2) 全部都是真实图片,来自于用户相机拍摄,而且图片清晰度足够高。

(3) 数据集多样性适中,包含了20类场景的自然场景,每一类的场景非常的均匀。图片的尺寸是300*400或者400*300,规格统一,符合大多数深度学习图像任务的处理分辨率,尤其是图像分类。

(4) 数据集类别分布非常的均匀,我们选择数据集的方式也是随机但均匀的选取。我们将数据集按照9:1的比率进行划分,训练集中包含20类,每一类450张图,测试集中包含20类,每一类50张图。

2.2 基准模型

如今深度学习模型已经有了非常多的变种,而它的本质并没有变,就是以卷积+非线性激活函数组成的基础单元进行叠加的模式。

经典的AlexNet是一个8层的网络,包含了5层卷积和3层全连接,这里我们也选择一个类似的模型,包括5层卷积,1层全局池化,1层全连接,因为公开的学术研究表明全连接层并不需要过多。

采用Caffe和Proto协议来定义网络,这样的模型配置可以手动进行,非常适合一边调试一边进行可视化,模型细节如下:

layer {

   name: "data"

   type: "ImageData"

   top: "data"

   top: "label"

   include {

     phase: TRAIN

   }

   transform_param {

     mirror: true

     crop_size: 224

     mean_value: 104.0

     mean_value: 117.0

     mean_value: 124.0

   }

   image_data_param {

     source: "list_train_shuffle.txt"

     batch_size: 16

     shuffle: true

     new_height: 256

     new_width: 256

   }

 }

layer {

   name: "data"

   type: "ImageData"

   top: "data"

   top: "label"

   include {

     phase: TEST

   }

   transform_param {

     mirror: false

     crop_size: 224

     mean_value: 104.0

     mean_value: 117.0

     mean_value: 124.0

   }

   image_data_param {

     source: "list_val_shuffle.txt"

     batch_size: 16

     shuffle: false

     new_height: 224

     new_width: 224

   }

 }

layer {

  bottom: "data"

  top: "conv1"

  name: "conv1"

  type: "Convolution"

  param {

    lr_mult: 1

    decay_mult: 1

  }

  param {

    lr_mult: 2

    decay_mult: 0

  }

  convolution_param {

    num_output: 64

    pad: 1

    kernel_size: 3    

    stride: 2

    weight_filler {

      type: "gaussian"

      std: 0.01

    }

    bias_filler {

      type: "constant"

      value: 0

    }

  }

}

layer {

  bottom: "conv1"

  top: "conv1"

  name: "relu1"

  type: "ReLU"

}

layer {

  bottom: "conv1"

  top: "conv2"

  name: "conv2"

  type: "Convolution"

  param {

    lr_mult: 1

    decay_mult: 1

  }

  param {

    lr_mult: 2

    decay_mult: 0

  }

  convolution_param {

    num_output: 64

    pad: 1

    kernel_size: 3

    stride: 2

    weight_filler {

      type: "gaussian"

      std: 0.01

    }

    bias_filler {

      type: "constant"

      value: 0

    }

  }

}

layer {

  bottom: "conv2"

  top: "conv2"

  name: "relu2"

  type: "ReLU"

}

layer {

  bottom: "conv2"

  top: "conv3"

  name: "conv3"

  type: "Convolution"

  param {

    lr_mult: 1

    decay_mult: 1

  }

  param {

    lr_mult: 2

    decay_mult: 0

  }

  convolution_param {

    num_output: 128

    pad: 1

    kernel_size: 3

    stride: 2

    weight_filler {

      type: "gaussian"

      std: 0.01

    }

    bias_filler {

      type: "constant"

      value: 0

    }

  }

}

layer {

  bottom: "conv3"

  top: "conv3"

  name: "relu3"

  type: "ReLU"

}

layer {

  bottom: "conv3"

  top: "conv4"

  name: "conv4"

  type: "Convolution"

  param {

    lr_mult: 1

    decay_mult: 1

  }

  param {

    lr_mult: 2

    decay_mult: 0

  }

  convolution_param {

    num_output: 128

    pad: 1

    stride: 2

    kernel_size: 3

    weight_filler {

      type: "gaussian"

      std: 0.01

    }

    bias_filler {

      type: "constant"

      value: 0

    }

  }

}

layer {

  bottom: "conv4"

  top: "conv4"

  name: "relu4"

  type: "ReLU"

}

layer {

  bottom: "conv4"

  top: "conv5"

  name: "conv5"

  type: "Convolution"

  param {

    lr_mult: 1

    decay_mult: 1

  }

  param {

    lr_mult: 2

    decay_mult: 0

  }

  convolution_param {

    num_output: 256

    pad: 1

    stride: 2

    kernel_size: 3

    weight_filler {

      type: "gaussian"

      std: 0.01

    }

    bias_filler {

      type: "constant"

      value: 0

    }

  }

}

layer {

  bottom: "conv5"

  top: "conv5"

  name: "relu5"

  type: "ReLU"

}

layer {

    bottom: "conv5"

    top: "pool5"

    name: "pool5"

    type: "Pooling"

    pooling_param {

        kernel_size: 7

        stride: 1

        pool: AVE

    }

}

layer {

  bottom: "pool5"

  top: "fc"

  name: "fc"

  type: "InnerProduct"

    inner_product_param {

        num_output: 20

        weight_filler {

            type: "xavier"

        }

        bias_filler {

            type: "constant"

            value: 0

        }

    }

}

layer {

  name: "accuracy_at_1"

  type: "Accuracy"

  bottom: "fc"

  bottom: "label"

  top: "accuracy_at_1"

  accuracy_param {

    top_k: 1

  }

}

layer {

  name: "accuracy_at_5"

  type: "Accuracy"

  bottom: "fc"

  bottom: "label"

  top: "accuracy_at_5"

  accuracy_param {

    top_k: 5

  }

}

layer {

  bottom: "fc"

  bottom: "label"

  top: "loss"

  name: "loss"

  type: "SoftmaxWithLoss"

}

使用在线工具http://ethereon.github.io/netscope/#/editor

对模型的可视化结果如下:

标签:...,name,bottom,调参,top,param,学习,type,mult
From: https://blog.51cto.com/u_14122493/5751152

相关文章