Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
ReductionLayer #2089
Conversation
jeffdonahue
added the
ready for review
label
Mar 10, 2015
jeffdonahue
changed the title from
Reduction Layer to ReductionLayer
Mar 10, 2015
myfavouritekk
added a commit
to myfavouritekk/caffe
that referenced
this pull request
Mar 16, 2015
|
|
myfavouritekk |
36a70ba
|
shelhamer
added the
needs rebase
label
Jun 1, 2015
shelhamer
and 1 other
commented on an outdated diff
Jun 3, 2015
| + const Dtype* bottom_data = bottom[0]->cpu_data(); | ||
| + const Dtype* mult_data = NULL; | ||
| + if (sum_multiplier_.count() > 0) { | ||
| + mult_data = sum_multiplier_.cpu_data(); | ||
| + } | ||
| + Dtype* top_data = top[0]->mutable_cpu_data(); | ||
| + for (int i = 0; i < num_; ++i) { | ||
| + switch (op_) { | ||
| + case ReductionParameter_ReductionOp_SUM: | ||
| + case ReductionParameter_ReductionOp_MEAN: | ||
| + *top_data = caffe_cpu_dot(dim_, mult_data, bottom_data); | ||
| + break; | ||
| + case ReductionParameter_ReductionOp_ASUM: | ||
| + *top_data = caffe_cpu_asum(dim_, bottom_data); | ||
| + break; | ||
| + case ReductionParameter_ReductionOp_SUM_OF_SQUARES: |
shelhamer
Owner
|
shelhamer
and 1 other
commented on an outdated diff
Jun 3, 2015
| + UniformFiller<Dtype> filler(filler_param); | ||
| + filler.Fill(this->blob_bottom_); | ||
| + blob_bottom_vec_.push_back(blob_bottom_); | ||
| + blob_top_vec_.push_back(blob_top_); | ||
| + } | ||
| + virtual ~ReductionLayerTest() { | ||
| + delete blob_bottom_; | ||
| + delete blob_top_; | ||
| + } | ||
| + | ||
| + void TestForward(ReductionParameter_ReductionOp op, float coeff = 1) { | ||
| + LayerParameter layer_param; | ||
| + ReductionParameter* reduction_param = layer_param.mutable_reduction_param(); | ||
| + reduction_param->set_operation(op); | ||
| + if (coeff != 1.0) { | ||
| + reduction_param->set_coeff(2.3); |
shelhamer
Owner
|
|
Once the comments are addressed this looks fine, although there could be a test for reducing over a tail that isn't all dimensions. p.s. N-D blobs are nice. |
|
Thanks for all the reviews @shelhamer! Tests for non-zero axis added; will merge after Travis. |
|
Wow... especially thanks for the suggestion to test other axes. I had a bug in Backward for |
|
Tests are more trustworthy than me. Good catch! |
jeffdonahue
added a commit
that referenced
this pull request
Jun 3, 2015
|
|
jeffdonahue |
0cc7e18
|
jeffdonahue commentedMar 10, 2015
Performs a "reduction" operation (currently
SUM,MEAN,ASUMfor sum of absolute values, andSUMSQfor sum of squares) to turn a number of "tail" axes into a single scalar value. TheMEANoperation, in combination with aloss_weight, is useful for creating custom losses that don't have an obnoxious amount of output. For example, thisEuclideanLoss:...is equivalent to this
Reduction:(would be more efficient to do as a single
ReductionwithSUM_OF_SQUARESand a certaincoeffsetting, but then you have to compute the batch size and everything is less pretty...)Eventually, this should support reduction along inner axes (e.g. support an
end_axis), but that makes the implementation substantially more involved than this...