John Tracid
John Tracid

Reputation: 4046

Strange classification output with DNN

I try to classify images using fine tuned network CaffeNet. I followed tutorial from Caffe and changed number of outputs in train file to 3, also I turned off learning for first two convolutional layers. For some reason when I use classifier with trained model I'm getting 0.3 for all classes for each image from test set.

number of classes: 3
train set size: 6570 images (80%)
test set size: 1645 images (20%)

Solver:

net: "train.prototxt"
test_iter: 100
test_interval: 1000
base_lr: 0.0001
lr_policy: "step"
gamma: 0.1
stepsize: 20000
display: 200
max_iter: 60000
momentum: 0.9
weight_decay: 0.0005
snapshot: 10000
snapshot_prefix: "snapshot"
solver_mode: GPU

How I run training:

caffe train -solver solver.prototxt -weights bvlc_reference_caffenet.caffemodel

some output:

I0531 00:35:52.622647  2944 data_layer.cpp:73] Restarting data prefetching from start.
I0531 00:36:02.699782  2944 data_layer.cpp:73] Restarting data prefetching from start.
I0531 00:36:03.900009  5528 solver.cpp:218] Iteration 3600 (10.1266 iter/s, 19.7499s/200 iters), loss = 0.679402
I0531 00:36:03.900009  5528 solver.cpp:237]     Train net output #0: loss = 0.679402 (* 1 = 0.679402 loss)
I0531 00:36:03.900009  5528 sgd_solver.cpp:105] Iteration 3600, lr = 0.0001

I0531 00:41:20.139937  2944 data_layer.cpp:73] Restarting data prefetching from start.
I0531 00:41:30.934025  2944 data_layer.cpp:73] Restarting data prefetching from start.
I0531 00:41:34.199774  5528 solver.cpp:218] Iteration 6800 (9.66881 iter/s, 20.6851s/200 iters), loss = 0.451174
I0531 00:41:34.199774  5528 solver.cpp:237]     Train net output #0: loss = 0.451174 (* 1 = 0.451174 loss)
I0531 00:41:34.199774  5528 sgd_solver.cpp:105] Iteration 6800, lr = 0.0001

I0531 00:41:41.794001  2944 data_layer.cpp:73] Restarting data prefetching from start.
I0531 00:41:52.743448  2944 data_layer.cpp:73] Restarting data prefetching from start.
I0531 00:41:55.126147  5528 solver.cpp:330] Iteration 7000, Testing net (#0)
I0531 00:41:55.891929  3704 data_layer.cpp:73] Restarting data prefetching from start.
I0531 00:41:58.393698  3704 data_layer.cpp:73] Restarting data prefetching from start.
I0531 00:41:58.862452  5528 solver.cpp:397]     Test net output #0: accuracy = 0.6952
I0531 00:41:58.862452  5528 solver.cpp:397]     Test net output #1: loss = 0.873388 (* 1 = 0.873388 loss)

I0531 00:43:08.320360  2944 data_layer.cpp:73] Restarting data prefetching from start.
I0531 00:43:18.514559  2944 data_layer.cpp:73] Restarting data prefetching from start.
I0531 00:43:18.920881  5528 solver.cpp:218] Iteration 7800 (10.0073 iter/s, 19.9854s/200 iters), loss = 0.196175
I0531 00:43:18.920881  5528 solver.cpp:237]     Train net output #0: loss = 0.196175 (* 1 = 0.196175 loss)
I0531 00:43:18.920881  5528 sgd_solver.cpp:105] Iteration 7800, lr = 0.0001
I0531 00:43:28.660408  2944 data_layer.cpp:73] Restarting data prefetching from start.
I0531 00:43:38.561293  5528 solver.cpp:330] Iteration 8000, Testing net (#0)
I0531 00:43:40.405230  3704 data_layer.cpp:73] Restarting data prefetching from start.
I0531 00:43:42.077230  5528 solver.cpp:397]     Test net output #0: accuracy = 0.7004
I0531 00:43:42.077230  5528 solver.cpp:397]     Test net output #1: loss = 0.991567 (* 1 = 0.991567 loss)

I0531 00:45:22.426592  3704 data_layer.cpp:73] Restarting data prefetching from start.
I0531 00:45:24.761165  3704 data_layer.cpp:73] Restarting data prefetching from start.
I0531 00:45:25.329238  5528 solver.cpp:397]     Test net output #0: accuracy = 0.6856
I0531 00:45:25.329238  5528 solver.cpp:397]     Test net output #1: loss = 1.08582 (* 1 = 1.08582 loss)
I0531 00:45:25.394567  5528 solver.cpp:218] Iteration 9000 (8.39955 iter/s, 23.8108s/200 iters), loss = 0.107816
I0531 00:45:25.394567  5528 solver.cpp:237]     Train net output #0: loss = 0.107816 (* 1 = 0.107816 loss)

I0531 00:46:49.099460  2944 data_layer.cpp:73] Restarting data prefetching from start.
I0531 00:46:59.269830  2944 data_layer.cpp:73] Restarting data prefetching from start.
I0531 00:47:03.997443  5528 solver.cpp:447] Snapshotting to binary proto file snapshot_iter_10000.caffemodel
I0531 00:47:05.185039  5528 sgd_solver.cpp:273] Snapshotting solver state to binary proto file snapshot_iter_10000.solverstate
I0531 00:47:05.403774  5528 solver.cpp:330] Iteration 10000, Testing net (#0)
I0531 00:47:07.122831  3704 data_layer.cpp:73] Restarting data prefetching from start.
I0531 00:47:08.870923  5528 solver.cpp:397]     Test net output #0: accuracy = 0.7012
I0531 00:47:08.870923  5528 solver.cpp:397]     Test net output #1: loss = 1.18649 (* 1 = 1.18649 loss)
I0531 00:47:08.964664  5528 solver.cpp:218] Iteration 10000 (8.12416 iter/s, 24.6179s/200 iters), loss = 0.0347012
I0531 00:47:08.964664  5528 solver.cpp:237]     Train net output #0: loss = 0.0347012 (* 1 = 0.0347012 loss)
I0531 00:47:08.964664  5528 sgd_solver.cpp:105] Iteration 10000, lr = 0.0001

How I run classification:

classification deploy.prototxt snapshot_iter_10000.caffemodel labels.txt ..\test

some output:

"0.jpg",0.333333,0.333333,0.333333
"1.jpg",0.333333,0.333333,0.333333
"10.jpg",0.333333,0.333333,0.333333
"100.jpg",0.333333,0.333333,0.333333
"101.jpg",0.333333,0.333333,0.333333
"102.jpg",0.333333,0.333333,0.333333,
"103.jpg",0.333333,0.333333,0.333333

For some reason with 70% accuracy I'm getting same result as with 50% - every class has 0.3.

Upvotes: 0

Views: 120

Answers (1)

Harsh Wardhan
Harsh Wardhan

Reputation: 2158

There's nothing strange with your classification output, it's just that you need to interpret it correctly. An accuracy of 0.333for 3 classes simply implies that your network isn't learning anything - it is random guessing. For N classes random guess will give you an accuracy of 1/N. So in your case it is 1/3, i.e., 0.333.

Now, there's no such standard rule for setting your hyperparameters but looking at the huge variations in your loss, I would suggest you to reduce your base learning rate to 0.00001.

Upvotes: 1

Related Questions