<commit_before>// Copyright 2014 BVLC and contributors.

#include <vector>

#include "caffe/filler.hpp"
#include "caffe/layer.hpp"
#include "caffe/vision_layers.hpp"
#include "caffe/util/math_functions.hpp"

namespace caffe {

template <typename Dtype>
void LRNMapLayer<Dtype>::SetUp(const vector<Blob<Dtype>*>& bottom,
      vector<Blob<Dtype>*>* top) {
  CHECK_EQ(bottom.size(), 1) <<
      "Local Response Normalization Layer takes a single blob as input.";
  CHECK_EQ(top->size(), 1) <<
      "Local Response Normalization Layer takes a single blob as output.";
  const int num = bottom[0]->num();
  const int channels = bottom[0]->channels();
  const int height = bottom[0]->height();
  const int width = bottom[0]->width();
  const int size_ = this->layer_param_.lrn_map_param().local_size();
  const Dtype pre_pad = (size_ - 1) / 2;
  const Dtype alpha = this->layer_param_.lrn_map_param().alpha();
  const Dtype beta = this->layer_param_.lrn_map_param().beta();
  // Set up square layer to square the inputs.
  square_input_.Reshape(num, channels, height, width);
  square_bottom_vec_.clear();
  square_top_vec_.clear();
  square_bottom_vec_.push_back(&square_input_);
  square_top_vec_.push_back(&square_output_);
  LayerParameter square_param;
  square_param.mutable_power_param()->set_power(Dtype(2));
  square_layer_.reset(new PowerLayer<Dtype>(square_param));
  square_layer_->SetUp(square_bottom_vec_, &square_top_vec_);
  CHECK_EQ(square_output_.num(), num);
  CHECK_EQ(square_output_.channels(), channels);
  CHECK_EQ(square_output_.height(), height);
  CHECK_EQ(square_output_.width(), width);
  // Output of pool layer gives us the neighborhood response.
  pool_top_vec_.clear();
  pool_top_vec_.push_back(&pool_output_);
  LayerParameter pool_param;
  pool_param.mutable_pooling_param()->set_pool(PoolingParameter_PoolMethod_AVE);
  pool_param.mutable_pooling_param()->set_pad(pre_pad);
  pool_param.mutable_pooling_param()->set_kernel_size(size_);
  pool_layer_.reset(new PoolingLayer<Dtype>(pool_param));
  pool_layer_->SetUp(square_top_vec_, &pool_top_vec_);
  CHECK_EQ(pool_output_.num(), num);
  CHECK_EQ(pool_output_.channels(), channels);
  CHECK_EQ(pool_output_.height(), height);
  CHECK_EQ(pool_output_.width(), width);
  // Set up power layer to compute (1 + alpha/N^2 s)^-beta, where s is the sum
  // of a squared neighborhood (as output by the conv layer).
  power_top_vec_.clear();
  power_top_vec_.push_back(&power_output_);
  LayerParameter power_param;
  power_param.mutable_power_param()->set_power(-beta);
  power_param.mutable_power_param()->set_scale(alpha / (size_ * size_));
  power_param.mutable_power_param()->set_shift(Dtype(1));
  power_layer_.reset(new PowerLayer<Dtype>(power_param));
  power_layer_->SetUp(pool_top_vec_, &power_top_vec_);
  CHECK_EQ(power_output_.num(), num);
  CHECK_EQ(power_output_.channels(), channels);
  CHECK_EQ(power_output_.height(), height);
  CHECK_EQ(power_output_.width(), width);
  // Set up a product layer to compute outputs by multiplying inputs by scale.
  product_bottom_vec_.clear();
  product_bottom_vec_.push_back(bottom[0]);
  product_bottom_vec_.push_back(&power_output_);
  product_top_vec_.clear();
  product_top_vec_.push_back((*top)[0]);
  LayerParameter product_param;
  product_layer_.reset(new EltwiseProductLayer<Dtype>(product_param));
  product_layer_->SetUp(product_bottom_vec_, &product_top_vec_);
  CHECK_EQ((*top)[0]->num(), num);
  CHECK_EQ((*top)[0]->channels(), channels);
  CHECK_EQ((*top)[0]->height(), height);
  CHECK_EQ((*top)[0]->width(), width);
}<commit_msg>bug fix: average pooling already divides by N^2<commit_after>// Copyright 2014 BVLC and contributors.

#include <vector>

#include "caffe/filler.hpp"
#include "caffe/layer.hpp"
#include "caffe/vision_layers.hpp"
#include "caffe/util/math_functions.hpp"

namespace caffe {

template <typename Dtype>
void LRNMapLayer<Dtype>::SetUp(const vector<Blob<Dtype>*>& bottom,
      vector<Blob<Dtype>*>* top) {
  CHECK_EQ(bottom.size(), 1) <<
      "Local Response Normalization Layer takes a single blob as input.";
  CHECK_EQ(top->size(), 1) <<
      "Local Response Normalization Layer takes a single blob as output.";
  const int num = bottom[0]->num();
  const int channels = bottom[0]->channels();
  const int height = bottom[0]->height();
  const int width = bottom[0]->width();
  const int size_ = this->layer_param_.lrn_map_param().local_size();
  const Dtype pre_pad = (size_ - 1) / 2;
  const Dtype alpha = this->layer_param_.lrn_map_param().alpha();
  const Dtype beta = this->layer_param_.lrn_map_param().beta();
  // Set up square layer to square the inputs.
  square_input_.Reshape(num, channels, height, width);
  square_bottom_vec_.clear();
  square_top_vec_.clear();
  square_bottom_vec_.push_back(&square_input_);
  square_top_vec_.push_back(&square_output_);
  LayerParameter square_param;
  square_param.mutable_power_param()->set_power(Dtype(2));
  square_layer_.reset(new PowerLayer<Dtype>(square_param));
  square_layer_->SetUp(square_bottom_vec_, &square_top_vec_);
  CHECK_EQ(square_output_.num(), num);
  CHECK_EQ(square_output_.channels(), channels);
  CHECK_EQ(square_output_.height(), height);
  CHECK_EQ(square_output_.width(), width);
  // Output of pool layer gives us the neighborhood response.
  pool_top_vec_.clear();
  pool_top_vec_.push_back(&pool_output_);
  LayerParameter pool_param;
  pool_param.mutable_pooling_param()->set_pool(PoolingParameter_PoolMethod_AVE);
  pool_param.mutable_pooling_param()->set_pad(pre_pad);
  pool_param.mutable_pooling_param()->set_kernel_size(size_);
  pool_layer_.reset(new PoolingLayer<Dtype>(pool_param));
  pool_layer_->SetUp(square_top_vec_, &pool_top_vec_);
  CHECK_EQ(pool_output_.num(), num);
  CHECK_EQ(pool_output_.channels(), channels);
  CHECK_EQ(pool_output_.height(), height);
  CHECK_EQ(pool_output_.width(), width);
  // Set up power layer to compute (1 + alpha/N^2 s)^-beta, where s is the sum
  // of a squared neighborhood (as output by the conv layer).
  power_top_vec_.clear();
  power_top_vec_.push_back(&power_output_);
  LayerParameter power_param;
  power_param.mutable_power_param()->set_power(-beta);
  power_param.mutable_power_param()->set_scale(alpha);
  power_param.mutable_power_param()->set_shift(Dtype(1));
  power_layer_.reset(new PowerLayer<Dtype>(power_param));
  power_layer_->SetUp(pool_top_vec_, &power_top_vec_);
  CHECK_EQ(power_output_.num(), num);
  CHECK_EQ(power_output_.channels(), channels);
  CHECK_EQ(power_output_.height(), height);
  CHECK_EQ(power_output_.width(), width);
  // Set up a product layer to compute outputs by multiplying inputs by scale.
  product_bottom_vec_.clear();
  product_bottom_vec_.push_back(bottom[0]);
  product_bottom_vec_.push_back(&power_output_);
  product_top_vec_.clear();
  product_top_vec_.push_back((*top)[0]);
  LayerParameter product_param;
  product_layer_.reset(new EltwiseProductLayer<Dtype>(product_param));
  product_layer_->SetUp(product_bottom_vec_, &product_top_vec_);
  CHECK_EQ((*top)[0]->num(), num);
  CHECK_EQ((*top)[0]->channels(), channels);
  CHECK_EQ((*top)[0]->height(), height);
  CHECK_EQ((*top)[0]->width(), width);
}
{'fraction_non_alphanumeric': 0.14126186487995535, 'fraction_numerical': 0.00628140703517588, 'mean_word_length': 6.230070635721494, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 71, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1061494', 'n_tokens_mistral': 2396, 'n_tokens_neox': 2366, 'n_words': 447}