diff --git a/agent.py b/agent.py index aa46106..ceb9158 100644 --- a/agent.py +++ b/agent.py @@ -28,7 +28,7 @@ SOFTWARE. Contributors: -- Adam Milton-Barker - First version - 2021-5-1 +- Nitin Mane """ @@ -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): @@ -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 """ diff --git a/configuration/config.json b/configuration/config.json index f78cd7a..2a230d5 100644 --- a/configuration/config.json +++ b/configuration/config.json @@ -1,8 +1,6 @@ { "agent": { "cores": 8, - "server": "", - "port": 1234, "params": [ "train", "classify", diff --git a/modules/AbstractModel.py b/modules/AbstractModel.py index 523c515..7d4b3a1 100644 --- a/modules/AbstractModel.py +++ b/modules/AbstractModel.py @@ -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 diff --git a/modules/data.py b/modules/data.py index cf111dd..bfed9e7 100644 --- a/modules/data.py +++ b/modules/data.py @@ -23,7 +23,7 @@ SOFTWARE. Contributors: -- Adam Milton-Barker +- Nitin Mane """ diff --git a/modules/model.py b/modules/model.py index cf57c34..5251ab2 100644 --- a/modules/model.py +++ b/modules/model.py @@ -23,7 +23,6 @@ SOFTWARE. Contributors: -- Adam Milton-Barker - Nitin Mane """ @@ -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() @@ -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" @@ -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() diff --git a/modules/mqtt.py b/modules/mqtt.py index cbbcbbb..c4e76dc 100644 --- a/modules/mqtt.py +++ b/modules/mqtt.py @@ -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 diff --git a/modules/server.py b/modules/server.py index 3afd546..442302f 100644 --- a/modules/server.py +++ b/modules/server.py @@ -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 diff --git a/modules/xDNN_class.py b/modules/xDNN_class.py index 6c15fde..274e46b 100644 --- a/modules/xDNN_class.py +++ b/modules/xDNN_class.py @@ -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 @@ -22,17 +46,17 @@ 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 @@ -40,18 +64,18 @@ def xDNN(Input,Mode): 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 = {} @@ -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) @@ -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 @@ -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 @@ -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'] @@ -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 - -############################################################################### diff --git a/scripts/install.sh b/scripts/install.sh index fa8991d..bdd4553 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -1,16 +1,25 @@ #!/bin/bash -echo "-- Installing requirements" -echo " " -conda install opencv -conda install psutil -conda install requests -conda install flask -conda install matplotlib -conda install tornado -conda install Pillow -conda install jsonpickle -conda install scikit-learn -conda install scikit-image -pip install mlxtend -echo "-- Done" \ No newline at end of file +FMSG="- SARS-CoV-2 xDNN Classifier installation terminated" + +read -p "? This script will install the SARS-CoV-2 xDNN Classifier required Python libraries on your device. Are you ready (y/n)? " cmsg + +if [ "$cmsg" = "Y" -o "$cmsg" = "y" ]; then + + echo "- Installing required Python libraries" + pip3 install --user urllib3 + pip3 install --user pandas + pip3 install --user pathlib + pip3 install --user numpy + pip3 install --user matplotlib + pip3 install --user scikit-plot + pip3 install --user scikit-learn + pip3 install --user Flask + pip3 install --user Werkzeug + pip3 install --user WSGIserver + pip3 install --user gevent + +else + echo $FMSG; + exit +fi \ No newline at end of file