mirror of
https://github.com/lordmathis/CUDANet.git
synced 2025-11-06 09:44:28 +00:00
Initial model implementation
This commit is contained in:
36
src/model/model.cpp
Normal file
36
src/model/model.cpp
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user