scieee AI-readable full text Open interactive document viewer

Moroccan Coin Detection and Classification Using YOLOv8: A Deep Learning Approach

Yassir, Moutia

Abstract

The manual counting of bulk coinage is tedious and prone to error; hence, an automated solution is highly beneficial for numerous applications, including but not limited to gaming machines, vending machines, and cash-intensive enterprises. With the advancement of machine learning techniques, automatic detection and valuation of coins have become increasingly viable. In this study, we present the development of a deep learning system for the detection and classification of Moroccan coins based on the YOLOv8 object detection model. A custom dataset was manually created by gathering images of Moroccan coins from the web and capturing them using smartphone cameras. The experimental results show that our model achieves high accuracy in detecting and discriminating between various denominations of Moroccan coins. For real-world applicability, we further developed the model, making it lightweight, converting it to TensorFlow Lite format, and deploying it on Android smartphones. This allows an efficient and responsive solution by enabling fast inference directly on the device without any cloud resources. The system thus represents a practical end-to-end framework for automatic coin detection and valuation.

Full text

MOROCCAN COIN DETECTION AND CLASSIFICATION USING YOLOV8: A DEEP LEARNING APPROACH Yassir Moutia Computer Systems and Vision Laboratory, Faculty of Sciences, Ibn Zohr University, Agadir, Morocco [email protected] October 31, 2025 ABSTRACT The manual counting of bulk coinage is tedious and prone to error; hence, an automated solution is highly beneficial for numerous applications, including but not limited to gaming machines, vending machines, and cash-intensive enterprises. With the advancement of machine learning techniques, automatic detection and valuation of coins have become increasingly viable. In this study, we present the development of a deep learning system for the detection and classification of Moroccan coins based on the YOLOv8 object detection model. A custom dataset was manually created by gathering images of Moroccan coins from the web and capturing them using smartphone cameras. The experimental results show that our model achieves high accuracy in detecting and discriminating between various denominations of Moroccan coins. For real-world applicability, we further developed the model, making it lightweight, converting it to TensorFlow Lite format, and deploying it on Android smartphones. This allows an efficient and responsive solution by enabling fast inference directly on the device without any cloud resources. An entire end-to-end framework for the automatic detection and valuation of Moroccan coins, the system is now a practical tool for individual cases or commercial applications. Keywords YOLOv8 ·Object detection ·Moroccan coins ·TensorFlow Lite ·Android deployment ·Computer vision 1 Introduction Accurate detection and valuation of coins represent a critical challenge in many financial and commercial contexts, particularly when dealing with large quantities of currency. Manual counting remains the most common approach; however, it is time-consuming, labor-intensive, and highly susceptible to human errors. In environments such as banks, vending machines, automated teller machines (ATMs), and retail businesses, the demand for fast, reliable, and automated solutions for coin recognition and calculation has increased significantly in recent years. With the rapid advancement of computer vision and machine learning, automated coin detection systems have garnered considerable attention. Traditional image-processing techniques, which rely on handcrafted features such as size, color, and texture, have shown limited performance in handling diverse lighting conditions, occlusions, and coin similarities. In contrast, deep learning-based object detection models, particularly You Only Look Once (YOLO) architectures, have demonstrated remarkable improvements in accuracy, speed, and robustness across various detection tasks. Despite these advancements, research specifically focusing on Moroccan coins remains scarce. Moroccan coins present unique challenges owing to their varying sizes, colors, and denominations, and the similarity between certain classes. Moreover, to the best of our knowledge, there are no publicly available datasets dedicated to Moroccan coin detection, making the development of accurate solutions more complex. In this study, we propose an end-to-end deep learning framework for the detection and valuation of Moroccan coins using the YOLOv8 object detection model. A custom dataset was constructed by combining images collected from online sources and photographs captured using smartphone cameras. The trained model achieved high detection accuracy across multiple Moroccan coin denominations. Furthermore, to enable real-world deployment, the model Moroccan Coin Detection Using YOLOv8 PREPRINT was converted to the TensorFlow Lite format, significantly reducing its size and computational requirements. This lightweight model was integrated into an Android application, allowing users to perform coin detection and automatic sum calculation directly on their smartphones without requiring Internet connectivity. The main contributions of this study are as follows: • Development of a custom dataset of Moroccan coin images sourced from both the web and smartphone photography. • Training and optimization of a YOLOv8-based detection model for the accurate recognition of multiple coin denominations. • Conversion of the trained model into TensorFlow Lite format for efficient inference on mobile devices. • Integration of the model into an Android application to enable real-time Moroccan coin detection and sum calculation. The remainder of this paper is organized as follows: Section ?? reviews the related work on coin detection and valuation using computer vision and deep learning. Section ?? presents the proposed methodology, including dataset preparation, model architecture, and Android integration. Section ?? discusses the experimental results and evaluation metrics. Finally, Section ?? concludes the paper and outlines potential future directions. 2 Related Work The automatic detection, classification, and valuation of coinage represent critical application domains for computer vision and deep learning, offering automated solutions for tedious and error-prone manual processes inherent in cash-intensive enterprises, gaming machines, and vending machines. The development of a deep learning system for Moroccan coin detection necessitates a review of prior work focusing on currency recognition techniques, the evolution of high-speed object detection architectures such as YOLO, and the challenges and methodologies associated with real-time deployment on mobile devices. 2.1 Traditional Approaches to Coin and Currency Recognition Early methods for currency and coin recognition predominantly utilized traditional machine learning (ML) and computer vision techniques Bellout et al. [2025]. These conventional approaches typically involve a multi-step process: lesion segmentation (in related fields), manual feature extraction, and classification Bellout et al. [2025]. Key attributes such as texture, color, morphological features, size, weight, thickness, and electromagnetic characteristics were identified and used to train ML models such as Support Vector Machines (SVM), k-nearest neighbors (k-NN), and Random Forest (RF). However, these traditional methods face several inherent limitations that constrain their practical applicability, including sensitivity to environmental factors, such as lighting conditions, the requirement for extensive preprocessing, and labor-intensive feature engineering Bellout et al. [2025]. In the specialized domain of numismatics, conventional object-matching algorithms based on local features (such as SIFT) have proven particularly fragile on real-world data owing to assumptions regarding coin centering, accurate registration, and near-circular shape Cooper and Arandjelovi´ c [2020]. The visual variability of individual coins of the same type, resulting from wear, patination, centering, and artistic depiction, poses significant technical challenges to reliable identification using automatic techniques Cooper and Arandjelovi´ c [2020]. Furthermore, most existing ancient coin work is severely limited by relying solely on visual matching against a small gallery of known types, which is impractical given that tens of thousands of different coin types exist Cooper and Arandjelovi´ c [2020]. This limitation highlights the need for systems focused on understanding the semantic content or identity of currency rather than mere visual matching. 2.2 The Deep Learning Era for Currency Detection and Classification The shift toward Deep Learning (DL), especially Convolutional Neural Networks (CNNs), has revolutionized image classification and object detection by automating feature extraction and classification, thereby significantly enhancing the reliability and efficiency of currency recognition systems Bellout et al. [2025]. CNNs are effective in capturing spatial hierarchies within images, making them well-suited for identifying banknotes and coinage with high accuracy Jaman et al. [2025]. Several studies have demonstrated the efficacy of deep learning across various currency types: 2 Moroccan Coin Detection Using YOLOv8 PREPRINT • CNN Architectures: Researchers have successfully employed models such as AlexNet, GoogleNet, ResNet, and custom CNN models for currency classification Bellout et al. [2025]. CNN-based models generally outperform older techniques, such as OCR, by effectively handling diverse lighting conditions, rotations, and worn-out notes. Examples of successful CNN application include models optimized for Bangladeshi banknotes, achieving high accuracy Jaman et al. [2025]. • Transfer Learning: To improve generalization and accuracy, transfer learning, often utilizing pre-trained models such as ResNet50V2, is frequently employed to fine-tune a model for the specific task of currency recognition Rao and Gowtham [2024]. • Specific Applications: Currency recognition is vital for commerce, banking, and assistive technologies for visually impaired individuals Jaman et al. [2025]. Advanced models are also critical for counterfeit detection, leveraging CNNs to analyze intricate security features, such as watermarks, security threads, and subtle printing inconsistencies Jaman et al. [2025]. 2.3 Advancements in YOLO Architectures for Real-Time Object Detection For applications requiring both high accuracy and speed, such as automated counting in cash-intensive environments, You Only Look Once (YOLO) models have become standard Dumaliang et al. [2021]. YOLO models are distinguished by their speed and accuracy, striking an essential balance for real-time applications Dumaliang et al. [2021]. The evolution of the YOLO architecture demonstrates a continuous effort to enhance detection capabilities. • YOLO Variants: Earlier versions, such as YOLOv3 and YOLOv4, were utilized effectively for real-time detection, incorporating techniques such as multi-scaling and bounding box predictions Dumaliang et al. [2021]. More recent iterations, including YOLOv7, YOLOv8, and YOLOv10, have further advanced detection capabilities by incorporating features such as efficient layer aggregation and segmentation. YOLOv8, the model chosen in this study, is recognized as a modern detector that enhances detection capabilities Bellout et al. [2025]. • Comparison with Other Detectors: Although regional proposal methods, such as Faster R-CNN, also achieve high accuracy in currency detection, they often require high computational resources, making them less suitable for deployment on low-power devices Jaman et al. [2025]. YOLO-based models are preferred because of their superior balance between speed and accuracy. 2.4 Lightweight Models and Mobile Deployment for Real-Time Use A significant challenge in utilizing sophisticated deep learning models is the trade-off between detection accuracy and computational efficiency, especially when deploying them on resource-constrained devices such as mobile phones or embedded systems. To deploy a model effectively in a real-world setting, the model must be optimized for size and inference speed Bellout et al. [2025]. • Necessity of Lightweight Architectures: Many state-of-the-art models are computationally intensive, which limits their practical application in scenarios such as rural farming communities or mobile financial tools. Research, even in domains such as tomato leaf disease detection, explicitly focuses on developing lightweight and efficient architectures (e.g., LT-YOLOv10n) to reduce the parameter count and computational demands, making them ideal for devices with limited resources Bellout et al. [2025]. • Real-Time Mobile Deployment: The goal of achieving fast inference directly on the device without any cloud resources aligns with recent research trends utilizing frameworks such as TensorFlow Lite (TFLite). TFLite model compression is critical for mobile applications Jaman et al. [2025]. – Successful mobile-optimized implementations have been demonstrated for real-time currency recognition and classification. Deploying optimized CNN models onto Android applications enables efficient, realtime, and offline functionality, providing practical and scalable solutions for users in various settings Jaman et al. [2025]. – Optimizations, such as knowledge distillation and lightweight backbone networks, are employed to reduce the model size while maintaining high accuracy, ensuring efficiency and responsiveness Jaman et al. [2025]. • Inference Speed: Achieving a high Frames Per Second (FPS) is critical for real-time applications. Studies have shown that lightweight, optimized models can achieve impressive real-time inference speeds on resourceconstrained platforms, such as processing images at up to 87.28 FPS on the Jetson Orin Nano. Deployment 3 Moroccan Coin Detection Using YOLOv8 PREPRINT in mobile applications allows real-time processing, ensuring instantaneous classification results Bellout et al. [2025]. In summary, the literature supports the proposed approach by validating the shift from traditional methods to CNNs and YOLO models for currency classification, recognizing the specific challenges posed by currency variability, and confirming the critical need for lightweight model optimization (such as YOLOv8 with TFLite conversion) to enable effective, real-time, and efficient deployment on modern mobile platforms. 3 Methodology This section outlines the methodological framework employed in the design, training, and deployment of the proposed Moroccan coin detection and valuation system. This approach integrates modern deep learning techniques with practical system engineering to deliver a robust, lightweight, and deployable solution for mobile devices. The process encompasses dataset creation, model training using YOLOv8, model optimization through TensorFlow Lite conversion, and the final integration into an Android application. The overall workflow is shown in Figure ?? (if applicable). 3.1 Dataset Development Because no public dataset of Moroccan coins exists, a dedicated dataset was constructed to train and evaluate the detection model. Seven denominations are represented: 0.1, 0.2, 0.5, 1, 2, 5, and 10 dirhams. The images were sourced from both publicly available online repositories and original photographs captured under various real-world conditions using smartphone cameras. The acquisition process aimed to incorporate variations in illumination, background texture, camera angle, and partial occlusion to ensure model generalization across realistic deployment environments such as vending systems or point-of-sale counters Rao and Gowtham [2024], Dumaliang et al. [2021]. All collected images were resized and normalized to 256×256 pixels to maintain uniformity. Annotation was performed using the open-source LabelImg tool, producing bounding boxes around individual coins. The annotations were initially stored in the Pascal VOC (XML) format and later converted into YOLO (TXT) format, which contains normalized coordinates and class indices suitable for YOLO-based training pipelines Wang [2023]. The dataset was divided into training (80%) and validation (20%) subsets, maintaining proportional representation of each class to prevent data imbalance. The directory structure adhered to YOLOv8’s standard convention, organizing the data as follows: dataset/ images/ train/ val/ labels/ train/ val/ A configuration file (data.yaml) defined dataset paths and class labels as shown below: path: dataset train: images/train val: images/val names: 0: 0.1 1: 0.2 2: 0.5 3: 1 4: 2 5: 5 6: 10 This setup ensured consistent class mapping and model interpretability during both training and evaluation. Data diversity and balanced representation were crucial to improving model generalization, especially given the high inter-class similarity among Moroccan coins. 4 Moroccan Coin Detection Using YOLOv8 PREPRINT 3.2 Model Architecture The detection task was performed using YOLOv8, a state-of-the-art anchor-free object detection framework developed by Ultralytics Wang [2023]. YOLOv8 integrates an advanced feature extraction backbone, multiscale neck, and efficient detection head optimized for real-time performance. Specifically, the YOLOv8n (nano) variant was selected to balance accuracy and computational cost, facilitating deployment on mobile devices. The architecture of YOLOv8 can be summarized as follows: • Backbone: The backbone employs CSPDarknet-like layers with Cross-Stage Partial (CSP) connections to enhance gradient flow and reduce redundancy Bochkovskiy et al. [2020]. • Neck: The neck integrates a Path Aggregation Network (PANet) to fuse features across multiple scales, improving the detection of coins with varying diameters and textures Liu et al. [2018]. • Head: The detection head utilizes an anchor-free mechanism that directly predicts object centers and bounding box dimensions without predefined anchor boxes, improving inference efficiency and accuracy on small, circular objects like coins Wang [2023]. This architecture enables the model to effectively discriminate between Moroccan coins that exhibit subtle visual differences in texture, metallic reflection, and edge patterns. The choice of YOLOv8n provides an excellent trade-off between detection accuracy and real-time inference speed, a critical requirement for embedded and mobile applications. 3.3 Training Configuration Model training was conducted using the official Ultralytics YOLOv8 framework in a GPU-accelerated environment. The pretrained weights from yolov8n.pt (trained on the COCO dataset) were fine-tuned on the Moroccan coin dataset to exploit transfer learning benefits. The main hyperparameters used in the training process are summarized as follows: • Epochs: 100 • Batch size: 2 • Image size: 256 ×256 • Optimizer: Auto (SGD or AdamW) • Learning rate: Initial 0.01 • Weight decay: 0.0005 • Momentum: 0.937 • Device: GPU (device ‘0’) Several data augmentation techniques, including random horizontal flipping, color jittering, and mosaic augmentation, were applied to enhance model robustness against illumination changes and background variability Shorten and Khoshgoftaar [2019]. Mosaic augmentation, in particular, was highly beneficial for learning multiple coin arrangements within a single frame, improving detection accuracy in cluttered scenes. 3.4 Model Optimization and Conversion To ensure real-world feasibility and mobile deployment, the trained PyTorch model was exported to the ONNX format and subsequently converted to TensorFlow Lite (TFLite). Post-training quantization techniques—specifically dynamic range quantization—were applied to reduce model size and inference latency without significant accuracy degradation Jacob et al. [2018]. The TFLite model achieved a substantial reduction in memory footprint, enabling real-time inference on mid-range Android smartphones. 3.5 Android Integration The optimized TFLite model was embedded in an Android application using the TensorFlow Lite Interpreter API Abadi et al. [2016]. The app enables users to capture or upload an image containing coins, perform on-device inference, and automatically compute the total monetary value. The application was designed to operate fully offline, ensuring data privacy and usability in low-connectivity environments. The user interface allows real-time visualization of detected coin bounding boxes and denomination labels, while the total calculated amount is displayed instantly on-screen. This integration demonstrates the end-to-end feasibility of deploying advanced deep learning models for real-world financial applications in the Moroccan context. 5 Moroccan Coin Detection Using YOLOv8 PREPRINT 4 Results and Discussion 4.1 Evaluation Metrics The performance of the proposed Moroccan coin detection and valuation system was evaluated using several standard object detection metrics, namely precision (P), recall (R), F1-score, and mean Average Precision (mAP) at Intersection over Union (IoU) thresholds of 0.5 and 0.5–0.95. These metrics collectively measure detection accuracy, localization precision, and robustness across all classes Bellout et al. [2025], Cooper and Arandjelovi´ c [2020]. Precision ( P ) measures the proportion of correctly identified coins among all detected instances, whereas recall ( R ) quantifies the proportion of actual coins that were successfully detected. The mean Average Precision at IoU threshold 0.5 (mAP@50) reflects the average detection performance at a moderate overlap criterion, while mAP@50–95 provides a stricter, multi-threshold evaluation. The F1-score harmonizes precision and recall, offering a balanced indicator of model accuracy. 4.2 Quantitative Results The YOLOv8n model exhibited competitive performance despite the limited dataset size. The overall mAP@50 achieved was 0.43, while larger and more visually distinct denominations such as 1 DH and 5 DH achieved mAP values above 0.80. In contrast, smaller denominations (0.1 DH and 0.2 DH) showed lower detection performance due to their small size, reflective surfaces, and limited representation in the dataset. Figure 1: Training and validation curves showing loss reduction and performance improvements over epochs. As depicted in Figure 1, both the training and validation curves converged smoothly, demonstrating stable learning behavior. Additional performance insights were obtained from the precision–recall and F1-score curves. 6 Moroccan Coin Detection Using YOLOv8 PREPRINT Figure 2: Precision–Recall curve and F1-score evolution, indicating balanced model generalization across classes. Furthermore, the confusion matrix (Figure 3) highlights per-class prediction accuracy. Diagonal dominance across most classes indicates consistent classification performance. However, occasional misclassifications occurred between 0.5 DH and 1DHcoins due to their visual similarities in edge texture and coloration. 7 Moroccan Coin Detection Using YOLOv8 PREPRINT Figure 3: Normalized confusion matrix demonstrating class-wise detection accuracy. 4.3 Qualitative Evaluation Beyond quantitative results, qualitative analysis demonstrated that the model effectively detected multiple overlapping coins, accurately localized their boundaries, and maintained robustness under varying lighting and background conditions. Figure ?? (not shown here) showcases successful detections across diverse scenarios. The real-time inference tests on Android devices confirmed high responsiveness, with average latency below 150 ms per image. The optimized TensorFlow Lite model operated efficiently on mid-range hardware, confirming the practicality of on-device deployment. 4.4 Discussion The experimental outcomes validate the suitability of YOLOv8 for small-scale, resource-constrained object detection applications. Its lightweight architecture allowed fast inference without compromising precision. Similar to other edge-oriented applications in agriculture Bellout et al. [2025] and currency recognition Jaman et al. [2025], Rao and Gowtham [2024], the proposed approach demonstrates that accurate real-time detection is achievable with optimized deep learning pipelines. Nonetheless, several challenges remain: • Detection of occluded or partially visible coins, • Sensitivity to reflective or metallic surfaces causing false positives, • Difficulty in recognizing worn or aged coins with faded engravings. Future research will explore synthetic dataset augmentation using Generative Adversarial Networks (GANs), multi-view imaging for improved spatial awareness, and joint learning architectures capable of both detection and automatic valuation. 5 Conclusion In this study, we developed an end-to-end framework for Moroccan coin detection and valuation using the YOLOv8 model. A custom dataset of Moroccan coins was compiled and annotated, and the trained model achieved competitive 8 Moroccan Coin Detection Using YOLOv8 PREPRINT detection performance for multiple denominations. To enhance accessibility, the model was optimized, converted to TensorFlow Lite, and successfully deployed as an Android smartphone application. The key contributions of this study include the creation of a Moroccan coin dataset, development of a YOLOv8-based detection pipeline, and demonstration of mobile deployment feasibility. The system represents a practical and efficient tool for automating coin recognition and calculation in both individual and commercial applications in the future. Future work will focus on expanding the dataset to include worn and damaged coins, improving detection under challenging conditions, and extending the system to handle mixed currency scenarios. References A. Bellout, A. Dliou, R. Latif, A. Saddik, M. Elhoseny, and M. Zarboubi. Lt-yolov10n: A lightweight iot-integrated deep learning model for real-time tomato leaf disease detection and management. Internet of Things, 33:101663, 2025. doi:10.1016/j.iot.2025.101663. J. Cooper and O. Arandjelovi´ c. Learning to describe: A new approach to computer vision based ancient coin analysis. Sci, 2(2):27, 2020. doi:10.3390/sci2020027. S. Jaman, M. Haque, M. Islam, and U. Noor. Bd currency detection: A cnn based approach with mobile app integration. 2025. doi:10.48550/arxiv.2502.17907. URL https://doi.org/10.48550/arxiv.2502.17907. arXiv preprint. M. Rao and N. Gowtham. Efficient currency recognition and value detection system using image processing. World Journal of Advanced Research and Reviews, 22(1):241–255, 2024. doi:10.30574/wjarr.2024.22.1.0949. D. M. Dumaliang, J. R. Cunado, J. M. Q. Rigor, R. G. Garcia, and J. F. Villaverde. Coin identification and conversion system using image processing. In 2021 IEEE 13th International Conference on Humanoid, Nanotechnology, Information Technology, Communication and Control, Environment, and Management (HNICEM), pages 1–6, 2021. doi:10.1109/hnicem54116.2021.9732002. Glenn Jocher et al. Wang. Yolov8: Next-generation object detection and image segmentation. Ultralytics, 2023. https://github.com/ultralytics/. Alexey Bochkovskiy, Chien-Yao Wang, and Hong-Yuan Mark Liao. Yolov4: Optimal speed and accuracy of object detection. arXiv preprint arXiv:2004.10934, 2020. Shuyang Liu, Xiaojuan Qi, Hong Qin, and Jianping Shi. Path aggregation network for instance segmentation. Proceedings of CVPR, 2018. Connor Shorten and Taghi M. Khoshgoftaar. A survey on image data augmentation for deep learning. In Journal of Big Data, 2019. Benoit Jacob, Skirmantas Kligys, Bo Chen, Menglong Zhu, Matthew Tang, Andrew Howard, Hartwig Adam, and Dmitry Kalenichenko. Quantization and training of neural networks for efficient integer-arithmetic-only inference. Proceedings of CVPR, 2018. Martín Abadi et al. Tensorflow: A system for large-scale machine learning. In 12th USENIX Symposium on Operating Systems Design and Implementation (OSDI), 2016. 9