Skip to content

Commit

Permalink
Merge pull request #4 from appxpy/appxpy-dev
Browse files Browse the repository at this point in the history
Bug fix & optimizations
  • Loading branch information
appxpy committed Jun 13, 2023
2 parents 5afbb68 + 673783e commit caf79d8
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 18 deletions.
13 changes: 0 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ To create and train your own neural network using the NNFS library, follow these
1. Install the NNFS library into your cmake project.
2. Download and preprocess the MNIST dataset (if not already available) using the fetch_mnist function.
3. Create the neural network model by adding layers to an instance of `NNFS::NeuralNetwork` class. For example:

```cpp
std::shared_ptr<NNFS::NeuralNetwork> model = std::make_shared<NNFS::NeuralNetwork>();
model->add_layer(std::make_shared<NNFS::Dense>(784, 128));
Expand All @@ -98,45 +97,33 @@ model->add_layer(std::make_shared<NNFS::ReLU>());
model->add_layer(std::make_shared<NNFS::Dense>(128, 10));
```
4. Compile the model by calling the compile method:
```cpp
model->compile();
```

5. Train the model on the training dataset using the `fit` method. Specify the number of epochs and the batch size. For example:

```cpp
model->fit(x_train, y_train, x_test, y_test, 20, 128);
```
6. Save the trained model to a file using the `save` method:
```cpp
std::string file_path = "path/to/save/model.bin";
model->save(file_path);
```

7. Load the saved model from the file using the `load` method:

```cpp
std::shared_ptr<NNFS::NeuralNetwork> model = std::make_shared<NNFS::NeuralNetwork>();
model->load(file_path);
```
8. Evaluate the model's accuracy on the test dataset using the `accuracy` method:
```cpp
double accuracy;
model->accuracy(accuracy, x_test, y_test);
std::cout << "Test set accuracy: " << accuracy << std::endl;
```

9. Make predictions using the `predict` method. Pass the input data to the method and obtain the predicted outputs:

```cpp
Eigen::MatrixXd predictions = model->predict(input_data);
```
10. Perform any necessary post-processing on the predictions and compare them with the actual labels to evaluate the model's performance.
Please note that this is a simplified explanation of the code. Additional code and configuration may be required depending on the specific implementation and requirements. If you need more information, please, follow the [documentation](https://appxpy.github.io/NNFS).
Expand Down
1 change: 1 addition & 0 deletions include/NNFS/Optimizer/Optimizer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace NNFS
* @brief Construct a new Optimizer object
*
* @param lr Learning rate
* @param decay Learning rate decay (default: 0.0)
*/
Optimizer(double lr, double decay) : _lr(lr), _current_lr(lr), _iterations(0), _decay(decay) {}

Expand Down
2 changes: 1 addition & 1 deletion tools/paint/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ endif()

enable_testing(true)

add_executable(tests test_canvas.h test_canvas.cpp canvas.h canvas.cpp)
add_executable(tests test_canvas.h test_canvas.cpp canvas.h canvas.cpp paint.ui paint.cpp paint.h)
add_test(NAME CanvasTest COMMAND tests)

target_link_libraries(tests PRIVATE Qt${QT_VERSION_MAJOR}::Test Eigen3::Eigen NNFSProject::NNFS Qt${QT_VERSION_MAJOR}::Widgets)
6 changes: 3 additions & 3 deletions tools/paint/canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ class Canvas : public QLabel
void mouseReleaseEvent(QMouseEvent *event) override;

private:
bool drawing; ///< Flag indicating whether the user is currently drawing.
QImage image; ///< The image used as the canvas.
QPointF lastPoint; ///< The last recorded point where the mouse was pressed or moved.
bool drawing; ///< Flag indicating whether the user is currently drawing.
QImage image; ///< The image used as the canvas.
QPointF lastPoint; ///< The last recorded point where the mouse was pressed or moved.
Eigen::MatrixXd image_matrix = Eigen::MatrixXd::Zero(1, 784); ///< The matrix representation of the image on the canvas.
};

Expand Down
1 change: 0 additions & 1 deletion tools/paint/test_canvas.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "test_canvas.h"
#include <iostream>

void TestCanvas::testClearImage_positive()
{
Expand Down

0 comments on commit caf79d8

Please sign in to comment.