使用ResNet的caffe实现进行图片分类
A CivilNet Maintainer
背景
图片分类是深度学习在图像领域的初级应用,更高阶的应用如目标检测、图像分割等。那就从最初级的应用-图像分类做起吧。
准备数据
准备数据包括训练集和测试集。
比方说gemfield要做个224分类的应用,那么先准备好224个子目录,每个目录里放的是同一分类的照片:
-
gemfield@ai:/bigdata/video_annotation_web/annotation_output$ find . -type f
-
./0/wzry223.mp4_7670_1051_385_126_140.jpg
-
./0/wzry110.mp4_2740_562_293_160_148.jpg
-
......
-
./65/wzry223.mp4_7670_1021_385_126_140.jpg
-
./65/wzry110.mp4_2740_572_293_160_148.jpg
-
......
-
./153/wzry61.mp4_1240_561_298_182_150.jpg
-
./153/wzry73.mp4_3660_792_424_280_238.jpg
-
......
-
./223/wzry73.mp4_3510_830_426_252_232.jpg
-
./223/wzry73.mp4_1450_820_434_274_240.jpg
那么如果我已有的照片目录并不是从0开始按照数字顺序排列的,而是一些用中文命名的目录,那怎么办呢?使用下面的shell命令可以做到:
-
#先保存个映射表
-
num=0;for f in $(ls);do echo "$num,$f" >> /tmp/gemfield.dict;num=$((num + 1));done
-
#改文件夹的名字
-
num=0;for f in $(ls);do mv $f $num ;num=$((num + 1));done
224分类的label是0到223,一定要从0开始,caffe框架决定的。那现在有了224个目录的照片,怎么生成对应的label文件呢?可以使用下面的python代码:
-
gemfield@ai:/bigdata/video_annotation_web/annotation_output$ find . -type f > ../gemfield.txt
-
gemfield@ai:/bigdata/video_annotation_web/annotation_output$ cd ..
-
gemfield@ai:/bigdata/video_annotation_web$ python
-
Python 2.7.13 (default, Nov 23 2017, 15:37:09)
-
[GCC 6.3.0 20170406] on linux2
-
Type "help", "copyright", "credits" or "license" for more information.
-
>>> l = open('gemfield.txt').readlines()
-
>>> ll = [x.strip() + ' ' + x.split('/')[1] + '\n' for x in l]
-
>>> import random
-
>>> random.shuffle(ll)
-
>>> with open('gemfield.lst', 'w') as f:
-
... f.writelines(ll)
-
...
-
>>>
现在label文件也生成了,我们需要将其分为训练集和测试集,针对本次实验,gemfield按照6:1的比例划分了训练集和测试集;这个划分过程不用动那224个图片目录,而只需要将上面的那个gemfield.txt按照6:1的比例划分为2个label文件:train.lst和val.lst 文件:
-
gemfield@ai:/bigdata/video_annotation_web$ tail -24319 gemfield.lst > val.lst
-
gemfield@ai:/bigdata/video_annotation_web$ head -120000 gemfield.lst > train.lst
准备Caffe环境
下载官方的caffe仓库,修改makefile.config的参数,编译就ok了。参考本专栏的前述文章。
准备ResNet的网络
Gemfield使用的是ResNet50版本:
KaimingHe/deep-residual-networks
这个下载下来的prototxt文件,拷贝2份出来,一份命名为ResNet-50-deploy-by-gemfield.prototxt,这个不作修改;另一份命名为ResNet-50-train-val-by-gemfield.prototxt,然后这个网络结构文件要进行修改,修改部分如下所示:
第一部分:修改input部分:
ResNet-50-deploy-by-gemfield.prototxt中的
-
input: "data"
-
input_dim: 1
-
input_dim: 3
-
input_dim: 224
-
input_dim: 224
改为ResNet-50-train-val-by-gemfield.prototxt中的
-
layer {
-
name: "data"
-
type: "Data"
-
top: "data"
-
top: "label"
-
include {
-
phase: TRAIN
-
}
-
transform_param {
-
mirror: false
-
# crop_size: 224
-
mean_value: 0
-
mean_value: 0
-
mean_value: 0
-
}
-
data_param {
-
source: "wzry_224_train_lmdb"
-
batch_size: 16
-
backend: LMDB
-
}
-
}
-
layer {
-
name: "data"
-
type: "Data"
-
top: "data"
-
top: "label"
-
include {
-
phase: TEST
-
}
-
transform_param {
-
mirror: false
-
# crop_size: 224
-
mean_value: 0
-
mean_value: 0
-
mean_value: 0
-
}
-
data_param {
-
source: "wzry_224_val_lmdb"
-
batch_size: 1
-
backend: LMDB
-
}
-
}
第二部分:
1,将全连接层的fc1000改为fc224,因为我们的分类是224种;
2,将softmax改为softmax with loss,因为训练的时候必须有loss作为反馈;
将ResNet-50-deploy-by-gemfield.prototxt中的
-
layer {
-
bottom: "pool5"
-
top: "fc1000"
-
name: "fc1000"
-
type: "InnerProduct"
-
inner_product_param {
-
num_output: 1000
-
}
-
}
-
layer {
-
bottom: "fc1000"
-
top: "prob"
-
name: "prob"
-
type: "Softmax"
-
}
改为ResNet-50-train-val-by-gemfield.prototxt中的
-
layer {
-
bottom: "pool5"
-
top: "fc224"
-
name: "fc224"
-
type: "InnerProduct"
-
inner_product_param {
-
num_output: 224
-
}
-
}
-
layer {
-
bottom: "fc224"
-
bottom: "label"
-
name: "loss"
-
type: "SoftmaxWithLoss"
-
top: "loss"
-
}
-
layer {
-
bottom: "fc224"
-
bottom: "label"
-
top: "acc/top-1"
-
name: "acc/top-1"
-
type: "Accuracy"
-
include {
-
phase: TEST
-
}
-
}
第三部分:
ResNet的输入参数是224x224,因此,在下面生成lmdb的时候,要将图像resize成224x224,除非你的图片本来就是224x224。
准备solver.prototxt
-
net: "ResNet-50-train-val-by-gemfield.prototxt"
-
#每次测试跑多少次迭代,照片数量/test的batch_size
-
test_iter: 24000
-
#每多少次迭代进行一次测试
-
test_interval: 2000
-
test_initialization: false
-
#初始的学习率
-
base_lr: 0.001
-
#学习率的下降策略
-
lr_policy: "step"
-
gamma: 0.1
-
stepsize: 5000
-
#每迭代多少次打印一次loss信息
-
display: 100
-
#最多迭代多少次
-
max_iter: 75000
-
#梯度下降策略,90%依赖这次,10%依赖上次
-
momentum: 0.9
-
#正则项的比重
-
weight_decay: 0.0001
-
#迭代多少次生成一次中间的caffemodel
-
snapshot: 5000
-
#caffemodel的前缀
-
snapshot_prefix: "models/resnet_gemfield_cls224"
-
solver_mode: GPU
生成lmdb
使用Caffe自带的工具convert_imageset来生成lmdb文件(在caffe仓库目录里),注意,resnet的输入都是224x224,所以在制作数据集的时候需要进行resize;其次,convert_imageset会简单的将下列命令中的root目录"./"和train.lst中的文件路径进行直接的字符串拼接;再次,生成的lmdb目录不能已经存在。
先生成训练集:
-
gemfield@ai:~$ convert_imageset -resize_height 224 -resize_width 224 ./ train.lst wzry_224_train_lmdb
-
I0113 12:13:44.050431 27 convert_imageset.cpp:89] A total of 120000 images.
-
E0113 12:13:44.051177 27 common.cpp:114] Cannot create Cublas handle. Cublas won't be available.
-
E0113 12:13:44.051475 27 common.cpp:121] Cannot create Curand generator. Curand won't be available.
-
I0113 12:13:44.051504 27 db_lmdb.cpp:35] Opened lmdb wzry_224_train_lmdb
-
I0113 12:13:45.643923 27 convert_imageset.cpp:147] Processed 1000 files.
-
I0113 12:13:47.270226 27 convert_imageset.cpp:147] Processed 2000 files.
-
I0113 12:13:48.633996 27 convert_imageset.cpp:147] Processed 3000 files.
-
I0113 12:13:50.994860 27 convert_imageset.cpp:147] Processed 4000 files.
-
I0113 12:13:52.172212 27 convert_imageset.cpp:147] Processed 5000 files.
-
I0113 12:13:53.344650 27 convert_imageset.cpp:147] Processed 6000 files.
-
I0113 12:13:55.925756 27 convert_imageset.cpp:147] Processed 7000 files.
-
I0113 12:13:57.467402 27 convert_imageset.cpp:147] Processed 8000 files.
-
I0113 12:13:59.090173 27 convert_imageset.cpp:147] Processed 9000 files.
-
I0113 12:14:00.676419 27 convert_imageset.cpp:147] Processed 10000 files.
-
I0113 12:14:02.851028 27 convert_imageset.cpp:147] Processed 11000 files.
-
I0113 12:14:04.404832 27 convert_imageset.cpp:147] Processed 12000 files.
-
I0113 12:14:05.979625 27 convert_imageset.cpp:147] Processed 13000 files.
-
I0113 12:14:07.152940 27 convert_imageset.cpp:147] Processed 14000 files.
-
I0113 12:14:09.217108 27 convert_imageset.cpp:147] Processed 15000 files.
-
I0113 12:14:10.806496 27 convert_imageset.cpp:147] Processed 16000 files.
-
I0113 12:14:12.268177 27 convert_imageset.cpp:147] Processed 17000 files.
-
I0113 12:14:13.508546 27 convert_imageset.cpp:147] Processed 18000 files.
-
I0113 12:14:15.016147 27 convert_imageset.cpp:147] Processed 19000 files.
-
I0113 12:14:17.189391 27 convert_imageset.cpp:147] Processed 20000 files.
-
I0113 12:14:19.469425 27 convert_imageset.cpp:147] Processed 21000 files.
-
I0113 12:14:20.869881 27 convert_imageset.cpp:147] Processed 22000 files.
-
I0113 12:14:22.358198 27 convert_imageset.cpp:147] Processed 23000 files.
-
I0113 12:14:23.811714 27 convert_imageset.cpp:147] Processed 24000 files.
-
I0113 12:14:25.611598 27 convert_imageset.cpp:147] Processed 25000 files.
-
I0113 12:14:27.188184 27 convert_imageset.cpp:147] Processed 26000 files.
-
I0113 12:14:28.578914 27 convert_imageset.cpp:147] Processed 27000 files.
-
I0113 12:14:30.235432 27 convert_imageset.cpp:147] Processed 28000 files.
-
I0113 12:14:31.867501 27 convert_imageset.cpp:147] Processed 29000 files.
-
I0113 12:14:33.497715 27 convert_imageset.cpp:147] Processed 30000 files.
-
I0113 12:14:34.925644 27 convert_imageset.cpp:147] Processed 31000 files.
-
I0113 12:14:36.906508 27 convert_imageset.cpp:147] Processed 32000 files.
-
I0113 12:14:38.464900 27 convert_imageset.cpp:147] Processed 33000 files.
-
I0113 12:14:40.249969 27 convert_imageset.cpp:147] Processed 34000 files.
-
I0113 12:14:42.774039 27 convert_imageset.cpp:147] Processed 35000 files.
-
I0113 12:14:44.158181 27 convert_imageset.cpp:147] Processed 36000 files.
-
I0113 12:14:45.778302 27 convert_imageset.cpp:147] Processed 37000 files.
-
I0113 12:14:47.252451 27 convert_imageset.cpp:147] Processed 38000 files.
-
I0113 12:14:49.799836 27 convert_imageset.cpp:147] Processed 39000 files.
-
I0113 12:14:51.288296 27 convert_imageset.cpp:147] Processed 40000 files.
-
I0113 12:14:52.484359 27 convert_imageset.cpp:147] Processed 41000 files.
-
I0113 12:14:54.095209 27 convert_imageset.cpp:147] Processed 42000 files.
-
I0113 12:14:56.525655 27 convert_imageset.cpp:147] Processed 43000 files.
-
I0113 12:14:58.033469 27 convert_imageset.cpp:147] Processed 44000 files.
-
I0113 12:14:59.409360 27 convert_imageset.cpp:147] Processed 45000 files.
-
I0113 12:15:00.880760 27 convert_imageset.cpp:147] Processed 46000 files.
-
I0113 12:15:02.602565 27 convert_imageset.cpp:147] Processed 47000 files.
-
I0113 12:15:04.345715 27 convert_imageset.cpp:147] Processed 48000 files.
-
I0113 12:15:05.799033 27 convert_imageset.cpp:147] Processed 49000 files.
-
I0113 12:15:06.995527 27 convert_imageset.cpp:147] Processed 50000 files.
-
I0113 12:15:08.686816 27 convert_imageset.cpp:147] Processed 51000 files.
-
I0113 12:15:11.079591 27 convert_imageset.cpp:147] Processed 52000 files.
-
I0113 12:15:12.673241 27 convert_imageset.cpp:147] Processed 53000 files.
-
I0113 12:15:14.083250 27 convert_imageset.cpp:147] Processed 54000 files.
-
I0113 12:15:15.629169 27 convert_imageset.cpp:147] Processed 55000 files.
-
I0113 12:15:17.027292 27 convert_imageset.cpp:147] Processed 56000 files.
-
I0113 12:15:18.703470 27 convert_imageset.cpp:147] Processed 57000 files.
-
I0113 12:15:20.178828 27 convert_imageset.cpp:147] Processed 58000 files.
-
I0113 12:15:21.541697 27 convert_imageset.cpp:147] Processed 59000 files.
-
I0113 12:15:23.018353 27 convert_imageset.cpp:147] Processed 60000 files.
-
I0113 12:15:24.517725 27 convert_imageset.cpp:147] Processed 61000 files.
-
I0113 12:15:26.077165 27 convert_imageset.cpp:147] Processed 62000 files.
-
I0113 12:15:27.476835 27 convert_imageset.cpp:147] Processed 63000 files.
-
I0113 12:15:28.695413 27 convert_imageset.cpp:147] Processed 64000 files.
-
I0113 12:15:30.552235 27 convert_imageset.cpp:147] Processed 65000 files.
-
I0113 12:15:32.182060 27 convert_imageset.cpp:147] Processed 66000 files.
-
I0113 12:15:33.655457 27 convert_imageset.cpp:147] Processed 67000 files.
-
I0113 12:15:34.957446 27 convert_imageset.cpp:147] Processed 68000 files.
-
I0113 12:15:36.233927 27 convert_imageset.cpp:147] Processed 69000 files.
-
I0113 12:15:37.818439 27 convert_imageset.cpp:147] Processed 70000 files.
-
I0113 12:15:39.956657 27 convert_imageset.cpp:147] Processed 71000 files.
-
I0113 12:15:41.336088 27 convert_imageset.cpp:147] Processed 72000 files.
-
I0113 12:15:42.587082 27 convert_imageset.cpp:147] Processed 73000 files.
-
I0113 12:15:44.044525 27 convert_imageset.cpp:147] Processed 74000 files.
-
I0113 12:15:45.632407 27 convert_imageset.cpp:147] Processed 75000 files.
-
I0113 12:15:47.075654 27 convert_imageset.cpp:147] Processed 76000 files.
-
I0113 12:15:48.567188 27 convert_imageset.cpp:147] Processed 77000 files.
-
I0113 12:15:49.854224 27 convert_imageset.cpp:147] Processed 78000 files.
-
I0113 12:15:51.043192 27 convert_imageset.cpp:147] Processed 79000 files.
-
I0113 12:15:52.586591 27 convert_imageset.cpp:147] Processed 80000 files.
-
I0113 12:15:54.092438 27 convert_imageset.cpp:147] Processed 81000 files.
-
I0113 12:15:55.546066 27 convert_imageset.cpp:147] Processed 82000 files.
-
I0113 12:15:56.811760 27 convert_imageset.cpp:147] Processed 83000 files.
-
I0113 12:15:57.987690 27 convert_imageset.cpp:147] Processed 84000 files.
-
I0113 12:15:59.671317 27 convert_imageset.cpp:147] Processed 85000 files.
-
I0113 12:16:01.283619 27 convert_imageset.cpp:147] Processed 86000 files.
-
I0113 12:16:02.826110 27 convert_imageset.cpp:147] Processed 87000 files.
-
I0113 12:16:04.015786 27 convert_imageset.cpp:147] Processed 88000 files.
-
I0113 12:16:05.246563 27 convert_imageset.cpp:147] Processed 89000 files.
-
I0113 12:16:07.631480 27 convert_imageset.cpp:147] Processed 90000 files.
-
I0113 12:16:09.503032 27 convert_imageset.cpp:147] Processed 91000 files.
-
I0113 12:16:10.790294 27 convert_imageset.cpp:147] Processed 92000 files.
-
I0113 12:16:12.273556 27 convert_imageset.cpp:147] Processed 93000 files.
-
I0113 12:16:14.271823 27 convert_imageset.cpp:147] Processed 94000 files.
-
I0113 12:16:15.744318 27 convert_imageset.cpp:147] Processed 95000 files.
-
I0113 12:16:17.090734 27 convert_imageset.cpp:147] Processed 96000 files.
-
I0113 12:16:18.353124 27 convert_imageset.cpp:147] Processed 97000 files.
-
I0113 12:16:19.863163 27 convert_imageset.cpp:147] Processed 98000 files.
-
I0113 12:16:21.596539 27 convert_imageset.cpp:147] Processed 99000 files.
-
I0113 12:16:23.036448 27 convert_imageset.cpp:147] Processed 100000 files.
-
I0113 12:16:24.533990 27 convert_imageset.cpp:147] Processed 101000 files.
-
I0113 12:16:25.711519 27 convert_imageset.cpp:147] Processed 102000 files.
-
I0113 12:16:27.407729 27 convert_imageset.cpp:147] Processed 103000 files.
-
I0113 12:16:29.793790 27 convert_imageset.cpp:147] Processed 104000 files.
-
I0113 12:16:31.340585 27 convert_imageset.cpp:147] Processed 105000 files.
-
I0113 12:16:32.955618 27 convert_imageset.cpp:147] Processed 106000 files.
-
I0113 12:16:34.523054 27 convert_imageset.cpp:147] Processed 107000 files.
-
I0113 12:16:36.220069 27 convert_imageset.cpp:147] Processed 108000 files.
-
I0113 12:16:37.792441 27 convert_imageset.cpp:147] Processed 109000 files.
-
I0113 12:16:39.185384 27 convert_imageset.cpp:147] Processed 110000 files.
-
I0113 12:16:40.366708 27 convert_imageset.cpp:147] Processed 111000 files.
-
I0113 12:16:41.930851 27 convert_imageset.cpp:147] Processed 112000 files.
-
I0113 12:16:43.605252 27 convert_imageset.cpp:147] Processed 113000 files.
-
I0113 12:16:45.682309 27 convert_imageset.cpp:147] Processed 114000 files.
-
I0113 12:16:47.001965 27 convert_imageset.cpp:147] Processed 115000 files.
-
I0113 12:16:48.201941 27 convert_imageset.cpp:147] Processed 116000 files.
-
I0113 12:16:50.482267 27 convert_imageset.cpp:147] Processed 117000 files.
-
I0113 12:16:53.129992 27 convert_imageset.cpp:147] Processed 118000 files.
-
I0113 12:16:55.065909 27 convert_imageset.cpp:147] Processed 119000 files.
-
I0113 12:16:56.272369 27 convert_imageset.cpp:147] Processed 120000 files.
再生成测试集:
-
gemfield@ai:~$ convert_imageset -resize_height 224 -resize_width 224 ./ val.lst wzry_224_val_lmdb
-
I0113 12:35:57.135522 28 convert_imageset.cpp:89] A total of 24319 images.
-
E0113 12:35:57.136313 28 common.cpp:114] Cannot create Cublas handle. Cublas won't be available.
-
E0113 12:35:57.136673 28 common.cpp:121] Cannot create Curand generator. Curand won't be available.
-
I0113 12:35:57.136708 28 db_lmdb.cpp:35] Opened lmdb wzry_224_val_lmdb
-
I0113 12:35:58.789322 28 convert_imageset.cpp:147] Processed 1000 files.
-
I0113 12:36:00.379387 28 convert_imageset.cpp:147] Processed 2000 files.
-
I0113 12:36:01.759858 28 convert_imageset.cpp:147] Processed 3000 files.
-
I0113 12:36:02.987604 28 convert_imageset.cpp:147] Processed 4000 files.
-
I0113 12:36:04.426345 28 convert_imageset.cpp:147] Processed 5000 files.
-
I0113 12:36:05.960880 28 convert_imageset.cpp:147] Processed 6000 files.
-
I0113 12:36:07.313741 28 convert_imageset.cpp:147] Processed 7000 files.
-
I0113 12:36:08.496649 28 convert_imageset.cpp:147] Processed 8000 files.
-
I0113 12:36:10.013240 28 convert_imageset.cpp:147] Processed 9000 files.
-
I0113 12:36:11.585314 28 convert_imageset.cpp:147] Processed 10000 files.
-
I0113 12:36:12.984436 28 convert_imageset.cpp:147] Processed 11000 files.
-
I0113 12:36:14.225903 28 convert_imageset.cpp:147] Processed 12000 files.
-
I0113 12:36:15.468725 28 convert_imageset.cpp:147] Processed 13000 files.
-
I0113 12:36:17.084775 28 convert_imageset.cpp:147] Processed 14000 files.
-
I0113 12:36:18.566448 28 convert_imageset.cpp:147] Processed 15000 files.
-
I0113 12:36:19.855185 28 convert_imageset.cpp:147] Processed 16000 files.
-
I0113 12:36:21.040355 28 convert_imageset.cpp:147] Processed 17000 files.
-
I0113 12:36:22.528937 28 convert_imageset.cpp:147] Processed 18000 files.
-
I0113 12:36:23.917870 28 convert_imageset.cpp:147] Processed 19000 files.
-
I0113 12:36:25.164480 28 convert_imageset.cpp:147] Processed 20000 files.
-
I0113 12:36:27.153021 28 convert_imageset.cpp:147] Processed 21000 files.
-
I0113 12:37:18.769785 28 convert_imageset.cpp:147] Processed 22000 files.
-
I0113 12:37:19.995821 28 convert_imageset.cpp:147] Processed 23000 files.
-
I0113 12:37:21.388216 28 convert_imageset.cpp:147] Processed 24000 files.
-
I0113 12:37:21.853869 28 convert_imageset.cpp:153] Processed 24319 files.
值得注意的是,1.5G的图片生成的lmdb大小为20.5GB!
获取pretrained的model
pre trained model主要是用来初始化当前网络结构的参数。
-
gemfield@ai:~$ ls -l ResNet-50-model.caffemodel
-
-rw-r--r-- 1 gemfield gemfield 102462397 1月 13 21:16 ResNet-50-model.caffemodel
开始训练
gemfield@ai:~$ build/tools/caffe train -solver solver.prototxt -weights ResNet-50-model.caffemodel
一些训练日志
-
I0114 03:52:23.357553 21226 solver.cpp:218] Iteration 73900 (6.61567 iter/s, 15.1156s/100 iters), loss = 0.0242063
-
I0114 03:52:23.357609 21226 solver.cpp:237] Train net output #0: loss = 0.0242095 (* 1 = 0.0242095 loss)
-
I0114 03:52:23.357619 21226 sgd_solver.cpp:105] Iteration 73900, lr = 1e-17
-
I0114 03:52:38.312636 21226 solver.cpp:330] Iteration 74000, Testing net (#0)
-
I0114 03:54:58.760177 21231 data_layer.cpp:73] Restarting data prefetching from start.
-
I0114 03:57:33.356952 21226 solver.cpp:397] Test net output #0: acc/top-1 = 0.969708
-
I0114 03:57:33.357126 21226 solver.cpp:397] Test net output #1: loss = 0.115373 (* 1 = 0.115373 loss)
-
I0114 03:57:33.503705 21226 solver.cpp:218] Iteration 74000 (0.322433 iter/s, 310.142s/100 iters), loss = 0.0952036
-
I0114 03:57:33.503748 21226 solver.cpp:237] Train net output #0: loss = 0.0952069 (* 1 = 0.0952069 loss)
-
I0114 03:57:33.503764 21226 sgd_solver.cpp:105] Iteration 74000, lr = 1e-17
-
I0114 03:57:48.466397 21226 solver.cpp:218] Iteration 74100 (6.68344 iter/s, 14.9624s/100 iters), loss = 0.00265225
-
I0114 03:57:48.466521 21226 solver.cpp:237] Train net output #0: loss = 0.00265556 (* 1 = 0.00265556 loss)
-
I0114 03:57:48.466542 21226 sgd_solver.cpp:105] Iteration 74100, lr = 1e-17
-
I0114 03:58:03.440867 21226 solver.cpp:218] Iteration 74200 (6.67818 iter/s, 14.9741s/100 iters), loss = 0.011983
-
I0114 03:58:03.441133 21226 solver.cpp:237] Train net output #0: loss = 0.0119865 (* 1 = 0.0119865 loss)
-
I0114 03:58:03.441164 21226 sgd_solver.cpp:105] Iteration 74200, lr = 1e-17
-
I0114 03:58:18.470480 21226 solver.cpp:218] Iteration 74300 (6.65372 iter/s, 15.0292s/100 iters), loss = 0.234399
-
I0114 03:58:18.470551 21226 solver.cpp:237] Train net output #0: loss = 0.234403 (* 1 = 0.234403 loss)
-
I0114 03:58:18.470561 21226 sgd_solver.cpp:105] Iteration 74300, lr = 1e-17
-
I0114 03:58:33.493978 21226 solver.cpp:218] Iteration 74400 (6.65636 iter/s, 15.0232s/100 iters), loss = 0.00225647
-
I0114 03:58:33.494228 21226 solver.cpp:237] Train net output #0: loss = 0.0022598 (* 1 = 0.0022598 loss)
-
I0114 03:58:33.494269 21226 sgd_solver.cpp:105] Iteration 74400, lr = 1e-17
-
I0114 03:58:48.538324 21226 solver.cpp:218] Iteration 74500 (6.6472 iter/s, 15.0439s/100 iters), loss = 2.68966e-05
-
I0114 03:58:48.538383 21226 solver.cpp:237] Train net output #0: loss = 3.02486e-05 (* 1 = 3.02486e-05 loss)
-
I0114 03:58:48.538391 21226 sgd_solver.cpp:105] Iteration 74500, lr = 1e-17
-
I0114 03:59:03.605232 21226 solver.cpp:218] Iteration 74600 (6.63717 iter/s, 15.0667s/100 iters), loss = 0.00452782
-
I0114 03:59:03.605480 21226 solver.cpp:237] Train net output #0: loss = 0.00453112 (* 1 = 0.00453112 loss)
-
I0114 03:59:03.605512 21226 sgd_solver.cpp:105] Iteration 74600, lr = 1e-17
-
I0114 03:59:18.693054 21226 solver.cpp:218] Iteration 74700 (6.62804 iter/s, 15.0874s/100 iters), loss = 0.173986
-
I0114 03:59:18.693130 21226 solver.cpp:237] Train net output #0: loss = 0.173989 (* 1 = 0.173989 loss)
-
I0114 03:59:18.693142 21226 sgd_solver.cpp:105] Iteration 74700, lr = 1e-17
-
I0114 03:59:33.762369 21226 solver.cpp:218] Iteration 74800 (6.63611 iter/s, 15.0691s/100 iters), loss = 0.237659
-
I0114 03:59:33.762547 21226 solver.cpp:237] Train net output #0: loss = 0.237662 (* 1 = 0.237662 loss)
-
I0114 03:59:33.762562 21226 sgd_solver.cpp:105] Iteration 74800, lr = 1e-17
-
I0114 03:59:48.851802 21226 solver.cpp:218] Iteration 74900 (6.62731 iter/s, 15.0891s/100 iters), loss = 0.0473921
-
I0114 03:59:48.851860 21226 solver.cpp:237] Train net output #0: loss = 0.0473955 (* 1 = 0.0473955 loss)
-
I0114 03:59:48.851868 21226 sgd_solver.cpp:105] Iteration 74900, lr = 1e-17
-
I0114 04:00:03.242220 21230 data_layer.cpp:73] Restarting data prefetching from start.
-
I0114 04:00:03.808995 21226 solver.cpp:447] Snapshotting to binary proto file models/resnet_gemfield_cls224_iter_75000.caffemodel
-
I0114 04:00:04.100811 21226 sgd_solver.cpp:273] Snapshotting solver state to binary proto file models/resnet_gemfield_cls224_iter_75000.solverstate
-
I0114 04:00:04.314110 21226 solver.cpp:310] Iteration 75000, loss = 0.225416
-
I0114 04:00:04.314160 21226 solver.cpp:315] Optimization Done.
-
I0114 04:00:04.314165 21226 caffe.cpp:259] Optimization Done.
清洗了一次训练集,把一些模糊的照片去掉后,再次用同样的参数去训练,得到的训练日志如下:
-
I0116 01:29:12.525300 61 sgd_solver.cpp:105] Iteration 73800, lr = 1e-17
-
I0116 01:29:45.552590 61 solver.cpp:218] Iteration 73900 (3.02776 iter/s, 33.0277s/100 iters), loss = 0.121681
-
I0116 01:29:45.554165 61 solver.cpp:237] Train net output #0: loss = 0.121683 (* 1 = 0.121683 loss)
-
I0116 01:29:45.554219 61 sgd_solver.cpp:105] Iteration 73900, lr = 1e-17
-
I0116 01:30:18.147012 61 solver.cpp:330] Iteration 74000, Testing net (#0)
-
I0116 01:33:34.854918 67 data_layer.cpp:73] Restarting data prefetching from start.
-
I0116 01:44:08.726112 61 solver.cpp:397] Test net output #0: acc/top-1 = 0.976
-
I0116 01:44:08.726408 61 solver.cpp:397] Test net output #1: loss = 0.0893586 (* 1 = 0.0893586 loss)
-
I0116 01:44:09.004158 61 solver.cpp:218] Iteration 74000 (0.115814 iter/s, 863.456s/100 iters), loss = 0.272815
-
I0116 01:44:09.004226 61 solver.cpp:237] Train net output #0: loss = 0.272817 (* 1 = 0.272817 loss)
-
I0116 01:44:09.004240 61 sgd_solver.cpp:105] Iteration 74000, lr = 1e-17
-
I0116 01:44:41.944175 61 solver.cpp:218] Iteration 74100 (3.03601 iter/s, 32.938s/100 iters), loss = 0.00181933
-
I0116 01:44:41.944440 61 solver.cpp:237] Train net output #0: loss = 0.00182139 (* 1 = 0.00182139 loss)
-
I0116 01:44:41.944473 61 sgd_solver.cpp:105] Iteration 74100, lr = 1e-17
-
I0116 01:45:15.054388 61 solver.cpp:218] Iteration 74200 (3.0204 iter/s, 33.1082s/100 iters), loss = 0.0241835
-
I0116 01:45:15.054733 61 solver.cpp:237] Train net output #0: loss = 0.0241856 (* 1 = 0.0241856 loss)
-
I0116 01:45:15.054776 61 sgd_solver.cpp:105] Iteration 74200, lr = 1e-17
-
I0116 01:45:48.085701 61 solver.cpp:218] Iteration 74300 (3.02762 iter/s, 33.0293s/100 iters), loss = 0.0254915
-
I0116 01:45:48.085886 61 solver.cpp:237] Train net output #0: loss = 0.0254935 (* 1 = 0.0254935 loss)
-
I0116 01:45:48.085896 61 sgd_solver.cpp:105] Iteration 74300, lr = 1e-17
-
I0116 01:46:21.485394 61 solver.cpp:218] Iteration 74400 (2.99422 iter/s, 33.3977s/100 iters), loss = 0.000650348
-
I0116 01:46:21.485787 61 solver.cpp:237] Train net output #0: loss = 0.000652366 (* 1 = 0.000652366 loss)
-
I0116 01:46:21.485879 61 sgd_solver.cpp:105] Iteration 74400, lr = 1e-17
-
I0116 01:46:54.568955 61 solver.cpp:218] Iteration 74500 (3.02283 iter/s, 33.0815s/100 iters), loss = 0.209352
-
I0116 01:46:54.569267 61 solver.cpp:237] Train net output #0: loss = 0.209354 (* 1 = 0.209354 loss)
-
I0116 01:46:54.569316 61 sgd_solver.cpp:105] Iteration 74500, lr = 1e-17
-
I0116 01:47:27.618690 61 solver.cpp:218] Iteration 74600 (3.02593 iter/s, 33.0477s/100 iters), loss = 0.0229688
-
I0116 01:47:27.618928 61 solver.cpp:237] Train net output #0: loss = 0.0229709 (* 1 = 0.0229709 loss)
-
I0116 01:47:27.618969 61 sgd_solver.cpp:105] Iteration 74600, lr = 1e-17
-
I0116 01:48:00.857776 61 solver.cpp:218] Iteration 74700 (3.0085 iter/s, 33.2391s/100 iters), loss = 0.00383524
-
I0116 01:48:00.857947 61 solver.cpp:237] Train net output #0: loss = 0.00383731 (* 1 = 0.00383731 loss)
-
I0116 01:48:00.857959 61 sgd_solver.cpp:105] Iteration 74700, lr = 1e-17
-
I0116 01:48:34.184334 61 solver.cpp:218] Iteration 74800 (3.00065 iter/s, 33.3261s/100 iters), loss = 0.126383
-
I0116 01:48:34.184636 61 solver.cpp:237] Train net output #0: loss = 0.126385 (* 1 = 0.126385 loss)
-
I0116 01:48:34.184814 61 sgd_solver.cpp:105] Iteration 74800, lr = 1e-17
-
I0116 01:49:07.174204 61 solver.cpp:218] Iteration 74900 (3.03142 iter/s, 32.9879s/100 iters), loss = 0.327584
-
I0116 01:49:07.174506 61 solver.cpp:237] Train net output #0: loss = 0.327586 (* 1 = 0.327586 loss)
-
I0116 01:49:07.174561 61 sgd_solver.cpp:105] Iteration 74900, lr = 1e-17
-
I0116 01:49:38.800302 66 data_layer.cpp:73] Restarting data prefetching from start.
-
I0116 01:49:40.076367 61 solver.cpp:447] Snapshotting to binary proto file models/resnet_gemfield_cls224_iter_75000.caffemodel
-
I0116 01:49:40.382776 61 sgd_solver.cpp:273] Snapshotting solver state to binary proto file models/resnet_gemfield_cls224_iter_75000.solverstate
-
I0116 01:49:40.630769 61 solver.cpp:310] Iteration 75000, loss = 0.0174639
-
I0116 01:49:40.630820 61 solver.cpp:315] Optimization Done.
-
I0116 01:49:40.630826 61 caffe.cpp:259] Optimization Done.
嗯,效果还是好了些。