
tive classification and robust model performance. In
the study, a comprehensive approach is applied for
the detection and classifications of ECG peaks, aim-
ing to distinguish between normal and abnormal pat-
terns. The approach focuses on automating the ECG
images, which is critical in diagnosing cardiac condi-
tions. Two deep learning models, a custom CNN and
MobileNet architectures are implemented to perform
the classification task.
The first step in this study involves designing and
training a custom CNN to classify the ECG images
into four predefined categories. The architecture con-
sisted of an input layer accepting images of size(100,
100, 3) followed by three CNN filter sizes of 32, 64
and 128. These layers are accompanied by ReLU ac-
tivation functions and max-pooling layers to reduce
the spatial dimensions of the feature maps. The fi-
nal layers include dense layer with 128 neurons us-
ing ReLU activation function. The output layer con-
sists of four neurons employing the softmax function
for multi-class classification, where the four neurons
indicate myocardial infarction, abnormal heartbeats,
history of myocardial infarction, and normal heart-
beats. The model is trained over 20 epochs. The per-
formance of the CNN model is remarkable achieving
a test accuracy of 90.98% and a minimal test loss of
0.029. It is observed that, as epochs increase, accu-
racy increases and loss decreases.
The next step employs MobileNet, a lightweight
and efficient CNN architecture, for image classifi-
cation. The approach is particularly effective for
medical imaging tasks due to its computational
efficiency and high accuracy. The base MobileNet
model is pre-trained on ImageNet data but initialized
with custom weights in this implementation. The
fully connected top layers are removed to allow
fine-tuning for type specific task. A custom classifier
is added, which includes a global average pooling
layer followed by two dense layers, one with 128
neurons using ReLU activation and the other with
softmax activation to output probabilities for multiple
classes. The MobileNet model is compiled using the
Adam optimizer with a learning rate of 0.0001. The
categorical cross entropy loss function is employed
as the dataset is multi-class in nature. Accuracy
is chosen as the evaluation metric. To prevent
overfitting and ensure early convergence, an early
stopping callback is applied monitoring validation
loss and restoring the best weights if no improvement
is observed after given consecutive epochs. Training
the model occurred over a minimum of 50 epochs,
although the early stopping criterion terminated
training early upon validation loss stabilization. The
training results showed a progressive improvement
in accuracy and reduction in loss over epochs. The
final evaluation gives test accuracy of approximately
91.73% and a test loss of 0.445. Figure 3, shows the
accuracy of the MobileNet model and it is observed
that, as epochs increase, accuracy also increases.
Figure 4, shows the loss of the MobileNet model and
it shows that, as epochs increase, loss decreases.
The confusion matrix in Figure 8 shows the
performance of the model on the ECG dataset. It
is observed that the model accurately classifies the
majority of normal and abnormal heartbeats, as well
as MI and patients with MI history. However, there
are a few misclassifications, with a small number of
abnormal heartbeats being misclassified as normal,
and vice versa. Overall, the loss is minimal, indi-
cating that the model performs well in detecting and
classifying ECG images. These highlight the capabil-
ity of the MobileNet model in effectively classifying
images. Compared to traditional CNN’s, MobileNet
offered a significant advantage in terms of reduced
computation and memory requirements while main-
taining high accuracy. The efficiency is achieved by
employing depth wise separable convolutions which
reduces the number of parameters and computational
cost. The inclusion of dropout layers and global
average pooling further reduced overfitting while
enabling robust feature extraction. In summary, the
MobileNet-based models successfully demonstrated
high accuracy and efficiency, underlining its potential
for real-world applications in detecting abnormalities
in ECG images.
The Table 2 clearly highlights the superiority
of MobileNet over CNN in detecting ECG abnor-
malities. MobileNet achieves a higher accuracy of
91.73% compared to CNN’s 90%, and excels with an
F1-Score of 96% versus CNN’s 95%. MobileNet also
outperforms CNN in precision and recall, achieving
96% for both, compared to CNN’s 95% precision and
94% recall, further emphasizing its effectiveness in
minimizing false positives and negatives. When com-
pared to other existing methods, such as the approach
proposed by (Agarwal et al., 2024), which focuses
on ECG anomaly detection using MobileNet50 CNN
autoencoder, and the method by Sane et al. (Cai and
Hu, 2020), which centers on detecting myocardial
infarction from 12-lead ECG images, MobileNet
demonstrates superior performance. The methods in
(Agarwal et al., 2024) and (Cai and Hu, 2020) report
lower accuracies and F1-Scores, with precision and
recall metrics that fall short of MobileNet’s consistent
96% values. Overall, MobileNet outperforms CNN
and existing methods in accuracy, precision, recall,
and F1-Score, solidifying its position as a highly
Automatic Detection of Cardiovascular Abnormalities in ECG Images: CNN and MobileNet
759