Early detection and treatment of skin cancer are important for patient recovery and survival. Dermoscopy images can help clinicians for timely identification of cancer, but manual diagnosis is time-consuming, costly, and prone to human error. To conduct this, an innovative deep learning-based approach has been proposed for automatic melanoma detection. The proposed method involves preprocessing dermoscopy images to remove artifacts, enhance contrast, and cancel noise, followed by feeding them into an optimized Convolutional Neural Network (CNN). The CNN is trained using an innovative metaheuristic called the Improved Chameleon Swarm Algorithm (CSA) to optimize its performance. The approach has been validated using the SIIM-ISIC Melanoma dataset and the results have been confirmed through rigorous evaluation metrics. Simulation results demonstrate the efficacy of the proposed method in accurately diagnosing melanoma from dermoscopy images by highlighting its potential as a valuable tool for clinicians in early cancer detection.