Skip to content

TheAypisamFpv/NeuralNetworkVisualisation

Repository files navigation

Neural Network Visualization Tool

Neural Network Visualization Tool Logo

This tool allows you to visualize the inner workings of a neural network model. You can load a pre-trained model, input data, and see how the data propagates through the network layers. The tool provides a graphical interface to input data, visualize neuron activations, and connections.

Features

  • Load and visualize pre-trained neural network models.
  • Input data through a graphical interface (Copy paste supported).
  • Visualize neuron activations and connections.
  • Cluster neurons for better visualization performance.
  • Display feature importance (if feature importance file is available).

Requirements

Python 3.11.x - 3.12.x

Python can be downloaded from the official website: python.org

PyTorch

If you want to use PyTorch with GPU support (recommended), check PyTorch documentation for instructions.

Installation

  1. Clone the repository:

    git clone <repository_url>
    cd <repository_directory>
  2. Create a Python virtual environment using the installed Python version (recommended).

  3. Install the required packages:

    pip install -r requirements.txt

note: the PyTorch included in the requirements file is for CPU support.


How to Use

Open your desired Python file:

  • VisualiseNeuralNetTensor.py for Tensor models.
  • VisualiseNeuralNetTorch.py for Torch models.

Select Device:

You will be asked to select what device you want to use.

  • If you have installed PyTorch with GPU support, the option to use the GPU will be available.
  • If you have multiple GPUs, you can select which one to use.

Select a Model:

  • Click on the Select Model button to open a file dialog.
  • Choose the .keras (Tensor) or .pt (Torch) model file to load.

Input Data:

  • Enter values for each feature in the input boxes on the left side of the window.
  • For categorical features, a dropdown menu will appear.

Model Preparation

Mapping Values

Create a MappingValues.csv file in the same directory as the model file. The MappingValues.csv file should contain the mapping of feature names to their possible values or ranges. This file is necessary for the tool to correctly interpret the input values for the model.

The format of the file should be as follows:

Feature1      , Feature2                  , Feature3      , ...
"[min1, max1]", "[value1, value2, value3]", "[min3, max3]", ...

⚠️ Features should be in the same order as when the model was trained. ⚠️

Example available in model example\ folder.

  • For numerical features:

    Use the format "[min, max]" to specify the range of possible values.

    Here, min will be mapped to 0, and max will be mapped to 1.

  • For categorical features:

    Use the format "[value1, value2, value3]" to specify the possible values, they will be interpreted from left to right in the range [0, 1].

    Here, value1 will be mapped to 0, value2 to 0.5, and value3 to 1.



Feature Importance (Optional)

The feature importance file should contain the importance values for each feature in the model. It's only used to adjust the size of the input neurons in the visualization.

The format of the file should be as follows:

Feature , Importance
Feature1, 0.5
Feature2, 0.3
Feature3, 0.2
...

Order does not matter.


Detailed Explanation

Colors and Layout

  • Colors:

    • Positive activations: #5BAFFC (blue)
    • Negative activations: #FD4F59 (red)
  • Layout:

    • Input boxes are aligned on the left side.
    • Visualization area is on the right side.
    • The window is resizable (with a min size), and the layout adjusts accordingly.

Clustering

  • Neurons are clustered using hierarchical clustering to improve visualization performance.
  • Clustering can be toggled on or off (no clustering can lead to performance issues with large networks).
  • The threshold for a layer to be clustered can be adjusted (default is 50 neurons).

Visualization

  • Neurons are displayed as circles.
  • Connections between neurons are displayed as lines.
  • The color of each connection represents the value transmitted.
  • The color alpha of each connection represents the weight of the connection.
  • The size of the input neurons represents their importance (if provided).

Troubleshooting

  • Ensure that the model file is in the correct .keras format for Tensor or in .pt for Torch.
  • Ensure that the mapping file MappingValues.csv is available in the same directory as the model file.
  • Check the console for any error messages.
  • If you are still facing issues, you can directly contact me at [email protected].

About

Visualize the inner workings of your Neural Networks.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages