EnergyEfficientAI
Overview
The EnergyEfficientAI Library provides a framework for training machine learning models while monitoring CPU and memory utilization. This library is particularly useful for understanding the energy consumption of various machine learning and deep learning algorithms during training and inference. By tracking system performance metrics, users can make informed decisions about model efficiency and power consumption.
Features
- Monitor CPU and memory utilization during model training.
- Calculate power and energy consumption based on system performance.
- Generate detailed reports including training metrics and classification results.
- Visualize CPU utilization with modern, aesthetically pleasing line graphs.
Installation
To use this library, you need to have Python 3.x installed along with the following dependencies:
numpypsutilscikit-learnmatplotlibseaborn
You can install the required packages using pip:
pip install numpy psutil scikit-learn matplotlib seaborn
You can install the library using pip:
pip install EnergyEfficientAI
How to use in Code
Calculating Energy Consumption of ML Algorithms
import numpy as np
from sklearn.datasets import fetch_openml
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from EnergyEfficientAI import EnergyConsumptionML # Import the class from the file
from sklearn.ensemble import RandomForestClassifier
from sklearn.datasets import fetch_openml
mnist = fetch_openml(data_id=554)
# Load MNIST data
# mnist = fetch_openml('mnist_784', as_frame=True)
X, y = mnist.data.astype('float32').to_numpy(), mnist.target.astype('int')
# Flatten the images
X_flatten = np.array([image.flatten() for image in X])
# Split the data into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(X_flatten, y, test_size=0.2, random_state=42)
# Define the model (you can pass any model here)
logreg_model = LogisticRegression()
cpuIdl = 70
cpuFull = 170
# Instantiate the CustomModelTrainer with the model
model_trainer = EnergyConsumptionML(logreg_model, cpuIdl, cpuFull)
# Generate the final report by calling generate_report
model_trainer.generate_report(X_train, y_train, X_test, y_test)
Calculating Energy Consumption of DL Algorithms
import numpy as np
import time
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Conv2D, MaxPooling2D, Flatten, Dense
from tensorflow.keras.datasets import mnist
from tensorflow.keras.utils import to_categorical
from EnergyEfficientAI import EnergyConsumptionDL
# Load and preprocess the dataset
(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train = np.expand_dims(x_train, axis=-1) / 255.0 # Normalize pixel values
x_test = np.expand_dims(x_test, axis=-1) / 255.0
y_train = to_categorical(y_train, num_classes=10) # One-hot encode labels
y_test = to_categorical(y_test, num_classes=10)
# Define the CNN model
model = Sequential([
Conv2D(32, (3, 3), activation='relu', input_shape=(28, 28, 1)),
MaxPooling2D((2, 2)),
Conv2D(64, (3, 3), activation='relu'),
MaxPooling2D((2, 2)),
Conv2D(64, (3, 3), activation='relu'),
Flatten(),
Dense(64, activation='relu'),
Dense(10, activation='softmax')
])
model.compile(optimizer='adam',
loss='categorical_crossentropy',
metrics=['accuracy'])
# Initialize EnergyConsumptionDL
energy_tracker = EnergyConsumptionDL(model=model, pcpu_idle=10, pcpu_full=100)
# Generate the report for the training and evaluation process
energy_tracker.generate_report(x_train, y_train, x_test, y_test, epochs=5, batch_size=64)
Metadata
Release files for EnergyEfficientAI 0.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| EnergyEfficientAI-0.7.tar.gz | 6.8 kB | Without provenance | Details for EnergyEfficientAI-0.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| EnergyEfficientAI-0.7-py3-none-any.whl | Python 3 | none | any | Details for EnergyEfficientAI-0.7-py3-none-any.whl |
Total release size: 16.6 kB
Release files / EnergyEfficientAI-0.7.tar.gz
| Download URL | EnergyEfficientAI-0.7.tar.gz |
|---|---|
| Size | 6.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2ede099bb258150ee6565700e4f2333088a2154fa14a4f0ad14c32bd583240fb
|
|
BLAKE2b-256 checksum How to use checksums |
3899cd3dc188291d13e932b1a62f440d3676d7d25d7c2b93d4ea49097ab0e655
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.4
|
Release files / EnergyEfficientAI-0.7-py3-none-any.whl
| Download URL | EnergyEfficientAI-0.7-py3-none-any.whl |
|---|---|
| Size | 9.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a725558927babafeefe9f800b7dadf3ee9b5abc6fd4a602b184b3e66d579ff8c
|
|
BLAKE2b-256 checksum How to use checksums |
06cb3de215f8e629926d14a257306f31ae7c9c8e241bf164a3a525d95e90b380
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.4
|
Security for EnergyEfficientAI 0.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.