|
|
|
@ -58,67 +58,4 @@ size_t ExpandConvBaseLayer::getOutputSize() {
|
|
|
|
|
return layerSize;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ExpandConvBaseLayer::addSharedBias() {
|
|
|
|
|
size_t mapW = getOutputSize() / numFilters_;
|
|
|
|
|
size_t mapH = getOutputValue()->getElementCnt() / mapW;
|
|
|
|
|
MatrixPtr out =
|
|
|
|
|
Matrix::create(getOutputValue()->getData(), mapH, mapW, false, useGpu_);
|
|
|
|
|
|
|
|
|
|
Matrix::resizeOrCreate(transOutValue_, mapW, mapH, false, useGpu_);
|
|
|
|
|
|
|
|
|
|
out->transpose(transOutValue_, false); // false means no memory allocation
|
|
|
|
|
transOutValue_->reshape(transOutValue_->getElementCnt() / numFilters_,
|
|
|
|
|
numFilters_);
|
|
|
|
|
|
|
|
|
|
MatrixPtr bias = Matrix::create(biases_->getW()->getData(),
|
|
|
|
|
1,
|
|
|
|
|
biases_->getW()->getElementCnt(),
|
|
|
|
|
false,
|
|
|
|
|
useGpu_);
|
|
|
|
|
transOutValue_->addBias(*bias, 1.0f);
|
|
|
|
|
|
|
|
|
|
transOutValue_->reshape(mapW, mapH);
|
|
|
|
|
transOutValue_->transpose(out, false); // false means no memory allocation
|
|
|
|
|
|
|
|
|
|
out->clear();
|
|
|
|
|
bias->clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ExpandConvBaseLayer::addUnsharedBias() {
|
|
|
|
|
MatrixPtr outValue = getOutputValue();
|
|
|
|
|
MatrixPtr bias = Matrix::create(biases_->getW()->getData(),
|
|
|
|
|
1,
|
|
|
|
|
biases_->getW()->getElementCnt(),
|
|
|
|
|
false,
|
|
|
|
|
useGpu_);
|
|
|
|
|
outValue->addBias(*bias, 1.0f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ExpandConvBaseLayer::bpropSharedBias(MatrixPtr biases, MatrixPtr v) {
|
|
|
|
|
size_t mapW = getOutputSize() / numFilters_;
|
|
|
|
|
size_t mapH = v->getElementCnt() / mapW;
|
|
|
|
|
MatrixPtr vTmp = Matrix::create(v->getData(), mapH, mapW, false, useGpu_);
|
|
|
|
|
|
|
|
|
|
Matrix::resizeOrCreate(transOutValue_, mapW, mapH, false, useGpu_);
|
|
|
|
|
|
|
|
|
|
vTmp->transpose(transOutValue_, false); // false means no memory allocation
|
|
|
|
|
transOutValue_->reshape(transOutValue_->getElementCnt() / numFilters_,
|
|
|
|
|
numFilters_);
|
|
|
|
|
biases->collectBias(*transOutValue_, 1.0f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ExpandConvBaseLayer::bpropBiases(MatrixPtr v) {
|
|
|
|
|
MatrixPtr biases = Matrix::create(biases_->getWGrad()->getData(),
|
|
|
|
|
1,
|
|
|
|
|
biases_->getWGrad()->getElementCnt(),
|
|
|
|
|
false,
|
|
|
|
|
useGpu_);
|
|
|
|
|
if (sharedBiases_) {
|
|
|
|
|
bpropSharedBias(biases, v);
|
|
|
|
|
} else {
|
|
|
|
|
biases->collectBias(*v, 1.0f);
|
|
|
|
|
}
|
|
|
|
|
biases->clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace paddle
|
|
|
|
|