Skip to content

Comments

New tutorial on python datalayers and multilabel classification#3471

Merged
shelhamer merged 3 commits intoBVLC:masterfrom
beijbom:clean-datalayer-tutorial
Mar 1, 2016
Merged

New tutorial on python datalayers and multilabel classification#3471
shelhamer merged 3 commits intoBVLC:masterfrom
beijbom:clean-datalayer-tutorial

Conversation

@beijbom
Copy link
Contributor

@beijbom beijbom commented Dec 21, 2015

The goal of this tutorial is twofold. First, it illustrates how to write python datalayers. Both syncronous and asyncronous. Second, it clarifies a common misconception that caffe "doesn't support multi-label classification". It does, and the correct loss layer is SigmoidCrossEntropyLoss.

@wangg12
Copy link

wangg12 commented Dec 21, 2015

How about the evaluation metrics of multilabel classification like the accuracy of the multi-label one?

@beijbom
Copy link
Contributor Author

beijbom commented Dec 21, 2015

hey Wangg12, I use the hamming distance during test-time directly in the notebook, but did not put it in a python layer. Is that what you refer to?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should cite the URL (https://github.com/rbgirshick/fast-rcnn) and tech report (http://arxiv.org/abs/1504.08083) that accompanies Fast R-CNN. The current citation isn't quite enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

citation updated. thanks for the pointer!

@wangg12
Copy link

wangg12 commented Dec 22, 2015

Hi, @beijbom

According to Multi-label_classification,the hamming loss and multi-label version accuracy are equivalent to some extent.

In my view, hamming distance cares more about the difference between prediction and groundtruth, while the multi-label version accuracy focuses more on how much groundtruth and top-k prediction are the same.(Correct me if I'm wrong.)

In your implementation, hamming distance is along all prediction larger than 0 which means we need to choose a proper threshold(e.g. 0) for the positive labels. Maybe the multi-label version top-k accuracy is more flexible like the single label one.

So if I want to use the multi-label version accuracy during test, could you give me some instructions on how to write this with python layer?

Thanks!

@kli-casia
Copy link
Contributor

Great, I have been looking for python data layer for a long time.
Thank you very much. @beijbom

@lukeyeager
Copy link
Contributor

lukeyeager commented Jan 26, 2016

This tutorial may also be useful. It's not a data layer, but it's a bit more beginner-friendly.

https://github.com/NVIDIA/DIGITS/blob/digits-3.0/examples/python-layer/README.md

@kli-casia
Copy link
Contributor

@lukeyeager Thank you very much, I will check it out. o(^▽^)o

By the way, is there an example of python layer with parameters, for example,
how to reimplement fully connected layer using python layer?
Thank you.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would be at home as caffe/examples/pycaffe/tools.py to make it more clearly related to pycaffe examples.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good. I just moved it.

from threading import Thread
from PIL import Image

from pascal_multilabel_with_datalayer_tools import SimpleTransformer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this not now be "from tools import SimpleTransformer"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, I'll fix that. Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@beijbom I have submitted a pull request to your personal branch that also addresses this. Please have a look.

By the way, the tutorial is great! I was able to reproduce it with my multi-label data layer that I am working on for #3653 as well (still need to push the lastest changes).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a ton Evan, very nicely done. I'm not sure the new layer code is ideal from a tutorial perspective though. While certainly more professional, I think it obscures things a bit, and the reader have to jump back and forth to follow the line of execution. I tend to favour showing people the easiest, dumbest, and most straight-forward way of doing things, and let them take it from there. Does that makes sense? What do other folks think? @shelhamer?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that you mention it, I might have gotten a bit carried away.

I was thinking about it this morning again, and I don't think a base class is necessarily required, but I would still think that using the BatchLoader in both the sync and async cases is a good idea as it clarifies what the steps in the process are, and users can "drill down" further if they need more info as to what actually happens when loading an image.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, sure, that makes sense. That's a good compromize. :). Do you want to make a new pull requests, or should I edit yours?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that I'm going to get much of a chance to have a look this weekend. If it can wait until Monday, then I don't mind doing it myself. Otherwise, feel free to edit it.

shelhamer added a commit that referenced this pull request Mar 1, 2016
[example] tutorial on python data layers and multilabel classification
@shelhamer shelhamer merged commit 358b60c into BVLC:master Mar 1, 2016
@shelhamer
Copy link
Member

Thanks for the multi-label tutorial Oscar!

Potential follow-ups for the willing:

  • train the defined multi-label CaffeNet classifier to convergence on PASCAL to have a more exciting conclusion and yet another model for the zoo
  • switch to proto solver definition like in the fine-tuning notebook
  • add more explanation of classification/multi-class classification/multi-label classification with pointers to the relevant losses
  • include a pre-fetching Python data layer as an IO optimization (this should be another data layer to make this easier on beginners)

@beijbom
Copy link
Contributor Author

beijbom commented Mar 1, 2016

tnx Evan!

I'll revisit some of the follow-ups after ECCV.

The tutorial doesn't appear right on http://caffe.berkeleyvision.org/. Do
we need to take further action to make that happen? Perhaps I missed
setting one of the ipython notebook metadata fields?

I did set:
"include_in_docs": true,

but are there others?

cheers

On Tue, Mar 1, 2016 at 10:33 AM, Evan Shelhamer notifications@github.com
wrote:

Thanks for the multi-label tutorial Oscar!

Potential follow-ups for the willing:

  • train the defined multi-label CaffeNet classifier to convergence on
    PASCAL to have a more exciting conclusion and yet another model for the zoo
  • switch to proto solver definition like in the fine-tuning notebook
  • add more explanation of classification/multi-class
    classification/multi-label classification with pointers to the relevant
    losses
  • include a pre-fetching Python data layer as an IO optimization (this
    should be another data layer to make this easier on beginners)


Reply to this email directly or view it on GitHub
#3471 (comment).

@shelhamer
Copy link
Member

I had to push the new site from the latest master. It's there now!

@kli-casia
Copy link
Contributor

Hi, @beijbom . Why did you remove the asyncronous layer?

In my opinion, It's benifical to prefetch a batch for next iteration when caffe is running.

For the syncronous layer, caffe have to waite for batch loadiing, right?

Thanks!

@beijbom
Copy link
Contributor Author

beijbom commented Apr 19, 2016

hi @kli-nlpr! We decided to remove it because we didn't see any significant time savings (I agree that it SHOULD make sense, it just didn't :). It was unclear whether it was a implementation or hardware issue. Did you notice any time saving?

@kli-casia
Copy link
Contributor

Hi, @beijbom I didn't test it, I just wondering why you delete it.
Does this mean that when writing python data layer, one don't have to consider prefetching?

@elezar
Copy link
Contributor

elezar commented Apr 21, 2016

@kli-nlpr If you are really interested in performance, you can have a look at #3653, which adds multi-label support to the standard image data layer. This already implements batch prefetching and is quite a bit faster than the python layers here. Some testing and feedback would be welcome, and if there is more interest from the community, then maybe the PR could get merged sooner. I tried to reproduce @beijbom's pascal tutorial there too, so it should be simple enough to get started.

Note: I am trying to knock @beijbom's layers. They are great examples of some of the more advanced uses of Caffe's python interface!

@kli-casia
Copy link
Contributor

@elezar Thank you very much, I will check it out.

In fact, I am much more comfortable with python than C++.
I think it’s much easier to do some complex data preparation using python layer.
But the speed is much slower than C++ layers.
I am looking for methods which can speed up python data layers. ^_^

@kli-casia
Copy link
Contributor

Is there a pre-fetching Python data layer right now? Thanks

@beijbom
Copy link
Contributor Author

beijbom commented Aug 31, 2016

We have experimented with a pre-fetching Python data layers, but were unable to see a consistent speed-up so far. Let me know if you get it to work.

fxbit pushed a commit to Yodigram/caffe that referenced this pull request Sep 1, 2016
[example] tutorial on python data layers and multilabel classification
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants