This repository contains a C++ implementation of a neural network designed for pattern recognition tasks. The project is structured to facilitate both training and inference operations, with support for custom datasets.
- Custom Neural Network: Implemented from scratch in C++.
- Training and Inference: Capable of training on labeled datasets and performing inference on new data.
- Dataset Generation: Includes scripts for generating training and testing datasets in a specific format.
- Evaluation Metrics: Outputs training time, number of epochs, inference time, and memory usage during training and inference.
OVS_lab1/
├── CMakeLists.txt # Build configuration
├── main.cpp # Main application entry point
├── include/ # Header files
│ └── neural_net.h # Neural network class and utilities
├── src/ # Source files
│ └── neural_network.cpp # Implementation of neural network
├── data/ # Dataset files
│ ├── train/ # Training samples
│ ├── test/ # Test samples
│ └── model # Neural network model
└── README.md # Project documentation
- C++17 or later
- CMake 3.10 or later
- Python 3.x (for dataset generation)
-
Clone the repository:
git clone https://github.com/Vsevomes/OVS_lab1.git cd OVS_lab1 -
Create a build directory and compile:
mkdir build cd build cmake .. make -
The build will produce an executable file (e.g., neural_network) in the build directory.
You can use the executable to either train a model or predict using a saved model.
-
Train a Model
./neural_net train <train_folder> <num_inputs> <hiddenLayers> <neuronsPerLayer> <num_outputs> <learningRate>
- <train_folder> – folder containing training files
- <num_inputs> – number of input neurons (e.g., 49 for 7×7 images)
- – number of hidden layers
- – number of neurons per hidden layer
- <num_outputs> – number of output neurons/classes
- – learning rate for training
Example:
./neural_net train ../data/train/ 49 1 20 3
-
Predict Using a Saved Model
./neural_netw predict <model_file> <input_folder>
- <model_file> – path to the saved model file
- <input_folder> – folder containing test files
Example:
./neural_net predict model.dat ../data/test/
Each dataset file should contain:
- The first line: a space-separated vector representing the one-hot encoded target class.
- Subsequent lines: a 7x7 grid of binary values representing the input pattern.
Example:
0 0 1
0 0 0 0 0 0 0
0 0 0 1 0 0 0
0 0 1 0 1 0 0
0 1 0 0 0 1 0
1 0 0 0 0 0 1
1 1 1 1 1 1 1
0 0 0 0 0 0 0
Python scripts are provided to generate training and testing datasets:
python generate_datasets.pyThis will create train/ and test/ directories populated with sample files.
Upon execution, the program will output:
- Training Time: Duration of the training process.
- Epoch Count: Number of epochs completed.
- Inference Time: Time taken to process the test dataset.
- Memory Usage: Estimated memory consumption during training and inference.