Diabetes is a potentially sight-threatening condition that can lead to blindness if left undetected. Timely diagnosis of diabetic retinopathy, a persistent eye ailment, is critical to prevent irreversible vision loss. However, the traditional method of diagnosing diabetic retinopathy through retinal testing by ophthalmologists is labor-intensive and time-consuming. Additionally, early identification of glaucoma, indicated by the Cup-to-Disc Ratio (CDR), is vital to prevent vision impairment, yet its subtle initial symptoms make timely detection challenging. This research addresses these diagnostic challenges by leveraging machine learning and deep learning techniques. In particular, the study introduces the application of Restricted Boltzmann Machines (RBM) to the domain. By extracting and analyzing multiple features from retinal images, the proposed model aims to accurately categorize anomalies and automate the diagnostic process. The investigation further advances with the utilization of a U-network model for optic segmentation and employs the Squirrel Search Algorithm (SSA) to fine-tune RBM hyperparameters for optimal performance. The experimental evaluation conducted on the RIM-ONE DL dataset demonstrates the efficacy of the proposed methodology. A comprehensive comparison of results against previous prediction models is carried out, assessing accuracy, cross-validation, and Receiver Operating Characteristic (ROC) metrics. Remarkably, the proposed model achieves an accuracy value of 99.2% on the RIM-ONE DL dataset. By bridging the gap between automated diagnosis and ophthalmological practice, this research contributes significantly to the medical field. The model's robust performance and superior accuracy offer a promising avenue to support healthcare professionals in enhancing their decisionmaking processes, ultimately improving the quality of care for patients with retinal anomalies.