Add layer name to vector

This commit is contained in:
2024-04-21 12:20:02 +02:00
parent 0170afaf3f
commit 942ee6a32b
2 changed files with 13 additions and 10 deletions

View File

@@ -11,7 +11,10 @@
namespace CUDANet { namespace CUDANet {
enum TensorType { WEIGHT, BIAS, }; enum TensorType {
WEIGHT,
BIAS,
};
struct TensorInfo { struct TensorInfo {
std::string name; std::string name;
@@ -42,8 +45,8 @@ class Model {
int outputSize; int outputSize;
std::vector<Layers::SequentialLayer*> layers; std::vector<std::pair<std::string, Layers::SequentialLayer*>> layers;
std::unordered_map<std::string, Layers::SequentialLayer*> layerMap; std::unordered_map<std::string, Layers::SequentialLayer*> layerMap;
}; };
} // namespace CUDANet } // namespace CUDANet

View File

@@ -15,7 +15,7 @@ Model::Model(const int inputSize, const int inputChannels, const int outputSize)
: inputSize(inputSize), : inputSize(inputSize),
inputChannels(inputChannels), inputChannels(inputChannels),
outputSize(outputSize), outputSize(outputSize),
layers(std::vector<Layers::SequentialLayer*>()), layers(std::vector<std::pair<std::string, Layers::SequentialLayer*>>()),
layerMap(std::unordered_map<std::string, Layers::SequentialLayer*>()) { layerMap(std::unordered_map<std::string, Layers::SequentialLayer*>()) {
inputLayer = new Layers::Input(inputSize * inputSize * inputChannels); inputLayer = new Layers::Input(inputSize * inputSize * inputChannels);
outputLayer = new Layers::Output(outputSize); outputLayer = new Layers::Output(outputSize);
@@ -25,7 +25,7 @@ Model::Model(const Model& other)
: inputSize(other.inputSize), : inputSize(other.inputSize),
inputChannels(other.inputChannels), inputChannels(other.inputChannels),
outputSize(other.outputSize), outputSize(other.outputSize),
layers(std::vector<Layers::SequentialLayer*>()), layers(std::vector<std::pair<std::string, Layers::SequentialLayer*>>()),
layerMap(std::unordered_map<std::string, Layers::SequentialLayer*>()) { layerMap(std::unordered_map<std::string, Layers::SequentialLayer*>()) {
inputLayer = new Layers::Input(*other.inputLayer); inputLayer = new Layers::Input(*other.inputLayer);
outputLayer = new Layers::Output(*other.outputLayer); outputLayer = new Layers::Output(*other.outputLayer);
@@ -34,8 +34,8 @@ Model::Model(const Model& other)
Model::~Model() { Model::~Model() {
delete inputLayer; delete inputLayer;
delete outputLayer; delete outputLayer;
for (auto layer : layers) { for (const auto& layer : layers) {
delete layer; delete layer.second;
} }
}; };
@@ -43,15 +43,15 @@ float* Model::predict(const float* input) {
float* d_input = inputLayer->forward(input); float* d_input = inputLayer->forward(input);
for (auto& layer : layers) { for (auto& layer : layers) {
std::cout << layer << std::endl; std::cout << layer.first << std::endl;
d_input = layer->forward(d_input); d_input = layer.second->forward(d_input);
} }
return outputLayer->forward(d_input); return outputLayer->forward(d_input);
} }
void Model::addLayer(const std::string& name, Layers::SequentialLayer* layer) { void Model::addLayer(const std::string& name, Layers::SequentialLayer* layer) {
layers.push_back(layer); layers.push_back({ name, layer });
layerMap[name] = layer; layerMap[name] = layer;
} }