mirror of
https://github.com/lordmathis/CUDANet.git
synced 2025-11-05 17:34:21 +00:00
Implement getting layer, weights and biases
This commit is contained in:
@@ -58,6 +58,13 @@ class Conv2d : public WeightedLayer {
|
||||
*/
|
||||
void setWeights(const float* weights_input);
|
||||
|
||||
/**
|
||||
* @brief Get the weights of the convolutional layer
|
||||
*
|
||||
* @return std::vector<float>
|
||||
*/
|
||||
std::vector<float> getWeights();
|
||||
|
||||
/**
|
||||
* @brief Set the biases of the convolutional layer
|
||||
*
|
||||
@@ -65,6 +72,13 @@ class Conv2d : public WeightedLayer {
|
||||
*/
|
||||
void setBiases(const float* biases_input);
|
||||
|
||||
/**
|
||||
* @brief Get the biases of the convolutional layer
|
||||
*
|
||||
* @return std::vector<float>
|
||||
*/
|
||||
std::vector<float> getBiases();
|
||||
|
||||
/**
|
||||
* @brief Get the output width (/ height) of the layer
|
||||
*
|
||||
|
||||
@@ -43,6 +43,13 @@ class Dense : public WeightedLayer {
|
||||
*/
|
||||
void setWeights(const float* weights);
|
||||
|
||||
/**
|
||||
* @brief Get the weights of the layer
|
||||
*
|
||||
* @return Vector of weights
|
||||
*/
|
||||
std::vector<float> getWeights();
|
||||
|
||||
/**
|
||||
* @brief Set the biases of the layer
|
||||
*
|
||||
@@ -50,6 +57,13 @@ class Dense : public WeightedLayer {
|
||||
*/
|
||||
void setBiases(const float* biases);
|
||||
|
||||
/**
|
||||
* @brief Get the biases of the layer
|
||||
*
|
||||
* @return Vector of biases
|
||||
*/
|
||||
std::vector<float> getBiases();
|
||||
|
||||
private:
|
||||
unsigned int inputSize;
|
||||
unsigned int outputSize;
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
#ifndef CUDANET_I_LAYER_H
|
||||
#define CUDANET_I_LAYER_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace CUDANet::Layers {
|
||||
|
||||
/**
|
||||
@@ -60,6 +62,12 @@ class WeightedLayer : public SequentialLayer {
|
||||
*/
|
||||
virtual void setWeights(const float* weights) = 0;
|
||||
|
||||
/**
|
||||
* @brief Virtual function for getting weights
|
||||
*
|
||||
*/
|
||||
virtual std::vector<float> getWeights() = 0;
|
||||
|
||||
/**
|
||||
* @brief Virtual function for setting biases
|
||||
*
|
||||
@@ -67,6 +75,12 @@ class WeightedLayer : public SequentialLayer {
|
||||
*/
|
||||
virtual void setBiases(const float* biases) = 0;
|
||||
|
||||
/**
|
||||
* @brief Virtual function for getting biases
|
||||
*
|
||||
*/
|
||||
virtual std::vector<float> getBiases() = 0;
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief Initialize the weights
|
||||
|
||||
@@ -29,6 +29,8 @@ class Model {
|
||||
float* predict(const float* input);
|
||||
|
||||
void addLayer(const std::string& name, Layers::SequentialLayer* layer);
|
||||
Layers::SequentialLayer* getLayer(const std::string& name);
|
||||
|
||||
void loadWeights(const std::string& path);
|
||||
|
||||
private:
|
||||
@@ -41,7 +43,7 @@ class Model {
|
||||
int outputSize;
|
||||
|
||||
std::vector<Layers::SequentialLayer*> layers;
|
||||
std::unordered_map<std::string, Layers::WeightedLayer*> layerMap;
|
||||
std::unordered_map<std::string, Layers::SequentialLayer*> layerMap;
|
||||
};
|
||||
|
||||
} // namespace CUDANet
|
||||
|
||||
Reference in New Issue
Block a user