Integrating Language Models and Machine Learning for Crop Disease Detection for Farmer Guidance Vishu Madaan1,∗,† , Gagan Bindal1 , Sandeep Singh1,† , Shiv Kumar Yadav1,† , Ankur Singh1,† , Piyush Sinha1,† and Dimple Nagpal1 1 School of Computer Science and Engineering, Lovely Professional University, India Abstract India’s two-third of the population are farmers who bear 10 to 25% loss of crop annually to crop diseases. To overcome that, this study proposed a Deep learning and AI enabled mobile application. Deep learning models can play a crucial role in helping farmers prevent crop failure by early detection in plant leaves. In the experiment, this study examined MobileNetV2 and ResNet50 models on 39,131 images divided among 21 classes in a dataset to detect crop disease. The dataset is being divided into 80% and 20% ratio for training and testing purpose and then passed through data augmentation techniques, hyper parameter tuning etc. to achieve higher accuracy. After analyzing the results of the mentioned models, this study gets the highest accuracy for the MobileNetV2 model with testing accuracies of 97% to 99% and found to be best fit for mobile application as its model size is very less compared to ResNet50. The proposed study not only focused on detecting crop diseases, but also provided the recommendation using LLM which finds the tailored solution to prevent the crop disease as well as helping farmers to make more profit. Keywords Plant Disease, MobileNetV2, Deep Learning Models, Agriculture, Computer Vision, Recommendation, Language Models (LM) 1. Introduction Agriculture, deeply entrenched in Indian culture and sustaining over 75 percent of the population, faces numerous challenges, including crop diseases that can devastate yields and livelihoods. Biotic and abiotic agents such as fungi, bacteria, viruses, and insects threaten crop health, resulting in significant losses during growing seasons. On average, during a typical growing season, 10 to 25 percent of a crop is lost to diseases and pests [1], with losses ranging from 0 to 100 percent, while it is estimated that the average loss is 12% for all crops. Traditional diagnosis methods often struggle to accurately identify diseases due to inconclusive symptoms and visual raters’ limitations. With the advent of AI and machine learning algorithms, there’s potential for revolutionary improvements in disease detection and prevention. By leveraging advanced technology, farmers can mitigate losses, ACI’23: Workshop on Advances in Computational Intelligence at ICAIDS 2023, December 29-30, 2023, Hyderabad, India ∗ Corresponding author. † These authors contributed equally. Envelope-Open dr.vishumadaan@gmail.com (V. Madaan); gaganbindal2002@gmail.com (G. Bindal); sandeep723992singh@gmail.com (S. Singh); yshiv7267@gmail.com (S. K. Yadav); ankursingh453@gmail.com (A. Singh); piyush720sinha@gmail.com (P. Sinha); dimple.nagpal@gmail.com (D. Nagpal) © 2024 Copyright for this paper by its authors. Use permitted under Creative Commons License Attribution 4.0 International (CC BY 4.0). CEUR ceur-ws.org Workshop ISSN 1613-0073 Proceedings 141 enhance crop quality, and bolster agricultural sustainability, ensuring a prosperous future for India’s agricultural sector and its people. The use of machine learning to help detect plant diseases and provide recommendations and methods to cure that disease which eventually benefit farmers. The method of detecting plant disease using machine learning is a process by which the machine is able to learn an input dataset consisting of images of healthy plants and plants with disease. The machine then processes the image to recognize the patterns and the characteristics of the image or in other words, the machine is learning the identifying features of the images such as the color, texture, or shape of the object in the image. After going through the process of learning by using a certain algorithm, a new image of an unknown plant can be tested to see the healthiness of the plant by comparing the patterns and characteristics to the database. When the disease gets predicted by our trained model, then it will go through the recommendation system which gives solutions to cure and prevent the crop from further diseases. The Recommendation system is an AI enabled solution which uses the API of Large Language Models to give the precise output. The output given by the LLM has been thoroughly compared with the already existing models which are being trained using the SVM algorithm.This research took feedback from farmers and research scholars for the output, and they are satisfied with the results that have been given by the model. It is well known that in recent years, modern agriculture has become more developed as a result of the implementation of technology in all aspects of agricultural development. Currently, the agricultural sector is utilizing technology to create innovations in the field of farming such as utilizing machine technology in the process of planting and monitoring plant growth, the implementation of technology to create superior plant seeds, and for the detection of plant diseases we utilize machine learning. By using the power of deep learning algorithms and artificial neural networks (ANNs), the system provides a revolutionary method for identifying agricultural diseases and suggesting treatments. Through the analysis of photos of sick crops, technology quickly pinpoints specific illnesses and gives farmers customized advice based on the most recent agricultural research. With this empowerment, farmers can protect their crops and livelihoods from the damaging effects of illness by putting timely and efficient solutions into place. In the end, this recommendation system could be used to improve agricultural resilience and output by employing proactive disease control techniques. 2. Literature Review Much research has been performed in the agriculture sector for the betterment of farmers and consumers. Mohanty S.P. et al. [2] discusses the importance of having an extensive and authenticated collection of pictures showing both sick and well plants for accurate image classification in plant disease diagnosis. The research has been performed on 14 crop species consisting of 54,306 images of 26 types of disease. The model achieved accuracy of 99.35% in tests. 2.1. Convolutional Neural Networks (CNNs): Within the category of deep learning algorithms are Convolutional Neural Networks (CNNs) that excel in image recognition tasks. They have the ability to instinctively learn hierarchical features 142 from raw pixel data, making them ideal for analyzing plant images and detecting diseases. CNNs have been successfully applied in various domains, including healthcare, autonomous driving, and agriculture. The related research works have used various pretrained Image processing models like AlexNet and GoogleNet [2], Night-CNN [3], VGG16, VGG19 and ResNet-50 [4], InceptionV3 [5]. Barkha M. Joshi and Dr. Hetal Bhavsar [3] highlights the importance of Early detection and prevention of crop diseases are critical for optimizing crop yield. The research paper introduced a model based on Convolutional Neural Network (CNN) to detect disease in Nightshade crops which are Lycopersicon, Capsicum and Tuberosum crops and named the model as Night-CNN. The model gave the accuracy rate of 93% to 95% for the night shade crops. Deep learning models are among the potential tools that can help in detecting plant diseases in their early stages. Islam et al. [4] conducted research on four deep learning models, including CNN, VGG-16, VGG-19, and ResNet-50, using the plant-village 10000 image dataset. All the above models were found to be highly accurate, with ResNet-50 recording the best accuracy level of 98.98%. Consequently, the above models have the potential to support farmers in easily detecting plant diseases and lessening their effects. In Konstantinos P. Ferentinos [6] the author delves into the application of CNNs for precise plant disease detection. The research showcases the practicality of utilizing CNNs for diagnosing plant diseases based on images, achieving an impressive accuracy rate of 99.53% on a dataset containing 17,458 previously unidentified images. The study lacks clarity regarding the specific CNN model employed. 2.2. Vision Transformer (ViT): Vision Transformer was introduced as an outstanding Convolutional Neural Network or today’s leading machine learning model in computer vision, used in numerous image recognition tasks. It is four times more efficient than all the best CNNs that had been developed before, and it functioned as follows: “the image is previously decomposed into patches and then flattened of that image and pre-training using image labels”. Vision Transformer was released in 2021. Boukabouya, R. A. [5] study was about tomato disease detection in leaf stage, and they used different deep learning architectures. Therefore, lots of comparative experiments were addressed to obtaining a stable and high-class classification performance exceeding previous cutting-edge results. The top performance on the deep learning models was Vision Transformers, the author used CNN with attention, InceptionV3, ViT1 and ViT2 which provided accuracies 96.7%, 98.52%, 99.1% and 99.7% respectively. The primary goal is to implement early automatic disease detection in leaf plants to help preserve the natural cycle. In their future work the authors, to improve the classification performance and stay away from noisy, unnecessary data, want to combine segmentation tables with classification models. 2.3. AI enabled Applications: Y Liu et al. [7] in their research meets the critical requirement for prompt and precise detection of plant disease in agricultural scenarios. A novel method based on to achieve automatic lesion; dynamic pruning is suggested.A pattern detection in low-computing environments. Specifically, the re-parameterization method was proposed, which further enhances the boosting accuracy of convolutional neural networks, and introduces the dynamic pruning gate, enabling the network 143 Table 1 State-of-the-art work analysis Research Works Number of Images Model Used Accuracy (%) and Classes Mohanty S.P. 54306 with 26 classes AlexNet, GoogleNet 85.53% to 99.35% et.al. [2] Barkha M. Joshi and 20304 with 15 classes Night-CNN 93% to 95% Dr. Hetal Bhavsar [3] Islam et al. [4] 10000 with 8 classes VGG16, VGG19, and ResNet- 92.39% to 98.89% 50 Konstantinos P. Fer- 75021 with 27 classes CNN based model 99.53% entinos [6] Boukabouya, R. A. 2652 with 6 classes CNN, Inception V3, Vision 96.7% to 99.7% et.al. [5] Transformers to dynamically adjust its structure in different hardware platforms. The theoretical model was constructed, and the application program, including the mobile application, was completed. The experimental results successfully confirmed the versatility of the model in various computing platforms and achieved an inference rate of 58 FPS. In addition, the authors enhanced sub-classes that are difficult for data augmentation techniques to detect which authors verified with the ablation experiment and achieved a precision of 0.94. Barman Utpal et. al. [8] has proposed a mobile application based on Vision Transformer models to detect disease in Tomato crops with the accuracy of 90.99%. The application was developed using the Java environment for Android Platform with the ability to provide the correct disease labels for the disease related to tomato plants. The author states to work on weeds and other plants in future. 2.4. Recommendation System: The research work [9] suggests the use of a regression systems that calculate various soil test values, such as phosphorus, nitrogen, and doses to be sprayed in the field, which are created for various crop types. Ready reckoner was created to make recommendations simple. Fertilizer recommendations are created for various crops of each soil value using an equation and a ready reckoner and it is cost effective. PRSER, a plant disease prescription recommendation method based on sentence embedding retrieval, is proposed in this study [10].This study has the potential to greatly advance scientific plant disease management, meet farmer needs, and make it easier to apply artificial intelligence in the treatment of plant diseases. Plant diseases are a serious risk to agricultural productivity and food safety. CNNs in particular, which are deep learning technologies, have demonstrated excellent potential in accurately identifying and diagnosing crop diseases. By leveraging machine learning algorithms and large datasets of plant images, researchers and farmers can improve disease detection, prevent crop losses,and enhance overall agricultural production. Continued research and innovation in the field of intelligent systems and applications in engineering are essential for guaranteeing the world’s food security and tackling the problems caused by plant diseases. 144 Figure 1: Proposed work-flow Diagram 3. Proposed Methodology The Process of identification of the diseases with the functional workflow is represented in Fig.1. The steps of the proposal are described below.In the description itself, every step of the proposal is explained, from identification to classification: 3.1. Data Collection: In this research, a public dataset available on Kaggle was referred. It has a collection of pictures that showed both healthy and disease plants across different crops, like apple, corn, potato, rice, 145 Figure 2: Resizing and rotating the diseased images tomato. The dataset consists of images of size 256*256 pixels and has over 39131 images and table 2 shows the distribution of crops in the dataset.Additionally, pre-processing methods such as resizing, normalization, and data augmentation were utilized to enhance the model’s ability to generalize which is being discussed in the next section. Table 2 Distribution of Dataset Crops Number of Images Number of Classifications Diseased Healthy Diseased Healthy Tomato 16416 1926 9 1 Potato 3878 1824 2 1 Apple 5736 2008 3 1 Corn 5457 1859 3 1 3.2. Data Pre-processing and Augmentation: It is imperative to pre-process the raw images obtained from the dataset in order to remove any potential noise before integrating them into the learning module. During the pre-processing stage, we apply shearing, rotation, and resizing to the image. Fig. 2 and Fig. 3 show the data Augmentation. Some parameters are being applied to the images like resizing, re-scaling, rotating, zoom,etc on the dataset and then applying the contrast and brightness on the images. After the data augmentation being applied on the dataset, in the set of 80% and 20%, the dataset is divided into training and validation subset respectively. After this step the different models being applied on the training and validation set which is being discussed in the next 146 Figure 3: Applying contrast, brightness parameters on images section. 3.3. Model Building 3.3.1. MobilenetV2 MobilenetV2 is a CNN architecture specifically designed for efficient deep learning on mobile and embedded systems. As shown in Fig. 4, it uses the inverted residual blocks allowing it for deeper networks, meanwhile minimizing computational cost. A lightweight bottleneck layer followed by a linear expansion layer and a point-wise convolution layer are present in these blocks. This design reduces the number of parameters and operations required, making the network more efficient. MobilenetV2 consists of 53 layers of neural network. 3.3.2. ResNet50 ResNet-50 is a CNN architecture that belongs to the ResNet (Residual Network) family. It is a deep neural network comprising 50 layers which enables it to learn complex features and representations from input images. As seen in Fig. 5 ResNet-50 makes use of residual connections or skip connections. This enables it to learn residual mapping instead of directly learning the desired underlying mapping and mitigates the vanishing gradient problem. It consists of building blocks that primarily use the bottleneck architecture, each containing a sequence of convolutional layers, batch normalization and ReLU activation functions. ResNet-50 also makes use of global average pooling, helping in preventing over-fitting and in reducing the number of parameters. The output layer of ResNet-50 is a fully connected layer followed by a 147 Figure 4: Mobilenet V2 architecture softmax activation function. ResNet-50 has been pre-trained on large datasets like ImageNet and is a popular base architecture for transfer learning in deep learning applications. 3.4. Model Evaluation The CNN model which was trained will be evaluated using a range of performance metrics, including F1 score, recall, accuracy, and precision. Furthermore visual representations in the form of confusion matrices will be created to show how well the model classifies types of plant diseases. This encompasses tasks, like gathering and preparing data, training the pre-trained deep learning models and assessing its performance while utilizing transfer learning and data expansion methods to enhance accuracy and resilience. The models which are being used are ResNet50 and MobileNetV2. The training accuracy of 98.09% and the validation accuracy of 98.42%. Based on the results of the in-depth experiments on leaf disease, this study determines the best model for the given dataset based on performance evaluation. The evaluation is conducted across multiple stages and involves various aspects, including: 3.4.1. Accuracy: is a measurement to determine which model is best to identify relation and pattern between the variables on the basis of training datasets. 148 Figure 5: ResNet-50 architecture 3.4.2. Precision: defines how many times “positive” predictions were calculated by the model. 3.4.3. Recall: measures how many times positive class which is present in the dataset is identified correctly by the models. 3.4.4. F1-Score: is basically a machine learning evaluation matrix from which we can calculate the model accuracy. It’s basically a combination of precision and recall scores of the provided models. The accuracy metrics predict how many time models give the correct prediction on the given datasets. All these aspects is being integrated on the flutter mobile application on which the dataset in continuously being checked and after the successful capturing the image of the diseased leaf through the tflite library of the flutter which is used for the integration will give the results of the finalized disease and it will accurately measures the disease and add on features. 149 Table 3 Architectural Comparison between ResNet50 and MobileNetV2 Properties ResNet-50 MobileNet_V2 Image 256*256*3 256*256*3 Weight imagenet imagenet Model Size 94 MB 9.8 MB Total Layers 50 53 Pooling Max Pooling (1) Global average pooling 2D Activation Function Softmax Softmax Total Parameters 23.8 million 2.5 million 4. Architectural comparison Table 3 compares the model architecture for both ResNet-50 and MobileNetV2. ResNet50 is a deep convolutional neural network with 50 layers that adopts skip connections to counteract the vanishing gradient problem while fitting.Its depth enables it to capture detailed features at various scales, but it comes with the tradeoff of high computational costs. MobileNetV2 is specifically optimized for mobile and embedded applications, making it a more lightweight architecture that balances performance and efficiency. The use of depth- wise separable convolutions and inverted residuals ensures that it gets competitive efficiency gains without sacrificing performance. ResNet50 performs very well on tasks such as image classification, although MobileNetV2 can handle multiple activities in resource-constrained environments. 5. Recommendation using LLM (Large language Models) To provide precise suggestions, the recommendation system uses LLMs. While providing context without specifically mentioning the model name, a fixed-sized prompt steers the interaction with LLMs. It is a brief prompt with descriptions of symptoms or crop diseases. After processing this data, LLMs produce recommendations that are appropriate for the given context. The proposed work is prepared using Flutter application. Here user can either choose the image of the affected crop leaf from their gallery or can use their mobile phone camera to click the image and that has been implemented using the Image picker package of flutter. Once the image is uploaded A detect button will be visible, then the integrated model identifies the crop and gives the description generated by the integrated LLM solution regarding the disease with the confidence rate. After successful detection of the disease a Solution button will be visible and by clicking on that the LLM model generates the tailored solution for that affected crop. 6. Result This research work has used two pretrained models i.e. ResNet-50 and MobileNetV2 for different crops like apple, potato, corn and tomato and evaluate the models on the basis of precision, recall, f1 score and accuracy. Table 4 shows accuracy and f1 score achieved using MobilenetV2 150 Figure 6: Training and Validation accuracy loss curves for MobileNetV2 and ResNet-50 for different crops dataset. Using MobileNetv2, the testing accuracy is achieved to be 99% for the particular datasets with training and validation accuracy of 98.34% and 98.83% respectively as shown in Fig. 6. The potato dataset is being trained on the ResNet-50 pretrained model which gives the testing accuracy of 97% against the training accuracy of 95.8% and validation accuracy of 95.31% as shown in Fig. 7. This study’s significance lies in its contributions to agricultural research. It proposes an AI-enabled system for detecting leaf diseases, enhancing prediction precision. Automated precautionary actions are made available through mobile application accessibility, aiding farmers in improving productivity by promptly uploading images of diseased crops. It advances machine learning techniques, particularly in deep learning models, applicable to smart agriculture sectors globally. The results facilitate the development of more accurate and user-friendly models for crop disease detection and prediction, seamlessly integrated into mobile systems with recommendations for organic fertilizers and pesticides. Table 4 Accuracy and F1-Score Comparison between MobileNetV2 and ResNet50 Crop MobileNetV2 ResNet50 Accuracy (%) F1 Score Accuracy (%) F1 Score Potato 99 0.99 97 0.97 Apple 97 0.97 96 0.95 Corn 95 0.99 93 0.97 151 Figure 7: ResNet50 Model Training and Validation curves Table 5 Precision and Recall Comparison between MobileNetV2 and ResNet50 Crop MobileNetV2 ResNet50 Precision Recall Precision Recall Potato 0.98 0.98 0.97 0.96 Apple 0.97 0.98 0.95 0.95 Corn 0.94 0.94 0.92 0.92 7. Conclusion This research paper and study majorly identified plant or leaf disease and its cause by using architecture based on convolutional neural networks. Several models were used, including the MobileNetV2, and ResNet50, to detect the leaf conditions. Among all models, MobileNetV2 has the highest accuracy rate of 99% for detecting potato leaf disease and for other models as well the MobileNetV2 outperforms the ResNet-50. Apart from the training results MobileNetV2 model size is around ten times less compared to ResNet50, which makes it the first choice to use in the proposed application. The recommendation system provides the cure of the disease by giving the alternatives of the fertilizers and pesticides which are being used in the crop for the betterment of disease prevention. Compared to past studies on plant leaf disease, the suggested approach yielded better results for assessing symptom severity. Although the research paper shows encouraging results with MobileNetV2 , more work could be done to optimize the model further or examine how well it performs with other crops and diseases to increase its practical application. In order to incorporate all plant-leaf diseases, we also employ an improved multiple-leaf dataset in the upcoming study and according to that dataset we will train and test our model by using multiple Deep learning algorithms to get more accurate results. Explainable artificial intelligence (AI) has enormous potential to transform agriculture and make it possible to protect the world’s food supply in a transparent, efficient, and sustainable manner. 152 Figure 8: Confusion Matrix for model based on Mobilenet V2 References [1] J. B. Ristaino, P. K. Anderson, D. P. Bebber, K. A. Brauman, N. J. Cunniffe, N. V. Fedoroff, C. Finegold, K. A. Garrett, C. A. Gilligan, C. M. Jones, et al., The persistent threat of emerging plant disease pandemics to global food security, Proceedings of the National Academy of Sciences 118 (2021) e2022239118. [2] S. P. Mohanty, D. P. Hughes, M. Salathé, Using deep learning for image-based plant disease detection, Frontiers in plant science 7 (2016) 215232. [3] B. M. Joshi, H. Bhavsar, Deep learning technology based night-cnn for nightshade crop leaf disease detection, International Journal of Intelligent Systems and Applications in Engineering 11 (2023) 215–227. [4] M. M. Islam, M. A. A. Adil, M. A. Talukder, M. K. U. Ahamed, M. A. Uddin, M. K. Hasan, S. Sharmin, M. M. Rahman, S. K. Debnath, Deepcrop: Deep learning-based crop disease prediction with web application, Journal of Agriculture and Food Research 14 (2023) 100764. [5] R. A. Boukabouya, A. Moussaoui, M. Berrimi, Vision transformer based models for plant disease detection and diagnosis, in: 2022 5th International Symposium on Informatics and its Applications (ISIA), IEEE, 2022, pp. 1–6. [6] K. P. Ferentinos, Deep learning models for plant disease detection and diagnosis, Computers and electronics in agriculture 145 (2018) 311–318. [7] Y. Liu, J. Liu, W. Cheng, Z. Chen, J. Zhou, H. Cheng, C. Lv, A high-precision plant disease detection method based on a dynamic pruning gate friendly to low-computing platforms, Plants 12 (2023) 2073. [8] U. Barman, P. Sarma, M. Rahman, V. Deka, S. Lahkar, V. Sharma, M. J. Saikia, Vit-smartagri: Vision transformer and smartphone-based plant disease detection for smart agriculture, Agronomy 14 (2024) 327. 153 [9] A. Kumar, S. Kumar, Y. Kumar, S. Singh, U. Shahi, A. Kumar, B. Singh, et al., Soil test base fertilizer recommendation by soil fertility rating for major field crops and vegetables in uttar pradesh for food security of india, Progressive Agriculture 21 (2021) 110–116. [10] J. Ding, Y. Qiao, L. Zhang, Plant disease prescription recommendation based on electronic medical records and sentence embedding retrieval, Plant Methods 19 (2023) 91. [11] M. Jaderberg, K. Simonyan, A. Vedaldi, A. Zisserman, Deep structured output learning for unconstrained text recognition, arXiv preprint arXiv:1412.5903 (2014). [12] S. Yousfi, S.-A. Berrani, C. Garcia, Deep learning and recurrent connectionist-based approaches for arabic text recognition in videos, in: 2015 13th international conference on document analysis and recognition (ICDAR), IEEE, 2015, pp. 1026–1030. 154