Intelligent Crop Pest and Disease Diagnosis System Based on Object Detection and Large Language Models: Design and Practice

    This article describes the design of a crop pest and disease diagnosis system that combines object detection with large language models. An object detection model locates and classifies disease and pest symptoms in images. A large language model turns the detection results into plain-language explanations and management advice. A front-end and back-end engineering stack connects both parts into a platform that several users can work on together. The article covers the system architecture, handling of different input sources, class design, permission control, front-end customization, and suggestions for data, performance, reliability, and trust.

    1. Background and Problem Analysis

    Crop pest and disease control relies heavily on experience-based judgment. Frontline agricultural extension staff and growers usually face three major problems:

    1. High identification barrier. Common crop diseases are numerous, and their symptoms often look alike. For example, early blight and late blight of tomato both produce brown lesions on leaves, so non-specialists can easily misdiagnose them.
    2. Strict response time requirements. Diseases can spread quickly. The shorter the time between spotting suspicious symptoms and receiving control recommendations, the smaller the losses.
    3. Severe data silos. Detection records are scattered across paper forms or personal devices. Without unified archiving, statistics, and reporting, it is hard to support regional analysis of disease trends.

    To address these problems, an effective intelligent diagnosis system needs three capabilities: accurate visual detection, clear diagnostic explanations with treatment advice, and good management through multi-user collaboration and data governance. The solution in this article follows that approach. An object detection model locates and classifies pests and diseases. A large language model interprets the detection results in professional language. A complete front-end and back-end system links the two parts into a platform that multiple users can operate.

    2. Overall System Architecture

    The system uses a front-end and back-end separated architecture with two services. It has four core layers.

    1. Visual Inference Layer

    A object detection model trained with PyTorch handles image understanding. Given an image, the model outputs bounding boxes for diseased areas, class labels, and confidence scores. This layer supports four input types:

    • Single image upload for quick on-site diagnosis;
    • Folder upload and batch inference for screening sample libraries;
    • Local video file parsing, with frame-by-frame detection and an annotated output video;
    • Live camera feed detection, for use cases such as greenhouse inspection.

    The inference service can be deployed independently, for example by exposing an HTTP interface through a lightweight web framework. It is decoupled from the business backend, so it can be scaled and its model versions updated on its own.

    2. Large Language Model Diagnosis Layer

    A detection model can only tell what the problem is. Farmers also want to know why it happened and what to do about it. In this layer, a large language model converts structured detection results (crop, disease, and confidence) into natural-language reports. These reports cover the likely cause, how the disease typically develops, chemical and biological control measures, and field management advice. The layer also supports open-ended plant protection Q&A, so users can describe symptoms in everyday language and receive a preliminary assessment.

    Large language model outputs carry a risk of hallucination. In production, answer quality should be controlled through prompt constraints, retrieval-augmented generation (injecting relevant snippets from a local plant protection knowledge base into the context), and filtering by confidence threshold. For low-confidence detection results, the system should label the result as “suspected, pending manual review” instead of giving a definitive conclusion.

    3. Business Service Layer

    The business backend uses the mature Java ecosystem, such as Spring Boot with MyBatis-Plus. It works together with the Python inference service. The Java side handles user authentication, permission management, task scheduling, data persistence, and report generation. The Python side focuses on model inference. The two services communicate through internal HTTP or RPC calls. Detection tasks are submitted asynchronously, so long-running inference does not block request threads. Data is stored in a relational database, and object storage is recommended for image files.

    4. Front-End Presentation Layer

    The front end is built with Vue 3 and TypeScript. It uses a component library and a charting library for the management interface. The core pages are the detection workspace (upload and real-time detection), history records, a statistics dashboard, a report center, and system management. ECharts generates visualizations automatically, including disease distribution, time trends, and confidence distribution. Detection results can be exported as PDF reports with one click, for archiving and for reporting up the chain of command.

    3. Key Design Points

    1. Unified Handling of Multiple Input Sources

    All input types are ultimately normalized into a frame sequence. The workflow is outlined below:

    1. def detect(source):
    2. frames = load_frames(source) # Normalize images, folders, videos, and camera feeds into frames
    3. results = []
    4. for frame in frames:
    5. boxes = model.infer(frame) # Detection boxes and class labels
    6. annotated = draw(frame, boxes)
    7. results.append(save(annotated, boxes))
    8. return aggregate(results)

    Real-time camera detection requires a streaming channel, for example one that pushes annotated frames over WebSocket. The front end renders those frames on a canvas to keep latency under control.

    2. Class System

    The solution covers several major economic crops with 37 label classes in total. Examples include:

    • Apple: black rot, scab, healthy
    • Corn: gray leaf spot, common rust, northern leaf blight, healthy
    • Rice: brown spot, blast, healthy
    • Tomato: bacterial spot, early blight, late blight, leaf mold, septoria leaf spot, healthy
    • Bell pepper, cassava, cherry, grape, citrus, peach, potato, and strawberry each have their own disease classes and a healthy class.

    Every crop includes a “healthy” class, which is important. It lets the model rule out abnormal conditions, so it does not classify every leaf as diseased. This reduces the false positive rate.

    3. Permissions and Multi-User Collaboration

    The system uses tiered permissions. Administrators manage users and view global statistics. Regular users can only access their own detection records, which isolates data at the user level. This fits multi-person collaboration in settings such as agricultural extension stations and planting bases, and it meets basic data security requirements. Permission checks should be enforced uniformly at the API layer. File uploads should be validated for type, size, and content, so that malicious files cannot enter the inference pipeline.

    4. Front-End Customization

    Users differ widely in visual preferences and operating habits. The front end supports custom theme colors, page layouts, and component sizes. These settings are saved to the user profile and loaded automatically at login, balancing appearance with efficiency.

    4. Deployment Recommendations and Optimization Directions

    1. Data. Training samples should cover lesions under different lighting conditions, viewing angles, and growth stages, and use data augmentation. After deployment, manually corrected samples should flow back into the training set to form a continuous improvement loop.
    2. Performance. Models can be exported to efficient inference formats and run with hardware acceleration. Batch jobs should use queues to smooth out peak load. Streaming output can be enabled for large language model responses to improve the user experience.
    3. Reliability. Detection tasks should use a state machine (queued, running inference, completed, failed), and failed tasks should be retryable. Critical operations should be recorded in audit logs.
    4. Trust. AI conclusions should be treated as decision support. Final treatment recommendations should keep an entry point for expert manual review, especially for pesticide recommendations, which must comply with local plant protection regulations.

    5. Summary

    Object detection handles precise visual inspection. The large language model handles professional interpretation. The business platform handles collaboration and data accumulation. Together, these three parts form a complete, deployable intelligent crop pest and disease diagnosis system. The architecture does not depend on vendor-specific proprietary capabilities. Its technology choices are common industry solutions, so developers can replace models, add crop categories, or connect to regional agricultural data platforms as needed. The system can then grow into a broader smart plant protection infrastructure.