mirror of
https://github.com/lordmathis/CUDANet.git
synced 2025-11-05 17:34:21 +00:00
Implement getOutputSize and getInputSize for seq layers
This commit is contained in:
@@ -20,13 +20,18 @@ class AvgPooling2D : public SequentialLayer {
|
||||
float* forward(const float* d_input);
|
||||
|
||||
/**
|
||||
* @brief Get the output width (/ height) of the layer
|
||||
* @brief Get output size
|
||||
*
|
||||
* @return int
|
||||
* @return int output size
|
||||
*/
|
||||
int getOutputSize() {
|
||||
return outputSize;
|
||||
}
|
||||
int getOutputSize();
|
||||
|
||||
/**
|
||||
* @brief Get input size
|
||||
*
|
||||
* @return int input size
|
||||
*/
|
||||
int getInputSize();
|
||||
|
||||
private:
|
||||
int inputSize;
|
||||
|
||||
@@ -80,13 +80,18 @@ class Conv2d : public WeightedLayer {
|
||||
std::vector<float> getBiases();
|
||||
|
||||
/**
|
||||
* @brief Get the output width (/ height) of the layer
|
||||
* @brief Get output size
|
||||
*
|
||||
* @return int
|
||||
* @return int output size
|
||||
*/
|
||||
int getOutputSize() {
|
||||
return outputSize;
|
||||
}
|
||||
int getOutputSize();
|
||||
|
||||
/**
|
||||
* @brief Get input size
|
||||
*
|
||||
* @return int input size
|
||||
*/
|
||||
int getInputSize();
|
||||
|
||||
/**
|
||||
* @brief Get the padding size of the layer
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "layer.cuh"
|
||||
#include "activation.cuh"
|
||||
#include "layer.cuh"
|
||||
|
||||
namespace CUDANet::Layers {
|
||||
|
||||
@@ -19,7 +19,8 @@ class Dense : public WeightedLayer {
|
||||
*
|
||||
* @param inputSize Size of the input vector
|
||||
* @param outputSize Size of the output vector
|
||||
* @param activationType Activation function type ('RELU', 'SIGMOID', 'SOFTMAX' or 'NONE')
|
||||
* @param activationType Activation function type ('RELU', 'SIGMOID',
|
||||
* 'SOFTMAX' or 'NONE')
|
||||
*/
|
||||
Dense(int inputSize, int outputSize, Layers::ActivationType activationType);
|
||||
|
||||
@@ -65,6 +66,20 @@ class Dense : public WeightedLayer {
|
||||
*/
|
||||
std::vector<float> getBiases();
|
||||
|
||||
/**
|
||||
* @brief Get output size
|
||||
*
|
||||
* @return int output size
|
||||
*/
|
||||
int getOutputSize();
|
||||
|
||||
/**
|
||||
* @brief Get input size
|
||||
*
|
||||
* @return int input size
|
||||
*/
|
||||
int getInputSize();
|
||||
|
||||
private:
|
||||
unsigned int inputSize;
|
||||
unsigned int outputSize;
|
||||
|
||||
@@ -13,25 +13,40 @@ class Input : public SequentialLayer {
|
||||
public:
|
||||
/**
|
||||
* @brief Create a new Input layer
|
||||
*
|
||||
*
|
||||
* @param inputSize Size of the input vector
|
||||
*/
|
||||
explicit Input(int inputSize);
|
||||
|
||||
/**
|
||||
* @brief Destroy the Input layer
|
||||
*
|
||||
*
|
||||
*/
|
||||
~Input();
|
||||
|
||||
/**
|
||||
* @brief Forward pass of the input layer. Just copies the input to the device
|
||||
*
|
||||
* @brief Forward pass of the input layer. Just copies the input to the
|
||||
* device
|
||||
*
|
||||
* @param input Host pointer to the input vector
|
||||
* @return Device pointer to the output vector
|
||||
*/
|
||||
float* forward(const float* input);
|
||||
|
||||
/**
|
||||
* @brief Get output size
|
||||
*
|
||||
* @return int output size
|
||||
*/
|
||||
int getOutputSize();
|
||||
|
||||
/**
|
||||
* @brief Get input size
|
||||
*
|
||||
* @return int input size
|
||||
*/
|
||||
int getInputSize();
|
||||
|
||||
private:
|
||||
int inputSize;
|
||||
float* d_output;
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#define CUDANET_SAME_PADDING(inputSize, kernelSize, stride) ((stride - 1) * inputSize - stride + kernelSize) / 2;
|
||||
|
||||
#define CUDANET_SAME_PADDING(inputSize, kernelSize, stride) \
|
||||
((stride - 1) * inputSize - stride + kernelSize) / 2;
|
||||
|
||||
namespace CUDANet::Layers {
|
||||
|
||||
@@ -28,6 +28,20 @@ class SequentialLayer {
|
||||
* @return float* Device pointer to the output
|
||||
*/
|
||||
virtual float* forward(const float* input) = 0;
|
||||
|
||||
/**
|
||||
* @brief Get output size
|
||||
*
|
||||
* @return int output size
|
||||
*/
|
||||
virtual int getOutputSize() = 0;
|
||||
|
||||
/**
|
||||
* @brief Get input size
|
||||
*
|
||||
* @return int input size
|
||||
*/
|
||||
virtual int getInputSize() = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,13 +20,18 @@ class MaxPooling2D : public SequentialLayer {
|
||||
float* forward(const float* d_input);
|
||||
|
||||
/**
|
||||
* @brief Get the output width (/ height) of the layer
|
||||
* @brief Get output size
|
||||
*
|
||||
* @return int
|
||||
* @return int output size
|
||||
*/
|
||||
int getOutputSize() {
|
||||
return outputSize;
|
||||
}
|
||||
int getOutputSize();
|
||||
|
||||
/**
|
||||
* @brief Get input size
|
||||
*
|
||||
* @return int input size
|
||||
*/
|
||||
int getInputSize();
|
||||
|
||||
private:
|
||||
int inputSize;
|
||||
|
||||
@@ -6,34 +6,48 @@
|
||||
namespace CUDANet::Layers {
|
||||
|
||||
class Output : public SequentialLayer {
|
||||
public:
|
||||
/**
|
||||
* @brief Create a new Output layer
|
||||
*
|
||||
* @param inputSize Size of the input vector
|
||||
*/
|
||||
explicit Output(int inputSize);
|
||||
public:
|
||||
/**
|
||||
* @brief Create a new Output layer
|
||||
*
|
||||
* @param inputSize Size of the input vector
|
||||
*/
|
||||
explicit Output(int inputSize);
|
||||
|
||||
/**
|
||||
* @brief Destroy the Output layer
|
||||
*
|
||||
*/
|
||||
~Output();
|
||||
/**
|
||||
* @brief Destroy the Output layer
|
||||
*
|
||||
*/
|
||||
~Output();
|
||||
|
||||
/**
|
||||
* @brief Forward pass of the output layer. Just copies the input from device to host
|
||||
*
|
||||
* @param input Device pointer to the input vector
|
||||
* @return Host pointer to the output vector
|
||||
*/
|
||||
float* forward(const float* input);
|
||||
/**
|
||||
* @brief Forward pass of the output layer. Just copies the input from
|
||||
* device to host
|
||||
*
|
||||
* @param input Device pointer to the input vector
|
||||
* @return Host pointer to the output vector
|
||||
*/
|
||||
float* forward(const float* input);
|
||||
|
||||
private:
|
||||
int inputSize;
|
||||
float* h_output;
|
||||
/**
|
||||
* @brief Get output size
|
||||
*
|
||||
* @return int output size
|
||||
*/
|
||||
int getOutputSize();
|
||||
|
||||
/**
|
||||
* @brief Get input size
|
||||
*
|
||||
* @return int input size
|
||||
*/
|
||||
int getInputSize();
|
||||
|
||||
private:
|
||||
int inputSize;
|
||||
float* h_output;
|
||||
};
|
||||
|
||||
|
||||
} // namespace CUDANet::Layers
|
||||
} // namespace CUDANet::Layers
|
||||
|
||||
#endif // CUDANET_OUTPUT_LAYER_H
|
||||
Reference in New Issue
Block a user