# Efficient Classification of ECG Images Using a Lightweight CNN with Attention Module and IoT
###### Abstract  
Cardiac disorders are a leading cause of global casualties, emphasizing the need for the initial diagnosis and prevention of cardiovascular diseases (CVDs). Electrocardiogram (ECG) procedures are highly recommended as they provide crucial cardiology information. Telemedicine offers an opportunity to provide low-cost tools and widespread availability for CVD management. In this research, we proposed an IoT-based monitoring and detection system for cardiac patients, employing a two-stage approach. In the initial stage, we used a routing protocol that combines routing by energy and link quality (REL) with dynamic source routing (DSR) to efficiently collect data on an IoT healthcare platform. The second stage involves the classification of ECG images using hybrid-based deep features. Our classification system utilizes the \"ECG Images dataset of Cardiac Patients\", comprising 12-lead ECG images with four distinct categories: abnormal heartbeat, myocardial infarction (MI), previous history of MI, and normal ECG. For feature extraction, we employed a lightweight CNN, which automatically extracts relevant ECG features. These features were further optimized through an attention module, which is the method's main focus. The model achieved a remarkable accuracy of 98.39%. Our findings suggest that this system can effectively aid in the identification of cardiac disorders. The proposed approach combines IoT, deep learning, and efficient routing protocols, showcasing its potential for improving CVD diagnosis and management. c 202  
ECG signifies the probability of cardiac irregularities in their ST segments: usually, the elevations in ST segments, variations in segments, or flipping of T waves indicate some cardiac abnormalities [5]. The IoT refers to the interconnections of an assortment of smart devices, including mobile phones, laptops, and sensors [6; 7; 8; 9]. One of the most compelling areas of application for the IoT is in the field of healthcare. The potential of the IoT has led to the development of various applications, such as remote health monitoring, fitness programs, elderly care, and the management of chronic ailments [10; 11; 12]. As a result, numerous medical devices, including diagnostic tools, imaging systems, and sensors, have transitioned into smart devices that serve as the foundation of the IoT. By utilizing IoT-based healthcare services, it is possible to reduce costs and improve user experience and quality of life. Recently, applications for deep learning have been found in diagnosis and prediction across various domains [7; 13; 14]. Furthermore, deep learning methods notably impact classification accuracy in numerous medical tasks [15; 16]. The utilization of deep neural networks (DNNs) in modern computer-aided diagnosis (CAD) systems holds the potential to reduce the efforts required for heart monitoring and improve predictive capabilities. Integrating wearable ECG monitoring systems with deep learning could further enhance the reliability of CAD systems for cardiac patients. Therefore, the IoT-based ECG monitoring system could help reduce diagnostic time and provide healthcare facilities at patients' doorsteps. Nevertheless, the automatic detection of heart disorders through ECG-based is faced with several important challenges, such as:  
* the properties of ECG signals that, in terms of amplitude, period, etc., vary from individual to individual due to different demographic factors such as gender, age, lifestyle, etc. ;
* the ECG signals of a single tested person vary across different states, such as sleeping, running, and walking;
* the noise and artifacts in the captured ECG can lead to variations and differences, as explained in the following subsection. Artifacts/Noises Affecting the ECG  
The ECG signal can become mixed up with different types of unwanted sounds, each with its own characteristics. Figure 1: Illustration of normal ECG [4]. Baseline wander: This occurs when the signal changes slowly because of things like skin contact or patient movement.