This research focuses on hyperparameter optimization in Convolutional Neural Networks (CNNs) for image classification tasks. The primary objective is to propose a novel KMA-LeNet algorithm for optimizing hyperparameters in the LeNet-5 model without modifying its architecture. This method is evaluated by testing and comparing it with the conventional LeNet model on MNIST, Fashion-MNIST, and CIFAR-10 datasets. Experimental results demonstrate that KMA-LeNet achieves superior accuracy, particularly on the CIFAR-10 dataset, and shows high stability for large and small datasets. The results indicate a significant improvement in CNN accuracy for image classification tasks using KMA for hyperparameter optimization. It demonstrates the potential of KMA as an efficient and innovative approach for enhancing performance. Further research possibilities include the application of KMA to more complex architectures such as AlexNet and ResNet. Additionally, exploring KMA for variable-length encoding optimization is another avenue for future investigation.