示例#1
0
class COVID19DN():
    """ COVID19DN Class

    Core COVID-19 Tensorflow DenseNet Classifier wrapper class using Tensroflow 2.
    """

    def __init__(self):
        """ Initializes the class. """

        self.Helpers = Helpers("Core")

        self.Model = Model()

        self.Helpers.logger.info(
            "COVID19DN Tensorflow initialization complete.")

    def do_data(self):
        """ Sorts the training data. """

        self.Data = Data()
        self.Data.process_data(
            self.Data.paths_n_labels())

    def do_train(self):
        """ Creates & trains the model. """

        self.Model.do_model(self.Data)
        self.Model.do_train()
        self.Model.do_evaluate()

    def do_load_model(self):
        """ Loads the model """

        self.Model.load_model_and_weights()

    def do_classify(self):
        """ Loads model and classifies test data """

        self.do_load_model()
        self.Model.test_classifier()

    def do_server(self):
        """ Loads the API server """

        self.do_load_model()
        self.Server = Server(self.Model)
        self.Server.start()

    def do_http_classify(self):
        """ Loads model and classifies test data """

        self.Model.test_http_classifier()
示例#2
0
class IdcQnn():
    """ IdcQnn

    IdcQnn is a wrapper class that creates the Invasive Ductal Carcinoma
    Tensorflow QNN (Quantum Neural Network).
    """
    def __init__(self):
        """ Initializes the class. """

        self.Helpers = Helpers("Core")
        self.QModel = QModel()

        self.Helpers.logger.info("IdcQnn QNN initialization complete.")

    def do_data(self):
        """ Sorts the training data """

        self.Data = Data()
        self.Data.get_paths_n_labels()
        self.Data.process_data()

    def do_train(self):
        """ Creates & trains the QNN. 
        
        CREDIT: https://www.tensorflow.org/quantum/tutorials/mnist
        CREDIT: https://arxiv.org/pdf/1802.06002.pdf 
        """

        self.QMNIST = QMNIST()

        # "Quantumize" the training data
        X_train_bin, X_test_bin = self.QMNIST.encode_data_as_binary(
            self.Data.X_train, self.Data.X_test)
        X_train_circ, X_test_circ = self.QMNIST.do_circuit_conversion(
            X_train_bin, X_test_bin)
        x_train_tfcirc, x_test_tfcirc = self.QMNIST.convert_to_tensors(
            X_train_circ, X_test_circ)

        # Create the Quantum Neural Network
        model_circuit, model_readout = self.QModel.create_quantum_model()
        self.QModel.create_keras_model(model_circuit, model_readout)

        # Train the Quantum Neural Network
        self.QModel.train_model(x_train_tfcirc, x_test_tfcirc,
                                self.Data.y_train, self.Data.y_test)
        self.QModel.do_evaluate(x_train_tfcirc, x_test_tfcirc,
                                self.Data.y_test)
示例#3
0
class QMNISTCOVID19():
    """ QMNISTCOVID19

    QMNISTCOVID19 is a wrapper class that creates the COVID-19 Tensorflow QNN (Quantum Neural Network).
    """
    def __init__(self):
        """ Initializes the class. """

        self.Helpers = Helpers("Core")

        self.Helpers.logger.info("QMNISTCOVID19 QNN initialization complete.")

    def do_data(self):
        """ Sorts the training data """

        self.Data = Data()
        self.Data.get_paths_n_labels()
        self.Data.process_data()

    def do_train(self):
        """ Creates & trains the QNN. """

        self.QMNIST = QMNIST()

        X_train_bin, X_test_bin = self.QMNIST.encode_as_binary(
            self.Data.X_train, self.Data.X_test)
        X_train_circ, X__test_circ = self.QMNIST.do_circuit_conversion(
            X_train_bin, X_test_bin)
        x_train_tfcirc, x_test_tfcirc = self.QMNIST.convert_to_tensors(
            X_train_circ, X__test_circ)

    def do_load_model(self):
        """ Loads the trained model """
        print("TODO")

    def do_classify(self):
        """ Classifies the test data """
        print("TODO")
class COVID19DN():
    """ COVID19DN Class

    Core COVID-19 Tensorflow DenseNet Classifier wrapper class using Tensroflow 2.
    """

    def __init__(self):
        """ Initializes the class. """

        self.Helpers = Helpers("Core")
        
        # Initiates the iotJumpWay connection class
        self.iotJumpWayDevice = iotJumpWay({
            "host": self.Helpers.confs["iotJumpWay"]["host"],
            "port": self.Helpers.confs["iotJumpWay"]["port"],
            "lid": self.Helpers.confs["iotJumpWay"]["loc"],
            "zid": self.Helpers.confs["iotJumpWay"]["zne"],
            "did": self.Helpers.confs["iotJumpWay"]["id"],
            "dn": self.Helpers.confs["iotJumpWay"]["name"],
            "un": self.Helpers.confs["iotJumpWay"]["mqtt"]["username"],
            "pw": self.Helpers.confs["iotJumpWay"]["mqtt"]["password"]
        })
        self.iotJumpWayDevice.connect() 

        self.Model = Model(self.iotJumpWayDevice)

        self.Helpers.logger.info(
            "COVID19DN Tensorflow initialization complete.")
            
    def life(self):
        """ Sends vital statistics to HIAS """
        
        cpu = psutil.cpu_percent()
        mem = psutil.virtual_memory()[2]
        hdd = psutil.disk_usage('/').percent
        tmp = psutil.sensors_temperatures()['coretemp'][0].current
        r = requests.get('http://ipinfo.io/json?token=' + self.Helpers.confs["iotJumpWay"]["key"])
        data = r.json()
        location = data["loc"].split(',')
  
        self.Helpers.logger.info("COVID19DN Life (TEMPERATURE): " + str(tmp) + "\u00b0")
        self.Helpers.logger.info("COVID19DN Life (CPU): " + str(cpu) + "%")
        self.Helpers.logger.info("COVID19DN Life (Memory): " + str(mem) + "%")
        self.Helpers.logger.info("COVID19DN Life (HDD): " + str(hdd) + "%")
        self.Helpers.logger.info("COVID19DN Life (LAT): " + str(location[0]))
        self.Helpers.logger.info("COVID19DN Life (LNG): " + str(location[1]))
        
        # Send iotJumpWay notification
        self.iotJumpWayDevice.devicePub("Life", {
            "CPU": cpu,
            "Memory": mem,
            "Diskspace": hdd,
            "Temperature": tmp,
            "Latitude": location[0],
            "Longitude": location[1]
        })
        
        threading.Timer(60.0, self.life).start()
        
    def threading(self):
        """ Creates required module threads. """
        
        # Life thread
        Thread(target = self.life, args = ()).start()
        threading.Timer(60.0, self.life).start()

    def do_data(self):
        """ Sorts the training data. """

        self.Data = Data()
        self.Data.process_data(
            self.Data.paths_n_labels())

    def do_train(self):
        """ Creates & trains the model. """

        self.Model.do_model(self.Data)
        self.Model.do_train()
        self.Model.do_evaluate()

    def do_load_model(self):
        """ Loads the model """

        self.Model.load_model_and_weights()

    def do_classify(self):
        """ Loads model and classifies test data """

        self.do_load_model()
        self.Model.test_classifier()

    def do_server(self):
        """ Loads the API server """

        self.do_load_model()
        self.Server = Server(self.Model)
        self.Server.start()

    def do_http_classify(self):
        """ Loads model and classifies test data """

        self.Model.test_http_classifier()