{"id":20779143,"url":"https://github.com/mattdibi/sense-hat-demo","last_synced_at":"2026-07-22T10:32:19.950Z","repository":{"id":102639663,"uuid":"462691395","full_name":"mattdibi/sense-hat-demo","owner":"mattdibi","description":"Kura AI Wire Component Sense Hat-based demo","archived":false,"fork":false,"pushed_at":"2022-10-03T13:21:51.000Z","size":3300,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-03-31T15:46:19.099Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mattdibi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-02-23T10:43:17.000Z","updated_at":"2024-01-22T09:37:00.000Z","dependencies_parsed_at":null,"dependency_job_id":"a8dfff48-27ad-4920-8591-1e637a3df450","html_url":"https://github.com/mattdibi/sense-hat-demo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mattdibi/sense-hat-demo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattdibi%2Fsense-hat-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattdibi%2Fsense-hat-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattdibi%2Fsense-hat-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattdibi%2Fsense-hat-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mattdibi","download_url":"https://codeload.github.com/mattdibi/sense-hat-demo/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattdibi%2Fsense-hat-demo/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35759166,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-07-20T02:08:10.276Z","status":"online","status_checked_at":"2026-07-22T02:00:06.236Z","response_time":124,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-17T13:26:15.628Z","updated_at":"2026-07-22T10:32:19.927Z","avatar_url":"https://github.com/mattdibi.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Kura AI Wire Component demo\n\nKura AI Wire Component SenseHat-based demo.\n\nThe goal of this repository is to demo the AI inference capabilities of Kura Wires through the use of [NVIDIA Triton Inference Server](https://developer.nvidia.com/nvidia-triton-inference-server). This project trains a [Autencoder](https://en.wikipedia.org/wiki/Autoencoder) in [Tensorflow](https://www.tensorflow.org/) using the data extracted from a Raspberry Pi equipped with a [Sense HAT](https://www.raspberrypi.com/products/sense-hat/) to detect anomalies in the data retrieved by the Sense HAT.\n\n## Project structure\n\nThe repository is organized into three main directories:\n- **models**: is the Triton server [model repository](https://github.com/triton-inference-server/server/blob/main/docs/model_repository.md) and contains the trained models generated by the training environment.\n- **training**: contains the training environment which is comprised of the dataset and the sources for generating the autoencoder model for anomaly detection.\n- **snapshots**: contains the Kura snapshots for the Wire Graph used for training, the one used for the inference, and the pre-configured SenseHat driver and assets.\n\n## Prerequisites\n\nIn order to be able to execute this demo on a RaspberryPi board, these requirements have to be met:\n- Configured SenseHat: see [SenseHat documentation](https://www.raspberrypi.com/documentation/accessories/sense-hat.html)\n- I2C interface should be unlocked using `sudo raspi-config`\n- The following Deployment Packages must be installed: `org.eclipse.kura.ai.triton.server_*.dp`, `org.eclipse.kura.wire.ai.component.provider_*.dp`, `org.eclipse.kura.example.driver.sensehat_*.dp`, `org.eclipse.kura.wire.script.filter`\n- Apply the [driver snapshot](snapshots/sensehat-driver.xml) and verify it works by selecting the \"asset-sensehat\" and clicking on \"Data\": a reading of the values should be successfully triggered\n- Apply the [H2DB configuration snapshot](snapshots/h2-config.xml): this will create an H2 web server running on http://192.168.2.8:9123 (use the raspberry IP address)\n- Open port 9123 in Kura Firewall\n\n## Steps to reproduce the demo\n\n- **Step 1** is not mandatory, some data is available in the [training folder](training/). However, since the environmental conditions may be different from where the data was originally collected, it is recommended to recollect the data to have a reliable anomaly detector.\n\n- **Step 2** performs the training of the models that are later loaded in the inference server.\n\n- **Step 3** describes how to run the inference server and how to set up the Anomaly Detector in Kura.\n\n## 1. Data collection\n\nThe [data collection wire graph snapshot](snapshots/graph-data-collection.xml) allows collecting data in the \"sensehat\" table of the default H2DB instance.\n\nTo later extract the collected data in a CSV file, access the H2 web console using username `SA` and a blank password, and execute the following statement from the H2 web console:\n```\nCALL CSVWRITE ('/home/pi/data.csv', 'SELECT * FROM \"sensehat\"')\n```\nThe data will be saved in CSV format under `/home/pi/data.csv`. The recommended number of training examples to collect is around 30'000.\n\n## 2. Training\n\n### Training environment setup\n\nThe creation of a Python virtual environment is highly recommended. Create a new environment with the following:\n\n```bash\npython3 -m venv .venv\n```\n\nActivate it with:\n\n```bash\nsource .venv/bin/activate\n```\n\nThen update `pip` and install the training environment requirements:\n\n```bash\npip3 install --upgrade pip\n```\n\n```bash\npip3 install -r training/requirements.txt\n```\n\n### Model training\n\nDecompress the datasets\n\n```bash\ncd training \u0026\u0026 unzip *.zip\n```\n\nTrain the model with the data provided in this repository with:\n\n```bash\n./train.py\n```\n\nTrain script options:\n\n```bash\nusage: train.py [-h] [-t TRAIN_DATA_PATH] [-s SAVED_MODEL_NAME]\n\nTraining script for Kura AI Wire Component anomaly detection\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -t TRAIN_DATA_PATH, --train_data_path TRAIN_DATA_PATH\n                        Path to .csv training set (default: new-train-raw.csv)\n  -s SAVED_MODEL_NAME, --saved_model_name SAVED_MODEL_NAME\n                        Folder where the trained model will be saved to (default: saved_model/autoencoder)\n```\n\nMove the trained model in the Triton model repository and rename it to `model.savedmodel`\n\n```bash\nmkdir models/tf_autoencoder_fp32/1/\n```\n\n```bash\ncp -r training/saved_model/autoencoder models/tf_autoencoder_fp32/1/model.savedmodel\n```\n\n## 3. Inference\n\n### Run the inference server\n\nFor running these models inside Triton, navigate to this repository and run:\n\n```bash\ndocker run --rm \\\n    -p4000:8000 \\\n    -p4001:8001 \\\n    -p4002:8002 \\\n    --shm-size=150m \\\n    -v $(pwd)/models:/models \\\n    nvcr.io/nvidia/tritonserver:22.01-py3 \\\n    tritonserver --model-repository=/models --model-control-mode=explicit\n```\n\nExcpected models folder structure:\n\n```bash\nmodels\n├── postprocessor\n│   ├── 1\n│   │   └── model.py\n│   └── config.pbtxt\n├── preprocessor\n│   ├── 1\n│   │   └── model.py\n│   └── config.pbtxt\n└── tf_autoencoder_fp32\n    ├── 1\n    │   └── model.savedmodel\n    │       ├── assets\n    │       ├── keras_metadata.pb\n    │       ├── saved_model.pb\n    │       └── variables\n    │           ├── variables.data-00000-of-00001\n    │           └── variables.index\n    └── config.pbtxt\n```\n\n### Kura setup\n\nFirst, create an `org.eclipse.kura.ai.triton.server.TritonServerService` instance under \"Services\". Configure it by setting the **Nvidia Triton Server address** to the IP of the machine where the inference server is running. Add `preprocessor,postprocessor,tf_autoencoder_fp32,ensemble_pipeline` to the **Inference Models** list. If you used the command above to run the docker container, you shouldn't need to modify **Nvidia Triton Server ports**.\n\nAfter having set up the inference service, apply the [anomaly detection snapshot](snapshots/graph-anomaly-detector.xml) to create the Kura Wire Graph that performs anomaly detection. In summary, such graph reads the inputs from the \"asset-sensehat\" every 1s, performs the inference using an AI Wire Component, and processes the outputs using a Script Filter to color by red the led matrix of the SenseHat if an anomaly has occurred, green if no anomaly is detected. Since the training was done also on the accelerometer features, it is sufficient to move the RaspberryPi to trigger the detection of an anomaly.\n\nA possible expansion of this demo could consider using the other output of the inference process, namely `ANOMALY_SCORE0`, to change the gradient of the led coloring so that it will be brighter according to extent of the measured anomaly.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattdibi%2Fsense-hat-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmattdibi%2Fsense-hat-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattdibi%2Fsense-hat-demo/lists"}