A Comparative Analysis for Optimizing Machine Learning Model Deployment in IoT Devices
Abstract
:1. Introduction
- A Comparative Analysis of ML Development Libraries: We have provided an extensive comparative analysis between high-level and low-level programming libraries for developing ML models, catering to a range of IoT machine learning tasks. This analysis leverages two distinct datasets, each aligned with a common IoT ML image classification objective.
- The Carbon Footprint Calculation Algorithm: A novel algorithm has been proposed, coined the green carbon footprint (GCF), to calculate the carbon footprint associated with the execution of ML training codes. This algorithm incorporates a comprehensive set of parameters, including execution time, memory utilization, power consumption, and CPU temperature.
- The Decision Support System: Based on the exhaustive experimental findings, a decision support system has been synthesized, presenting key insights and recommendations for developers. This system aids in navigating the complex landscape of IoT-ML integration, highlighting optimal development approaches that balance performance, hardware compatibility, and environmental sustainability.
2. Related Work
3. Methodology
3.1. Selection of Dataset and Model
Convolutional Neural Network
3.2. Selection of Programming Libraries
3.3. Experimental Setup
3.4. Measuring Green Carbon Footprint
Algorithm 1 Calculate Carbon Footprint |
Require: Ensure: ▹ Define based on empirical data return |
Mathematical Representation
3.5. Evaluation Metrics
- Accuracy: Accuracy is the proportion of correctly predicted observations out of the total observations. It provides a general measure of the model’s performance. However, in scenarios with imbalanced datasets, accuracy might not be sufficient to understand the model’s true performance. In our context, accuracy helps to obtain the overall correctness of our ML models across various IoT tasks.
- Precision: The ratio of correctly predicted positive observations to the total predicted positive observations. It reflects the model’s ability to return relevant results. Precision is crucial in IoT-based real-world applications, where false positives can lead to unnecessary negative consequences that can be costly.
- Recall (Sensitivity): The ratio of correctly predicted positive observations to all observations of individual classes. It measures the model’s capability to find all relevant cases. High recall is particularly important in scenarios where missing positive instances can lead to significant issues, such as in security or health monitoring IoT applications.
- F1 Score: The harmonic mean of precision and recall. This score takes both false positives and false negatives into account, making it a better measure of the incorrectly classified cases than the accuracy metric alone. The F1 Score is critical in our study as it offers a more summarized measure of the model’s performance by accounting for both false positives and false negatives, thus providing a comprehensive understanding of the model in various IoT applications.
- Execution Time: Measures the total time taken by the machine learning model to complete its training process. A shorter execution time is generally preferable, indicating an efficient model capable of learning quickly, which is crucial in time-sensitive or resource-limited environments. In Python, the execution time can be accurately measured using the time library.
- Memory Utilization: Reflects the amount of memory required by the machine learning models during their execution. Effective memory management is critical, especially in environments with limited memory resources such as IoT devices. The command line utility free is used to monitor and optimize memory consumption during model training.
- Power Consumption: Indicates the electrical power used by the computing device while running the machine learning model. Energy efficiency is paramount in scenarios where power availability is constrained, such as mobile or embedded systems. Power consumption is typically measured using a USB power meter or multimeter to track the voltage and current draw of a device, like a Raspberry Pi, thus allowing for the calculation of power usage in watts. Power draw can be estimated using powertop. The command also logs CPU usage.
- CPU Temperature: Monitoring CPU temperature is essential for maintaining system stability and efficiency. High temperatures may suggest excessive computational demand or inadequate cooling, potentially leading to hardware throttling or failure. Temperature can be tracked using the vcgencmd utility on the device, which allows for real-time temperature monitoring. This will allow us critical data for managing thermal conditions during intensive computational tasks.
3.6. Decision Support System Framework
- Raw Data Collection: Gathering unprocessed data from various sources relevant to the application domain.
- Data Transformation: Applying transformations to the raw data to convert them into a more manageable or suitable format for analysis.
- Data Normalization: Normalizing data to ensure that the model is not biased towards variables with larger scales.
- Data Cleaning: Removing or correcting data anomalies, missing values, and outliers to improve data quality.
- Data Compression: Reducing the size of the data through various compression techniques to enhance storage efficiency and speed up processing.
- Feeding Data to Model: Inputting the processed data into the machine learning model for training.
- Model Deployment: Deploying the trained model into a real-world environment where it can provide insights or make decisions based on new data.
4. Result Analysis
4.1. Training on FashionMNIST
4.2. Training on MNIST Dataset
4.3. Validation of the Green Carbon Footprint Algorithm
4.3.1. Determining Conversion Factors
- Power to Carbon Conversion Factor (PGCF): This factor converts the energy consumed (in kWh) by the system into grams of a CO2 equivalent. It is influenced by the regional energy mix and the efficiency of the power supply. To establish this factor, data from local utility companies and renewable energy contributions are considered.
- Memory to Carbon Conversion Factor (MGCF): Memory utilization is converted to carbon emissions based on the energy cost of memory operations and the production impact of the memory hardware. This factor accounts for the embodied carbon of producing and maintaining memory hardware, amortized over its operational lifespan.
- Temperature Cost Conversion: The CPU temperature directly affects the system’s energy efficiency and cooling requirements. A higher temperature indicates more energy-intensive cooling, translating to higher emissions. A mathematical model is developed to relate CPU temperature to carbon output, using empirical data from thermal performance studies.
4.3.2. Empirical Validation and Adjustments
- Iterative Adjustments: The initial results are compared against independently verified benchmarks of carbon emissions for similar operations [31]. Discrepancies lead to iterative adjustments in the conversion factors. This iterative process continues until the calculated carbon emissions align closely with the benchmark data, ensuring accuracy and reliability.
- Algorithm Sensitivity Analysis: Sensitivity analysis is also performed to understand how changes in each factor affect the overall carbon footprint. This analysis helps prioritize adjustments in the conversion factors to minimize errors in the footprint estimation.
4.3.3. Finalization and Implementation
5. Case Studies
- PyTorch Model Size: 34.5 Kb
- LibTorch Model Size: 33.7 Kb
5.1. Case Study 1: FashionMNIST with PyTorch
5.1.1. Temperature Cost Calculation
5.1.2. Factor Adjustment
5.1.3. GCF Calculation
5.2. Case Study 2: FashionMNIST with LibTorch
5.3. Case Study 3: MNIST with PyTorch
5.4. Case Study 4: MNIST with LibTorch
6. Conclusions
Author Contributions
Funding
Institutional Review Board Statement
Informed Consent Statement
Data Availability Statement
Conflicts of Interest
References
- Fanariotis, A.; Orphanoudakis, T.; Kotrotsios, K.; Fotopoulos, V.; Keramidas, G.; Karkazis, P. Power efficient machine learning models deployment on edge IoT devices. Sensors 2023, 23, 1595. [Google Scholar] [CrossRef] [PubMed]
- Rysak, P. Comparative analysis of code execution time by C and Python based on selected algorithms. J. Comput. Sci. Inst. 2023, 26, 93–99. [Google Scholar] [CrossRef]
- Salihu, B.; Tafa, Z. On Computational Performances of the Actual Image Classification Methods in C# and Python. In Proceedings of the 2020 9th Mediterranean Conference on Embedded Computing (MECO), Budva, Montenegro, 8–11 June 2020; pp. 1–5. [Google Scholar]
- de la Fraga, L.G.; Tlelo-Cuautle, E.; Azucena, A.D.P. On the execution time of a computational intensive application in scripting languages. In Proceedings of the 2017 5th International Conference in Software Engineering Research and Innovation (CONISOFT), Merida, Mexico, 25–27 October 2017; pp. 149–152. [Google Scholar]
- Zehra, F.; Javed, M.; Khan, D.; Pasha, M. Comparative Analysis of C++ and Python in Terms of Memory and Time. Preprints 2020. [Google Scholar] [CrossRef]
- Prechelt, L. An empirical comparison of c, c++, java, perl, python, rexx and tcl. IEEE Comput. 2000, 33, 23–29. [Google Scholar] [CrossRef]
- Georgiou, S.; Kechagia, M.; Spinellis, D. Analyzing programming languages’ energy consumption: An empirical study. In Proceedings of the 21st Pan-Hellenic Conference on Informatics, Larissa, Greece, 28–30 September 2017; pp. 1–6. [Google Scholar]
- Onyango, K.A.; Mariga, G.W. Comparative Analysis on the Evaluation of the Complexity of C, C++, Java, PHP and Python Programming Languages based on Halstead Software Science. Int. J. Comput. Inf. Technol. 2023, 12, 8–19. [Google Scholar]
- Mengistu, D.; Frisk, F. Edge machine learning for energy efficiency of resource constrained IoT devices. In Proceedings of the SPWID 2019: The Fifth International Conference on Smart Portable, Wearable, Implantable and Disabilityoriented Devices and Systems, Nice, France, 28 July–2 August 2019; pp. 9–14. [Google Scholar]
- Lu, Q.; Murmann, B. Enhancing the energy efficiency and robustness of TinyML computer vision using coarsely-quantized log-gradient input images. ACM Trans. Embed. Comput. Syst. 2023, 23, 1–20. [Google Scholar] [CrossRef]
- Blum, R.; Bresnahan, C. Python Programming for Raspberry Pi; Pearson Education: Upper Saddle River, NJ, USA, 2013. [Google Scholar]
- Kesrouani, K.; Kanso, H.; Noureddine, A. A preliminary study of the energy impact of software in raspberry pi devices. In Proceedings of the 2020 IEEE 29th International Conference on Enabling Technologies: Infrastructure for Collaborative Enterprises (WETICE), Online, 10–13 September 2020; pp. 231–234. [Google Scholar]
- Ghael, H.D.; Solanki, L.; Sahu, G. A review paper on raspberry pi and its applications. Int. J. Adv. Eng. Manag. (IJAEM) 2020, 2, 4. [Google Scholar]
- Corral-García, J.; González-Sánchez, J.L.; Pérez-Toledano, M.Á. Evaluation of strategies for the development of efficient code for Raspberry Pi devices. Sensors 2018, 18, 4066. [Google Scholar] [CrossRef] [PubMed]
- Abdulkareem, S.A.; Abboud, A.J. Evaluating python, c++, javascript and java programming languages based on software complexity calculator (halstead metrics). Iop Conf. Ser. Mater. Sci. Eng. 2021, 1076, 012046. [Google Scholar] [CrossRef]
- Plauska, I.; Liutkevičius, A.; Janavičiūtė, A. Performance evaluation of c/c++, micropython, rust and tinygo programming languages on esp32 microcontroller. Electronics 2022, 12, 143. [Google Scholar] [CrossRef]
- Besimi, N.; Çiço, B.; Besimi, A.; Shehu, V. Using distributed raspberry PIs to enable low-cost energy-efficient machine learning algorithms for scientific articles recommendation. Microprocess. Microsyst. 2020, 78, 103252. [Google Scholar] [CrossRef]
- Mehmood, M.U.; Chun, D.; Han, H.; Jeon, G.; Chen, K. A review of the applications of artificial intelligence and big data to buildings for energy-efficiency and a comfortable indoor living environment. Energy Build. 2019, 202, 109383. [Google Scholar] [CrossRef]
- Lannelongue, L.; Grealey, J.; Inouye, M. Green algorithms: Quantifying the carbon footprint of computation. Adv. Sci. 2021, 8, 2100707. [Google Scholar] [CrossRef] [PubMed]
- Herelius, S. Green Coding: Can We Make Our Carbon Footprint Smaller through Coding? Bachelor’s Thesis, Blekinge Institute of Technology, Karlskrona, Sweden, 2022. [Google Scholar]
- Pandey, D.; Agrawal, M.; Pandey, J.S. Carbon footprint: Current methods of estimation. Environ. Monit. Assess. 2011, 178, 135–160. [Google Scholar] [CrossRef] [PubMed]
- Vieira, G.; Barbosa, J.; Leitão, P.; Sakurada, L. Low-cost industrial controller based on the raspberry pi platform. In Proceedings of the 2020 IEEE International Conference on Industrial Technology (ICIT), Buenos Aires, Argentina, 26–28 February 2020; pp. 292–297. [Google Scholar]
- Abdulsalam, S.; Lakomski, D.; Gu, Q.; Jin, T.; Zong, Z. Program energy efficiency: The impact of language, compiler and implementation choices. In Proceedings of the International Green Computing Conference, Dallas, TX, USA, 3–5 November 2014; pp. 1–6. [Google Scholar]
- Shoaib, M.; Venkataramani, S.; Hua, X.S.; Liu, J.; Li, J. Exploiting on-device image classification for energy efficiency in ambient-aware systems. In Mobile Cloud Visual Media Computing: From Interaction to Service; Springer: Cham, Switerland, 2015; pp. 167–199. [Google Scholar]
- Benavente-Peces, C.; Ibadah, N. Buildings energy efficiency analysis and classification using various machine learning technique classifiers. Energies 2020, 13, 3497. [Google Scholar] [CrossRef]
- Stančin, I.; Jović, A. An overview and comparison of free Python libraries for data mining and big data analysis. In Proceedings of the 2019 42nd International Convention on Information and Communication Technology, Electronics and Microelectronics (MIPRO), Opatija, Croatia, 20–24 May 2019; pp. 977–982. [Google Scholar]
- Zhang, X.; Wang, Y.; Shi, W. {pCAMP}: Performance Comparison of Machine Learning Packages on the Edges. In Proceedings of the USENIX Eorkshop on Hot Topics in Edge Computing (HotEdge 18), Boston, MA, USA, 11–13 July 2018. [Google Scholar]
- Oliveira, L.P.; Santos, J.H.d.S.; de Almeida, E.L.; Barbosa, J.R.; da Silva, A.W.; de Azevedo, L.P.; da Silva, M.V. Deep learning library performance analysis on raspberry (IoT device). In Proceedings of the International Conference on Advanced Information Networking and Applications; Springer: Berlin/Heidelberg, Germany, 2021; pp. 383–392. [Google Scholar]
- Green Software Foundation. Software Carbon Intensity Standard; Green Software Foundation: San Francisco, CA, USA, 2021. [Google Scholar]
- Climate Transparency. Climate Transparency Report 2022. 2022. Available online: https://www.climate-transparency.org/g20-climate-performance/g20report2022 (accessed on 15 May 2024).
- Dodge, J.; Prewitt, T.; Tachet des Combes, R.; Odmark, E.; Schwartz, R.; Strubell, E.; Luccioni, A.S.; Smith, N.A.; DeCario, N.; Buchanan, W. Measuring the carbon intensity of ai in cloud instances. In Proceedings of the 2022 ACM Conference on Fairness, Accountability, and Transparency, Seoul, Republic of Korea, 21–24 June 2022; pp. 1877–1894. [Google Scholar]
Reference | Key Findings or Features | Identified Gaps and Our Contributions |
---|---|---|
Shoaib et al. [24] | Introduced a lightweight ML model for image classification and an optimized hardware engine for IoT devices. The image classifier was used to remove irrelavant frame from video and reduce the communication time by training the model on-device instead of relying on the cloud server. This was made possible by building the hierarchical structured accelerator tailored to be used with resource-constraint devices. | Limited to image processing tasks using one library. Focused on optimizing the hardware accelerator instead of trying out less expensive software solutions that are more versatile. The experiments can be costly to replicate due to hardware specificity. Our work extends to using low-level library, offering a more holistic IoT solution. |
Benavente-Peces et al. [25] | Analyzed power consumption for ML models in cloud environments. Energy efficiency of a regular building in a smart city was measured and the building was classified according to their respective energy efficiencies using various ML models. | On-device execution was not considered. The ML algorithms used were shallow algorithms due to the structured dataset in use providing the energy efficiency of a building instead of the IoT device constructing the system. We have provided an in-depth analysis of on-device power consumption and its environmental impact on a particular device. |
Stančin et al. [26] | Twenty Python libraries of six different catagories were benchmarked. Deep learning was of one of those categories that had 4 libraries. The comparision was made based on the available feature each library offered. Pytorch and Keras was recommended for rapid prototyping. | Practical evaluation was not considered to assess the efficiency of the selected libraries. Only Python libraries were analyzed instead of covering lower-level libraries written in C++. Environmental sustainability was overlooked. Our system includes an environmental impact assessment, guiding towards more sustainable ML development. |
Zhang et al. [27] | Compared and analyzed the deployment of two trained model architectures using five ML libraries in multiple types of devices. The device selection ranged from low-resource to high-performing laptops. | The CPU temperature was not measured during the experiments, although it was in our case. Only trained models were loaded in the device. We train the model in the device. |
Oliveira et al. [28] | Compared two commonly used deep learning libraries in Raspberry Pi by considering resource usage and energy consumption. | Limited to only high-level language library. Low-level libraries for deep learning are assessed in our study. |
Entity | Specification |
---|---|
Processor | ARM64 Quad-Core |
RAM | LPDDR4-3200 8 GB |
Power consumption | 2.5 A |
Operating temperature | 0–50 °C ambient |
Interfaces | 2 USB jacks, Gigabit Ethernet |
Storage | 32 GB micro-SD Card |
Operating System | Raspberry Pi OS |
Metrics | PyTorch | Libtorch |
---|---|---|
Accuracy | 89.52% | 89.7% |
Precision | 89.50% | 88.7% |
Recall | 89.52% | 89.3% |
F1-Score | 89.48% | 88.9% |
Training time | 3.03 h | 2.01 h |
Total Power | 2.925 kW | 2.511 kW |
Average Temperature | 51.4 °C | 50.2 °C |
Metrics | PyTorch | Libtorch |
---|---|---|
Accuracy | 98.53% | 98.80% |
Precision | 98.52% | 98.73% |
Recall | 98.51% | 98.79% |
F1-Score | 98.51% | 98.75% |
Training time | 1.20 h | 1.29 h |
Total Power | 0.21 kW | 0.14 kW |
Average Temperature | 76.3 °C | 78.5 °C |
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |
© 2024 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/).
Share and Cite
Sayeedi, M.F.A.; Deepti, J.F.; Osmani, A.M.I.M.; Rahman, T.; Islam, S.S.; Islam, M.M. A Comparative Analysis for Optimizing Machine Learning Model Deployment in IoT Devices. Appl. Sci. 2024, 14, 5459. https://doi.org/10.3390/app14135459
Sayeedi MFA, Deepti JF, Osmani AMIM, Rahman T, Islam SS, Islam MM. A Comparative Analysis for Optimizing Machine Learning Model Deployment in IoT Devices. Applied Sciences. 2024; 14(13):5459. https://doi.org/10.3390/app14135459
Chicago/Turabian StyleSayeedi, Md. Faiyaz Abdullah, Jannatul Ferdous Deepti, Anas Mohammad Ishfaqul Muktadir Osmani, Taimur Rahman, Safrin Sanzida Islam, and Md. Motaharul Islam. 2024. "A Comparative Analysis for Optimizing Machine Learning Model Deployment in IoT Devices" Applied Sciences 14, no. 13: 5459. https://doi.org/10.3390/app14135459
APA StyleSayeedi, M. F. A., Deepti, J. F., Osmani, A. M. I. M., Rahman, T., Islam, S. S., & Islam, M. M. (2024). A Comparative Analysis for Optimizing Machine Learning Model Deployment in IoT Devices. Applied Sciences, 14(13), 5459. https://doi.org/10.3390/app14135459