Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.0.0 #5

Merged
merged 2 commits into from
Jun 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
SOFTWARE.

Contributors:
- Adam Milton-Barker - First version - 2021-5-1
- Nitin Mane

"""

Expand Down Expand Up @@ -58,7 +58,6 @@ def train(self):
self.model.prepare_data()
self.model.prepare_network()
self.model.train()
self.model.evaluate()

def set_model(self, mtype):

Expand All @@ -67,7 +66,7 @@ def set_model(self, mtype):
def load_model(self):
""" Loads the trained model """

self.model.load()
self.model.prepare_network()

def server(self):
""" Loads the API server """
Expand Down
2 changes: 0 additions & 2 deletions configuration/config.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"agent": {
"cores": 8,
"server": "",
"port": 1234,
"params": [
"train",
"classify",
Expand Down
3 changes: 1 addition & 2 deletions modules/AbstractModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ def http_request(self, img_path):
self.helpers.logger.info("Sending request for: " + img_path)

_, img_encoded = cv2.imencode('.png', cv2.imread(img_path))
response = requests.post(
self.addr, data=img_encoded.tostring(), headers=self.headers)
response = requests.post(self.addr, data=img_encoded.tostring(), headers=self.headers)
response = json.loads(response.text)

return response
Expand Down
2 changes: 1 addition & 1 deletion modules/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
SOFTWARE.

Contributors:
- Adam Milton-Barker
- Nitin Mane

"""

Expand Down
7 changes: 2 additions & 5 deletions modules/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
SOFTWARE.

Contributors:
- Adam Milton-Barker
- Nitin Mane

"""
Expand Down Expand Up @@ -89,7 +88,7 @@ def prepare_network(self):

self.load()
self.tf_intermediate_layer_model = keras.Model(
inputs=self.model.input, outputs=self.model.get_layer(layer_name).output)
inputs=self.model.input, outputs=self.model.get_layer(layer_name).output, name="SarsCov2xDNN")

self.load()
self.tf_intermediate_layer_model.summary()
Expand Down Expand Up @@ -400,8 +399,7 @@ def test(self):
msg = ""
status = ""
outcome = ""
print(prediction)
print(testFile)

if prediction == 1 and "Non-Covid" in testFile:
fp += 1
status = "incorrectly"
Expand Down Expand Up @@ -455,7 +453,6 @@ def test_http(self):
for testFile in os.listdir(self.testing_dir):
if os.path.splitext(testFile)[1] in self.valid:

print(self.testing_dir + "/" + testFile)
start = time.time()
prediction = self.http_request(self.testing_dir + "/" + testFile)
end = time.time()
Expand Down
67 changes: 27 additions & 40 deletions modules/mqtt.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,31 @@
#!/usr/bin/env python
###################################################################################
##
## HIAS iotJumpWay MQTT Module.
## This module connects devices, applications, robots and software to the
## HIAS iotJumpWay MQTT Broker.
##
###################################################################################
##
## Permission is hereby granted, free of charge, to any person obtaining a copy
## of this software and associated documentation files(the "Software"), to deal
## in the Software without restriction, including without limitation the rights
## to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
## copies of the Software, and to permit persons to whom the Software is
## furnished to do so, subject to the following conditions:
##
## The above copyright notice and this permission notice shall be included in all
## copies or substantial portions of the Software.
##
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
## AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
## SOFTWARE.
##
###################################################################################
##
## Project: HIAS Hospital Intelligent Automation Server
## Author: Adam Milton-Barker
## Copyright: 2020, Asociacion De Investigacion En Inteligencia Artificial Para La
## Leucemia Peter Moss.
## Credits: ["Adam Milton-Barker"]
## License: MIT
## Version: 3.0.0
## Maintainer: Adam Milton-Barker
## Website: adammiltonbarker.com
## Last Modified: 2021-1-9
##
###################################################################################
""" HIAS iotJumpWay MQTT module

This module connects devices, applications, robots and other softwares to the
HIAS iotJumpWay MQTT Broker.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files(the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Contributors:
- Adam Milton-Barker

"""

import json

Expand Down
61 changes: 26 additions & 35 deletions modules/server.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,30 @@
#!/usr/bin/env python
###################################################################################
##
## Project: COVID -19 xDNN Classifier 2020
## Version: 1.0.0
## Module: Server
## Desription: The COVID -19 xDNN Classifier 2020 server.
## License: MIT
## Copyright: 2021, Asociacion De Investigacion En Inteligencia Artificial Para
## La Leucemia Peter Moss.
## Author: Nitin Mane
## Maintainer: Nitin Mane
##
## Modified: 2021-2-19
##
###################################################################################
##
## Permission is hereby granted, free of charge, to any person obtaining a copy
## of this software and associated documentation files(the "Software"), to deal
## in the Software without restriction, including without limitation the rights
## to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
## copies of the Software, and to permit persons to whom the Software is
## furnished to do so, subject to the following conditions:
##
## The above copyright notice and this permission notice shall be included in all
## copies or substantial portions of the Software.
##
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
## AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
## SOFTWARE.
##
###################################################################################
""" HIAS AI Agent Server Class.

Class for the HIAS IoT Agent server/API.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files(the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Contributors:
- Nitin Mane

"""

import cv2
import json
Expand Down
66 changes: 44 additions & 22 deletions modules/xDNN_class.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,31 @@
"""
Please cite:

Angelov, P., & Soares, E. (2020). Towards explainable deep neural networks (xDNN). Neural Networks.
""" XDNN Class

Provides the HIAS AI Model with the required required data
processing functionality.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files(the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Citation: Angelov, P., & Soares, E. (2020). Towards explainable deep neural networks (xDNN). Neural Networks.

Contributors:
- Nitin Mane

"""

import math
Expand All @@ -22,36 +46,36 @@ def xDNN(Input,Mode):
Output['xDNNParms']['Parameters'] = Prototypes
MemberLabels = {}
for i in range(0,CN+1):
MemberLabels[i]=Input['Labels'][Input['Labels']==i]
MemberLabels[i]=Input['Labels'][Input['Labels']==i]
Output['xDNNParms']['CurrentNumberofClass']=CN+1
Output['xDNNParms']['OriginalNumberofClass']=CN+1
Output['xDNNParms']['MemberLabels']=MemberLabels
return Output

elif Mode == 'Validation':
Params=Input['xDNNParms']
datates=Input['Features']
Test_Results = DecisionMaking(Params,datates)
EstimatedLabels = Test_Results['EstimatedLabels']
EstimatedLabels = Test_Results['EstimatedLabels']
Scores = Test_Results['Scores']
Output = {}
Output['EstLabs'] = EstimatedLabels
Output['Scores'] = Scores
Output['ConfMa'] = confusion_matrix(Input['Labels'],Output['EstLabs'])
Output['ClassAcc'] = np.sum(Output['ConfMa']*np.identity(len(Output['ConfMa'])))/len(Input['Labels'])
return Output

elif Mode == 'classify':
Params=Input['xDNNParms']
datates=Input['Features']
Test_Results = DecisionMaking(Params,datates)
EstimatedLabels = Test_Results['EstimatedLabels']
EstimatedLabels = Test_Results['EstimatedLabels']
Scores = Test_Results['Scores']
Output = {}
Output['EstLabs'] = EstimatedLabels
Output['Scores'] = Scores
return Output

def PrototypesIdentification(Image,GlobalFeature,LABEL,CL):
data = {}
image = {}
Expand All @@ -67,7 +91,7 @@ def PrototypesIdentification(Image,GlobalFeature,LABEL,CL):
for i in range(0, CL+1):
Prototypes[i] = xDNNclassifier(data[i],image[i])
return Prototypes


def xDNNclassifier(Data,Image):
L, N, W = np.shape(Data)
Expand Down Expand Up @@ -95,7 +119,7 @@ def xDNNclassifier(Data,Image):
distance = cdist(data[i-1,].reshape(1,-1),Centre,'euclidean')[0]
value,position= distance.max(0),distance.argmax(0)
value=value**2

if DataDensity > CDmax or DataDensity < CDmin or value > 2*Radius[position]:
Centre=np.vstack((Centre,data[i-1,]))
Noc=Noc+1
Expand All @@ -106,7 +130,7 @@ def xDNNclassifier(Data,Image):
else:
Centre[position,] = Centre[position,]*(Support[position]/Support[position]+1)+data[i-1]/(Support[position]+1)
Support[position]=Support[position]+1
Radius[position]=0.5*Radius[position]+0.5*(X[position,]-sum(Centre[position,]**2))/2
Radius[position]=0.5*Radius[position]+0.5*(X[position,]-sum(Centre[position,]**2))/2
dic = {}
dic['Noc'] = Noc
dic['Centre'] = Centre
Expand All @@ -116,9 +140,9 @@ def xDNNclassifier(Data,Image):
dic['Prototype'] = VisualPrototype
dic['L'] = L
dic['X'] = X
return dic
return dic



def DecisionMaking(Params,datates):
PARAM=Params['Parameters']
Expand All @@ -143,17 +167,15 @@ def DecisionMaking(Params,datates):
indx = np.argsort(Value)[::-1]
EstimatedLabels[i-1]=indx[0]
LABEL1=np.zeros((CurrentNC,1))
for i in range(0,CurrentNC):


for i in range(0,CurrentNC):
LABEL1[i] = np.unique(LAB[i])

EstimatedLabels = EstimatedLabels.astype(int)
EstimatedLabels = LABEL1[EstimatedLabels]
EstimatedLabels = LABEL1[EstimatedLabels]
dic = {}
dic['EstimatedLabels'] = EstimatedLabels
dic['Scores'] = Scores
return dic

###############################################################################

Loading