Classify handwritten digits from Images: Do we need to create label file?

84 views
Skip to first unread message

Kevin George

unread,
Dec 15, 2016, 8:45:33 PM12/15/16
to Caffe Users
Hi all,

I am trying to use a trained LeNet model from mnist example to classify a digit from a given image. I am following the cpp classification caffe example as it reads an image(ImageNet data though) and classifies it. 
I am confused about what the sysnet file in Imagenet is and how it is used for classification? Also do we need a label file for Lenet to classify handwritten digits as during the training, no label file was used, so I'm guessing that's in lmdb file right? 

Przemek D

unread,
Dec 16, 2016, 7:11:58 AM12/16/16
to Caffe Users
You do not need a synset file unless you're doing ImageNet classification - this provides hierarchic classes information so you can give your network a partial credit: it might have failed to guess the exact breed of dog in the picture, but it did get the "animal", "mammal", and "dog" subclasses correctly. No need for that level of complexity if you're doing simple tasks like OCR.
LMDB does not contain label information aside from raw indices, that is: your examples (images) are paired with labels (integers) but no label descriptions are packed with them. So you know image a shows an object of class 4 and image b - class 17, but you don't know what those classes are until you look into a label file, which provides those descriptions, listing label names so that you can associate them with indices. You might get away without them in this particular case when you're classifying digits and class 0 corresponds to string "0" and class 1 to "1" etc. but if you want to know if your network found a dog or a cat in an image you need it.

Kevin George

unread,
Dec 16, 2016, 10:38:43 PM12/16/16
to Caffe Users
Is Lmdb is of the <key,value> format?  So for mnist, key would be a vector containing pixel values and value would be the label i.e actual number right?
Then I have the confusion of classifying an image with the digits. Following the cpp_classification example (for ImageNet data), they have used a mean image file and label file. So for mnist, do I just need to make a label file? Also isn't mean image file only used during training and not during testing?

Przemek D

unread,
Dec 19, 2016, 2:23:43 AM12/19/16
to Caffe Users
LMDB "datum" has a data and label fields. If data is a vector, I wouldn't say as I think it's actually an 3-dimensional array, but yet it stores pixel values. Label is an integer representing a label index.
For mean image file, I think the rule is that if you used one for training, then you should also subtract the same mean during inference. At least I found that if I don't do that, my test results are much worse.
Reply all
Reply to author
Forward
0 new messages