Fix adding module layers

This commit is contained in:
2024-05-29 21:02:26 +02:00
parent 4159454842
commit 8ac2da004c
4 changed files with 31 additions and 20 deletions

View File

@@ -1,16 +1,6 @@
#include <cudanet.cuh>
#include <iostream>
int main(int argc, const char *const argv[]) {
if (argc != 3) {
std::cerr << "Usage: " << argv[0] << "<model_weights_path> <image_path>"
<< std::endl;
return 1; // Return error code indicating incorrect usage
}
std::cout << "Loading model..." << std::endl;
}
class BasicConv2d : public CUDANet::Module {
public:
BasicConv2d(
@@ -702,7 +692,7 @@ class InceptionE : public CUDANet::Module {
}
shape2d getOutputDims() {
branch3x3_2a->getOutputDims();
return branch3x3_2a->getOutputDims();
}
int getOutputChannels() {
@@ -823,7 +813,7 @@ class InceptionV3 : public CUDANet::Model {
Mixed_7c->getOutputSize(), 1000,
CUDANet::Layers::ActivationType::SOFTMAX
);
addLayer("", fc);
addLayer("fc", fc);
}
float* predict(const float* input) {
@@ -906,3 +896,19 @@ class InceptionV3 : public CUDANet::Model {
CUDANet::Layers::Dense *fc;
};
int main(int argc, const char *const argv[]) {
InceptionV3 *inception_v3 = new InceptionV3({299, 299}, 3, 1000);
inception_v3->printSummary();
if (argc != 3) {
std::cerr << "Usage: " << argv[0] << "<model_weights_path> <image_path>"
<< std::endl;
return 1; // Return error code indicating incorrect usage
}
std::cout << "Loading model..." << std::endl;
}

View File

@@ -11,8 +11,6 @@ namespace CUDANet {
class Module : public Layers::SequentialLayer {
public:
virtual ~Module() = 0;
virtual float* forward(const float* d_input) = 0;
int getOutputSize();

View File

@@ -56,17 +56,18 @@ float* Model::predict(const float* input) {
}
void Model::addLayer(const std::string& name, Layers::SequentialLayer* layer) {
Module* module = dynamic_cast<Module*>(layer);
const Module* module = dynamic_cast<Module*>(layer);
if (module != nullptr) {
layers.push_back({name, module});
for (const auto& moduleLayer : module->getLayers()) {
layerMap[moduleLayer.first] = moduleLayer.second;
layers.push_back({moduleLayer.first, moduleLayer.second});
}
return;
}
layers.push_back({name, layer});
layerMap[name] = layer;
}

View File

@@ -5,23 +5,29 @@
using namespace CUDANet;
void Module::addLayer(const std::string& name, Layers::SequentialLayer* layer) {
Module* module = dynamic_cast<Module*>(layer);
const Module* module = dynamic_cast<Module*>(layer);
if (module != nullptr) {
layers.push_back({ name, module });
for (const auto& moduleLayer : module->getLayers()) {
layerMap[moduleLayer.first] = moduleLayer.second;
layers.push_back({moduleLayer.first, moduleLayer.second});
}
return;
}
layers.push_back({name, layer});
layerMap[name] = layer;
// std::cout << "Wat?! - module" << name << std::endl;
}
Layers::SequentialLayer* Module::getLayer(const std::string& name) {
return layerMap[name];
}
const std::unordered_map<std::string, Layers::SequentialLayer*>& Module::getLayers() const {
const std::unordered_map<std::string, Layers::SequentialLayer*>&
Module::getLayers() const {
return layerMap;
}