Edge intelligence packages, examples and unit tests#10
Conversation
| @@ -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 | |||
|
|
||
| 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. |
| @@ -0,0 +1,34 @@ | |||
| # Edge Intelligence Models | |||
| @@ -0,0 +1,77 @@ | |||
| # -*- coding: utf-8 -*- | |||
| @@ -0,0 +1,76 @@ | |||
| # -*- coding: utf-8 -*- | |||
| @@ -0,0 +1,31 @@ | |||
| 30,1 | |||
There was a problem hiding this comment.
windmill_tf_test
windmill_tf_train
| import os | ||
| import numpy as np | ||
| import tensorflow as tf | ||
|
|
There was a problem hiding this comment.
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.?
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
Remove set properties and remove abstract method
|
|
||
| def __init__(self, model_path, actuator_udm): | ||
| super(SKLearnEdgeComponent, self).__init__(model_path, actuator_udm) | ||
| if not os.path.exists(model_path): |
| import logging | ||
| import Queue | ||
|
|
||
| log = logging.getLogger(__name__) |
| action_taken.put(value) | ||
|
|
||
| def get_action_taken(): | ||
| return action_taken.get(block=True) |
There was a problem hiding this comment.
add pass and mention you can write your own login in comment
| pass | ||
|
|
||
| def process(self, message): | ||
| self.actuator_udm(self.model.predict(message)[0]) |
There was a problem hiding this comment.
Add a check for actuator_udm here
There was a problem hiding this comment.
Added in edge_component.py
| import os | ||
| import numpy as np | ||
| import tensorflow as tf | ||
|
|
There was a problem hiding this comment.
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 | ||
|
|
There was a problem hiding this comment.
Explain the queue approach for better understanding.
|
|
||
| # 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 |
There was a problem hiding this comment.
The returned value as actions on console and metrics are being sent to Graphite DCC.
| # 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 | ||
|
|
There was a problem hiding this comment.
Simulating windmill RPM which is a device connected to Edge.
|
|
||
| class PackageClass(LiotaPackage): | ||
|
|
||
| def run(self, registry): |
There was a problem hiding this comment.
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))) |
There was a problem hiding this comment.
Done. unload package works now
| __metaclass__ = ABCMeta | ||
|
|
||
| @abstractmethod | ||
| def __init__(self, model_path, actuator_udm): |
There was a problem hiding this comment.
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.
| from liota.core.package_manager import LiotaPackage | ||
| from liota.lib.utilities.utility import read_user_config | ||
|
|
||
| dependencies = ["edge_systems/dell5k/edge_system"] |
| @@ -0,0 +1,139 @@ | |||
| # -*- coding: utf-8 -*- | |||
There was a problem hiding this comment.
You are publishing to graphite so rename the file to windmill_graphite_rule_edge.py
|
|
||
| # 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. |
There was a problem hiding this comment.
the returned value is from RuleEdgeComponent as actions. Only the gateway metrics are being published to Graphite DCC.
|
|
||
| # 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. |
There was a problem hiding this comment.
only the gateway metrics are being published to Graphite DCC.
| @@ -0,0 +1,147 @@ | |||
| # -*- coding: utf-8 -*- | |||
| @@ -0,0 +1,145 @@ | |||
| # -*- coding: utf-8 -*- | |||
| if met_cnt == 0: | ||
| return | ||
| for _ in range(met_cnt): | ||
| m = reg_metric.values.get(block=True) |
| self.actuator_udm(0) | ||
|
|
||
| def _format_data(self, reg_metric): | ||
| met_cnt = reg_metric.values.qsize() |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
We need to discuss this piece of code.
| def build_model(self): | ||
| pass | ||
|
|
||
|
|
| class PackageClass(LiotaPackage): | ||
| def create_udm(self, windmill_model): | ||
|
|
||
| def get_rpm(): |
There was a problem hiding this comment.
get vibration
Rename the function
tensorflow_edge_component, rule_edge_component.py).
graphite_rule_thermistor_simulated.py, graphite_rule_windmill_simulated.py,
graphite_sklearn_windmill_simulated.py, graphite_tensorflow_windmill_simulated.py).