Skip to content
This repository has been archived by the owner on Nov 25, 2022. It is now read-only.

seanwu1105/neural-network-sandbox

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Neural Network Sandbox

An assignment collection for course CE5037 Neural Network in National Central University, Taiwan.

Features

  • Back-end completely separates from front-end by setContextProperty() and BridgeProperty
  • Animated Qt Chart in QML.
  • Automatically update UI when specific variables in back-end changed.
  • Modulized UI components.

Actually, neural networks are not the point.

Previews

perceptron preview

mlp preview

rbfn preview

som preview

Introduction to Architecture

I created the toy, Neural Network Sandbox, to explore if I could completely separate business logic (algorithms) from UI with Python and QML. Take mlp_algorithm.py for example, the class does not know anything about UI but the users still can interact with it via a QML app.

The QML UI needs to automatically observe some variables in the business logic. Thus, I need to inherit each algorithm with the Observable class. For example, ObservableMlpAlgorithm inherits Observable and MlpAlgorithm. Whenever a property has changed in the MlpAlgorithm, ObserableMlpAlgorithm.__setattr__(self, name, value) would be called. I can know which property has changed with the name parameter and notify the Observer with its new value.

But who is the observer? The bridge classes are the observer in this scenario. I created the bridge classes (e.g. mlp_bridge.py) containing a list of BridgeProperty. When a property has been updated by the observable via setattr(self, name, value), the corresponding (having the same name) BridgeProperty will get updated. When a BridgeProperty has been updated, its setter method will be called and emit PyQt signal to change QML UI.

In the early version of the project, there is no BridgeProperty class. For instance, the old version of perceptron_bridge.py having multiple pyqtProperty and its setter. To make the code cleaner, I have to create these pyqtProperties dynamically. BridgeProperty and BridgeMeta classes solve the problem. You can find more details from this Stackoverflow answer about creating pyqtProperty dynamically and this Stackoverflow answer about different ways to communicate between QML and Python.

Actually, after I finished the project, I feel it is a little bit over-engineered, and there are still many boilerplates scattering in the project. My solution to separate business logic (algorithms) from UI is definitely NOT the best way, which can be further improved. Hence, if you have a better idea about the architecture, feel free to create a pull request.

By the way, as far as I know, the architecture mentioned above cannot be applied to PySide2 currently due to this issue. I hope the Qt company would provide a cleaner and simpler solution regarding the interaction between Python and QML in the future (Qt 6).

Installation

Clone the project.

git clone https://github.com/seanwu1105/neural-network-sandbox

Install requirements.

pip install -r requirements.txt

Start the application.

python main.py

About

A toy about fundamental neural network algorithms and Qt Quick 2 interface.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published