#include <CscNeuralNetworkTensorFlow.h>
|
| | CscNeuralNetworkTensorFlow (CscNeuralNetworkType neuralNetworkType, NeuralNetworkHyperparameters *neuralNetworkHyperparametersInit, TrainingHyperparameters *trainingHyperparametersInit) |
| |
| | CscNeuralNetworkTensorFlow (CscNeuralNetworkType neuralNetworkType, NeuralNetworkHyperparameters *neuralNetworkHyperparametersInit, TrainingHyperparameters *trainingHyperparametersInit, float **weightsLoadedFromModel, float **biasesLoadedFromModel, bool withCostFunction) |
| |
| virtual | ~CscNeuralNetworkTensorFlow () |
| |
| CscNeuralNetworkTensorFlow * | getDuplicata () |
| |
| vector< TF_Session * > | getSessions () |
| |
| CscNeuralNetworkBuilderTensorFlow * | getBuilder () const |
| |
| CscNeuralNetworkPersistenceTensorFlow * | getPersistence () const |
| |
| ResultTraining | trainNeuralNetwork (const int nbEpochs, const int nbMiniBatchs, DataSet *trainingDataSet, DataSet *validationDataSet, const bool debugMode=false) override |
| | Trains a neural network using the specified parameters and datasets. More...
|
| |
| float | testNeuralNetworkOnValidationDataSet (DataSet *validationDataSet, const bool nnNeverInitialized=false) |
| | Tests the neural network on the provided validation dataset and calculates the mean error. More...
|
| |
| vector< float > | executeWithoutCostFunction (TF_Session *session, float **inputs) |
| | Executes the neural network without a cost function and returns the results. More...
|
| |
| | CscNeuralNetwork (CscNeuralNetworkType neuralNetworkType, NeuralNetworkHyperparameters *neuralNetworkHyperparametersInit, TrainingHyperparameters *trainingHyperparametersInit) |
| |
| | CscNeuralNetwork (CscNeuralNetworkType neuralNetworkType, NeuralNetworkHyperparameters *neuralNetworkHyperparametersInit, TrainingHyperparameters *trainingHyperparametersInit, float **weightsLoadedFromModel, float **biasesLoadedFromModel) |
| |
| virtual | ~CscNeuralNetwork () |
| |
| CscNeuralNetworkType | getNeuralNetworkType () const |
| |
| CscNeuralNetwork::NeuralNetworkHyperparameters * | getNeuralNetworkHyperparameters () const |
| |
| CscNeuralNetwork::TrainingHyperparameters * | getTrainingHyperparameters () const |
| |
|
| static CscNeuralNetworkTensorFlow * | loadModelFromDirectory (const fs::path &dirPath, bool forTraining) |
| | Loads a neural network model from a specified directory. More...
|
| |
| static float *** | adaptDataForMiniBatches (float **dataToTransform, const int minibatchSize, const int dataSetSize) |
| | Prepares the dataset for minibatch processing by dividing it into smaller batches. More...
|
| |
| static void | normalizeDataAutoRange (float **data, size_t size, int nbInputsOrOutputs, CscNormalizationType normalizationType) |
| |
| static void | normalizeDataCustomRange0to1 (float **data, size_t size, int nbInputsOrOutputs, float *minValue, float *maxValue) |
| |
| static void | normalizeDataCustomRangeMinus1to1 (float **data, size_t size, int nbInputsOrOutputs, float *minValue, float *maxValue) |
| |
| static void | normalizeData (float **data, size_t size, int rowData, float newMin, float newMax, float minValue, float maxValue) |
| |
| static void | deleteAllDataMiniBatches (float ***dataMiniBatches, const int nbMiniBatches, const int nbDataPerMinibatch) |
| | Frees the memory allocated for the mini-batches of data. More...
|
| |
| static void | initializeWeights (float *weightsToInitialize, int size, CscInitializationWeightsStrategy strategy, int fanIn, int fanOut=0, float *weightsLoaded=nullptr) |
| | Initializes the weights of the neural network according to a specified initialization strategy. More...
|
| |
| static void | initializeBias (float *biasToInitialize, int size, CscInitializationBiasStrategy strategy, float *biasLoaded=nullptr) |
| |
|
| void | shuffleMinibatchData (float ***minibatchDataInputs, float ***minibatchDataTargets, const int numberOfBatches, const int minibatchSize) |
| | Shuffles the data within each minibatch as well as between minibatches. More...
|
| |
| static float | calculateStddevHe (int fanIn) |
| |
| static float | calculateLimitGlorot (int fanIn, int fanOut) |
| |
| static float | calculateStddevGlorot (int fanIn, int fanOut) |
| |
| static float | calculateStddevLeCun (int fanIn) |
| |
| static void | initNormal (float *weights, int size, mt19937 &gen, double stddev) |
| |
| static void | initUniform (float *weights, int size, mt19937 &gen, float limit) |
| |
| CscNeuralNetworkType | neuralNetworkType |
| |
| TrainingHyperparameters * | trainingHyperparameters = nullptr |
| |
| NeuralNetworkHyperparameters * | neuralNetworkHyperparameters = nullptr |
| |
| unique_ptr< CscLogger > | logger |
| |
◆ CscNeuralNetworkTensorFlow() [1/2]
◆ CscNeuralNetworkTensorFlow() [2/2]
◆ ~CscNeuralNetworkTensorFlow()
| conscience_core::ai::nn::CscNeuralNetworkTensorFlow::~CscNeuralNetworkTensorFlow |
( |
| ) |
|
|
virtual |
◆ executeWithoutCostFunction()
| vector< float > conscience_core::ai::nn::CscNeuralNetworkTensorFlow::executeWithoutCostFunction |
( |
TF_Session * |
session, |
|
|
float ** |
inputs |
|
) |
| |
Executes the neural network without a cost function and returns the results.
- Parameters
-
| session | Pointer to the TensorFlow session. |
| inputs | Pointer to the input data. |
- Returns
- A vector of floats containing the results of the neural network execution.
This function initializes the neural network values and prepares the input data as a TensorFlow tensor. It then executes the graph without a cost function and retrieves the results. The results are converted into a vector of floats and returned. The function ensures proper cleanup of TensorFlow tensors used in the process.
◆ getBuilder()
◆ getDuplicata()
◆ getPersistence()
◆ getSessions()
| vector< TF_Session * > conscience_core::ai::nn::CscNeuralNetworkTensorFlow::getSessions |
( |
| ) |
|
◆ loadModelFromDirectory()
| CscNeuralNetworkTensorFlow * conscience_core::ai::nn::CscNeuralNetworkTensorFlow::loadModelFromDirectory |
( |
const fs::path & |
dirPath, |
|
|
bool |
forTraining |
|
) |
| |
|
static |
Loads a neural network model from a specified directory.
- Parameters
-
| filePath | The file path to the directory containing the model. |
| forTraining | Flag indicating if the model is to be loaded for training. |
- Returns
- A pointer to the loaded CscNeuralNetworkTensorFlow object.
This function loads a neural network model from the specified directory. It utilizes the CscNeuralNetworkPersistenceTensorFlow class to retrieve all the necessary parameters (including training hyperparameters, neural network hyperparameters, weights, and biases). It then constructs a new CscNeuralNetworkTensorFlow object with these parameters and returns a pointer to it.
◆ testNeuralNetworkOnValidationDataSet()
| float conscience_core::ai::nn::CscNeuralNetworkTensorFlow::testNeuralNetworkOnValidationDataSet |
( |
DataSet * |
validationDataSet, |
|
|
const bool |
nnNeverInitialized = false |
|
) |
| |
Tests the neural network on the provided validation dataset and calculates the mean error.
- Parameters
-
| validationDataSet | Pointer to the dataset used for validation. |
| nnNeverInitialized | Flag indicating if the neural network has never been initialized. |
- Returns
- The mean error of the neural network on the validation dataset.
This function tests the neural network on a given validation dataset. It first checks that the number of data points per mini-batch does not exceed a predefined maximum. If the neural network has never been initialized (nnNeverInitialized is true), it initializes the weights and biases. The function then calculates and returns the mean error by executing the network on mini-batches of the validation dataset.
◆ trainNeuralNetwork()
| CscNeuralNetwork::ResultTraining conscience_core::ai::nn::CscNeuralNetworkTensorFlow::trainNeuralNetwork |
( |
const int |
nbEpochs, |
|
|
const int |
nbMiniBatchs, |
|
|
DataSet * |
trainingDataSet, |
|
|
DataSet * |
validationDataSet, |
|
|
const bool |
debugMode = false |
|
) |
| |
|
overridevirtual |
Trains a neural network using the specified parameters and datasets.
- Parameters
-
| nbEpochs | The number of epochs for training. |
| nbMiniBatchs | The number of mini-batches to use for each epoch. |
| trainingDataSet | Pointer to the dataset used for training. |
| validationDataSet | Pointer to the dataset used for validation. |
| debugMode | Flag to enable or disable debug mode, which logs additional information. |
- Returns
- A ResultTraining object containing details about the training process, such as the number of epochs performed, the epoch with the best validation result, the mean error on training data, and the best mean error on validation data.
The function first asserts that the number of data per mini-batch matches the expected value based on the training dataset size and number of mini-batches. It then initializes the training process, including session creation, weight and bias initialization, and optimizer-specific initializations. The main training loop iterates through the specified number of epochs, shuffling the training data, and executing training on mini-batches. During each epoch, the mean error on training and validation data is calculated and logged if debug mode is enabled. The function also includes an early stopping mechanism, which terminates training if there is no improvement in validation error for a specified number of epochs (patience). Finally, the function returns a ResultTraining object summarizing the training results.
Implements conscience_core::ai::nn::CscNeuralNetwork.
The documentation for this class was generated from the following files: