caffe学习笔记17-find-tuning微调学习

来源:互联网 发布:多益网络线上笔试题目 编辑:程序博客网 时间:2024/05/17 07:33

find-tuning

        对已有模型进行find-tuning(softmax层的变动,只需要微调),比如我们现在有一个1000类的分类模型,但目前我们的需求仅是20类,此时我们不需要重新训练一个模型,只需要将最后一层换成20类的softmax层,然后使用已有数据对原模型进行fine-tuning即可。

1.Fine-tuning微调(train + solver.prototxt + caffemodel) 

  # 微调 CaffeNet 模型的权值以完成风格识别任务(style recognition)
./build/tools/caffe train -solver examples/finetuning_on_flickr_style/solver.prototxt -weights models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel
        注:(变动的层fc8需要改名字,不然还是原来的参数,caffenet结构的输出层的类别数一定要大于我训练集的类别数才可以收敛!)

        比如原来我把图像类别的label设置成1,2,3,改成0,1,2后,最后全连接层的转出改成3就OK了。

2.style recognition调参策略

   1) we will change the name of the last layer form fc8 to fc8_flickr in our prototxt, it will begin training with random weights.

    2)decrease base_lr(初始学习率,在train_val.protxt文件值中) and boost the lr_mult(局部学习倍率,conv和fc层才有) on the newly introduced layer(fc8_flickr).

    3)set stepsize(solver.prototxt,迭代多少次就下降一次学习率) to a lower value. So the learning rate to go down faster

    4)So in the solver.prototxt,we can find the base_lr is 0.001 from 0.01,and the stepsize is become to 20000 from 100000.(重要)

          base_lr: 0.001~0.01 (不改小,loss容易输出non)

          lr_mult: w:10,b:20

          stepsize: 20000~100000


3.进行微调训练分类时,loss一直是87.3365,可能的原因是:
1.标签的问题:
  imagelist中,图像分类的标签label一定要从0开始,
  分类层的 num_output 和 标签的值域 不符合:
a. 要知道imagenet是进行1000类的分类任务,我自己的数据是一个二分类,就一定要把最后‘fc8’InnerProduct的分类层的num_output: 2原来是1000,这个设成自己label的类别总数就可以。 
b. 但是注意同时要修改train.prototxt和deploy.prototxt两个网络配置文件中的num_output
2.可能是学习率太高了 
  另外如果是最初的迭代的loss很小,然后突然变成87.3365。如果是这样,可以尝试一下调低学习率,我开始学习率是0.1,后来调成了0.001,反正就是调小,可以多试几次。

0 0
原创粉丝点击