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:
@@ -45,7 +45,7 @@ CUDANet::Model *createModel(
|
||||
CUDANet::Layers::ActivationType::RELU
|
||||
);
|
||||
model->addLayer("features.0", conv1); // Match pytorch naming
|
||||
CUDANet::Layers::MaxPooling2D *pool1 = new CUDANet::Layers::MaxPooling2D(
|
||||
CUDANet::Layers::MaxPooling2d *pool1 = new CUDANet::Layers::MaxPooling2d(
|
||||
56, 64, 3, 2, CUDANet::Layers::ActivationType::NONE
|
||||
);
|
||||
model->addLayer("pool1", pool1);
|
||||
@@ -55,7 +55,7 @@ CUDANet::Model *createModel(
|
||||
27, 64, 5, 1, 192, 2, CUDANet::Layers::ActivationType::RELU
|
||||
);
|
||||
model->addLayer("features.3", conv2);
|
||||
CUDANet::Layers::MaxPooling2D *pool2 = new CUDANet::Layers::MaxPooling2D(
|
||||
CUDANet::Layers::MaxPooling2d *pool2 = new CUDANet::Layers::MaxPooling2d(
|
||||
27, 192, 3, 2, CUDANet::Layers::ActivationType::NONE
|
||||
);
|
||||
model->addLayer("pool2", pool2);
|
||||
@@ -77,7 +77,7 @@ CUDANet::Model *createModel(
|
||||
13, 256, 3, 1, 256, 1, CUDANet::Layers::ActivationType::RELU
|
||||
);
|
||||
model->addLayer("features.10", conv5);
|
||||
CUDANet::Layers::MaxPooling2D *pool5 = new CUDANet::Layers::MaxPooling2D(
|
||||
CUDANet::Layers::MaxPooling2d *pool5 = new CUDANet::Layers::MaxPooling2d(
|
||||
13, 256, 3, 2, CUDANet::Layers::ActivationType::NONE
|
||||
);
|
||||
model->addLayer("pool5", pool5);
|
||||
|
||||
@@ -30,7 +30,7 @@ class BasicConv2d : public CUDANet::Module {
|
||||
|
||||
int batchNormSize = conv->getOutputSize();
|
||||
|
||||
CUDANet::Layers::BatchNorm2D *batchNorm = new CUDANet::Layers::BatchNorm2D(
|
||||
CUDANet::Layers::BatchNorm2d *batchNorm = new CUDANet::Layers::BatchNorm2d(
|
||||
batchNormSize, outputChannels, 1e-3f,
|
||||
CUDANet::Layers::ActivationType::RELU
|
||||
);
|
||||
|
||||
@@ -6,16 +6,16 @@
|
||||
|
||||
namespace CUDANet::Layers {
|
||||
|
||||
class AvgPooling2D : public SequentialLayer {
|
||||
class AvgPooling2d : public SequentialLayer {
|
||||
public:
|
||||
AvgPooling2D(
|
||||
AvgPooling2d(
|
||||
dim2d inputSize,
|
||||
int nChannels,
|
||||
dim2d poolingSize,
|
||||
dim2d stride,
|
||||
ActivationType activationType
|
||||
);
|
||||
~AvgPooling2D();
|
||||
~AvgPooling2d();
|
||||
|
||||
float* forward(const float* d_input);
|
||||
|
||||
|
||||
@@ -8,11 +8,11 @@
|
||||
|
||||
namespace CUDANet::Layers {
|
||||
|
||||
class BatchNorm2D : public WeightedLayer {
|
||||
class BatchNorm2d : public WeightedLayer {
|
||||
public:
|
||||
BatchNorm2D(dim2d inputSize, int inputChannels, float epsilon, ActivationType activationType);
|
||||
BatchNorm2d(dim2d inputSize, int inputChannels, float epsilon, ActivationType activationType);
|
||||
|
||||
~BatchNorm2D();
|
||||
~BatchNorm2d();
|
||||
|
||||
/**
|
||||
* @brief Compute the forward pass of the batchnorm layer
|
||||
|
||||
@@ -6,16 +6,16 @@
|
||||
|
||||
namespace CUDANet::Layers {
|
||||
|
||||
class MaxPooling2D : public SequentialLayer {
|
||||
class MaxPooling2d : public SequentialLayer {
|
||||
public:
|
||||
MaxPooling2D(
|
||||
MaxPooling2d(
|
||||
dim2d inputSize,
|
||||
int nChannels,
|
||||
dim2d poolingSize,
|
||||
dim2d stride,
|
||||
ActivationType activationType
|
||||
);
|
||||
~MaxPooling2D();
|
||||
~MaxPooling2d();
|
||||
|
||||
float* forward(const float* d_input);
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -28,7 +28,7 @@ TEST(AvgPoolingLayerTest, AvgPoolForwardTest) {
|
||||
// clang-format on
|
||||
};
|
||||
|
||||
CUDANet::Layers::AvgPooling2D avgPoolingLayer(
|
||||
CUDANet::Layers::AvgPooling2d avgPoolingLayer(
|
||||
inputSize, nChannels, poolingSize, stride,
|
||||
CUDANet::Layers::ActivationType::NONE
|
||||
);
|
||||
|
||||
@@ -12,7 +12,7 @@ TEST(BatchNormLayerTest, BatchNormSmallForwardTest) {
|
||||
|
||||
cudaError_t cudaStatus;
|
||||
|
||||
CUDANet::Layers::BatchNorm2D batchNorm(
|
||||
CUDANet::Layers::BatchNorm2d batchNorm(
|
||||
inputSize, nChannels, 1e-5f, CUDANet::Layers::ActivationType::NONE
|
||||
);
|
||||
|
||||
@@ -69,7 +69,7 @@ TEST(BatchNormLayerTest, BatchNormSmallForwardTest) {
|
||||
-0.0269f, 0.26878f, 0.81411f, 0.09022f,
|
||||
0.9126f, 0.71485f, -0.08184f, -0.19131f};
|
||||
|
||||
// std::cout << "BatchNorm2D: " << std::endl;
|
||||
// std::cout << "BatchNorm2d: " << std::endl;
|
||||
for (int i = 0; i < output.size(); i++) {
|
||||
EXPECT_NEAR(output[i], expected[i], 1e-5);
|
||||
// std::cout << output[i] << " ";
|
||||
|
||||
@@ -28,7 +28,7 @@ TEST(MaxPoolingLayerTest, MaxPoolForwardTest) {
|
||||
// clang-format on
|
||||
};
|
||||
|
||||
CUDANet::Layers::MaxPooling2D maxPoolingLayer(
|
||||
CUDANet::Layers::MaxPooling2d maxPoolingLayer(
|
||||
inputSize, nChannels, poolingSize, stride,
|
||||
CUDANet::Layers::ActivationType::NONE
|
||||
);
|
||||
|
||||
@@ -42,8 +42,8 @@ class ModelTest : public ::testing::Test {
|
||||
inputSize.first - kernelSize.first + 1,
|
||||
inputSize.second - kernelSize.second + 1
|
||||
};
|
||||
CUDANet::Layers::MaxPooling2D *maxpool2d =
|
||||
new CUDANet::Layers::MaxPooling2D(
|
||||
CUDANet::Layers::MaxPooling2d *maxpool2d =
|
||||
new CUDANet::Layers::MaxPooling2d(
|
||||
poolingInput, numFilters, poolingSize,
|
||||
poolingStride, CUDANet::Layers::ActivationType::RELU
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user