-
Notifications
You must be signed in to change notification settings - Fork 18.7k
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
Add a layer for in-memory datasets, and expose it to Python #294
Conversation
I can't wait for this data layer!
The raw pointer is fine. A
Nice.
To me, the ideal interface would be to simply assign to
Accept both. The 4d will be important for multilabel and regression inputs and we should sort it out now instead of bolting it on later. However, a 1d array is convenient, like you said, so why not accept a 1d arg and upgrade it to a 4d array?
Tests are a must. |
|
Don't worry about using a Blob to store all the data. The original SyncedMem and thus Blob do not allocate any memory until it is used. #250 also strives to be as lazy as possible. |
Re: data length everything's fine. No copy is worth it, and don't worry Le samedi 5 avril 2014, longjon notifications@github.com a écrit :
|
Needs rebase + tests, then I'll review and merge. Thanks @longjon. |
Wow, this is awesome, I was looking to implement something similar to this for my project, but I'm glad I saw this first! Thanks @longjon! In my project my outputs aren't labels, so they don't have the required Nx1x1x1 dimensions. There's nothing inherently preventing me from getting this to work with non label outputs, correct? If I modified the I only recently started getting familiar with the caffe source, so forgive me for my ignorance. Just wanted to make sure I wasn't missing anything fundamental! |
@jlreyes yes, everything should work the way you describe. You'll also need to modify the checks in the Python wrapper if you'll be using that. We could consider generalizing this layer to take an arbitrary specification of any number of input blobs of various sizes. That actually feels more natural to me than the way it's done now, but I'll probably not make those changes for this PR. (This PR is almost ready for review, I just need to chase down a possible crash.) |
Bug fixed, code rebased, history rewritten, basic tests added, 1d label arrays accepted, all tests and lint pass, ready for review and merge. |
For some reason these changes expose a lint error that |
@@ -325,6 +325,40 @@ class EltwiseProductLayer : public Layer<Dtype> { | |||
}; | |||
|
|||
template <typename Dtype> | |||
class MemoryDataLayer : public Layer<Dtype> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry for the nitpick, but can you put this class in the right place in the file alphabetically?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. All nitpicks are welcome. I missed this because of the double-alphabetical order of the file.
Please rebase for a clean merge. I'd love to include this soon! |
This allows a blob to be updated without copy to use already existing memory (and will support MemoryDataLayer).
This will facilitate input size checking for pycaffe (and potentially others).
Doing this, rather than constructing the CaffeNet wrapper every time, will allow the wrapper to hold references that last at least as long as SGDSolver (which will be necessary to ensure that data used by MemoryDataLayer doesn't get freed).
This requires a net whose first layer is a MemoryDataLayer.
Rebased and ready-to-go. |
Add a layer for in-memory data, and expose it to Python
Thanks Jon! |
Add a layer for in-memory data, and expose it to Python
(This PR is related to but distinct from #196. Together with #286 it addresses #135.)
This PR adds a new layer called
MemoryDataLayer
that accepts two contiguous blocks of memory (for data and labels) and (inForward
) updates the top blobs to walk along the provided memory.MemoryDataLayer
; shouldshared_ptr
s be used instead?Blob
andSyncedMemory
both get aset_cpu_data
method to allow them to point to memory owned by someone elseNet.set_input_arrays
is added to pycaffe for telling theMemoryDataLayer
to point to ndarray dataMemoryDataLayer
(perhaps merging should wait until they do?)When combined with #286, training in Python with ndarray data is now possible, e.g.,