diff --git a/VS2N.py b/VS2N.py index 13671d2a0edb617fb96a74a2c02c7905ce7203bf..ed1580f36743b79659b11e9286daf00c9b151edd 100755 --- a/VS2N.py +++ b/VS2N.py @@ -268,6 +268,7 @@ class VS2N(): # Loading Modules to Dashboard layout().load(self.app_vis, self.g) + return "done" def Module(self, n, g): """ Helper function to execute each module sparks pre processing (if exist) diff --git a/src/Modules/General/callbacks.py b/src/Modules/General/callbacks.py index 38c1a476e1af7b8de5e22067e918f74569da6f88..46215799ef6e44bfd1fddacfd1a138975a7fa351 100755 --- a/src/Modules/General/callbacks.py +++ b/src/Modules/General/callbacks.py @@ -566,6 +566,7 @@ class callbacks(callbacksOp): elements = super.Spikes2D matrix = {} indices = {} + labelData = getNetworkInput(int(sliderValue)*float(updateInterval), g.updateInterval) if callback_context.triggered[0]['prop_id'].split('.')[0] in ["v-step","vis-update"]: super.SpikesActivityPerInput = {i:[[0 for j in range(g.nbrClasses+1)] for i in range(g.Layer_Neuron[i])] for i in g.Layer_Neuron if i != "Input"} for element in elements: @@ -611,7 +612,7 @@ class callbacks(callbacksOp): heatmaps = [{"data":[go.Heatmap(z = matrix[layer], colorscale= 'Reds', customdata = indices[layer], hovertemplate=('Neuron: %{customdata} <br>Spikes: %{z} <extra></extra>'),xgap=4,ygap=4)],"layout":{"xaxis":dict(showgrid = False, zeroline = False),"yaxis":dict(autorange = 'reversed',scaleanchor = 'x',showgrid = False, zeroline = False),"margin":{'l': 0, 'r': 0, 't': 5, 'b': 0},"uirevision":'no reset of zoom', "hoverlabel_align": 'right'}} for layer in super.AccumulatedSpikes2D] - SpikesActivityPerInput = [{"data":[go.Heatmap(z=super.SpikesActivityPerInput[layer], colorscale= 'Reds',hovertemplate=('Class: %{x} <br>Neuron: %{y} <br>Spikes: %{z} <extra></extra>'),xgap=4,ygap=4)],"layout":{"xaxis":dict(title="Class",tickmode="array",zeroline = False,tickvals=[i for i in range(g.nbrClasses+1)]),"yaxis":dict(title="Neuron",zeroline = False),"margin":{'r': 0,'t': 0},"uirevision":'no reset of zoom'}} for layer in super.SpikesActivityPerInput] + SpikesActivityPerInput = [make_SpikeActivityPerInput(layer,labelData) for layer in super.SpikesActivityPerInput] return [elements,[],heatmaps,SpikesActivityPerInput] else: @@ -628,7 +629,7 @@ class callbacks(callbacksOp): heatmaps = [{"data":[go.Heatmap(z = matrix[layer], colorscale= 'Reds', customdata = indices[layer], hovertemplate=('Neuron: %{customdata} <br>Spikes: %{z} <extra></extra>'),xgap=4,ygap=4)],"layout":{"xaxis":dict(showgrid = False, zeroline = False),"yaxis":dict(autorange = 'reversed',scaleanchor = 'x',showgrid = False, zeroline = False),"margin":{'l': 0, 'r': 0, 't': 5, 'b': 0},"uirevision":'no reset of zoom', "hoverlabel_align": 'right'}} for layer in super.AccumulatedSpikes2D] - SpikesActivityPerInput = [{"data":[go.Heatmap(z=super.SpikesActivityPerInput[layer], colorscale= 'Reds',hovertemplate=('Class: %{x} <br>Neuron: %{y} <br>Spikes: %{z} <extra></extra>'),xgap=4,ygap=4)],"layout":{"xaxis":dict(title="Class",tickmode="array",zeroline = False,tickvals=[i for i in range(g.nbrClasses+1)]),"yaxis":dict(title="Neuron",zeroline = False),"margin":{'r': 0,'t': 0},"uirevision":'no reset of zoom'}} for layer in super.SpikesActivityPerInput] + SpikesActivityPerInput = [make_SpikeActivityPerInput(layer,labelData) for layer in super.SpikesActivityPerInput] return [elements,f"Neuron {mouseOverNodeData['label']} : {mouseOverNodeData['spikes']}" if 'spikes' in mouseOverNodeData else "", heatmaps,SpikesActivityPerInput] except Exception: print("OnHover:"+traceback.format_exc()) @@ -691,7 +692,17 @@ class callbacks(callbacksOp): else: res.append(getLoss(timestamp, g.updateInterval)) return res - + + def make_SpikeActivityPerInput(layer,dataLabel): + fig = make_subplots(rows=5, cols=1, shared_xaxes=True, vertical_spacing=0.08, specs=[[{'rowspan': 4}],[None],[None],[None],[{'rowspan': 1}]]) + fig.add_trace(go.Heatmap(z=super.SpikesActivityPerInput[layer], colorscale= 'Reds',hovertemplate=('Class: %{x} <br>Neuron: %{y} <br>Spikes: %{z} <extra></extra>'),xgap=4,ygap=4),row=1, col=1) + fig.update_layout({"xaxis":dict(title="Class",tickmode="array",zeroline = False,tickvals=[i for i in range(g.nbrClasses+1)]),"yaxis":dict(title="Neuron",zeroline = False),"margin":{'l': 0, 'r': 0, 't': 5, 'b': 0},"uirevision":'no reset of zoom'}) + if dataLabel == None: + fig.add_trace(go.Bar(x=[],y=[],hovertemplate=('Label: %{x} <br>Nbr: %{y} <extra></extra>')),row=5, col=1) + else: + fig.add_trace(go.Bar(x=list(dataLabel[0].keys()),y=list(dataLabel[0].values()),hovertemplate=('Label: %{x} <br>Nbr: %{y} <extra></extra>')),row=5, col=1) + fig.update_xaxes(tickvals=[i for i in range(g.nbrClasses+1)]) + return fig # --------------------------------------------------------- # MongoDB operations # ---------------------------------------------------------