Skip to content

Commit

Permalink
Merge pull request #6 from pitdagosti/pitdagosti-update-readme
Browse files Browse the repository at this point in the history
Update README.md
  • Loading branch information
pitdagosti authored Oct 4, 2024
2 parents 3c7f5ac + 82ac977 commit 89f0e0b
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ This project implements a **Long Short-Term Memory (LSTM)** model, converted to
## How It Works

1. **Data Collection**: The script listens for incoming temperature data via a TCP socket connection. Each node sends temperature readings and labels in the format `node_name;temperature_label;temperature_value`.
2. **Preprocessing**:

3. **Preprocessing**:
- Each node's temperature data is normalized using a **MinMaxScaler**.
- Data is stored in sliding windows containing a fixed number of past temperature readings (20 time steps).

3. **LSTM Model**:
4. **LSTM Model**:
- A pre-trained LSTM model is loaded to perform predictions in **TFLite** format.
- For each node, once enough data is collected, the model predicts the next temperature value based on the sliding window of past temperatures.

4. **Prediction Output**:
5. **Prediction Output**:
- The predicted temperature is unscaled and saved to a CSV file along with the actual temperature, label, node ID, and timestamp.

## Model Architecture

- The model used is an LSTM network trained on historical temperature data, which is then converted to TFLite format for optimized inference on edge devices or limited-resource environments.
-

<img width="662" alt="Screenshot 2024-09-26 alle 16 51 20" src="https://github.com/user-attachments/assets/bdb6aa85-8d7f-4c33-8d39-641e9f294242">

```python
Expand Down Expand Up @@ -52,7 +52,9 @@ pip install numpy==1.26.3 pandas==2.1.4 h5py==3.10.0 ujson==5.4.0 tensorflow==2.

## Usage

This script is designed to run in a containerized environment alongside another container responsible for reading, sending data, and creating the TCP server. The pre-built Docker image is available at `pit836/lstm:latest`, and the docker-compose.yml file can spin up the container that performs these operations. All prediction results are saved in a CSV file (`temperature_predictions.csv`), located in the shared volume `dbFiles`, mapped to the directory: `/dbFiles:/usr/src/app/dist/dbFiles`.
This script is designed to run in a containerized environment alongside another container responsible for reading, sending data, and creating the TCP server.
The pre-built Docker image is available at `pit836/lstm:latest`, and the docker-compose.yml file can spin up the container that performs these operations.
All prediction results are saved in a CSV file (`temperature_predictions.csv`), located in the shared volume `dbFiles`, mapped to the directory: `/dbFiles:/usr/src/app/dist/dbFiles`.

### Step 1: Load and Prepare the Model
Ensure the LSTM model in TFLite format (`lstm.tflite`) is in the working directory. The script will load this model using the TensorFlow Lite interpreter.
Expand All @@ -62,7 +64,7 @@ The script establishes a TCP connection to receive real-time data from nodes.

1. Set the correct `TCP_IP` and `TCP_PORT` in the script.
2. The incoming data should be in the format:
```
```bash
node_name;temperature_label;temperature_value
```

Expand All @@ -82,7 +84,7 @@ This will:

The incoming data is expected to follow this format:

```
```bash
NODE_01;T1;22.5
NODE_02;T0;19.8
...
Expand All @@ -101,7 +103,7 @@ The predicted temperatures are saved in a CSV file (`temperature_predictions.csv

Example of output in CSV format:

```
```bash
ID, Node_Name, Temperature_Actual, Temperature_Future, Label, Timestamp
1, NODE_01, 22.5, 23.1, T1, 1701234567
2, NODE_02, 19.8, 20.3, T0, 1701234570
Expand All @@ -110,7 +112,7 @@ ID, Node_Name, Temperature_Actual, Temperature_Future, Label, Timestamp
### CSV Output File Location

By default, the predictions are saved in the following path:
```
```bash
/usr/src/app/dist/dbFiles/temperature_predictions.csv
```

Expand All @@ -122,9 +124,9 @@ By default, the predictions are saved in the following path:

## Results

The container works with a usage of around 1% of CPU and 266 MB of memory.
The container works with a usage of a maximum of 20% of CPU and 260 MB of memory.

<img width="1391" alt="Screenshot 2024-09-26 alle 17 06 48" src="https://github.com/user-attachments/assets/0ce04447-4fe3-4c6f-a16f-7e3b611d718f">
<img width="1390" alt="Screenshot 2024-09-30 alle 16 08 26" src="https://github.com/user-attachments/assets/751b4e13-b03e-44cc-94ac-e92cc890ac19">

**The predictions are quite precise, with a RMSE of ????**

Expand Down

0 comments on commit 89f0e0b

Please sign in to comment.