From ff074ed10538b1bfc121af04e87e09b3d4dfe7a2 Mon Sep 17 00:00:00 2001 From: Elbez Hammouda <hammoudae@gmail.com> Date: Tue, 22 Jun 2021 03:20:46 +0200 Subject: [PATCH] General module multilayer with labels --- src/Global_Var.py | 6 ++++-- src/Modules/General/callbacks.py | 12 ++++++------ src/Modules/General/layout.py | 4 ++-- src/Modules/General/spark.py | 1 + 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/Global_Var.py b/src/Global_Var.py index d3202bd..9745a89 100755 --- a/src/Global_Var.py +++ b/src/Global_Var.py @@ -37,7 +37,8 @@ class Global_Var(): Input = 0 Date = "" Accuracy = "0" - Labels = None + finalLabels = None + labelsExistance = False oldIdSpike = None def __init__(self): @@ -54,7 +55,8 @@ class Global_Var(): self.Input = 0 self.Date = "" self.Accuracy = "0" - self.Labels = None + self.finalLabels = None + self.labelsExistance = False self.oldIdSpike = None # MongoDB connection --------------------------------------------- diff --git a/src/Modules/General/callbacks.py b/src/Modules/General/callbacks.py index 0a65427..7ee5c08 100644 --- a/src/Modules/General/callbacks.py +++ b/src/Modules/General/callbacks.py @@ -87,7 +87,7 @@ class callbacks(): fill='tozeroy' if len( generalGraphFilter) == 1 else 'none', line=dict(color="rgb(31, 119, 180)"), - name='Spikes ['+layer+']', + name='Spikes'+ ('['+layer+']' if len(generalLayerFilter) > 1 else ''), mode='lines+markers', text=list(super.xAxisLabel), customdata=list(super.SpikeGraphY[layer]), @@ -112,7 +112,7 @@ class callbacks(): fill='tozeroy' if len( generalGraphFilter) == 1 else 'none', line=dict(color="rgb(255, 127, 14)"), - name='Synapses activity ['+layer+']', + name='Synapses activity'+ ('['+layer+']' if len(generalLayerFilter) > 1 else ''), mode='lines+markers', text=list(super.xAxisLabel), customdata=list(super.SynapseGraphY[layer]), @@ -136,7 +136,7 @@ class callbacks(): fill='tozeroy' if len( generalGraphFilter) == 1 else 'none', line=dict(color="rgb(44, 160, 44)"), - name='Neuron\'s potential ['+layer+']', + name='Neuron\'s potential'+ ('['+layer+']' if len(generalLayerFilter) > 1 else ''), mode='lines+markers', text=list(super.xAxisLabel), customdata=list(super.PotentialGraphY[layer]), @@ -145,7 +145,7 @@ class callbacks(): if(len(graphs) != 0): - if(g.Labels != None): + if(g.finalLabels != None): if(data[-1] != None): super.LossGraphY.append(round(data[-1], 2)) @@ -736,7 +736,7 @@ class callbacks(): Returns: loss value """ - if g.Labels == None: + if g.finalLabels == None: return None # MongoDB--------------------- col = pymongo.collection.Collection(g.db, 'spikes') @@ -754,7 +754,7 @@ class callbacks(): loss = 0 for a in spikes: - for l in g.Labels: + for l in g.finalLabels: if (str(a["i"]["N"]) == str(l["N"]) and str(a["i"]["L"]) == l["L"]): if (str(l["Label"]) != str(a["Input"])): loss += 1 diff --git a/src/Modules/General/layout.py b/src/Modules/General/layout.py index abb951f..97e0d87 100644 --- a/src/Modules/General/layout.py +++ b/src/Modules/General/layout.py @@ -148,7 +148,7 @@ class layout(): style={"minWidth":"10%","marginLeft": "15px", "textAlign": "start"})], className="row", style={"paddingLeft": "20px",'width': '100%'}) ], className="col-12") ], className="row"), - html.Div([dcc.Graph(id='general-graph', animate=False, config={"displaylogo": False})])], className="col-lg-9 col-sm-12 col-xs-12" if(g.Labels != None) else "col-lg-12 col-sm-12 col-xs-12"), + html.Div([dcc.Graph(id='general-graph', animate=False, config={"displaylogo": False})])], className="col-lg-9 col-sm-12 col-xs-12" if(g.labelsExistance) else "col-lg-12 col-sm-12 col-xs-12"), html.Div([ html.Div([ html.P("Inputs", style={ @@ -160,7 +160,7 @@ class layout(): color="#28a745", style={"marginLeft": "10px"} )], className="row"), - dcc.Graph(id='label-graph', animate=False, config={"displaylogo": False})], className="col-lg-3 col-sm-12 col-xs-12") if(g.Labels != None) else []], className="row") + dcc.Graph(id='label-graph', animate=False, config={"displaylogo": False})], className="col-lg-3 col-sm-12 col-xs-12") if(g.labelsExistance) else []], className="row") ], style={"padding": "5px"})), label="General information", value="General information"), dcc.Tab(dbc.Card( dbc.CardBody([ diff --git a/src/Modules/General/spark.py b/src/Modules/General/spark.py index 9495e03..d5182d5 100644 --- a/src/Modules/General/spark.py +++ b/src/Modules/General/spark.py @@ -63,6 +63,7 @@ def preProcessing(g): M = max(M, pymongo.collection.Collection( g.db, 'synapseWeight').find_one(sort=[("T", -1)])["T"]) if ('labels' in g.db.list_collection_names()): + g.labelsExistance = True M = max(M, pymongo.collection.Collection( g.db, 'labels').find_one(sort=[("T", -1)])["T"]) else: -- GitLab