From ba4bee90adf7062b203afbc3f05abc9be073ac83 Mon Sep 17 00:00:00 2001 From: LordMathis Date: Sun, 19 May 2024 20:22:26 +0200 Subject: [PATCH] Start implementing inception block A --- examples/inception_v3/inception_v3.cpp | 29 +++++++++++++++++++------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/examples/inception_v3/inception_v3.cpp b/examples/inception_v3/inception_v3.cpp index 5091df7..ba6cc4d 100644 --- a/examples/inception_v3/inception_v3.cpp +++ b/examples/inception_v3/inception_v3.cpp @@ -21,10 +21,7 @@ class BasicConv2d : public CUDANet::Module { const int stride, const int padding, const std::string &prefix - ) - : inputSize(inputSize), - inputChannels(inputChannels), - outputChannels(outputChannels) { + ) { // Create the convolution layer CUDANet::Layers::Conv2d *conv = new CUDANet::Layers::Conv2d( inputSize, inputChannels, kernelSize, stride, outputChannels, @@ -43,16 +40,13 @@ class BasicConv2d : public CUDANet::Module { } float* forward(const float* d_input) { + for (auto& layer : layers) { d_input = layer.second->forward(d_input); } return d_input; } - private: - int inputSize; - int inputChannels; - int outputChannels; }; class InceptionA : public CUDANet::Module { @@ -71,34 +65,53 @@ class InceptionA : public CUDANet::Module { CUDANet::Module *branch1x1 = new BasicConv2d( inputSize, inputChannels, 64, 1, 1, 0, prefix + ".branch1x1" ); + addLayer("", branch1x1); // Branch 5x5 CUDANet::Module *branch5x5_1 = new BasicConv2d( inputSize, inputChannels, 48, 1, 1, 0, prefix + ".branch5x5_1" ); + addLayer("", branch5x5_1); CUDANet::Module *branch5x5_2 = new BasicConv2d( inputSize, 48, 64, 5, 1, 2, prefix + ".branch5x5_2" ); + addLayer("", branch5x5_2); // Branch 3x3 CUDANet::Module *branch3x3_1 = new BasicConv2d( inputSize, inputChannels, 64, 1, 1, 0, prefix + ".branch3x3_1" ); + addLayer("", branch3x3_1); CUDANet::Module *branch3x3_2 = new BasicConv2d( inputSize, 64, 96, 3, 1, 1, prefix + ".branch3x3_2" ); + addLayer("", branch3x3_2); CUDANet::Module *branch3x3_3 = new BasicConv2d( inputSize, 96, 96, 3, 1, 1, prefix + ".branch3x3_3" ); + addLayer("", branch3x3_3); // Branch Pool CUDANet::Module *branchPool = new BasicConv2d( inputSize, inputChannels, poolFeatures, 1, 1, 0, prefix + ".branchPool" ); + addLayer("", branchPool); + + // Concat + concat_1 = new CUDANet::Layers::Concat( + branch1x1->getOutputSize(), branch5x5_2->getOutputSize() + ); + concat_2 = new CUDANet::Layers::Concat( + concat_1->getOutputSize(), branch3x3_3->getOutputSize() + ); + } private: int inputSize; int inputChannels; int poolFeatures; + + CUDANet::Layers::Concat *concat_1; + CUDANet::Layers::Concat *concat_2; }; \ No newline at end of file