New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Training for a multi label loss using lmdb #2407
Comments
Please ask usage questions on caffe-users -- this issues tracker is primarily for Caffe development discussion. Thanks! |
I'm sorry to dredge up a closed thread; @sukritshankar , can you share your network definition? In particular, what accuracy layer are you using? |
Hi @gavinmh. We used such a thing for a slightly different purpose, where we had many softmax layers, and their outputs went into a multi-label Euclidean loss, but in all cases, we used the simple accuracy layer (http://caffe.berkeleyvision.org/doxygen/classcaffe_1_1AccuracyLayer.html). I am pasting the network definition below; you might ignore the slicing and concatenation parts since we were experimenting for a different purpose. We have tested this prototxt, and it can take in multiple labels correctly for each given image. name: "AlexNet -- msr_face_LM_0_1_2_3" |
@sukritshankar |
Hello! How did you make the lmdb files? Did you use any script of the caffe master or did you make your own import just labels into lmdb files? |
Hi Elpidam You can use script in this page to convert label vectors to lmdb: and use caffe-root/tool/convert_imageset in order to convert images to lmdb format. |
Hello, this might be helpful to some, it is code I slightly modified from a google groups forum to create separate training and testing lmdb files using continuous valued labels (in my case a 6D vector) the Y_train variable should be loaded first as a Mx6 ndarray (of course, the 6 is arbitrary, just change the line in the code at the reshape part) , and the trainingset.txt and testingset.txt should contain the names of the images to be loaded
|
@sukritshankar , could you share your code to write the prototxt you have provided please? |
Sorry for the delayed reply !! I was entangled in some critical personal matters. Please see my recent Github code checkin at https://github.com/sukritshankar/CaffeLMDBCreationMultiLabel . That should solve the issue !! |
@sukritshankar thank you very much |
@sukritshankar I looked through your code and noticed that you require to "make sure labels are integer values in [0, 255]. I have continuous labels in the range [0, 1], what would I need to modify? Thank you! |
Well, normally you will have continuous labels in [0,1]. Even I had the On Mon, Aug 15, 2016 at 7:22 PM, mvasil notifications@github.com wrote:
|
hey, here is the code I had used to pass from a regular jpg image to separate lmdb files for labels and images. I plan on posting a blogpost soon going through all the steps more in detail at some point in the near future. I was still testing a bunch of stuff in this version of the code, will update with a cleaner version at some point or other. I used preprocessed jpeg images to 227x227 with mirror images as well (also preprocessed), used approx a total of 50 000 images for regression with a 1x6 continuous vector as my label with values between [0,1] , it worked decently well.
the following is an example of what trainingset.txt contained, line by line (col 0 is the image name for the file, I pre processed my images to be 227x227 to use alexnet, col 1-6 the appropriate normalized values I used for regression)
|
@sukritshankar and @jerpint -- Thank you for the useful LMDB conversion examples. |
No we did not have to modify the loss function or the gradient computation code !!
|
I did not use cross entropy, I used euclidean loss (L2 norm) only. I am currently away from my work computer so I cannot provide my prototxt files just yet :/ |
Thank you, @jerpint, that would be very helpful when you get a chance! I started fine-tuning a pre-trained VGG model using the above multi-class training schema, and tried both Sigmoid+Cross Entropy Loss layer, and a Euclidean Loss layer, but results are not good (high value of the loss function and oscillations for even up to 50 epochs of training). I based my conversion of training instances and labels to LMDB on @sukritshankar's linked code, but will give your Python script a go too, to make sure the problem is not how I read the data in. |
@mvasil no problem, tag me again in a few days in case I forget. A big challenge was figuring out how to prepare my data (images) to match the preprocessing steps used for Alexnet because I couldn't use their code directly for many practical reasons |
@jerpint Are you able to share your solver prototxt and network configuration prototxt files? |
hey @mvasil , sorry for the slow reply. Below are both my solver and deploy prototxt files. I had to use fine-tuning using AlexNet to get my regression to work. I also did all the pre processing outside of caffe, for practical reasons related to my application, so all of my images are 227x227. Hope this helps. deploy.prototxt
Solver.prototxt :
|
@sukritshankar Hi sukritshankar, you mentioned to have the continuous labels in [0,1], I am not sure about this. I have labels in 3 classes with each of 7 categories. So the label vector should be 3 numbers? So what do you mean continuous labels in [0, 1] sukritshankar commented on 16 Aug On Mon, Aug 15, 2016 at 7:22 PM, mvasil _@_.***> wrote: — |
Perhaps I did not write this clearly. Sorry for that !! By continuous labels in [0,1], I mean that for each given label, we have a ground truth score in [0,1]. For your case, if you have 3 classes with 7 labels each, you then have 21 labels in all, and for a given data instance, your ground truth will be a 21-dim vector, with each value in [0,1]. |
@sukritshankar oh I see, but the ground truth should be in the 21-dim vector with the number either 0 or 1 which should be mapped into 0 or 255 according to what you said. So what do you mean continuous? I check you example label.mat file, which contains many numbers between 0 and 255. |
[0,1] does not mean only 0 or 1, but any real number from 0 to 1 inclusive On Mon, Oct 10, 2016 at 3:18 AM, minitfly notifications@github.com wrote:
|
@sukritshankar sorry for that. What I am confused is that, for the ground truth label, which is labeled mannually. But this number is 0 or 1? So the ground truth label is {0, 1}? |
Thats fine !! Yes your groundtruth labels are {0,1}. Think of 0 and 1 as On Mon, Oct 10, 2016 at 3:46 AM, minitfly notifications@github.com wrote:
|
Thanks a lot for so many useful discussions! I have a question about this issue, does this code support the variable numbers of image's label? @sukritshankar |
If you data instances have variable number of image labels, make them On Tue, Oct 11, 2016 at 12:23 PM, shengyudingli notifications@github.com
|
@sukritshankar Hi, I am trying to apply the multi regression architecture you posted above to my net, but one error come out: How did you resize your mean_file, namely imagenet_mean.binaryproto to match lmdb size? Thank you in advance! |
@jerpint I guess your label shape is wrong.it should be N x M x 1 x 1. Not N x 1 x 1 x M |
@xcmax why do you say this? look at the line :
this is the line that embeds each label, M of them, for a total of N samples, hence the Nx1x1xM |
@jerpint I have seen many use N x M x 1 x 1, including @sukritshankar's example https://github.com/sukritshankar/Caffe-LMDBCreation-MultiLabel print X.shape # Check to see if X is of shape N x M x 1 x 1 with env.begin(write=True) as txn: |
I wish to train AlexNet with Cross Entropy Loss, for which every input has multiple label probabilities. Till now, I have been doing this using an HDF5 layer. However, one has to do all sorts of manual pre processing and access to this layer is around twice as slow as that to lmdb.
In view of the above, I wish to know how can one train for a multi label loss using an lmdb layer in caffe. More precisely, what should be done in train.txt so that one can specify multiple labels for a given image ?
The text was updated successfully, but these errors were encountered: