# Efficient Classification of ECG Images Using a Lightweight CNN with Attention Module and IoT
## 4 Experimentation
### Results and Discussion  
The description of the lightweight model's parameters is depicted in Table 5. The Table provides a comprehensive summary of the model's architecture, including the number of float operations and the input shape for each layer. The proposed lightweight CNN model has achieved an impressive accuracy with the possibility of further enhancement through the fine-tuning of hyper-parameters. The results in Table 6 display the performance of the model. The accuracy, which is 98.39%, represents the portion of correct predictions. Precision, given as 0.985, indicates that about 98.5% of the positive predictions made by the model were accurate. Recall, at 0.98, signifies that the model identified around 98% of all actual positive cases. The results are presented graphically in Figure 8, illustrating the loss and accuracy trends across each epoch during the training phase. The graph distinctly illustrates that the model's accuracy improved with the progression of training epochs. This outcome gains further validation through the utilization of a confusion matrix (Figure 9). This matrix offers a concise overview of how well the model performed in terms of its projected and actual classifications. Notably, it is important to mention that the confusion matrix displayed in Figure 9 is derived exclusively from the test data, constituting 20% of the total dataset. \begin{table}
\begin{tabular}{c c c} \hline \hline
**Accuracy (\%)** & **Precision** & **Recall** \\ \hline
98.39 & 0.985 & 0.98 \\ \hline \hline \end{tabular}
\end{table} 
Table 6: Obtained results. \begin{table}
\begin{tabular}{c c c} \hline \hline
**Layer** & **Float Operations** & **Input Shape** \\ \hline Conv2D & 7,962,624 & 1, 288, 432, 1 \\ Conv2D & 7,077,888 & 1, 24, 72, 32 \\ MatMul & 786,432 & 1, 3072 \\ BiasAdd & 442,368 & 1, 96, 144, 32 \\ MaxPool & 442,368 & 1, 96, 144, 32 \\ BiasAdd & 12,288 & 1, 8, 24, 64 \\ MaxPool & 12,288 & 1, 8, 24, 64 \\ MatMul & 1024 & 1, 128 \\ BiasAdd & 128 & 1, 128 \\ SoftMax & 20 & 1, 4 \\ BiasAdd & 4 & 1, 4 \\ All Layers & 16,737,432 & \\ \hline \hline \end{tabular}
\end{table} 
Table 5: Float operations. Clearly, these results show that the model's ability to comprehend hierarchical features from a limited dataset underscores its potential to capture intricate patterns and representations within the data, resulting in enhanced performance in tasks characterized by data scarcity. Furthermore, its deliberate design prioritizes computational efficiency, distinguishing it from deeper and more intricate CNN architectures. This efficiency renders the lightweight CNN particularly suitable for resource-constrained scenarios, such as IoT devices and wearable sensors, where computational resources may be restricted. The advantage of a lightweight CNN lies in its automatic feature learning capability from the  
Figure 8: Loss vs. accuracy. Figure 9: Confusion matrix. raw ECG data. By directly capturing abstract patterns and representations from the data, it enhances the potential for better discrimination between different classes. This feature extraction process removes the requirement for manual feature engineering, simplifying the model's architecture, and contributing to its overall interpretability. This manuscript discusses an IoT-based cardiac patient monitoring and detection system, which, by design, involves real-time data collection from IoT sensors. However, to demonstrate the model's effectiveness, we initially used a publicly available ECG image dataset, widely accepted as a benchmark in the field. This dataset served as an initial testbed, and its results are presented in Figure 10, where an input image is successfully predicted. We specifically worked with a dataset consisting of 12-lead cardiac ECG images recorded at a 500 Hz frequency. However, we acknowledge that ECG images can significantly vary across different sources and clinical settings. To ensure our model's robustness and applicability to a wider range of datasets, including real-world data, extensive training is necessary.