Skip to content

Commit

Permalink
Add train function in NeuralNetwork Class.
Browse files Browse the repository at this point in the history
Add train member function of NeuralNetwork Class.
- NeuralNetwork Class has DataBuffer instance to handle datas.
- New Keywords are introduced for specify data set
  . TrainData, ValidData, TestData, LabelData
- DataBuffer instance is initialized with parameters from Neural
Network instance.
- In train function,
   . Data Buffer instance is running ( collecting or generating data )
   . get the data from Data Buffer instance.
   . Backwarding
   . Display progress ( Data Buffer member funciton )
   . Validate if it is enabled.
- Add Classification Example with train member function

**Self evaluation:**
1. Build test:	 [X]Passed [ ]Failed [ ]Skipped
2. Run test:	 [X]Passed [ ]Failed [ ]Skipped

Signed-off-by: jijoong.moon <jijoong.moon@samsung.com>
  • Loading branch information
jijoongmoon committed Apr 22, 2020
1 parent 7127632 commit 9c5b23a
Show file tree
Hide file tree
Showing 7 changed files with 330 additions and 50 deletions.
3 changes: 3 additions & 0 deletions Applications/Classification/res/Classification.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ minibatch = 32 # mini batch size
beta1 = 0.9 # beta 1 for adam
beta2 = 0.9999 # beta 2 for adam
epsilon = 1e-7 # epsilon for adam
TrainData="trainingSet.dat"
ValidData="trainingSet.dat"
LabelData="label.dat"

# Layer Section : Name
[inputlayer]
Expand Down
72 changes: 69 additions & 3 deletions nntrainer/include/databuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ class DataBuffer {
val_thread(), test_thread() {
for (int i = 0; i < NBUFTYPE; ++i)
validation[i] = true;
input_size = 0;
class_num = 0;
};

/**
Expand Down Expand Up @@ -110,6 +112,11 @@ class DataBuffer {
unsigned int max_val, unsigned int max_test, unsigned int in_size,
unsigned int c_num);

/**
* @brief Initialize Buffer with data buffer private variables
* @retval #ML_ERROR_NONE Successful.
* @retval #ML_ERROR_INVALID_PARAMETER invalid parameter.
*/
int init();

/**
Expand All @@ -128,6 +135,13 @@ class DataBuffer {
*/
void run(BufferType type, std::ifstream &file);

/**
* @brief function for thread ( training, validation, test )
* @param[in] BufferType training, validation, test
* @retval void
*/
void run(BufferType type);

/**
* @brief clear thread ( training, validation, test )
* @param[in] BufferType training, validation, test
Expand All @@ -136,6 +150,13 @@ class DataBuffer {
*/
void clear(BufferType type, std::ifstream &file);

/**
* @brief clear thread ( training, validation, test )
* @param[in] BufferType training, validation, test
* @retval void
*/
void clear(BufferType type);

/**
* @brief get Status of Buffer. if number of rest data
* is samller than minibatch, the return false
Expand All @@ -160,6 +181,18 @@ class DataBuffer {
std::vector<std::vector<std::vector<float>>> &out_label, unsigned int batch,
unsigned int width, unsigned int height, unsigned int c_num);

/**
* @brief get Data from Data Buffer using databuffer param
* @param[in] BufferType training, validation, test
* @param[in] outVec feature data ( minibatch size )
* @param[in] outLabel label data ( minibatch size )
* @retval true/false
*/
bool
getDataFromBuffer(BufferType type,
std::vector<std::vector<std::vector<float>>> &out_vec,
std::vector<std::vector<std::vector<float>>> &out_label);

/**
* @brief set train data file name
* @param[in] path file path
Expand Down Expand Up @@ -201,6 +234,38 @@ class DataBuffer {
*/
int setFeatureSize(unsigned int n);

/**
* @brief set feature size
* @retval max_train
*/
unsigned int getMaxTrain() { return max_train; }

/**
* @brief set feature size
* @retval max_val
*/
unsigned int getMaxVal() { return max_val; }

/**
* @brief set feature size
* @retval max_test
*/
unsigned int getMaxTest() { return max_test; }

/**
* @brief Display Progress
* @param[in] count calculated set ( mini_batch size )
* @param[in] type buffer type ( BUF_TRAIN, BUF_VAL, BUF_TEST )
* @retval void
*/
void displayProgress(const int count, BufferType type, float loss);

/**
* @brief return validation of data set
* @retval validation
*/
bool *getValidation() { return validation; }

private:
std::vector<std::vector<float>> train_data;
std::vector<std::vector<float>> train_data_label;
Expand Down Expand Up @@ -244,9 +309,10 @@ class DataBuffer {
std::thread val_thread;
std::thread test_thread;

std::string train_file;
std::string val_file;
std::string test_file;
std::ifstream train_stream;
std::ifstream val_stream;
std::ifstream test_stream;

std::vector<std::string> labels;
bool validation[NBUFTYPE];
};
Expand Down
2 changes: 2 additions & 0 deletions nntrainer/include/neuralnet.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ class NeuralNetwork {
*/
void finalize();

int train();

private:
/**
* @brief batch size
Expand Down
Loading

0 comments on commit 9c5b23a

Please sign in to comment.