How taherfattahi/dnn-distance-line-protection-zone works
1. Repository purpose
- This repo is a small ML-to-embedded deployment pipeline for distance relay protection zone classification.
- The core business goal is to reproduce the Micom P543 distance relay curve from measured test data, then run the resulting classifier on an embedded target.
2. Data generation layer
- The source data is stored in DistanceDataset.csv.
- Per the README, the dataset was created by testing a Schneider Electric Micom P543 relay with a Vebko AMT105 relay tester.
- This is the only clearly identified external hardware/data-acquisition boundary in the project.
3. Offline model development subsystem
- Training and experimentation happen outside the runtime application in:
- DistanceLineProtectionZone_DNN.ipynb
- DistanceLineProtectionZone_RandomForest.ipynb
- distancelineprotectionzone_DNN.py
- DistanceLineProtectionZone_randomforest.py
- These files represent two alternative model paths:
- a TensorFlow deep neural network
- a scikit-learn random forest
- The README indicates the DNN is the primary path for deployment because it reaches the embedded runtime via TFLite.
4. Model artifact layer
- Trained artifacts are checked into model/:
- model/model.h5: the TensorFlow/Keras model checkpoint/export
- model/tfliteModel.tflite: the converted TensorFlow Lite model used at runtime
- This is the key boundary between training and deployment: the training stack produces the .h5, and deployment consumes the .tflite.
5. Conversion step
- The architecture includes a model conversion stage from TensorFlow/Keras to TensorFlow Lite.
- That conversion is what makes the model suitable for constrained or embedded environments such as ARM boards.
- In practice, this creates a portability boundary: full TensorFlow for training, TFLite for inference.
6. Runtime inference application
- The executable entrypoint is main.go.
- It is a Go application that calls into the TensorFlow Lite C API via CGO.
- The app is the deployment-time inference wrapper: it loads the TFLite model and runs prediction, rather than retraining or doing offline analysis.
7. Native ML runtime dependency
- The repo vendors the TensorFlow Lite C headers under include/tensorflow/lite/c/.
- It also includes platform-specific native libraries:
- amd64/
- arm/
- macosx/libtensorflowlite_c.dylib
- This indicates the runtime is intentionally split across platforms and relies on native shared libraries outside the Go code.
8. Target deployment environments
- The README explicitly targets:
- Linux/macOS amd64
- ARM-based embedded boards, especially Xilinx Zynq-7020
- The runtime boundary is therefore not a cloud service or web app; it is an embedded inference application that must be built per architecture.
9. Containerization
- Dockerfile provides a containerized execution path.
- Docker is used to package the runtime environment, likely including the Go binary and native TFLite dependencies.
- This is a deployment convenience layer, not part of the ML pipeline itself.
10. Build/tooling model
- The README shows two distinct build concerns:
- building TensorFlow Lite C from source externally
- building this repo’s Go binary against that native library
- So the repo depends on a system-level native ML runtime rather than pure-Go inference.
11. Architecture summary for diagramming
- A good diagram would show:
- hardware test setup → generates CSV dataset
- training notebooks/scripts → produce TensorFlow model
- TFLite conversion → produces deployment model
- Go/TFLite runtime → loads model and performs inference
- platform-specific native libs → support execution on amd64 / ARM / macOS
- Docker as an optional packaging layer around the runtime
12. Important boundary to preserve
- The project is split cleanly into offline ML development and online embedded inference.
- The training side is Python/TensorFlow/scikit-learn; the runtime side is Go + TFLite C.
- That separation is the central architectural feature of the repository.
Main entry points: main.go Go app · DistanceDataset.csv Dataset · c_api.h TFLite C API · README.md README
Components 17
Data acquisition
External relay test data captured from protection hardware and stored for model development.
- Dataset · Measured relay test data used to learn the distance protection zones.
DistanceDataset.csv
Offline ML
Python and notebook workflows for training and comparing zone classifiers.
- DNN notebook · Interactive TensorFlow workflow for the deep neural network path.
DistanceLineProtectionZone_DNN.ipynb - RF notebook · Interactive scikit-learn workflow for the random forest path.
DistanceLineProtectionZone_RandomForest.ipynb - DNN script · Scripted TensorFlow/Keras training and experimentation entrypoint.
distancelineprotectionzone_DNN.py - RF script · Scripted random forest training and evaluation path.
DistanceLineProtectionZone_randomforest.py
Model artifacts
Persisted trained model outputs used as deployment inputs.
- TensorFlow model · Primary learned classifier before conversion to embedded format.
model/model.h5 - TFLite model · Converted model consumed by the runtime inference app.
model/tfliteModel.tflite
Embedded runtime
Go-based inference application that executes the deployed classifier.
- Go app · Deployment-time application that loads the TFLite model and runs predictions.
main.go - main package · Go entry package wiring the executable runtime.
main - Go module · Module definition for building the Go inference binary.
go.mod
Native TFLite
Platform-specific TensorFlow Lite C runtime and vendored headers.
- TFLite C API · Vendored TensorFlow Lite C headers used through CGO.
include/tensorflow/lite/c/c_api.h - TFLite common · Additional TensorFlow Lite C interface headers.
include/tensorflow/lite/c/common.h - amd64 lib · Platform-specific TensorFlow Lite shared library for amd64 builds.
amd64 - arm lib · Platform-specific TensorFlow Lite shared library for ARM builds.
arm - macOS lib · macOS TensorFlow Lite shared library for local builds.
macosx/libtensorflowlite_c.dylib
Packaging
Container and repo-level build packaging for deployment.
- Dockerfile · Container recipe packaging the runtime and native dependencies.
Dockerfile - README · Project documentation describing dataset, training, conversion, and deployment.
README.md
Connections 21
- Dataset → DNN notebook: trains · Dataset feeds the DNN experimentation notebook.
- Dataset → RF notebook: trains · Dataset feeds the random forest experimentation notebook.
- Dataset → DNN script: trains · Dataset feeds scripted TensorFlow training.
- Dataset → RF script: trains · Dataset feeds scripted random forest training.
- DNN notebook → TensorFlow model: produces · Notebook workflow produces the TensorFlow/Keras model artifact.
- DNN script → TensorFlow model: produces · Scripted DNN training produces the Keras model artifact.
- RF notebook → RF script: matches · Notebook and script represent the same random forest path.
- TensorFlow model → TFLite model: converts · TensorFlow model is converted to TensorFlow Lite for deployment.
- TFLite model → Go app: loads · Runtime loads the embedded inference model.
- Go app → TFLite C API: calls · Go runtime uses the TensorFlow Lite C API via CGO.
- Go app → TFLite common: calls · Runtime depends on additional vendored TFLite headers.
- TFLite C API → amd64 lib: links · amd64 builds resolve against the native TFLite shared library.
- TFLite C API → arm lib: links · ARM builds resolve against the native TFLite shared library.
- TFLite C API → macOS lib: links · macOS builds resolve against the native TFLite shared library.
- Go module → Go app: builds · Go module defines the executable build.
- main package → Go app: packages · Main package contains the program entry wiring.
- Dockerfile → Go app: packages · Container image packages the Go inference binary.
- Dockerfile → amd64 lib: bundles · Container may include platform-specific native runtime support.
- README → Dataset: documents · README describes the measured relay dataset source.
- README → Go app: documents · README describes the deployment runtime and targets.
- README → TFLite model: documents · README explains the TFLite deployment artifact.