Energy Consumption Prediction

Energy Consumption Models are needed for Energy Conservation and they serve as the basic building blocks of Smart Buildings and Smart grid Systems. With the help of Deep Learning, we can predict the energy consumption and deliver only that much energy which is needed and hence contribute towards energy conservation.

Energy Consumption Prediction
Photo by Alex Pirenis, Konstantinos Pappas on Dribbble

Table of Content

  • Introduction to cAInvas
  • Source of Data
  • Data Visualization and Preprocessing
  • Model Training
  • Introduction to DeepC
  • Compilation with DeepC

Introduction to cAInvas

cAInvas is an integrated development platform to create intelligent edge devices. Not only we can train our deep learning model using Tensorflow, Keras, or Pytorch, we can also compile our model with its edge compiler called DeepC to deploy our working model on edge devices for production.

The energy consumption model is also developed on cAInvas and all the dependencies which you will be needing for this project are also pre-installed.

cAInvas also offers various other deep learning notebooks in its gallery which one can use for reference or to gain insight about deep learning. It also has GPU support and which makes it the best in its kind.

Source of Data

While working on cAInvas one of its key features is UseCases gallery. Since the Energy Consumption Detection model is also a part of cAInvas gallery now we don’t have to look for data manually. We can load the data in a dataframe by using pandas module, we just have to enter the following commands:

Running the above command will load the data in a dataframe which wewill use for model training.

Data Visualization and Preprocessing

The next step in the pipeline is to visualize some of the features in our dataset and pre-process our data for better training results. Pre-processing step involves dropping the null values or the NaN values, drop the columns from our dataframe that do not participate much in model training, and scale our data for faster and better training results.

For the visualization step, we will have a look at the Mean and Standard values of some columns of the dataset and we can do that by plotting a graph. For example, we can have a look at the graph plotted for the Mean and standard of Global active power:

Mean Global active power
Mean Global active power
Sum Global active power
Sum Global active power

After we are done with Data Preprocessing we will create the trainset and the testset for the model. For this we can run the following commands:

Model Training

After creating the dataset next step is to pass our training data into our Deep Learning model to learn to predict the trends in the Energy Consumption. The model architecture used was:

Model: "sequential"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
lstm (LSTM)                  (None, 100)               43200     
_________________________________________________________________
dropout (Dropout)            (None, 100)               0         
_________________________________________________________________
dense (Dense)                (None, 1)                 101       
=================================================================
Total params: 43,301
Trainable params: 43,301
Non-trainable params: 0
_________________________________________________________________

The loss function used was “mean_squared_error” and optimizer used was “Adam”.For training the model we used Keras API with tensorflow at backend. Here are the training plots for the model:

Model Loss
Model Loss

And here is the final prediction made on the test set and we have plotted it on a graph.

Final Prediction
Final Prediction

Introduction to DeepC

DeepC Compiler and inference framework is designed to enable and perform deep learning neural networks by focussing on features of small form-factor devices like micro-controllers, eFPGAs, cpus, and other embedded devices like raspberry-pi, odroid, arduino, SparkFun Edge, risc-V, mobile phones, x86 and arm laptops among others.

DeepC also offers ahead of time compiler-producing optimized executable based on LLVM compiler tool chain specialized for deep neural networks with ONNX as front end.

Compilation with DeepC

After training the model, it was saved in an H5 format using Keras as it easily stores the weights and model configuration in a single file.

After saving the file in H5 format we can easily compile our model using DeepC compiler which comes as a part of cAInvas platform so that it converts our saved model to a format which can be easily deployed to edge devices. And all this can be done very easily using a simple command.

And that’s it, our Energy Consumption Detection model is set to be deployed on edge devices.

Link for the cAInvas Notebook: https://cainvas.ai-tech.systems/use-cases/energy-consumption-prediction-app/

Credit: Ashish Arya

Also Read: Glass quality assessment — on cAInvas