Initial model implementation

This commit is contained in:
2024-03-20 22:31:39 +01:00
parent 6f4cdf3792
commit af6838e8ae
4 changed files with 76 additions and 2 deletions

36
src/model/model.cpp Normal file
View File

@@ -0,0 +1,36 @@
#include "model.hpp"
#include "layer.cuh"
#include "input.cuh"
using namespace CUDANet;
Model::Model(const int inputSize, const int inputChannels)
: inputSize(inputSize), inputChannels(inputChannels) {
layerMap = std::map<std::string, Layers::WeightedLayer*>();
layers = std::vector<Layers::SequentialLayer*>();
const int inputLayerSize = inputSize * inputSize * inputChannels;
Layers::Input* inputLayer = new Layers::Input(inputLayerSize);
layers.push_back(inputLayer);
};
Model::~Model(){};
float* Model::predict(const float* input) {
for (auto& layer : layers) {
input = layer->forward(input);
}
}
void Model::addLayer(const std::string& name, Layers::SequentialLayer* layer) {
layers.push_back(layer);
if (dynamic_cast<Layers::WeightedLayer*>(layer) != nullptr) {
layerMap[name] = dynamic_cast<Layers::WeightedLayer*>(layer);
}
}