# Automated Gluten Detection in Bread Images Using Convolutional Neural Networks
## 5 Discussion  
After training six models on the Pinterest bread dataset, ResNet50V2 emerged as the best-performing model (see Table 2). This result aligns with findings in the literature, where ResNet architectures have demonstrated strong feature extraction capabilities due to their deep residual connections, which enhance gradient flow and improve training efficiency [53, 54, 55]. Compared to simpler architectures, such as traditional CNNs and even Inception-based models, ResNet50V2 provides a balanced trade-off between depth, accuracy, and computational efficiency, making it a robust choice for image classification tasks. After selecting ResNet50V2 as the best-performing model on the Pinterest bread dataset, we tested its performance on another dataset from Instagram. However, the results on this new dataset were not as high as those achieved with the Pinterest dataset (see Table 3). Differences in the dataset characteristics may have contributed to this discrepancy; the Instagram dataset included additional types of flour, making classification more challenging. To address this issue, we applied a fine-tuning approach by retraining the pre-trained ResNet50V2 model on combined dataset of images taken from Pinterest and Instagram datasets. This strategy proved effective, as the model showed improvement when tested on unseen data from the same dataset (see Table 3). The improved performance highlights the importance of fine-tuning pre-trained models on images from diverse sources, demonstrating that incorporating data from different social media platforms can significantly enhance the classifier's ability to generalize across varied datasets. This is particularly crucial for tasks involving heterogeneous image distributions, where variations in content, lighting, and composition between platforms can impact classification performance. When applying the final model to the new custom bread dataset, the results showed an improved performance, achieving accuracy, recall and F1 scores of 86% and precision of 87%. With respect to the trade-off between false positives and false negatives in the combined dataset of images taken from Pinterest, Instagram, and custom bread datasets, the number of false negatives (misclassifying \"Gluten Free\" as \"Gluten Containing\") is higher than the false positives. Depending on the application's context, this trade-off may have significant implications. If prioritizing safety (e.g., individuals with celiac disease avoiding gluten for health reasons), minimizing false negatives is critical, as a \"Gluten Free\" sample misclassified as \"Gluten Containing\" could lead to unnecessary dietary restrictions, causing inconvenience or limiting food choices unnecessarily. However, this type of misclassification is less harmful than a false positive, where a gluten-containing item is mistakenly classified as gluten-free, potentially leading to serious health consequences. From a user-experience perspective, a higher false negative rate may result in frustration if users frequently receive overly cautious classifications, leading them to avoid safe foods unnecessarily. Balancing model sensitivity and specificity is crucial to ensuring both safety and usability. Future work could explore strategies such as adjusting classification thresholds, incorporating uncertainty estimation, or implementing a user feedback mechanism to refine predictions and enhance reliability. These findings highlight the need for context-aware model optimization, where different applications--such as consumer-facing mobile apps vs. industrial gluten detection tools--may require different risk tolerances when tuning model performance. The custom bread dataset included information regarding the flour composition in each bread and provided insight into the accuracy of flour classification. The gluten-free flows commonly represented in the dataset included rice, potato, corn, tapioca, and maize flours, aligning with the literature findings [56].