A Collaborative Vision Model and LLM Architecture for Crop Disease and Pest Diagnosis

    This article presents a layered platform that combines a visual detection model with a general-purpose large language model for crop disease and pest diagnosis. It covers the problem background, a five-layer architecture, the data and fine-grained category system, the detection-to-language-model collaboration workflow, multi-source input and real-time pipelines, role-based access control and frontend configuration, statistics and reporting with observability, and practical rollout recommendations with clear operational boundaries.

    1. Problem Background and Solution Positioning

    Grassroots plant protection work faces three persistent pressures. First, sample sources are scattered: farmer photos, drone inspection videos, and fixed-camera snapshots all arrive in different formats. Second, disease categories are highly fine-grained, and lesion morphology on the same crop varies noticeably across growth stages. Third, diagnostic conclusions must be recorded and reported, while paper records are difficult to aggregate.

    A single image classification model can only output a category label; it cannot explain causes or recommend treatment. Relying solely on a general-purpose large language model, on the other hand, lacks precise perception of lesion locations in images. This solution therefore combines a visual detection model with a general-purpose large language model: the former handles “seeing,” and the latter handles “explaining,” forming an integrated platform that can run offline and support extensible consultation.

    It is worth emphasizing that the capabilities described here are combinations of common industry technical approaches and are not tied to any specific vendor product. Model selection can be replaced, where compliance allows, with equivalent open-source implementations or general-purpose cloud services, such as object storage, message queues, container platforms, logging services, and monitoring and alerting.

    2. Layered Architecture

    The platform is divided into five layers, top to bottom:

    1. Access layer: unified handling of images, batch folder packages, local videos, and live camera streams, with format normalization and frame-sampling scheduling.
    2. Inference layer: the visual detection service handles object localization and fine-grained classification, while the language model service handles consultation-style Q&A and treatment recommendation generation. The two are decoupled through a message queue so that long-text generation does not block the image pipeline.
    3. Business layer: task orchestration, sample management, report generation, and statistical aggregation.
    4. Data layer: a relational database stores users, tasks, and detection records; object storage holds raw materials and result images; a cache stores hot model metadata.
    5. Presentation layer: detection dashboards, batch task center, statistical charts, and report preview.

    The key benefit of layering is that visual inference can be deployed on edge or intranet compute nodes to guarantee offline availability, and the language model can switch on demand between local weights or a cloud general-purpose API, with no changes required in the business layer.

    3. Data and Category System

    The system covers multiple crop categories with 37 fine-grained classes in total, such as apple black rot and healthy, bacterial spot in bell pepper, cassava brown streak and mosaic virus, northern corn leaf blight and common rust in maize, citrus huanglongbing, rice blast and brown spot, angular leaf spot in strawberry, and leaf mold and target spot in tomato. Data governance recommendations:

    • Unified annotation standards: distinguish “whole-leaf level” boxes from “lesion level” boxes to avoid loss oscillation caused by inconsistent annotation granularity within the same directory.
    • Long-tail handling: healthy samples usually make up the majority, so resampling and class-weighted loss are used to mitigate bias.
    • Data augmentation: color jitter, random occlusion, and rotation and flipping simulate field lighting and leaf occlusion; excessive geometric deformation should be used cautiously to avoid destroying lesion texture.
    • Splitting strategy: split training and validation sets by collection batch rather than randomly, which better reflects real generalization evaluation.

    Illustrative training configuration:

    1. # Structure illustration only; parameters must be tuned based on the dataset
    2. train_cfg = {
    3. "img_size": 640,
    4. "batch": 16,
    5. "epochs": 120,
    6. "lr0": 0.01,
    7. "cos_lr": True,
    8. "mosaic": 1.0,
    9. "hsv_h": 0.015, "hsv_s": 0.7, "hsv_v": 0.4,
    10. }

    4. Collaboration Between Visual Detection and the Language Model

    The collaboration workflow has four steps: detection outputs the category, confidence, and box coordinates; low-confidence or cross-category confusable samples trigger a second cropped and enlarged re-check; the structured result (crop, suspected disease, confidence, affected part) is passed to the language model as prompt context; the language model returns readable cause analysis, control windows, and medication precautions, and explicitly states “for reference only; human review required.”

    Illustrative prompt construction:

    1. Crop: rice; suspected: rice blast (0.71); part: middle of leaf; environment: continuous rain.
    2. Please output: possible causes, field scouting points, non-chemical control measures, and medication compliance reminders.

    Engineering guardrails are mandatory: language model output must not replace pesticide registration labels or guidance from the local plant protection authority; questions beyond the 37 classes should be explicitly refused and escalated to a human.

    5. Multi-Source Input and Real-Time Pipeline

    Batch folder tasks use a producer-consumer model, with decoding, inference, and disk writing running as a parallel three-stage pipeline. Video and camera feeds use frame sampling plus time-window aggregation, with cross-frame voting on the same target to suppress jittery false positives. The backpressure strategy is a queue upper bound plus dropping the oldest frames, prioritizing real-time performance.

    1. // Simplified frame sampling and cross-frame voting logic
    2. if (frameIndex % sampleStep != 0) return;
    3. List<Box> boxes = detector.infer(frame);
    4. votes.merge(boxes, IoU_THRESHOLD); // cross-frame merge
    5. if (votes.confidence(id) > 0.6) emit(id);

    6. Permissions, Isolation, and Frontend Configuration

    The platform uses tiered permissions (admin, agronomist, read-only guest) and row-level data isolation. Each task is bound to its owning organization, and queries are forced to carry the tenant condition to prevent unauthorized access to other users’ samples. The frontend is built on a component-based framework and provides visual configuration of theme colors, layout grids, and component sizes. Once persisted, configuration items are distributed by role, balancing appearance with usability across different screens.

    7. Statistics, Reporting, and Observability

    On the statistics side, multi-dimensional aggregation is performed by crop, disease, time, and plot, and a charting library renders disease incidence trends and category distributions. On the reporting side, original images, annotation boxes, conclusions, and recommendations are rendered into a template and exported as PDF for archiving and aggregated reporting. On the operations side, logging services and monitoring alerts are integrated, with threshold alerts for inference latency, queue backlog, and model loading failures.

    8. Rollout Recommendations and Boundaries

    It is recommended to first close the loop on a single crop with a small number of categories, then expand the range step by step. Establish a human review feedback mechanism and incorporate corrections into incremental training. Make clear that model output is auxiliary, and final decisions are made by qualified agronomists.