mirror of
https://github.com/lordmathis/CUDANet.git
synced 2025-11-05 17:34:21 +00:00
Unify 2d layer naming
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
|
||||
using namespace CUDANet::Layers;
|
||||
|
||||
AvgPooling2D::AvgPooling2D(
|
||||
AvgPooling2d::AvgPooling2d(
|
||||
dim2d inputSize,
|
||||
int nChannels,
|
||||
dim2d poolingSize,
|
||||
@@ -31,12 +31,12 @@ AvgPooling2D::AvgPooling2D(
|
||||
));
|
||||
}
|
||||
|
||||
AvgPooling2D::~AvgPooling2D() {
|
||||
AvgPooling2d::~AvgPooling2d() {
|
||||
cudaFree(d_output);
|
||||
delete activation;
|
||||
}
|
||||
|
||||
float* AvgPooling2D::forward(const float* d_input) {
|
||||
float* AvgPooling2d::forward(const float* d_input) {
|
||||
dim3 block(8, 8, 8);
|
||||
dim3 grid(
|
||||
(outputSize.first + block.x - 1) / block.x,
|
||||
@@ -55,10 +55,10 @@ float* AvgPooling2D::forward(const float* d_input) {
|
||||
return d_output;
|
||||
}
|
||||
|
||||
int AvgPooling2D::getOutputSize() {
|
||||
int AvgPooling2d::getOutputSize() {
|
||||
return outputSize.first * outputSize.second * nChannels;
|
||||
}
|
||||
|
||||
int AvgPooling2D::getInputSize() {
|
||||
int AvgPooling2d::getInputSize() {
|
||||
return inputSize.first * inputSize.second * nChannels;
|
||||
}
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
using namespace CUDANet::Layers;
|
||||
|
||||
BatchNorm2D::BatchNorm2D(
|
||||
BatchNorm2d::BatchNorm2d(
|
||||
dim2d inputSize,
|
||||
int inputChannels,
|
||||
float epsilon,
|
||||
@@ -72,7 +72,7 @@ BatchNorm2D::BatchNorm2D(
|
||||
(inputSize.first * inputSize.second + BLOCK_SIZE - 1) / BLOCK_SIZE;
|
||||
}
|
||||
|
||||
BatchNorm2D::~BatchNorm2D() {
|
||||
BatchNorm2d::~BatchNorm2d() {
|
||||
cudaFree(d_output);
|
||||
cudaFree(d_mean);
|
||||
cudaFree(d_mean_sub);
|
||||
@@ -83,33 +83,33 @@ BatchNorm2D::~BatchNorm2D() {
|
||||
cudaFree(d_epsilon);
|
||||
}
|
||||
|
||||
void BatchNorm2D::initializeWeights() {
|
||||
void BatchNorm2d::initializeWeights() {
|
||||
std::fill(weights.begin(), weights.end(), 1.0f);
|
||||
}
|
||||
|
||||
void BatchNorm2D::initializeBiases() {
|
||||
void BatchNorm2d::initializeBiases() {
|
||||
std::fill(biases.begin(), biases.end(), 0.0f);
|
||||
}
|
||||
|
||||
void BatchNorm2D::setWeights(const float *weights_input) {
|
||||
void BatchNorm2d::setWeights(const float *weights_input) {
|
||||
std::copy(weights_input, weights_input + weights.size(), weights.begin());
|
||||
toCuda();
|
||||
}
|
||||
|
||||
std::vector<float> BatchNorm2D::getWeights() {
|
||||
std::vector<float> BatchNorm2d::getWeights() {
|
||||
return weights;
|
||||
}
|
||||
|
||||
void BatchNorm2D::setBiases(const float *biases_input) {
|
||||
void BatchNorm2d::setBiases(const float *biases_input) {
|
||||
std::copy(biases_input, biases_input + biases.size(), biases.begin());
|
||||
toCuda();
|
||||
}
|
||||
|
||||
std::vector<float> BatchNorm2D::getBiases() {
|
||||
std::vector<float> BatchNorm2d::getBiases() {
|
||||
return biases;
|
||||
}
|
||||
|
||||
void BatchNorm2D::toCuda() {
|
||||
void BatchNorm2d::toCuda() {
|
||||
CUDA_CHECK(cudaMemcpy(
|
||||
d_weights, weights.data(), sizeof(float) * inputChannels,
|
||||
cudaMemcpyHostToDevice
|
||||
@@ -120,15 +120,15 @@ void BatchNorm2D::toCuda() {
|
||||
));
|
||||
}
|
||||
|
||||
int BatchNorm2D::getInputSize() {
|
||||
int BatchNorm2d::getInputSize() {
|
||||
return inputSize.first * inputSize.second * inputChannels;
|
||||
}
|
||||
|
||||
int BatchNorm2D::getOutputSize() {
|
||||
int BatchNorm2d::getOutputSize() {
|
||||
return inputSize.first * inputSize.second * inputChannels;
|
||||
}
|
||||
|
||||
float *BatchNorm2D::forward(const float *d_input) {
|
||||
float *BatchNorm2d::forward(const float *d_input) {
|
||||
// Compute per-channel batch normalization
|
||||
for (int i = 0; i < inputChannels; i++) {
|
||||
// Compute mean
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
using namespace CUDANet::Layers;
|
||||
|
||||
MaxPooling2D::MaxPooling2D(
|
||||
MaxPooling2d::MaxPooling2d(
|
||||
dim2d inputSize,
|
||||
int nChannels,
|
||||
dim2d poolingSize,
|
||||
@@ -29,12 +29,12 @@ MaxPooling2D::MaxPooling2D(
|
||||
));
|
||||
}
|
||||
|
||||
MaxPooling2D::~MaxPooling2D() {
|
||||
MaxPooling2d::~MaxPooling2d() {
|
||||
cudaFree(d_output);
|
||||
delete activation;
|
||||
}
|
||||
|
||||
float* MaxPooling2D::forward(const float* d_input) {
|
||||
float* MaxPooling2d::forward(const float* d_input) {
|
||||
dim3 block(8, 8, 8);
|
||||
dim3 grid(
|
||||
(outputSize.first + block.x - 1) / block.x,
|
||||
@@ -53,10 +53,10 @@ float* MaxPooling2D::forward(const float* d_input) {
|
||||
return d_output;
|
||||
}
|
||||
|
||||
int MaxPooling2D::getOutputSize() {
|
||||
int MaxPooling2d::getOutputSize() {
|
||||
return outputSize.first * outputSize.second * nChannels;
|
||||
}
|
||||
|
||||
int MaxPooling2D::getInputSize() {
|
||||
int MaxPooling2d::getInputSize() {
|
||||
return inputSize.first * inputSize.second * nChannels;
|
||||
}
|
||||
Reference in New Issue
Block a user