dynapcnn_visualizer#
DynapcnnVisualizer is a GUI module for testing and visualizing results of on-chip models in real-time and real-life conditions.
- class DynapcnnVisualizer(window_scale: Tuple[int, int] = (4, 8), dvs_shape: Tuple[int, int] = (128, 128), add_readout_plot: bool = False, add_power_monitor_plot: bool = False, spike_collection_interval: int = 500, readout_prediction_threshold: int = 10, readout_default_return_value: int | None = None, readout_default_threshold_low: int | None = 0, readout_default_threshold_high: int | None = 32000, power_monitor_number_of_items: int | None = 3, feature_names: List[str] | None = None, readout_images: List[str] | None = None, feature_count: int | None = None, extra_arguments: Dict[str, Dict[str, any]] | None = None)[source]#
(tlx, tly, brx, bry)
Quick wrapper around Samna objects to get a basic dynapcnn visualizer.
- Parameters:
window_scale – Tuple[int, int] (defaults to (4, 8)) Scale of window based on a 16/9 monitor layout. (in height, width)
dvs_shape (Tuple[int, int], optional) – Shape of the DVS sensor in (height, width). Defaults to (128, 128) – Speck sensor resolution.
add_readout_plot – bool (defaults to False) If set true adds a readout plot to the GUI
add_power_monitor_plot – bool (defaults to False) If set true adds a power monitor plot to the GUI.
spike_collection_interval – int (defaults to 500) (in milliseconds) Spike collection is done using a low-pass filter with a window size. This parameter sets the window size of the spike collection
readout_prediction_threshold – int (defaults to 10) Defines the number of spikes needed for making a prediction.
readout_default_return_value – Optional[int] (defaults to None) Defines the default prediction of the network. Usually used for other class in the network.
readout_default_threshold_low – Optional[int] (defaults to 0) Default lower threshold value for MajorityReadoutNode
readout_default_threshold_high – Optional[int] (defaults to int.max()) Default higher threshold value for MajorityReadoutNode
power_monitor_number_of_items – Optional[int] (defaults to 3) Can be set to 3 or 5
feature_names – Optional[List[str]] (defaults to None) List of feature names. If this is passed they will be displayed on the spike count plot as output labels
readout_images – Optional[List[str]] (defaults to None) List of paths of the images to be shown in the readout plot. If the feature_names parameter is not passed the names of the images will be parsed and used as the spike count plot labels. Format of the individual file name should be of the following type. classnumber`_`classlabel.`extension` NOTE: Class numbers should match that of the network output channels. This is so that they can be sorted properly. At each operating system the behaviour in which the extraction of the images from a folder may differ. NOTE: For now only .png images are supported.
feature_count – Optional[int] (defaults to None) If the feature_names and readout_images was passed, this is not needed. Otherwise this parameter should be passed, so that the GUI knows how many lines should be drawn on the Spike Count Plot and Readout Layer Plot.
extra_arguments – Optional[Dict[str, Dict[str, any]]] (defaults to None) Extra arguments that can be passed to individual plots. Available keys are: - spike_count: Arguments that can be passed to spike_count plot. - readout: Arguments that can be passed to readout plot. - power_measurement: Arguments that can be passed power_measurement plot.
- DEFAULT_LAYOUT_DS = [(0, 0, 0.5, 1), (0.5, 0, 1, 1), None, None]#
- DEFAULT_LAYOUT_DSP = [(0, 0, 0.5, 0.66), (0.5, 0, 1, 0.66), None, (0, 0.66, 1, 1)]#
- DEFAULT_LAYOUT_DSR = [(0, 0, 0.33, 1), (0.33, 0, 0.66, 1), (0.66, 0, 1, 1), None]#
- DEFAULT_LAYOUT_DSRP = [(0, 0, 0.33, 0.66), (0.33, 0, 0.66, 0.66), (0.66, 0, 1, 0.66), (0, 0.66, 1, 1)]#
- LAYOUTS_DICT = {'ds': [(0, 0, 0.5, 1), (0.5, 0, 1, 1), None, None], 'dsp': [(0, 0, 0.5, 0.66), (0.5, 0, 1, 0.66), None, (0, 0.66, 1, 1)], 'dsr': [(0, 0, 0.33, 1), (0.33, 0, 0.66, 1), (0.66, 0, 1, 1), None], 'dsrp': [(0, 0, 0.33, 0.66), (0.33, 0, 0.66, 0.66), (0.66, 0, 1, 0.66), (0, 0.66, 1, 1)]}#
- add_dvs_plot(shape: Tuple[int, int], layout: Tuple[float, float, float, float])[source]#
Add an activity plot (dvs plot) to a visualizer
- Parameters:
shape (Tuple(int, int)) – Shape of the plot in (height, width)
layout (Tuple[float, float, float, float]) – Layout to position the plot on the samnagui visualizer in (top-left-x, top-left-y, bottom-right-x, bottom-right-y)
- Returns:
Tuple[samna.ui.ActivityPlot, int] – A tuple of the plot object and its id.
- add_output_prediction_layer_plot()[source]#
What we want to have is something as described below: Plot for visualizating the chip readout layers.
output neuron id ^ | +——-+———————-+ + out0 + x + + out1 + x + + out2 + xxxxxxxx xxxxx + +——-+———————-+ –> time
Where every time the readout layer has been read, if some output returns True, put an x there, denoting a prediction
- add_power_monitor_plot(layout: Tuple[int, int, int, int])[source]#
- Parameters:
layout (Tuple[float, float, float, float]) – Layout to position the plot on the samnagui visualizer in (top-left-x, top-left-y, bottom-right-x, bottom-right-y)
- Returns:
Tuple[samna.ui.PowerMeasurementPlot, int] – A tuple of the plot object and its id.
- add_readout_plot(layout: Tuple[float, float, float, float])[source]#
Add a readout plot (image showing the predicted class) to the visualizer
- Parameters:
layout (Tuple[float, float, float, float]) – Layout to position the plot on the samnagui visualizer in (top-left-x, top-left-y, bottom-right-x, bottom-right-y)
images (List[str]) – A list of paths to the images corresponding to be shown in the case that the class is predicted. – Note that order of this list should match the order of the lookup table.
- Returns:
Tuple[samna.ui.ReadoutPlot, int] – A tuple of the plot object and its id.
- add_spike_count_plot(layout: Tuple[float, float, float, float])[source]#
- Add a spike count plot (line plot showing recent predicitons from network
for each class)
- Parameters:
layout (Tuple[float, float, float, float]) – Layout to position the plot on the samnagui visualizer in (top-left-x, top-left-y, bottom-right-x, bottom-right-y)
- Returns:
Tuple[samna.ui.SpikeCountPlot, int] – A tuple of the plot object and its id.
- connect(dynapcnn_network: DynapcnnNetwork, disjoint_process: bool = False)[source]#
The method does the bulk of the work of creating the graphs and launching the visualizer
- Parameters:
dynapcnn_network (DynapcnnNetwork) – The network that needs to be deployed and visualized
disjoint_process (bool, optional) – If true, the GUI is launched as a separate disjoint process. Useful for MacOS users. Defaults to False.
- Raises:
ConnectionError – _description_
ValueError – _description_
ValueError – _description_
NotImplementedError – _description_
- create_plots()[source]#
Utility function to create a Cluster visualizer
Args:
- Returns:
Tuple[Tuple[samna.ui.Plot, int]] – A tuple of tuples of the plot objects and their ids.
- create_visualizer_process(visualizer_endpoint: str, disjoint_process: bool = False)[source]#
Create a samnagui visualizer process
- Parameters:
visualizer_endpoint (str) – TCP url with the port for the visualizer. eg. tcp://0.0.0.0:40000
disjoint_process (bool) – If True, the visualizer is launched with a terminal command and is run as an independent process (Useful for MacOS users). Else, it is run as a subprocess by default.
- Returns:
subprocess( Optional[Process]) – Returns a process in case the GUI is not launched as a disjoint process.
- static parse_feature_names_from_image_names(readout_image_paths: List[str])[source]#
Method the parse the feature names directly from the names of the images. :param readout_image_paths: List[str]
List of paths to all the feature images
- update_feature_count(dynapcnn_network: DynapcnnNetwork)[source]#
Extract feature count from the last layer and pass it to GUI :param dynapcnn_network: DynapcnnNetwork
sinabs-dynapcnn, DynapcnnNetwork object.