Skip to content

Edge intelligence packages, examples and unit tests#10

Open
lucifercr07 wants to merge 8 commits into
KohliDev:masterfrom
lucifercr07:liota_edge_intelligence
Open

Edge intelligence packages, examples and unit tests#10
lucifercr07 wants to merge 8 commits into
KohliDev:masterfrom
lucifercr07:liota_edge_intelligence

Conversation

@lucifercr07

Copy link
Copy Markdown
Collaborator
  1. Added ModelPath to conf file for the edge_intelligence_models e.g windmill_iotcc_pfa.py etc.
  2. Removed the training files from edge_intelligence_models i.e eval-build.py and build-model.py
  3. Added readme information to the edge_intelligence_models.
  4. Removed file_reader_package.py from edge_component
  5. Added comments for actuator in edge_intelligence_models e.g windmill_iotcc_pfa.py etc.
  6. Added loadModel for the tensor_flow_edge_component.py
  7. Added files windmill_graphite_tf.py and windmill_iotcc_tf.py to the edge_intelligence_models.
  8. Added rule_edge_component
  9. Added windmill_graphite_rule.py
  10. Added packages for edge_components (sklearn_edge_component, pfa_component,
    tensorflow_edge_component, rule_edge_component.py).
  11. Example packages for each edge_component (graphite_pfa_windmill_simulated.py,
    graphite_rule_thermistor_simulated.py, graphite_rule_windmill_simulated.py,
    graphite_sklearn_windmill_simulated.py, graphite_tensorflow_windmill_simulated.py).
  12. Tests for edge_components under tests folder.

@@ -0,0 +1 @@
{"@": "PrettyPFA document", "name": "Engine_1", "input": "double", "output": "double", "method": "map", "action": [{"@": "PrettyPFA line 14", "let": {"baseLL": {"@": "PrettyPFA line 14", "prob.dist.gaussianLL": ["input", {"@": "PrettyPFA line 14", "cell": "baseline", "path": [{"@": "PrettyPFA line 14", "string": "mu"}]}, {"@": "PrettyPFA line 14", "cell": "baseline", "path": [{"@": "PrettyPFA line 14", "string": "sig"}]}]}}}, {"@": "PrettyPFA line 15", "let": {"altLL": {"@": "PrettyPFA line 15", "prob.dist.gaussianLL": ["input", {"@": "PrettyPFA line 15", "cell": "alternate", "path": [{"@": "PrettyPFA line 15", "string": "mu"}]}, {"@": "PrettyPFA line 15", "cell": "alternate", "path": [{"@": "PrettyPFA line 15", "string": "sig"}]}]}}}, {"@": "PrettyPFA lines 16-17", "cell": "cusum", "to": {"params": [{"old": "double"}], "ret": "double", "do": [{"@": "PrettyPFA line 17", "stat.change.updateCUSUM": [{"@": "PrettyPFA line 17", "-": ["altLL", "baseLL"]}, "old", {"@": "PrettyPFA line 17", "cell": "reset"}]}]}}], "cells": {"cusum": {"@": "PrettyPFA line 8", "type": "double", "init": 0.0, "shared": true, "rollback": false}, "reset": {"@": "PrettyPFA line 9", "type": "double", "init": 0.0, "shared": false, "rollback": false}, "alternate": {"@": "PrettyPFA line 11", "type": {"fields": [{"type": "double", "name": "mu"}, {"type": "double", "name": "sig"}], "type": "record", "name": "Record_1"}, "init": {"mu": 24.23076923076923, "sig": 9.420276925706693}, "shared": false, "rollback": false}, "baseline": {"@": "PrettyPFA line 10", "type": "Record_1", "init": {"mu": 10.448598130841122, "sig": 2.0227690446443916}, "shared": false, "rollback": false}}} No newline at end of file

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

analytics_model.pfa

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Completed.


This folder contains [PFA](http://dmg.org/pfa/docs/motivation/), [scikit-learn](http://scikit-learn.org/) and [TensorFlow](https://www.tensorflow.org/) and RuleEdgeComponent examples.
Trained [PFA](http://dmg.org/pfa/docs/motivation/), [scikit-learn](http://scikit-learn.org/) and [TensorFlow](https://www.tensorflow.org/) models are present under the trained_models directory.
The generated data is using the [TI SensorTag](http://www.ti.com/ww/en/wireless_connectivity/sensortag/) which has been used for training the windmill model.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove extra TI SensorTag link.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Completed.

@@ -0,0 +1,34 @@
# Edge Intelligence Models

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

README in capitals everywhere

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -0,0 +1,77 @@
# -*- coding: utf-8 -*-

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove it.

@@ -0,0 +1,76 @@
# -*- coding: utf-8 -*-

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove it.

@@ -0,0 +1,31 @@
30,1

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

windmill_tf_test
windmill_tf_train

import os
import numpy as np
import tensorflow as tf

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent of Liota.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have this file as for sklearn and pfa model there is no such file which shows how the model was trained or to check it's accuracy etc.?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's okay to keep one file to showcase how training is done.

def load_model(self):
pass

def set_properties(self, reg_entity, properties):

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove set properties and remove abstract method

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.


def __init__(self, model_path, actuator_udm):
super(SKLearnEdgeComponent, self).__init__(model_path, actuator_udm)
if not os.path.exists(model_path):

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add skv check

import logging
import Queue

log = logging.getLogger(__name__)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this

action_taken.put(value)

def get_action_taken():
return action_taken.get(block=True)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add pass and mention you can write your own login in comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

pass

def process(self, message):
self.actuator_udm(self.model.predict(message)[0])

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a check for actuator_udm here

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in edge_component.py

import os
import numpy as np
import tensorflow as tf

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's okay to keep one file to showcase how training is done.

_rpm_list.append(int((abs(z_degree) * 0.16667)))
rpm_model_queue.put(rpm)
return rpm

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explain the queue approach for better understanding.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explained.


# This example depicts how edge component can be used to take actions locally based on trained TensorFlow model
# and actions can then be send to device using actuator_udm method defined here, which is currently just printing
# actions on console, metrics are sent to Graphite DCC

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The returned value as actions on console and metrics are being sent to Graphite DCC.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

# actuator_udm can be used to pass on the value to the actuator, as of now we are printing them
def actuator_udm(value):
print value

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simulating windmill RPM which is a device connected to Edge.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread packages/sklearn_edge_component.py Outdated

class PackageClass(LiotaPackage):

def run(self, registry):

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way package is written we might have to change and enforce actuator_udm and metrics to be passed in the package itself.

return np.array([message], dtype=np.float32)

def process(self, message):
prediction = list(self.model.predict_classes(input_fn=lambda:self.input_fn(message)))

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check for unregister

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. unload package works now

__metaclass__ = ABCMeta

@abstractmethod
def __init__(self, model_path, actuator_udm):

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Model_path check should be removed and put only in the packages needs it and ruleEdgeComponent will be implemented on basis of EdgeComponent.

Actutor_udm check will come here and the way packages are written will be changed.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Completed.

Comment thread packages/sklearn_edge_component.py Outdated
from liota.core.package_manager import LiotaPackage
from liota.lib.utilities.utility import read_user_config

dependencies = ["edge_systems/dell5k/edge_system"]

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove dependency

@@ -0,0 +1,139 @@
# -*- coding: utf-8 -*-

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are publishing to graphite so rename the file to windmill_graphite_rule_edge.py

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


# This example depicts how edge component can be used to take actions locally based on a rule defined
# and actions can then be send to device using actuator_udm method defined here, which is currently just printing
# the returned value as actions on console and metrics are being sent to Graphite DCC.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the returned value is from RuleEdgeComponent as actions. Only the gateway metrics are being published to Graphite DCC.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


# This example depicts how edge component can be used to take actions locally based on sklearn model
# and actions can then be send to device using actuator_udm method defined here, which is currently just printing
# the returned value as actions on console and metrics are being sent to Graphite DCC.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only the gateway metrics are being published to Graphite DCC.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

@@ -0,0 +1,147 @@
# -*- coding: utf-8 -*-

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add graphite in the name.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -0,0 +1,145 @@
# -*- coding: utf-8 -*-

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graphite in the name.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

if met_cnt == 0:
return
for _ in range(met_cnt):
m = reg_metric.values.get(block=True)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename "m", add comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

self.actuator_udm(0)

def _format_data(self, reg_metric):
met_cnt = reg_metric.values.qsize()

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reg_metric_queue

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed since it's in abstract method in edge_component.py name not changed.

action_taken = Queue.Queue()

class PackageClass(LiotaPackage):
def create_udm(self, windmill_model):

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to discuss this piece of code.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Completed.

def build_model(self):
pass


Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove extra lines

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

class PackageClass(LiotaPackage):
def create_udm(self, windmill_model):

def get_rpm():

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get vibration

Rename the function

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants