package org.ea.javacnn.layers;
import org.ea.javacnn.data.BackPropResult;
import org.ea.javacnn.data.DataBlock;
import org.ea.javacnn.data.OutputDefinition;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/**
* This layer is useful when we are dealing with ReLU neurons. Why is that?
* Because ReLU neurons have unbounded activations and we need LRN to normalize
* that. We want to detect high frequency features with a large response. If we
* normalize around the local neighborhood of the excited neuron, it becomes even
* more sensitive as compared to its neighbors.
*
* At the same time, it will dampen the responses that are uniformly large in any
* given local neighborhood. If all the values are large, then normalizing those
* values will diminish all of them. So basically we want to encourage some kind
* of inhibition and boost the neurons with relatively larger activations. This
* has been discussed nicely in Section 3.3 of the original paper by Krizhevsky et al.
*
* @author Daniel Persson (mailto.woden@gmail.com)
*/
public class LocalResponseNormalizationLayer implements Layer,Serializable {
/*
The constants k, n, alpha and beta are hyper-parameters whose
values are determined using a validation set; we used
k = 2, n = 5, alpha = 10^-4, beta = 0.75
quote from http://www.cs.toronto.edu/~fritz/absps/imagenet.pdf
*/
private final double k = 2.0;
private final double n = 5.0;
private final double alpha = 0.0001;
private final double beta = 0.75;
private DataBlock in_act, out_act, S_cache_;
public LocalResponseNormalizationLayer() {
// checks
if(this.n%2 == 0) {
System.out.println("WARNING n should be odd for LRN layer");
}
}
@Override
public DataBlock forward(DataBlock db, boolean training) {
this.in_act = db;
DataBlock A = db.cloneAndZero();
this.S_cache_ = db.cloneAndZero();
double n2 = Math.floor(this.n/2);
for(int x=0;x getBackPropagationResult() {
return new ArrayList();
}
}
Ads help maintain this website.