17#include "velox/ml_functions/functions.h"
19using namespace facebook::velox;
20using namespace facebook::velox::test;
21using namespace facebook::velox::exec::test;
43 compute_string =
"{}";
52 weightsFile_ = weightsFile;
66 return compute_string;
84 std::string mat_mul_name =
86 std::string mat_add_name =
88 std::string act_name =
"";
90 exec::registerVectorFunction(
93 std::make_unique<MatrixMultiply>(weights, input_size, units));
95 exec::registerVectorFunction(
97 MatrixVectorAddition::signatures(),
98 std::make_unique<MatrixVectorAddition>(bias, units));
101 act_name =
Relu::getName() + std::to_string(function_count++);
102 exec::registerVectorFunction(
106 exec::registerVectorFunction(
110 compute_string = fmt::format(
111 "{}({}({}({})))", act_name, mat_add_name, mat_mul_name, compute_string);
123 std::string mat_mul_name =
125 std::string mat_add_name =
127 std::string act_name =
"";
129 exec::registerVectorFunction(
132 std::make_unique<MatrixMultiply>(weightsFile_, input_size, units));
134 exec::registerVectorFunction(
137 std::make_unique<MatrixAddition>(biasFile_, units));
140 act_name =
Relu::getName() + std::to_string(function_count++);
141 exec::registerVectorFunction(
145 exec::registerVectorFunction(
149 compute_string = fmt::format(
150 "{}({}({}({})))", act_name, mat_add_name, mat_mul_name, compute_string);
169 std::string conv_name =
171 std::string scal_add_name =
173 std::string act_name =
"";
175 exec::registerVectorFunction(
178 std::make_unique<Convolute>(weights, dims));
180 exec::registerVectorFunction(
183 std::make_unique<VectorScalarAddition>(bias, num_filters));
186 act_name =
Relu::getName() + std::to_string(function_count++);
187 exec::registerVectorFunction(
191 exec::registerVectorFunction(
196 fmt::format(
"{}({}({}))", scal_add_name, conv_name, compute_string);
198 compute_string = fmt::format(
199 "{}({}({}({})))", act_name, scal_add_name, conv_name, compute_string);
212 std::string max_pool_name =
214 exec::registerVectorFunction(
217 std::make_unique<MaxPool>(side, height, width));
218 compute_string = fmt::format(
"{}({})", max_pool_name, compute_string);
224 std::string compute_string;
225 std::string weightsFile_;
226 std::string biasFile_;
Activation
Enumeration of activation functions supported by the neural network builder.
Definition NNBuilder.h:27
@ RELU
Rectified Linear Unit (ReLU) activation.
Definition NNBuilder.h:27
@ SOFTMAX
Softmax activation.
Definition NNBuilder.h:28
@ NONE
No activation.
Definition NNBuilder.h:29
static std::vector< std::shared_ptr< exec::FunctionSignature > > signatures()
Returns the function signatures for the convolution operation.
Definition functions.h:3290
static std::string getName()
Returns the name of the function.
Definition functions.h:3317
static std::string getName()
Get the name of the function.
Definition functions.h:866
static std::vector< std::shared_ptr< exec::FunctionSignature > > signatures()
Get the function signatures for matrix addition.
Definition functions.h:839
static std::string getName()
Get the name of the function.
Definition functions.h:291
static std::vector< std::shared_ptr< exec::FunctionSignature > > signatures()
Get the function signatures for matrix multiplication.
Definition functions.h:257
static std::string getName()
Static method to return the name of the function.
Definition functions.h:1080
static std::string getName()
Static method to return the name of the function.
Definition functions.h:3866
static std::vector< std::shared_ptr< exec::FunctionSignature > > signatures()
Returns the function signatures supported by this class.
Definition functions.h:3836
std::string build()
Builds and returns the computation string representing the neural network.
Definition NNBuilder.h:65
NNBuilder & convLayer(int num_filters, int *dims, float *weights, float *bias, Activation ac)
Adds a convolutional layer to the neural network.
Definition NNBuilder.h:163
NNBuilder()
Default constructor for NNBuilder.
Definition NNBuilder.h:41
NNBuilder(std::string weightsFile, std::string biasFile)
Constructor for NNBuilder with weights and bias files.
Definition NNBuilder.h:51
NNBuilder & denseLayer(int units, int input_size, float *weights, float *bias, Activation ac)
Adds a dense layer to the neural network.
Definition NNBuilder.h:78
NNBuilder & maxPoolLayer(int side, int height, int width)
Adds a max pooling layer to the neural network.
Definition NNBuilder.h:211
~NNBuilder()
Destructor for NNBuilder.
Definition NNBuilder.h:59
NNBuilder & denseLayer(int units, int input_size, Activation ac)
Adds a dense layer to the neural network using weights and biases from files.
Definition NNBuilder.h:122
static std::vector< std::shared_ptr< exec::FunctionSignature > > signatures()
Returns the function signatures supported by this class.
Definition functions.h:1305
static std::string getName()
Static method to return the name of the function.
Definition functions.h:1335
static std::vector< std::shared_ptr< exec::FunctionSignature > > signatures()
Returns the function signatures supported by this class.
Definition functions.h:1471
static std::string getName()
Static method to return the name of the function.
Definition functions.h:1501
static std::string getName()
Static method to return the name of the function.
Definition functions.h:3731
static std::vector< std::shared_ptr< exec::FunctionSignature > > signatures()
Returns the function signatures supported by this class.
Definition functions.h:3701