Produce the layers using the abstract factory pattern for simplicity#1064
Conversation
|
This patch seems to trade duplication of the engine selection code for duplication of the layer selection code. I see two drawbacks to this:
So I'm not sure this is strictly better than what we have now. I would welcome a patch that simply reduced the duplicated engine selection code, and I would also be interested in some way around the current tedium of writing out the protobuf types and C++ types for every layer in |
|
I think there is some kind of polymorphism possible through protobuf On Wednesday, September 10, 2014, longjon notifications@github.com wrote:
Evan Shelhamer |
|
The implementation is changed to be more faithful to the abstract factory pattern to avoid duplication. |
|
Not sure if this really solves the problem here, since the code is essentially the same... My picture of a registerer will be something that looks like this (this is a random piece of example I found, not saying it is good quality): https://code.google.com/p/mapreduce-lite/source/browse/trunk/src/base/class_register.h Such registration allows the users to simply register a class and forget about all others. This comes with drawbacks (have to always link into one single binary, cannot register across binary boundaries, kind-of unstable behavior across platforms), so not sure what is the right direction to go to. Just my 2 cents :) |
|
(This being said, a "real factory" factory is really needed in Caffe :)) |
|
I.e. Opencv use the Algorithm class |
There was a problem hiding this comment.
This parameter is embedded in the respective layer messages for future-proofing: while CAFFE and CUDNN are the only engines at the moment, each layer could have different engines that are not necessarily shared. For instance convolution could pick up an FFT engine but that has no bearing on pooling and the rest.
There was a problem hiding this comment.
I'm not sure about the most suitable general way to manage the different implementations of the same layer. The problem is related to #1108.
|
Just want to provide a pointer to #1167 - with the registry and the registration of creators (something like a factory?) this PR's purpose may partially be fullfilled. |
"For me, the lesson learned when writing Caffe as a grad student is simplicity: reduce my problem to one already solved." -- Yangqing
The factory pattern is on the todo list since the public release of Caffe. As more and more implementations are added, it is time to refactor how the layers are created.
The theory is not repeated here as there are already plenty of articles talking about the abstract factory pattern.