Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Caffe need data to be shuffled?

I convert my image data to caffe db format (leveldb, lmdb) using C++ as example I use this code for imagenet.

Is data need to be shuffled, can I write to db all my positives and then all my negatives like 00000000111111111, or data need to be shuffled and labels should look like 010101010110101011010?

How caffe sample data from DB, is it true that it use random subset of all data with size = batch_size?

like image 839
mrgloom Avatar asked Jun 06 '16 12:06

mrgloom


1 Answers

Should you shuffle the samples? Think about the learning process if you don't shuffle; caffe sees only 0 samples - what do you expect the algorithm to deduce? simply predict 0 all the time and everything is cool. If you have plenty of 0 before you hit the first 1 caffe will be very confident in predicting always 0. It will be very difficult to move the model from this point.
On the other hand, if it constantly sees a mix of 0 and 1 it learns from the beginning meaningful features for separating the examples.
Bottom line: it is very advantageous to shuffle the training samples, especially when using SGD-based approaches.

AFAIK, caffe does not randomly sample batch_size samples, but rather goes sequentially over the input DB batch_size after batch_size samples.

TL;DR
shuffle.

like image 77
Shai Avatar answered Nov 15 '22 06:11

Shai