Adding some suggestion
This commit is contained in:
committed by
nishantkr18
parent
e027b41de8
commit
4e147f5fef
@@ -44,10 +44,10 @@ AddMerge<InputDataType, OutputDataType, CustomLayers...>::AddMerge(
|
||||
template<typename InputDataType, typename OutputDataType,
|
||||
typename... CustomLayers>
|
||||
AddMerge<InputDataType, OutputDataType, CustomLayers...>::AddMerge(
|
||||
const AddMerge& network) :
|
||||
model(network.model),
|
||||
run(network.run),
|
||||
ownsLayers(network.ownsLayers)
|
||||
const AddMerge& layer) :
|
||||
model(layer.model),
|
||||
run(layer.run),
|
||||
ownsLayers(layer.ownsLayers)
|
||||
{
|
||||
// Nothing to do here.
|
||||
}
|
||||
|
||||
@@ -318,12 +318,6 @@ class AtrousConvolution
|
||||
output = arma::fliplr(arma::flipud(input));
|
||||
}
|
||||
|
||||
//! Locally-stored number of padding width.
|
||||
std::tuple<size_t, size_t> padW;
|
||||
|
||||
//! Locally-stored number of padding height.
|
||||
std::tuple<size_t, size_t> padH;
|
||||
|
||||
//! Locally-stored number of input channels.
|
||||
size_t inSize;
|
||||
|
||||
@@ -384,9 +378,6 @@ class AtrousConvolution
|
||||
//! Locally-stored transformed gradient parameter.
|
||||
arma::cube gradientTemp;
|
||||
|
||||
//! Locally-stored paddingType
|
||||
std::string paddingType;
|
||||
|
||||
//! Locally-stored padding layer.
|
||||
ann::Padding<> padding;
|
||||
|
||||
|
||||
@@ -51,49 +51,25 @@ AtrousConvolution<
|
||||
InputDataType,
|
||||
OutputDataType
|
||||
>::AtrousConvolution(
|
||||
const AtrousConvolution& network) :
|
||||
inSize(network.inSize),
|
||||
outSize(network.outSize),
|
||||
kernelWidth(network.kernelWidth),
|
||||
kernelHeight(network.kernelHeight),
|
||||
strideWidth(network.strideWidth),
|
||||
strideHeight(network.strideHeight),
|
||||
inputWidth(network.inputWidth),
|
||||
inputHeight(network.inputHeight),
|
||||
outputWidth(network.outputWidth),
|
||||
outputHeight(network.outputHeight),
|
||||
dilationWidth(network.dilationWidth),
|
||||
dilationHeight(network.dilationHeight),
|
||||
weight(network.weight),
|
||||
bias(network.bias),
|
||||
paddingType(network.paddingType),
|
||||
padH(network.padH),
|
||||
padW(network.padW)
|
||||
const AtrousConvolution& layer) :
|
||||
inSize(layer.inSize),
|
||||
outSize(layer.outSize),
|
||||
kernelWidth(layer.kernelWidth),
|
||||
kernelHeight(layer.kernelHeight),
|
||||
strideWidth(layer.strideWidth),
|
||||
strideHeight(layer.strideHeight),
|
||||
inputWidth(layer.inputWidth),
|
||||
inputHeight(layer.inputHeight),
|
||||
outputWidth(layer.outputWidth),
|
||||
outputHeight(layer.outputHeight),
|
||||
dilationWidth(layer.dilationWidth),
|
||||
dilationHeight(layer.dilationHeight),
|
||||
weight(layer.weight),
|
||||
bias(layer.bias),
|
||||
padding(layer.padding)
|
||||
{
|
||||
weights.set_size((outSize * inSize * kernelWidth * kernelHeight) + outSize,
|
||||
1);
|
||||
|
||||
// Transform paddingType to lowercase.
|
||||
std::string paddingTypeLow = paddingType;
|
||||
util::ToLower(paddingType, paddingTypeLow);
|
||||
|
||||
size_t padWLeft = std::get<0>(padW);
|
||||
size_t padWRight = std::get<1>(padW);
|
||||
size_t padHTop = std::get<0>(padH);
|
||||
size_t padHBottom = std::get<1>(padH);
|
||||
if (paddingTypeLow == "valid")
|
||||
{
|
||||
padWLeft = 0;
|
||||
padWRight = 0;
|
||||
padHTop = 0;
|
||||
padHBottom = 0;
|
||||
}
|
||||
else if (paddingTypeLow == "same")
|
||||
{
|
||||
InitializeSamePadding(padWLeft, padWRight, padHTop, padHBottom);
|
||||
}
|
||||
|
||||
padding = ann::Padding<>(padWLeft, padWRight, padHTop, padHBottom);
|
||||
}
|
||||
|
||||
template<
|
||||
@@ -135,8 +111,7 @@ AtrousConvolution<
|
||||
inputWidth,
|
||||
inputHeight,
|
||||
dilationWidth,
|
||||
dilationHeight,
|
||||
paddingType)
|
||||
dilationHeight)
|
||||
{
|
||||
// Nothing to do here.
|
||||
}
|
||||
@@ -179,10 +154,7 @@ AtrousConvolution<
|
||||
outputWidth(0),
|
||||
outputHeight(0),
|
||||
dilationWidth(dilationWidth),
|
||||
dilationHeight(dilationHeight),
|
||||
paddingType(paddingType),
|
||||
padH(padH),
|
||||
padW(padW)
|
||||
dilationHeight(dilationHeight)
|
||||
{
|
||||
weights.set_size((outSize * inSize * kernelWidth * kernelHeight) + outSize,
|
||||
1);
|
||||
|
||||
@@ -33,14 +33,14 @@ BatchNorm<InputDataType, OutputDataType>::BatchNorm() :
|
||||
|
||||
template<typename InputDataType, typename OutputDataType>
|
||||
BatchNorm<InputDataType, OutputDataType>::BatchNorm(
|
||||
const BatchNorm& network) :
|
||||
size(network.size),
|
||||
eps(network.eps),
|
||||
loading(network.loading),
|
||||
deterministic(network.deterministic),
|
||||
count(network.count),
|
||||
gamma(network.gamma),
|
||||
beta(network.beta)
|
||||
const BatchNorm& layer) :
|
||||
size(layer.size),
|
||||
eps(layer.eps),
|
||||
loading(layer.loading),
|
||||
deterministic(layer.deterministic),
|
||||
count(layer.count),
|
||||
gamma(layer.gamma),
|
||||
beta(layer.beta)
|
||||
{
|
||||
weights.set_size(size + size, 1);
|
||||
runningMean.zeros(size, 1);
|
||||
|
||||
@@ -53,13 +53,13 @@ BilinearInterpolation(
|
||||
|
||||
template<typename InputDataType, typename OutputDataType>
|
||||
BilinearInterpolation<InputDataType, OutputDataType>::
|
||||
BilinearInterpolation(const BilinearInterpolation& network):
|
||||
inRowSize(network.inRowSize),
|
||||
inColSize(network.inColSize),
|
||||
outRowSize(network.outRowSize),
|
||||
outColSize(network.outColSize),
|
||||
depth(network.depth),
|
||||
batchSize(network.batchSize)
|
||||
BilinearInterpolation(const BilinearInterpolation& layer):
|
||||
inRowSize(layer.inRowSize),
|
||||
inColSize(layer.inColSize),
|
||||
outRowSize(layer.outRowSize),
|
||||
outColSize(layer.outColSize),
|
||||
depth(layer.depth),
|
||||
batchSize(layer.batchSize)
|
||||
{
|
||||
// Nothing to do here.
|
||||
}
|
||||
|
||||
@@ -39,12 +39,12 @@ Concat<InputDataType, OutputDataType, CustomLayers...>::Concat(
|
||||
template<typename InputDataType, typename OutputDataType,
|
||||
typename... CustomLayers>
|
||||
Concat<InputDataType, OutputDataType, CustomLayers...>::Concat(
|
||||
const Concat& network) :
|
||||
inputSize(network.inputSize),
|
||||
axis(network.axis),
|
||||
useAxis(network.useAxis),
|
||||
model(network.model),
|
||||
run(network.run)
|
||||
const Concat& layer) :
|
||||
inputSize(layer.inputSize),
|
||||
axis(layer.axis),
|
||||
useAxis(layer.useAxis),
|
||||
model(layer.model),
|
||||
run(layer.run)
|
||||
{
|
||||
parameters.set_size(0, 0);
|
||||
|
||||
|
||||
@@ -43,9 +43,9 @@ ConcatPerformance<
|
||||
OutputLayerType,
|
||||
InputDataType,
|
||||
OutputDataType
|
||||
>::ConcatPerformance(const ConcatPerformance& network) :
|
||||
inSize(network.inSize),
|
||||
outputLayer(network.outputLayer)
|
||||
>::ConcatPerformance(const ConcatPerformance& layer) :
|
||||
inSize(layer.inSize),
|
||||
outputLayer(layer.outputLayer)
|
||||
{
|
||||
// Nothing to do here.
|
||||
}
|
||||
|
||||
@@ -27,9 +27,9 @@ Concatenate<InputDataType, OutputDataType>::Concatenate()
|
||||
|
||||
template<typename InputDataType, typename OutputDataType>
|
||||
Concatenate<InputDataType, OutputDataType>::Concatenate(
|
||||
const Concatenate& network) :
|
||||
inRows(network.inRows),
|
||||
concat(network.concat)
|
||||
const Concatenate& layer) :
|
||||
inRows(layer.inRows),
|
||||
concat(layer.concat)
|
||||
{
|
||||
// Nothing to do here.
|
||||
}
|
||||
|
||||
@@ -32,10 +32,10 @@ Constant<InputDataType, OutputDataType>::Constant(
|
||||
|
||||
template<typename InputDataType, typename OutputDataType>
|
||||
Constant<InputDataType, OutputDataType>::Constant(
|
||||
const Constant& network) :
|
||||
inSize(network.inSize),
|
||||
outSize(network.outSize),
|
||||
constantOutput(network.constantOutput)
|
||||
const Constant& layer) :
|
||||
inSize(layer.inSize),
|
||||
outSize(layer.outSize),
|
||||
constantOutput(layer.constantOutput)
|
||||
{
|
||||
// Nothing to do here.
|
||||
}
|
||||
|
||||
@@ -342,9 +342,6 @@ class Convolution
|
||||
//! Locally-stored top padding height.
|
||||
size_t padHTop;
|
||||
|
||||
//! Locally-stored paddingType
|
||||
std::string paddingType;
|
||||
|
||||
//! Locally-stored weight object.
|
||||
OutputDataType weights;
|
||||
|
||||
|
||||
@@ -154,45 +154,28 @@ Convolution<
|
||||
InputDataType,
|
||||
OutputDataType
|
||||
>::Convolution(
|
||||
const Convolution& network) :
|
||||
inSize(network.inSize),
|
||||
outSize(network.outSize),
|
||||
kernelWidth(network.kernelWidth),
|
||||
kernelHeight(network.kernelHeight),
|
||||
strideWidth(network.strideWidth),
|
||||
strideHeight(network.strideHeight),
|
||||
padWLeft(network.padWLeft),
|
||||
padWRight(network.padWRight),
|
||||
padHBottom(network.padHBottom),
|
||||
padHTop(network.padHTop),
|
||||
inputWidth(network.inputWidth),
|
||||
inputHeight(network.inputHeight),
|
||||
outputWidth(network.outputWidth),
|
||||
outputHeight(network.outputHeight),
|
||||
paddingType(network.paddingType),
|
||||
weight(network.weight),
|
||||
bias(network.bias)
|
||||
const Convolution& layer) :
|
||||
inSize(layer.inSize),
|
||||
outSize(layer.outSize),
|
||||
kernelWidth(layer.kernelWidth),
|
||||
kernelHeight(layer.kernelHeight),
|
||||
strideWidth(layer.strideWidth),
|
||||
strideHeight(layer.strideHeight),
|
||||
padWLeft(layer.padWLeft),
|
||||
padWRight(layer.padWRight),
|
||||
padHBottom(layer.padHBottom),
|
||||
padHTop(layer.padHTop),
|
||||
inputWidth(layer.inputWidth),
|
||||
inputHeight(layer.inputHeight),
|
||||
outputWidth(layer.outputWidth),
|
||||
outputHeight(layer.outputHeight),
|
||||
paddingType(layer.paddingType),
|
||||
weight(layer.weight),
|
||||
bias(layer.bias),
|
||||
padding(layer.padding)
|
||||
{
|
||||
weights.set_size((outSize * inSize * kernelWidth * kernelHeight) + outSize,
|
||||
1);
|
||||
|
||||
// Transform paddingType to lowercase.
|
||||
std::string paddingTypeLow = paddingType;
|
||||
util::ToLower(paddingType, paddingTypeLow);
|
||||
|
||||
if (paddingTypeLow == "valid")
|
||||
{
|
||||
padWLeft = 0;
|
||||
padWRight = 0;
|
||||
padHTop = 0;
|
||||
padHBottom = 0;
|
||||
}
|
||||
else if (paddingTypeLow == "same")
|
||||
{
|
||||
InitializeSamePadding();
|
||||
}
|
||||
|
||||
padding = ann::Padding<>(padWLeft, padWRight, padHTop, padHBottom);
|
||||
}
|
||||
|
||||
template<
|
||||
|
||||
@@ -168,9 +168,6 @@ class DropConnect
|
||||
//! The scale fraction.
|
||||
double scale;
|
||||
|
||||
//! Locally-stored copy visitor
|
||||
CopyVisitor<CustomLayers...> copyVisitor;
|
||||
|
||||
//! Locally-stored weight object.
|
||||
OutputDataType parameters;
|
||||
|
||||
|
||||
@@ -54,12 +54,14 @@ DropConnect<InputDataType, OutputDataType, CustomLayers...>::DropConnect(
|
||||
template<typename InputDataType, typename OutputDataType,
|
||||
typename... CustomLayers>
|
||||
DropConnect<InputDataType, OutputDataType, CustomLayers...>::DropConnect(
|
||||
const DropConnect& network) :
|
||||
ratio(network.ratio),
|
||||
scale(network.scale),
|
||||
deterministic(network.deterministic)
|
||||
const DropConnect& layer) :
|
||||
ratio(layer.ratio),
|
||||
scale(layer.scale),
|
||||
deterministic(layer.deterministic)
|
||||
{
|
||||
baseLayer = boost::apply_visitor(copyVisitor, network.baseLayer);
|
||||
CopyVisitor<CustomLayers...> copyVisitor;
|
||||
|
||||
baseLayer = boost::apply_visitor(copyVisitor, layer.baseLayer);
|
||||
this->network.push_back(baseLayer);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,11 +31,11 @@ Dropout<InputDataType, OutputDataType>::Dropout(
|
||||
|
||||
template<typename InputDataType, typename OutputDataType>
|
||||
Dropout<InputDataType, OutputDataType>::Dropout(
|
||||
const Dropout& network) :
|
||||
ratio(network.ratio),
|
||||
scale(network.scale),
|
||||
deterministic(network.deterministic),
|
||||
mask(network.mask)
|
||||
const Dropout& layer) :
|
||||
ratio(layer.ratio),
|
||||
scale(layer.scale),
|
||||
deterministic(layer.deterministic),
|
||||
mask(layer.mask)
|
||||
{
|
||||
// Nothing to do here.
|
||||
}
|
||||
|
||||
@@ -48,22 +48,22 @@ FastLSTM<InputDataType, OutputDataType>::FastLSTM(
|
||||
|
||||
template <typename InputDataType, typename OutputDataType>
|
||||
FastLSTM<InputDataType, OutputDataType>::FastLSTM(
|
||||
const FastLSTM& network) :
|
||||
inSize(network.inSize),
|
||||
outSize(network.outSize),
|
||||
rho(network.rho),
|
||||
grad(network.grad),
|
||||
forwardStep(network.forwardStep),
|
||||
backwardStep(network.backwardStep),
|
||||
gradientStep(network.gradientStep),
|
||||
batchSize(network.batchSize),
|
||||
batchStep(network.batchStep),
|
||||
gradientStepIdx(network.gradientStepIdx),
|
||||
rhoSize(network.rho),
|
||||
bpttSteps(network.bpttSteps),
|
||||
input2GateWeight(network.input2GateWeight),
|
||||
input2GateBias(network.input2GateBias),
|
||||
output2GateWeight(network.output2GateWeight)
|
||||
const FastLSTM& layer) :
|
||||
inSize(layer.inSize),
|
||||
outSize(layer.outSize),
|
||||
rho(layer.rho),
|
||||
grad(layer.grad),
|
||||
forwardStep(layer.forwardStep),
|
||||
backwardStep(layer.backwardStep),
|
||||
gradientStep(layer.gradientStep),
|
||||
batchSize(layer.batchSize),
|
||||
batchStep(layer.batchStep),
|
||||
gradientStepIdx(layer.gradientStepIdx),
|
||||
rhoSize(layer.rho),
|
||||
bpttSteps(layer.bpttSteps),
|
||||
input2GateWeight(layer.input2GateWeight),
|
||||
input2GateBias(layer.input2GateBias),
|
||||
output2GateWeight(layer.output2GateWeight)
|
||||
{
|
||||
// Weights for: input to gate layer (4 * outsize * inSize + 4 * outsize)
|
||||
// and output to gate (4 * outSize).
|
||||
|
||||
@@ -33,9 +33,9 @@ FlexibleReLU<InputDataType, OutputDataType>::FlexibleReLU(
|
||||
|
||||
template<typename InputDataType, typename OutputDataType>
|
||||
FlexibleReLU<InputDataType, OutputDataType>::FlexibleReLU(
|
||||
const FlexibleReLU& network) :
|
||||
userAlpha(network.userAlpha),
|
||||
alpha(network.alpha)
|
||||
const FlexibleReLU& layer) :
|
||||
userAlpha(layer.userAlpha),
|
||||
alpha(layer.alpha)
|
||||
{
|
||||
this->alpha.set_size(1, 1);
|
||||
this->alpha(0) = userAlpha;
|
||||
|
||||
@@ -22,17 +22,17 @@ namespace ann /** Artificial Neural Network. */ {
|
||||
|
||||
template <typename InputDataType, typename OutputDataType>
|
||||
Glimpse<InputDataType, OutputDataType>::Glimpse(
|
||||
const Glimpse& network) :
|
||||
inSize(network.inSize),
|
||||
size(network.size),
|
||||
depth(network.depth),
|
||||
scale(network.scale),
|
||||
inputWidth(network.inputWidth),
|
||||
inputHeight(network.inputHeight),
|
||||
outputWidth(network.outputWidth),
|
||||
outputHeight(network.outputHeight),
|
||||
inputDepth(network.inputDepth),
|
||||
deterministic(network.deterministic)
|
||||
const Glimpse& layer) :
|
||||
inSize(layer.inSize),
|
||||
size(layer.size),
|
||||
depth(layer.depth),
|
||||
scale(layer.scale),
|
||||
inputWidth(layer.inputWidth),
|
||||
inputHeight(layer.inputHeight),
|
||||
outputWidth(layer.outputWidth),
|
||||
outputHeight(layer.outputHeight),
|
||||
inputDepth(layer.inputDepth),
|
||||
deterministic(layer.deterministic)
|
||||
{
|
||||
// Nothing to do here.
|
||||
}
|
||||
|
||||
@@ -249,9 +249,6 @@ class GRU
|
||||
|
||||
//! Locally-stored output parameter object.
|
||||
OutputDataType outputParameter;
|
||||
|
||||
//! Locally-stored copy visitor
|
||||
CopyVisitor<CustomLayers...> copyVisitor;
|
||||
}; // class GRU
|
||||
|
||||
} // namespace ann
|
||||
|
||||
@@ -33,33 +33,35 @@ GRU<InputDataType, OutputDataType, CustomLayers...>::GRU()
|
||||
template<typename InputDataType, typename OutputDataType,
|
||||
typename... CustomLayers>
|
||||
GRU<InputDataType, OutputDataType, CustomLayers...>::GRU(
|
||||
const GRU& network) :
|
||||
inSize(network.inSize),
|
||||
outSize(network.outSize),
|
||||
rho(network.rho),
|
||||
batchSize(network.batchSize),
|
||||
forwardStep(network.forwardStep),
|
||||
backwardStep(network.backwardStep),
|
||||
gradientStep(network.gradientStep),
|
||||
deterministic(network.deterministic),
|
||||
prevError(network.prevError),
|
||||
allZeros(network.allZeros),
|
||||
outParameter(network.outParameter),
|
||||
prevOutput(network.prevOutput),
|
||||
backIterator(network.backIterator),
|
||||
gradIterator(network.gradIterator)
|
||||
const GRU& layer) :
|
||||
inSize(layer.inSize),
|
||||
outSize(layer.outSize),
|
||||
rho(layer.rho),
|
||||
batchSize(layer.batchSize),
|
||||
forwardStep(layer.forwardStep),
|
||||
backwardStep(layer.backwardStep),
|
||||
gradientStep(layer.gradientStep),
|
||||
deterministic(layer.deterministic),
|
||||
prevError(layer.prevError),
|
||||
allZeros(layer.allZeros),
|
||||
outParameter(layer.outParameter),
|
||||
prevOutput(layer.prevOutput),
|
||||
backIterator(layer.backIterator),
|
||||
gradIterator(layer.gradIterator)
|
||||
{
|
||||
CopyVisitor<CustomLayers...> copyVisitor;
|
||||
|
||||
// Input specific linear layers(for zt, rt, ot).
|
||||
input2GateModule = boost::apply_visitor(copyVisitor,
|
||||
network.input2GateModule);
|
||||
layer.input2GateModule);
|
||||
|
||||
// Previous output gates (for zt and rt).
|
||||
output2GateModule = boost::apply_visitor(copyVisitor,
|
||||
network.output2GateModule);
|
||||
layer.output2GateModule);
|
||||
|
||||
// Previous output gate for ot.
|
||||
outputHidden2GateModule = boost::apply_visitor(copyVisitor,
|
||||
network.outputHidden2GateModule);
|
||||
layer.outputHidden2GateModule);
|
||||
|
||||
this->network.push_back(input2GateModule);
|
||||
this->network.push_back(output2GateModule);
|
||||
|
||||
@@ -40,26 +40,26 @@ Highway<InputDataType, OutputDataType, CustomLayers...>::Highway() :
|
||||
template<typename InputDataType, typename OutputDataType,
|
||||
typename... CustomLayers>
|
||||
Highway<InputDataType, OutputDataType, CustomLayers...>::Highway(
|
||||
const Highway& network) :
|
||||
inSize(network.inSize),
|
||||
model(network.model),
|
||||
reset(network.reset),
|
||||
width(network.width),
|
||||
height(network.height),
|
||||
transformWeight(network.transformWeight),
|
||||
transformBias(network.transformBias),
|
||||
transformGateActivation(network.transformGateActivation),
|
||||
transformGateError(network.transformGateError),
|
||||
networkOwnerships(network.networkOwnerships),
|
||||
networkOutput(network.networkOutput)
|
||||
const Highway& layer) :
|
||||
inSize(layer.inSize),
|
||||
model(layer.model),
|
||||
reset(layer.reset),
|
||||
width(layer.width),
|
||||
height(layer.height),
|
||||
transformWeight(layer.transformWeight),
|
||||
transformBias(layer.transformBias),
|
||||
transformGateActivation(layer.transformGateActivation),
|
||||
transformGateError(layer.transformGateError),
|
||||
networkOwnerships(layer.networkOwnerships),
|
||||
networkOutput(layer.networkOutput)
|
||||
{
|
||||
weights.set_size(inSize * inSize + inSize, 1);
|
||||
for (size_t i = 0; i < network.network.size(); ++i)
|
||||
for (size_t i = 0; i < layer.network.size(); ++i)
|
||||
{
|
||||
if (network.networkOwnerships[i])
|
||||
if (layer.networkOwnerships[i])
|
||||
{
|
||||
this->network.push_back(boost::apply_visitor(copyVisitor,
|
||||
network.network[i]));
|
||||
layer.network[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,12 +30,12 @@ LayerNorm<InputDataType, OutputDataType>::LayerNorm() :
|
||||
}
|
||||
|
||||
template<typename InputDataType, typename OutputDataType>
|
||||
LayerNorm<InputDataType, OutputDataType>::LayerNorm(const LayerNorm& network) :
|
||||
size(network.size),
|
||||
eps(network.eps),
|
||||
loading(network.loading),
|
||||
gamma(network.gamma),
|
||||
beta(network.beta)
|
||||
LayerNorm<InputDataType, OutputDataType>::LayerNorm(const LayerNorm& layer) :
|
||||
size(layer.size),
|
||||
eps(layer.eps),
|
||||
loading(layer.loading),
|
||||
gamma(layer.gamma),
|
||||
beta(layer.beta)
|
||||
{
|
||||
weights.set_size(size + size, 1);
|
||||
}
|
||||
|
||||
@@ -31,12 +31,12 @@ Linear<InputDataType, OutputDataType, RegularizerType>::Linear() :
|
||||
template<typename InputDataType, typename OutputDataType,
|
||||
typename RegularizerType>
|
||||
Linear<InputDataType, OutputDataType, RegularizerType>::Linear(
|
||||
const Linear& network) :
|
||||
inSize(network.inSize),
|
||||
outSize(network.outSize),
|
||||
regularizer(network.regularizer),
|
||||
weight(network.weight),
|
||||
bias(network.bias)
|
||||
const Linear& layer) :
|
||||
inSize(layer.inSize),
|
||||
outSize(layer.outSize),
|
||||
regularizer(layer.regularizer),
|
||||
weight(layer.weight),
|
||||
bias(layer.bias)
|
||||
{
|
||||
weights.set_size(outSize * inSize + outSize, 1);
|
||||
}
|
||||
|
||||
@@ -31,11 +31,11 @@ LinearNoBias<InputDataType, OutputDataType, RegularizerType>::LinearNoBias() :
|
||||
template<typename InputDataType, typename OutputDataType,
|
||||
typename RegularizerType>
|
||||
LinearNoBias<InputDataType, OutputDataType, RegularizerType>::LinearNoBias(
|
||||
const LinearNoBias& network) :
|
||||
inSize(network.inSize),
|
||||
outSize(network.outSize),
|
||||
regularizer(network.regularizer),
|
||||
weight(network.weight)
|
||||
const LinearNoBias& layer) :
|
||||
inSize(layer.inSize),
|
||||
outSize(layer.outSize),
|
||||
regularizer(layer.regularizer),
|
||||
weight(layer.weight)
|
||||
{
|
||||
weights.set_size(outSize * inSize, 1);
|
||||
}
|
||||
|
||||
@@ -31,9 +31,9 @@ Lookup<InputDataType, OutputDataType>::Lookup(
|
||||
|
||||
template <typename InputDataType, typename OutputDataType>
|
||||
Lookup<InputDataType, OutputDataType>::Lookup(
|
||||
const Lookup& network) :
|
||||
inSize(network.inSize),
|
||||
outSize(network.outSize)
|
||||
const Lookup& layer) :
|
||||
inSize(layer.inSize),
|
||||
outSize(layer.outSize)
|
||||
{
|
||||
weights.set_size(outSize, inSize);
|
||||
}
|
||||
|
||||
@@ -26,32 +26,32 @@ LSTM<InputDataType, OutputDataType>::LSTM()
|
||||
|
||||
template <typename InputDataType, typename OutputDataType>
|
||||
LSTM<InputDataType, OutputDataType>::LSTM(
|
||||
const LSTM& network) :
|
||||
inSize(network.inSize),
|
||||
outSize(network.outSize),
|
||||
rho(network.rho),
|
||||
forwardStep(network.forwardStep),
|
||||
backwardStep(network.backwardStep),
|
||||
gradientStep(network.gradientStep),
|
||||
batchSize(network.batchSize),
|
||||
batchStep(network.batchStep),
|
||||
rhoSize(network.rhoSize),
|
||||
bpttSteps(network.bpttSteps),
|
||||
input2GateOutputWeight(network.input2GateOutputWeight),
|
||||
input2GateOutputBias(network.input2GateOutputBias),
|
||||
input2GateForgetWeight(network.input2GateForgetWeight),
|
||||
input2GateForgetBias(network.input2GateForgetBias),
|
||||
input2GateInputWeight(network.input2GateInputWeight),
|
||||
input2GateInputBias(network.input2GateInputBias),
|
||||
input2HiddenWeight(network.input2HiddenWeight),
|
||||
input2HiddenBias(network.input2HiddenBias),
|
||||
output2GateOutputWeight(network.output2GateOutputWeight),
|
||||
output2GateForgetWeight(network.output2GateForgetWeight),
|
||||
output2GateInputWeight(network.output2GateInputWeight),
|
||||
output2HiddenWeight(network.output2HiddenWeight),
|
||||
cell2GateOutputWeight(network.cell2GateOutputWeight),
|
||||
cell2GateForgetWeight(network.cell2GateForgetWeight),
|
||||
cell2GateInputWeight(network.cell2GateInputWeight)
|
||||
const LSTM& layer) :
|
||||
inSize(layer.inSize),
|
||||
outSize(layer.outSize),
|
||||
rho(layer.rho),
|
||||
forwardStep(layer.forwardStep),
|
||||
backwardStep(layer.backwardStep),
|
||||
gradientStep(layer.gradientStep),
|
||||
batchSize(layer.batchSize),
|
||||
batchStep(layer.batchStep),
|
||||
rhoSize(layer.rhoSize),
|
||||
bpttSteps(layer.bpttSteps),
|
||||
input2GateOutputWeight(layer.input2GateOutputWeight),
|
||||
input2GateOutputBias(layer.input2GateOutputBias),
|
||||
input2GateForgetWeight(layer.input2GateForgetWeight),
|
||||
input2GateForgetBias(layer.input2GateForgetBias),
|
||||
input2GateInputWeight(layer.input2GateInputWeight),
|
||||
input2GateInputBias(layer.input2GateInputBias),
|
||||
input2HiddenWeight(layer.input2HiddenWeight),
|
||||
input2HiddenBias(layer.input2HiddenBias),
|
||||
output2GateOutputWeight(layer.output2GateOutputWeight),
|
||||
output2GateForgetWeight(layer.output2GateForgetWeight),
|
||||
output2GateInputWeight(layer.output2GateInputWeight),
|
||||
output2HiddenWeight(layer.output2HiddenWeight),
|
||||
cell2GateOutputWeight(layer.cell2GateOutputWeight),
|
||||
cell2GateForgetWeight(layer.cell2GateForgetWeight),
|
||||
cell2GateInputWeight(layer.cell2GateInputWeight)
|
||||
{
|
||||
weights.set_size(4 * outSize * inSize + 7 * outSize +
|
||||
4 * outSize * outSize, 1);
|
||||
|
||||
@@ -53,22 +53,22 @@ MaxPooling<InputDataType, OutputDataType>::MaxPooling(
|
||||
|
||||
template<typename InputDataType, typename OutputDataType>
|
||||
MaxPooling<InputDataType, OutputDataType>::MaxPooling(
|
||||
const MaxPooling& network) :
|
||||
kernelWidth(network.kernelWidth),
|
||||
kernelHeight(network.kernelHeight),
|
||||
strideWidth(network.strideWidth),
|
||||
strideHeight(network.strideHeight),
|
||||
floor(network.floor),
|
||||
inSize(network.inSize),
|
||||
outSize(network.outSize),
|
||||
reset(network.reset),
|
||||
inputWidth(network.inputWidth),
|
||||
inputHeight(network.inputHeight),
|
||||
outputWidth(network.outputWidth),
|
||||
outputHeight(network.outputHeight),
|
||||
deterministic(network.deterministic),
|
||||
offset(network.offset),
|
||||
batchSize(network.batchSize)
|
||||
const MaxPooling& layer) :
|
||||
kernelWidth(layer.kernelWidth),
|
||||
kernelHeight(layer.kernelHeight),
|
||||
strideWidth(layer.strideWidth),
|
||||
strideHeight(layer.strideHeight),
|
||||
floor(layer.floor),
|
||||
inSize(layer.inSize),
|
||||
outSize(layer.outSize),
|
||||
reset(layer.reset),
|
||||
inputWidth(layer.inputWidth),
|
||||
inputHeight(layer.inputHeight),
|
||||
outputWidth(layer.outputWidth),
|
||||
outputHeight(layer.outputHeight),
|
||||
deterministic(layer.deterministic),
|
||||
offset(layer.offset),
|
||||
batchSize(layer.batchSize)
|
||||
{
|
||||
// Nothing to do here.
|
||||
}
|
||||
|
||||
@@ -53,22 +53,22 @@ MeanPooling<InputDataType, OutputDataType>::MeanPooling(
|
||||
|
||||
template<typename InputDataType, typename OutputDataType>
|
||||
MeanPooling<InputDataType, OutputDataType>::MeanPooling(
|
||||
const MeanPooling& network) :
|
||||
kernelWidth(network.kernelWidth),
|
||||
kernelHeight(network.kernelHeight),
|
||||
strideWidth(network.strideWidth),
|
||||
strideHeight(network.strideHeight),
|
||||
floor(network.floor),
|
||||
inSize(network.inSize),
|
||||
outSize(network.outSize),
|
||||
reset(network.reset),
|
||||
inputWidth(network.inputWidth),
|
||||
inputHeight(network.inputHeight),
|
||||
outputWidth(network.outputWidth),
|
||||
outputHeight(network.outputHeight),
|
||||
deterministic(network.deterministic),
|
||||
offset(network.offset),
|
||||
batchSize(network.batchSize)
|
||||
const MeanPooling& layer) :
|
||||
kernelWidth(layer.kernelWidth),
|
||||
kernelHeight(layer.kernelHeight),
|
||||
strideWidth(layer.strideWidth),
|
||||
strideHeight(layer.strideHeight),
|
||||
floor(layer.floor),
|
||||
inSize(layer.inSize),
|
||||
outSize(layer.outSize),
|
||||
reset(layer.reset),
|
||||
inputWidth(layer.inputWidth),
|
||||
inputHeight(layer.inputHeight),
|
||||
outputWidth(layer.outputWidth),
|
||||
outputHeight(layer.outputHeight),
|
||||
deterministic(layer.deterministic),
|
||||
offset(layer.offset),
|
||||
batchSize(layer.batchSize)
|
||||
{
|
||||
// Nothing to do here.
|
||||
}
|
||||
|
||||
@@ -46,12 +46,12 @@ MiniBatchDiscrimination<InputDataType, OutputDataType
|
||||
template <typename InputDataType, typename OutputDataType>
|
||||
MiniBatchDiscrimination<InputDataType, OutputDataType
|
||||
>::MiniBatchDiscrimination(
|
||||
const MiniBatchDiscrimination& network) :
|
||||
A(network.A),
|
||||
B(network.B),
|
||||
C(network.C),
|
||||
batchSize(network.batchSize),
|
||||
weight(network.weight)
|
||||
const MiniBatchDiscrimination& layer) :
|
||||
A(layer.A),
|
||||
B(layer.B),
|
||||
C(layer.C),
|
||||
batchSize(layer.batchSize),
|
||||
weight(layer.weight)
|
||||
{
|
||||
weights.set_size(A * B * C, 1);
|
||||
}
|
||||
|
||||
@@ -28,8 +28,8 @@ MultiplyConstant<InputDataType, OutputDataType>::MultiplyConstant(
|
||||
|
||||
template<typename InputDataType, typename OutputDataType>
|
||||
MultiplyConstant<InputDataType, OutputDataType>::MultiplyConstant(
|
||||
const MultiplyConstant& network) :
|
||||
scalar(network.scalar)
|
||||
const MultiplyConstant& layer) :
|
||||
scalar(layer.scalar)
|
||||
{
|
||||
// Nothing to do here.
|
||||
}
|
||||
|
||||
@@ -35,10 +35,10 @@ MultiplyMerge<InputDataType, OutputDataType, CustomLayers...>::MultiplyMerge(
|
||||
template<typename InputDataType, typename OutputDataType,
|
||||
typename... CustomLayers>
|
||||
MultiplyMerge<InputDataType, OutputDataType, CustomLayers...>::MultiplyMerge(
|
||||
const MultiplyMerge& network) :
|
||||
model(network.model),
|
||||
run(network.run),
|
||||
ownsLayer(network.ownsLayer)
|
||||
const MultiplyMerge& layer) :
|
||||
model(layer.model),
|
||||
run(layer.run),
|
||||
ownsLayer(layer.ownsLayer)
|
||||
{
|
||||
// Nothing to do here.
|
||||
}
|
||||
|
||||
@@ -42,15 +42,15 @@ template<typename InputDataType, typename OutputDataType,
|
||||
typename... CustomLayers>
|
||||
RecurrentAttention<InputDataType, OutputDataType, CustomLayers...>::
|
||||
RecurrentAttention(
|
||||
const RecurrentAttention& network) :
|
||||
outSize(network.outSize),
|
||||
rho(network.rho),
|
||||
forwardStep(network.forwardStep),
|
||||
backwardStep(network.backwardStep),
|
||||
deterministic(network.deterministic)
|
||||
const RecurrentAttention& layer) :
|
||||
outSize(layer.outSize),
|
||||
rho(layer.rho),
|
||||
forwardStep(layer.forwardStep),
|
||||
backwardStep(layer.backwardStep),
|
||||
deterministic(layer.deterministic)
|
||||
{
|
||||
rnnModule = boost::apply_visitor(copyVisitor, network.rnnModule);
|
||||
actionModule = boost::apply_visitor(copyVisitor, network.actionModule);
|
||||
rnnModule = boost::apply_visitor(copyVisitor, layer.rnnModule);
|
||||
actionModule = boost::apply_visitor(copyVisitor, layer.actionModule);
|
||||
|
||||
this->network.push_back(rnnModule);
|
||||
this->network.push_back(actionModule);
|
||||
|
||||
@@ -31,11 +31,11 @@ Reparametrization<InputDataType, OutputDataType>::Reparametrization() :
|
||||
|
||||
template<typename InputDataType, typename OutputDataType>
|
||||
Reparametrization<InputDataType, OutputDataType>::Reparametrization(
|
||||
const Reparametrization& network) :
|
||||
latentSize(network.latentSize),
|
||||
stochastic(network.stochastic),
|
||||
includeKl(network.includeKl),
|
||||
beta(network.beta)
|
||||
const Reparametrization& layer) :
|
||||
latentSize(layer.latentSize),
|
||||
stochastic(layer.stochastic),
|
||||
includeKl(layer.includeKl),
|
||||
beta(layer.beta)
|
||||
{
|
||||
// Nothing to do here.
|
||||
}
|
||||
|
||||
@@ -37,12 +37,12 @@ Sequential(const bool model) :
|
||||
template <typename InputDataType, typename OutputDataType, bool Residual,
|
||||
typename... CustomLayers>
|
||||
Sequential<InputDataType, OutputDataType, Residual, CustomLayers...>::
|
||||
Sequential(const Sequential& network) :
|
||||
model(network.model),
|
||||
reset(network.reset),
|
||||
width(network.width),
|
||||
height(network.height),
|
||||
ownsLayers(network.ownsLayers)
|
||||
Sequential(const Sequential& layer) :
|
||||
model(layer.model),
|
||||
reset(layer.reset),
|
||||
width(layer.width),
|
||||
height(layer.height),
|
||||
ownsLayers(layer.ownsLayers)
|
||||
{
|
||||
// Nothing to do here.
|
||||
}
|
||||
|
||||
@@ -451,9 +451,6 @@ class TransposedConvolution
|
||||
//! Locally-stored padding layer for back propagation.
|
||||
ann::Padding<> paddingBackward;
|
||||
|
||||
//! Locally-stored paddingType
|
||||
std::string paddingType;
|
||||
|
||||
//! Locally-stored delta object.
|
||||
OutputDataType delta;
|
||||
|
||||
|
||||
@@ -186,70 +186,29 @@ TransposedConvolution<
|
||||
InputDataType,
|
||||
OutputDataType
|
||||
>::TransposedConvolution(
|
||||
const TransposedConvolution& network) :
|
||||
inSize(network.inSize),
|
||||
outSize(network.outSize),
|
||||
kernelWidth(network.kernelWidth),
|
||||
kernelHeight(network.kernelHeight),
|
||||
strideWidth(network.strideWidth),
|
||||
strideHeight(network.strideHeight),
|
||||
padWLeft(network.padWLeft),
|
||||
padWRight(network.padWRight),
|
||||
padHBottom(network.padHBottom),
|
||||
padHTop(network.padHTop),
|
||||
inputWidth(network.inputWidth),
|
||||
inputHeight(network.inputHeight),
|
||||
outputWidth(network.outputWidth),
|
||||
outputHeight(network.outputHeight),
|
||||
weight(network.weight),
|
||||
bias(network.bias),
|
||||
paddingType(network.paddingType)
|
||||
const TransposedConvolution& layer) :
|
||||
inSize(layer.inSize),
|
||||
outSize(layer.outSize),
|
||||
kernelWidth(layer.kernelWidth),
|
||||
kernelHeight(layer.kernelHeight),
|
||||
strideWidth(layer.strideWidth),
|
||||
strideHeight(layer.strideHeight),
|
||||
padWLeft(layer.padWLeft),
|
||||
padWRight(layer.padWRight),
|
||||
padHBottom(layer.padHBottom),
|
||||
padHTop(layer.padHTop),
|
||||
inputWidth(layer.inputWidth),
|
||||
inputHeight(layer.inputHeight),
|
||||
outputWidth(layer.outputWidth),
|
||||
outputHeight(layer.outputHeight),
|
||||
weight(layer.weight),
|
||||
bias(layer.bias),
|
||||
paddingType(layer.paddingType),
|
||||
paddingForward(layer.paddingForward),
|
||||
paddingBackward(layer.paddingBackward)
|
||||
{
|
||||
weights.set_size((outSize * inSize * kernelWidth * kernelHeight) + outSize,
|
||||
1);
|
||||
// Transform paddingType to lowercase.
|
||||
std::string paddingTypeLow = paddingType;
|
||||
util::ToLower(paddingType, paddingTypeLow);
|
||||
|
||||
if (paddingTypeLow == "valid")
|
||||
{
|
||||
// Set Padding to 0.
|
||||
padWLeft = 0;
|
||||
padWRight = 0;
|
||||
padHTop = 0;
|
||||
padHBottom = 0;
|
||||
}
|
||||
else if (paddingTypeLow == "same")
|
||||
{
|
||||
InitializeSamePadding();
|
||||
}
|
||||
|
||||
const size_t totalPadWidth = padWLeft + padWRight;
|
||||
const size_t totalPadHeight = padHTop + padHBottom;
|
||||
|
||||
aW = (outputWidth + totalPadWidth - kernelWidth) % strideWidth;
|
||||
aH = (outputHeight + totalPadHeight - kernelHeight) % strideHeight;
|
||||
|
||||
const size_t padWidthLeftForward = kernelWidth - padWLeft - 1;
|
||||
const size_t padHeightTopForward = kernelHeight - padHTop - 1;
|
||||
const size_t padWidthRightForward = kernelWidth - padWRight - 1;
|
||||
const size_t padHeightBottomtForward = kernelHeight - padHBottom - 1;
|
||||
|
||||
paddingForward = ann::Padding<>(padWidthLeftForward,
|
||||
padWidthRightForward + aW, padHeightTopForward,
|
||||
padHeightBottomtForward + aH);
|
||||
paddingBackward = ann::Padding<>(padWLeft, padWRight, padHTop, padHBottom);
|
||||
|
||||
// Check if the output height and width are possible given the other
|
||||
// parameters of the layer.
|
||||
if (outputWidth != strideWidth * (inputWidth - 1) +
|
||||
aW + kernelWidth - totalPadWidth ||
|
||||
outputHeight != strideHeight * (inputHeight - 1) +
|
||||
aH + kernelHeight - totalPadHeight)
|
||||
{
|
||||
Log::Fatal << "The output width / output height is not possible given "
|
||||
<< "the other parameters of the layer." << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
template<
|
||||
|
||||
@@ -32,16 +32,16 @@ VirtualBatchNorm<InputDataType, OutputDataType>::VirtualBatchNorm() :
|
||||
|
||||
template<typename InputDataType, typename OutputDataType>
|
||||
VirtualBatchNorm<InputDataType, OutputDataType>::VirtualBatchNorm(
|
||||
const VirtualBatchNorm& network) :
|
||||
size(network.size),
|
||||
eps(network.eps),
|
||||
loading(network.loading),
|
||||
referenceBatchMean(network.referenceBatchMean),
|
||||
referenceBatchMeanSquared(network.referenceBatchMeanSquared),
|
||||
newCoefficient(network.newCoefficient),
|
||||
oldCoefficient(network.oldCoefficient),
|
||||
gamma(network.gamma),
|
||||
beta(network.beta)
|
||||
const VirtualBatchNorm& layer) :
|
||||
size(layer.size),
|
||||
eps(layer.eps),
|
||||
loading(layer.loading),
|
||||
referenceBatchMean(layer.referenceBatchMean),
|
||||
referenceBatchMeanSquared(layer.referenceBatchMeanSquared),
|
||||
newCoefficient(layer.newCoefficient),
|
||||
oldCoefficient(layer.oldCoefficient),
|
||||
gamma(layer.gamma),
|
||||
beta(layer.beta)
|
||||
{
|
||||
weights.set_size(size + size, 1);
|
||||
}
|
||||
|
||||
@@ -40,13 +40,13 @@ WeightNorm<InputDataType, OutputDataType, CustomLayers...>::WeightNorm(
|
||||
template<typename InputDataType, typename OutputDataType,
|
||||
typename... CustomLayers>
|
||||
WeightNorm<InputDataType, OutputDataType, CustomLayers...>::WeightNorm(
|
||||
const WeightNorm& network) :
|
||||
layerWeightSize(network.layerWeightSize),
|
||||
biasWeightSize(network.biasWeightSize),
|
||||
vectorParameter(network.vectorParameter),
|
||||
scalarParameter(network.scalarParameter),
|
||||
layerWeights(network.layerWeights),
|
||||
layerGradients(network.layerGradients)
|
||||
const WeightNorm& layer) :
|
||||
layerWeightSize(layer.layerWeightSize),
|
||||
biasWeightSize(layer.biasWeightSize),
|
||||
vectorParameter(layer.vectorParameter),
|
||||
scalarParameter(layer.scalarParameter),
|
||||
layerWeights(layer.layerWeights),
|
||||
layerGradients(layer.layerGradients)
|
||||
{
|
||||
weights.set_size(layerWeightSize + 1, 1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user