Heart disease significantly impacts global mortality rates, underscoring the need for improved early-stage diagnosis through deep learning algorithms to enhance prognosis accuracy and prevent mortality. However, challenges such as missing values, class imbalance, redundant features and faulty predictions persist in heart disease diagnosis. To address these issues, this research proposes an Optimized Cross-layer Densenet121 Pyramid mutual attention Network (OCDPN) to improve prediction accuracy. Initially, a Hybrid Bag-boost K-means Synthetic Minority Oversampling TEchnique (HBK-SMOTE) is employed to eliminate missing values and handle class imbalance issues. Subsequently, a Two-layer Angle Kernel Linear Discriminant Extreme Learning (TK-LDE) method extracts features and the Hybrid Binary Aquila Beluga whale Optimization (HBABO)selects the most significant features. Finally, the selected features are classified using Fick's law algorithm to achieve high accuracy. The OCDPN model, comprising several dense layers and a softmax classifier, with Fick's law optimization, enhances feature understanding and classification performance. The model's efficiency is assessed using the Framingham Heart Study (FHS), Statlog (Heart), Cleveland Heart Disease (CHD) and Z-Alizadeh Sani datasets. The introduced technique demonstrates outstanding performance, achieving accuracies of 98.2%, 99.8%, 99.2% and 98.5%, respectively, for the considered datasets. These outcomes highlight the effectiveness of the introduced method in predicting heart diseases.