Use pre-trained model and printed loss, accuracy issue
Hi, I have a question about using pre-trained model and printed loss, accuracy issue
-
When I used pre-trained caffemodel of Densenet-121 (link), Intel caffe didn't work because of blob size of batch normalization. I think the reason of malfunction is that Intel caffe use different engine compared to conventional caffe. So, I want to know solution such as converting the blob size of caffemodel for MKLDNN, or other solutions to fix it.
-
When I trained the model, Top-1 and Top 5 accuracy is going higher, but loss is a standstill. So, I wonder if I designed the model wrong, or loss is incorrectly printed in the caffe. I use intel caffe 1.0.2 version with MKLDNN, Densenet 121 model and Imagenet 2012 dataset. Below is printed output of training process.
I1108 10:16:02.065809 16091 solver.cpp:729] Test net output # 0: Top1 = 0.19 I1108 10:16:02.066671 16091 solver.cpp:729] Test net output # 1: Top5 = 0.411875 I1108 10:16:03.035044 16091 solver.cpp:329] Iteration 116000, loss = 6.35148 I1108 10:16:03.035331 16091 solver.cpp:345] Train net output #0: prob = 6.35148 (* 1 = 6.35148 loss) I1108 10:16:03.035464 16091 sgd_solver.cpp:176] Iteration 116000, lr = 0.0005 I1108 10:17:43.860158 16091 solver.cpp:329] Iteration 116100, loss = 6.58037 I1108 10:17:43.860481 16091 solver.cpp:345] Train net output #0: prob = 6.58037 (* 1 = 6.58037 loss) I1108 10:17:43.860565 16091 sgd_solver.cpp:176] Iteration 116100, lr = 0.0005 I1108 10:19:25.387732 16091 solver.cpp:329] Iteration 116200, loss = 6.48806 I1108 10:19:25.388109 16091 solver.cpp:345] Train net output #0: prob = 6.48806 (* 1 = 6.48806 loss) I1108 10:19:25.388193 16091 sgd_solver.cpp:176] Iteration 116200, lr = 0.0005 I1108 10:21:11.253371 16091 solver.cpp:329] Iteration 116300, loss = 6.4692 I1108 10:21:11.253679 16091 solver.cpp:345] Train net output #0: prob = 6.4692 (* 1 = 6.4692 loss) I1108 10:21:11.253765 16091 sgd_solver.cpp:176] Iteration 116300, lr = 0.0005 I1108 10:23:05.052292 16091 solver.cpp:329] Iteration 116400, loss = 6.54121 I1108 10:23:05.052832 16091 solver.cpp:345] Train net output #0: prob = 6.54121 (* 1 = 6.54121 loss)
Thank you.
did you try to specify caffe engine for batch norm layer?
Yes, I specified Caffe engine by 'MKLDNN' to the model prototxt file like this.
layer { engine: "MKLDNN" name: "conv1/bn" type: "BatchNorm" bottom: "conv1" top: "conv1/bn" batch_norm_param { eps: 1e-5 } }
When I tested the pre-trained caffe model, below errors occured and I think that BVLC Caffe use 3 blobs for batch normalization, but Intel Caffe with MKLDNN seems to use 5 blobs for batch normalization.
F1115 15:59:33.571871 31499 net.cpp:1315] Check failed: target_blobs.size() == source_layer.blobs_size() (5 vs. 3) Incompatible number of blobs for layer conv2_1/x1/bn *** Check failure stack trace: *** @ 0x7ff8a06a5a7d google::LogMessage::Fail() @ 0x7ff8a06a784c google::LogMessage::SendToLog() @ 0x7ff8a06a566c google::LogMessage::Flush() @ 0x7ff8a06a815e google::LogMessageFatal::~LogMessageFatal() @ 0x7ff8a0ccc728 caffe::Net<>::CopyTrainedLayersFrom() @ 0x7ff8a0ccce52 caffe::Net<>::CopyTrainedLayersFromBinaryProto() @ 0x7ff8a0ccceb6 caffe::Net<>::CopyTrainedLayersFrom() @ 0x7ff8a952c254 test() @ 0x7ff8a952733c main @ 0x7ff89d8d4b35 __libc_start_main @ 0x7ff8a952806d (unknown)
Thank you.
if you are using intel caffe latest code, it will use MKLDNN engine as default engine. so to specify CAFFE engine for a specific layer, you need add blow
layer { engine: "CAFFE" //<- modify from "MKLDNN" to "CAFFE" name: "conv1/bn" type: "BatchNorm" bottom: "conv1" top: "conv1/bn" batch_norm_param { eps: 1e-5 } }
@ftian1 Hello, I am very interested in this discussion. Then, is there any way to use the pre-trained model while using the MKL-DNN engine for the BatchNorm layer?
Thank you.
@HAIDJ that's the default behavior of latest intel caffe. All the layers will use MKLDNN engine if no other engines are specified.
@ftian1
"When I used pre-trained caffemodel of Densenet-121 (link), Intel caffe didn't work because of blob size of batch normalization."
As sj-leo said, pre-trained caffemodel of Densenet-121 does not seem to fit well with batch normalization implementation of mkl-dnn. So I wonder if there is a way to use the pre-trained model while using mkl-dnn.
@HAIDJ I couldn't reproduce the issue sj-leo met with latest caffe. The only issue I met is Desenet121 has a ceil_mode parameter in pooling layer which doesn't exist in intel caffe proto definition file, which will cause protobuf parser assert.
and of course using pre-trained model in caffe is supported whatever which engine is used.
we have root caused this issue, which only happens when user manually modify prototxt to specify a different engine for bn layer.
we will fix it soon.
We will release the fixing soon.