Intelligent flower classification method based on lightweight cross-layer network structure

By using a lightweight, cross-layer network structure for intelligent flower classification, we have solved the problems of deployment difficulties and insufficient user interaction in existing systems on computing-limited devices. This method achieves efficient, multi-modal flower recognition, improving recognition accuracy and user experience.

CN120997578APending Publication Date: 2025-11-21CHANGZHOU UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511105942.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-08-08
Publication Date
2025-11-21

AI Technical Summary

Technical Problem

Existing flower classification systems have large model structures and a huge number of parameters, making them difficult to deploy in embedded devices or mobile terminals with limited computing power. They also lack the ability to continuously process long video streams or real-time camera video streams, resulting in insufficient user interaction and visualization capabilities, which affects recognition results and user experience.

Method used

It adopts a lightweight cross-layer network structure, including data normalization processing, image enhancement, and lightweight cross-layer network model construction. It combines encoder, bridging layer and decoder, uses cross-layer GCN-ViT fusion module and multi-head self-attention Transformer Encoder, supports multiple inference modes such as single image, batch image, pre-recorded video and real-time camera stream, and provides a visual interface and RESTful interface.

Benefits of technology

It achieves efficient operation in computing-constrained environments, supports multiple inference modes, improves recognition accuracy and user interaction experience, lowers the barrier to entry, and adapts to diverse needs in scientific research, teaching, agricultural production, and ecological monitoring.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120997578A_ABST
    Figure CN120997578A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of computer vision, pattern recognition and artificial intelligence, in particular to an intelligent flower classification method based on a lightweight cross-layer network structure for constructing the lightweight cross-layer network structure which comprises an encoder, a bridging layer and a decoder. In the bridging layer, flattening and position coding are firstly carried out on the deepest layer features in the encoder, and then the deepest layer features are sent into two layers of lightweight multi-head self-attention Transform Encoder to generate a global semantic sequence T; the decoder recovers the spatial resolution through the up-sampling module in sequence; after each level of up-sampling, a cross-layer GCN-ViT fusion module is firstly entered to obtain a fusion feature Ffuse, and then the fusion feature Ffuse is handed over to a decoding convolution dk for continuous processing; and finally, outputting a classification result through 1 * 1 convolution + Softmax. According to the method, the lightweight cross-layer network model is constructed, the calculation efficiency and deployment flexibility of flower identification are effectively improved, and the visual interaction experience of a user on the experiment process and result is remarkably enhanced.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of computer vision, pattern recognition and artificial intelligence, and particularly relates to a flower intelligent classification method based on a lightweight cross-layer network structure. BACKGROUND

[0002] With the rapid breakthroughs of computer vision and deep learning algorithms in the past few years, the use of image recognition technology for automatic classification and monitoring of plant varieties has become an important research direction in the fields of agricultural production, horticultural management and environmental protection. Especially the flower variety identification, not only can help flower breeding experts and producers to realize efficient variety screening, cultivation quality monitoring and pest warning, but also can provide real-time species census and health assessment for public gardens, plant exhibition halls and ecological protection areas. However, most of the existing flower classification systems mainly rely on classic convolutional neural network (CNN) models, which are often large in structure and huge in parameter quantity, requiring a large amount of computing power and storage resources, not only high in training cost, but also difficult to deploy and run in embedded devices or mobile terminals with limited computing power and energy consumption. In addition, most of the existing solutions can only perform one-time inference on a single static image, lack continuous processing capability for long video streams or real-time camera video streams, and cannot meet the real-time and continuous application scenarios of modern agriculture, horticultural field monitoring and intelligent inspection, which have high requirements. When trying to use these static recognition models directly for video or streaming media, not only is the delay high and the throughput low, but also there may be frame inconsistency, identification jitter and other problems, affecting the overall monitoring effect and experience. More importantly, most current research and products often ignore user interaction and visualization requirements at the functional implementation level, only providing some command line scripts or simple batch processing tools, lacking a friendly and intuitive graphical interface, and ordinary users need to understand complex parameter configurations in the use process, which is extremely unfriendly to non-professionals. The lack of visual interaction makes it difficult for researchers, gardeners and even ordinary observers to conveniently view the model inference process, adjust the identification threshold, analyze the identification results or export reports, thereby restricting the promotion and application of flower intelligent identification technology in a larger range.

[0003] Therefore, the market and academia urgently need to develop a lightweight yet highly accurate intelligent flower recognition system. This system should ensure efficient operation of the model in computationally limited environments (such as embedded devices and mobile terminals) while maintaining excellent recognition accuracy across various usage scenarios. More importantly, this system should support multiple inference modes, including single images, batch images, pre-recorded videos, and real-time camera streams. This is to meet the needs of researchers in the laboratory for batch processing of large-scale data samples, the real-time requirements for demonstration and interaction in higher education, the need for immediate feedback for flower enthusiasts and tourists when viewing or taking photos, and the reliability requirements for continuous, all-weather monitoring in agricultural production and ecological monitoring. Through modular design and a visual interface, users can not only flexibly switch between different inference modes but also intuitively configure parameters, view intermediate results, and generate reports, thereby significantly reducing the barrier to entry and enhancing the overall application value. Summary of the Invention

[0004] The present invention aims to solve one of the problems existing in the background art.

[0005] Therefore, this invention provides a flower intelligent classification method based on a lightweight cross-layer network structure.

[0006] The technical solution adopted by this invention to solve its technical problem is:

[0007] A flower intelligent classification method based on a lightweight cross-layer network structure includes,

[0008] Step 1: Data normalization and image enhancement;

[0009] Step two involves constructing a lightweight cross-layer network structure, including an encoder, a bridging layer, and a decoder. In the bridging layer, the deepest features from the encoder are first flattened and positionally encoded, then fed into a two-layer lightweight multi-head self-attention TransformerEncoder to generate a global semantic sequence T. The decoder sequentially restores spatial resolution through an upsampling module. After upsampling at each level, the sequence first enters a cross-layer GCN-ViT fusion module to obtain the fused features F. fused Then it is passed to the decoding convolution d k Continue processing; finally, output the classification result through 1×1 convolution + Softmax;

[0010] Step 3: Perform inference annotation on the image classification results, and then export and visualize them.

[0011] Furthermore, in step one, the file format and image size are standardized, the pixel values ​​are normalized, and the image brightness, contrast, saturation, and hue are adjusted independently.

[0012] Further, in the step two, the GCN branch in the cross-layer GCN-ViT fusion module converts the feature map into a graph structure, extracts local topological information based on graph convolution, and finally reconstructs the spatial features to be sent to the ViT branch for subsequent fusion.

[0013] Further, in the GCN branch, the feature map convolution operation is performed based on the adjacency matrix and the degree matrix: where A is the adjacency matrix, D is the degree matrix, F flat ∈R N×C is the flattened node feature matrix, W g ∈R C×C’ , b g are learnable parameters, σ is an activation function, and c' is the channel dimension of the output feature after convolution.

[0014] Further, G flat is reshaped into a feature map form for spatial shape reconstruction to form the spatial feature G = reshape(G flat , C' × H × W). The reshaped feature G recovers the position distribution of the graph convolution result in the two-dimensional image space.

[0015] Further, in the ViT branch, a multi-head self-attention mechanism is used to establish cross-layer interaction between Query→Key→Value, so that the current level of graph convolution feature is fused with the highest level of global context, and the reconstructed spatial feature T' is obtained.

[0016] Further, in the cross-layer multi-head attention mechanism: where W o ∈R c”×c” , c" is the projection back to the channel number, and after completing the multi-head attention calculation, the shape of the output tensor is: E ∈ R B×L×C″ , L = H × W. In order to be connected with the convolution operation later, it is necessary to remap the L tokens in the "sequence" form back to the H × W spatial pattern, that is, to reshape the tensor to T' ∈ R B ×C″×H×W .

[0017] Further, in the channel dimension, the GCN output G and the cross-layer attention output M are spliced, the channel number is reduced back to the original C through 1 × 1 convolution, and then the channel attention A C and the spatial attention A S of CBAM are applied in turn to remove redundant activations and highlight key areas, and finally the fusion feature F fused is generated.

[0018] Further, in the step three, the image inference includes static image inference and dynamic image inference, for the static image, one image is selected for preprocessing and sent to the loaded lightweight model for forward inference, then the detection frame and the variety label are superimposed on the original image, a result image with label is generated and saved as "original file name_result.jpg", and a JSON report with the same name is output, recording all detection frame coordinates, corresponding variety label and confidence, the client displays the labeled image and the prediction result in real time, and supports user saving or exporting.

[0019] Further, the dynamic image inference includes: the system automatically lists the local and USB camera device list, the user selects and clicks "start detection", the system captures the video stream at a maximum of 30fps, performs real-time inference and superimposes the detection frame and the label on the screen, and simultaneously dynamically outputs the statistical information of each frame in the log area, the system calls the model to detect and render the label by frame, and finally recombines the processed frame into a labeled video.

[0020] The application has the beneficial effects that the application constructs a lightweight cross-layer network model, the model adopts lightweight configuration, and adjacent pruning k-nearest neighbor and optional superpixel clustering are performed; cross-layer ViT reduces the number of heads or dimension; the channel after 1x1Conv can be reduced as needed; all new modules support switching, and different levels can be started according to performance / efficiency requirements. Thus, while improving IoU / precision, the overall parameters of the model are increased by ≤5%, and the inference time is increased by ≤10%.

[0021] Dynamic adjacent learning is performed in the GCN branch, and the adjacent weight is based on the Gaussian kernel of feature distance, and the automatically updated learnable parameter Only k-nearest neighbors (k≈8-16) are retained, and optional SLIC superpixel post-clustering is used to reduce the number of nodes, so as to capture irregular deformation, avoid uniform smoothing of fixed grid convolution, and make the edge details more sharp. Deepening the local topological feature expression through convolution operation improves the sensitivity to curved boundaries and winding structures. The cross-layer multi-head attention makes up for the lack of shallow semantic information, the Query comes from deeper or global fusion features, so that each level can "see" the global context; the Key / Value comes from the GCN output, so that the attention is focused on the structured area; the number of heads h can be set differently at each level (such as h=4 for the middle layer and h=2 for the shallow layer) to improve the recognition accuracy of small targets (such as flower stamens and flower bud tips). A layer-by-layer fusion strategy is used to insert Fusion at each level, rather than only at the Bottleneck; CBAM is performed after fusion to ensure channel / spatial double optimization; channel dimension reduction 1x1Conv ensures that the parameter growth is controllable (about +3%). It guarantees multi-level interaction of details and the whole, and avoids information bottleneck caused by single-level fusion. BRIEF DESCRIPTION OF DRAWINGS

[0022] The application will be further described below with reference to the accompanying drawings and examples.

[0023] Figure 1 is a schematic diagram of the implementation process of a flower intelligent classification method based on a lightweight cross-layer network structure in the application.

[0024] Figure 2 is a structural schematic diagram of a lightweight cross-layer network model in the application.

[0025] Figure 3 is a structural schematic diagram of an encoder in the lightweight cross-layer network model in the application.

[0026] Figure 4 is a structural schematic diagram of a bridging layer in the lightweight cross-layer network model in the application.

[0027] Figure 5 is a structural schematic diagram of a decoder in the lightweight cross-layer network model in the application.

[0028] Figure 6 is a structural schematic diagram of a Fusion k module in the application.

[0029] Figure 7 is a schematic diagram of static image reasoning of a flower intelligent classification system based on a lightweight cross-layer network structure in the application.

[0030] Figure 8 is a schematic diagram of dynamic image reasoning of a flower intelligent classification system based on a lightweight cross-layer network structure in the application. DETAILED DESCRIPTION

[0031] The application will now be described in further detail with reference to the accompanying drawings. These drawings are simplified schematic diagrams, and only illustrate the basic structure of the application in a schematic manner, and therefore only show the components related to the application.

[0032] In the description of the application, it should be understood that the terms "center", "longitudinal", "transverse", "length", "width", "thickness", "upper", "lower", "front", "rear", "left", "right", "vertical", "horizontal", "top", "bottom", "inner", "outer", "clockwise", "counterclockwise", "axial", "radial", "circumferential" and the like indicate the orientation or positional relationship based on the orientation or positional relationship shown in the drawings, and are only for the convenience of describing the application and simplifying the description, and therefore cannot be understood as indicating or implying that the devices or elements referred to must have a particular orientation, be constructed and operated in a particular orientation, and therefore cannot be understood as limiting the application. In addition, features limited as "first", "second" can explicitly or implicitly include one or more of the features. In the description of the application, unless otherwise stated, the meaning of "a plurality of" is two or more.

[0033] In the description of the present application, it should be noted that unless otherwise explicitly specified and limited, the terms "mounting", "connection", "connecting" should be understood broadly, for example, it can be fixed connection, or detachable connection, or integrally connected; it can be mechanical connection, or electrical connection; it can be directly connected, or indirectly connected through intermediate medium, or internal communication of two elements. For those skilled in the art, the specific meaning of the above terms in the present application can be understood according to the specific circumstances.

[0034] A flower intelligent classification system based on a lightweight cross-layer network structure, comprising a data preprocessing unit, a model training unit, an inference unit, a visualization interface unit and an external interface unit.

[0035] The data preprocessing unit is used to process the received image file data, unify the file data format, and unify the image size and pixel value, and perform enhancement processing on the image.

[0036] The model training unit is provided with a lightweight cross-layer network model, and the model training unit receives image file data from the data preprocessing unit, identifies image features using the lightweight cross-layer network model and classifies the image.

[0037] The inference unit performs image labeling based on the classification result of the model training unit and outputs the inference result. Four flexible usage modes are provided to meet the diversified needs from single sample identification to large-scale, real-time monitoring, etc.

[0038] Single image mode. In the desktop client, the user only needs to click the "load picture" button to select a flower image from the local file system; the system performs model forward inference on the image immediately, automatically identifies the flower bounding box and predicts the variety category and confidence; the inference result is superimposed on the original image to form a visual annotation image with detection box and label, and a structured JSON file containing detection box coordinates, category name and confidence value is generated in the background for user to save or subsequent analysis.

[0039] Batch mode. The user specifies a folder containing a large number of flower pictures in the client interface, and the system automatically starts multi-thread parallel processing task queue; the model inference is performed on each picture in sequence or in parallel to generate {original name}_result.jpg visual annotation image and corresponding {original name}.json prediction report; after all image processing is completed, the system automatically summarizes the prediction results of each single image to generate a unified report.csv (or report.json) batch statistical report, which contains the variety prediction, confidence and processing time of each image, etc. for user to perform batch analysis and performance evaluation.

[0040] Video mode. In the "Video Inference" interface, users can import video files in common formats such as.mp4,.avi, etc., and set the frame extraction rate (default 5 frames / second) and output resolution; the system extracts key frames at the specified frame rate, performs model inference on each frame, and draws detection boxes and label information onto the frame image; after completing the processing of all frames, the annotated frame sequence is recombined into an output video using OpenCVVideoWriter, and users can preview or export MP4 files in one click for popular science demonstration or monitoring playback.

[0041] Real-time mode. The system automatically scans and lists available local and USB camera devices, and users select the camera to be connected and the desired resolution in the interface; after starting detection, the system captures video streams in real time at a rate of up to 30 frames / second, and each frame is immediately sent to the model for processing; the inference results are displayed in real time in the form of a scrolling log on the side of the interface, while the detection boxes, category labels, and current frame confidence are overlaid on the video screen; users can dynamically adjust the confidence threshold and frame rate settings during the running process to achieve the best balance between speed and accuracy.

[0042] The above four modes are independent of each other and can be seamlessly switched, meeting the needs of one-time sample verification and large-scale offline batch processing, supporting pre-recorded video analysis and live monitoring, and covering various application scenarios such as scientific research, teaching, field inspection, and intelligent patrol.

[0043] Visual interface unit, connected with the inference unit, outputs the results. The present application builds a cross-platform desktop client based on Tkinter, modularly integrates user login / registration, project management, mode switching, parameter setting, and result display into a main window, adopts a tab(Tab) layout to ensure that users can intuitively switch between different modules and complete the entire operation process in one step. In the "Training Monitor" tab, the system real-time draws and updates the training loss and accuracy curves, and provides scaling and exporting functions; in the "Inference Statistics" tab, it dynamically displays the FPS(frame / second) curve and each batch processing duration distribution under different inference modes. The log panel below the curve chart records operation history, warnings, and error information, facilitating users to track the execution status. The "Export" button is set in the upper right corner of the client interface, and users can export the current view or all results in the following formats according to their needs: PNG format curve and annotated screenshot for teaching demonstration; JSON / CSV format report for batch data analysis; MP4 format video for popular science demonstration or monitoring playback. The visual interface not only improves the usability of the system, but also provides users with full-process monitoring and sharing capabilities.

[0044] The external interface unit is based on FastAPI to build a RESTful ` / predict / ` interface, supports multipart-form submission of pictures and returns the recognition result in JSON format; a Dockerfile and one-key deployment script are provided to simplify containerized deployment and version management. Specifically: the backend uses the FastAPI framework to build a standardized interface, providing / predict / POST services, supporting multiple calling methods: single image calling: the client or third-party system uploads a single image through HTTP multipart / form-data, and the server returns a JSON list containing detection box coordinates, variety labels and confidence; batch calling: support uploading multiple images in one request, or initiating multiple requests concurrently, the server automatically combines the results and returns a unified batch detection report; high concurrency optimization: the interface layer has built-in asynchronous queues and flow limiting strategies, which can dynamically adjust the maximum concurrency according to the deployment environment, ensuring low latency and high throughput during business peak periods; at the same time, the system is accompanied by Dockerfile, docker-compose configuration and deployment script, users only need to execute docker-compose up to complete the containerized deployment and automated operation and maintenance of the entire service.

[0045] The system has the following advantages: high model accuracy: Top-1 classification accuracy ≥ 92%, inference speed can reach more than 30fps; support multiple inference modes, wide coverage of scenarios; lightweight system, easy to deploy: friendly client interface, standard API interface; perfect visualization and report functions, convenient for user analysis and secondary development.

[0046] A flower intelligent classification method based on a lightweight cross-layer network structure, the system core adopts a lightweight cross-layer-Transformer-UNet model, which realizes fast inference while ensuring high-precision identification; and integrates single-image recognition, batch processing, video analysis and real-time camera four modes to adapt to laboratory batch data processing, popular science display, on-site monitoring and other diversified needs. In addition, the system provides a graphical desktop client based on Tkinter and a RESTful interface based on FastAPI, users can flexibly configure parameters and view recognition results in real time through the visual interface, or easily integrate into third-party applications through standard HTTP requests, significantly improving the overall ease of use and scalability. Specifically,

[0047] Step one, data preprocessing

[0048] After the system starts, the target data path is first obtained through the configuration file or user interface, and the specified local folder is automatically scanned recursively to identify all flower image files with suffixes.jpg,.jpeg and.png. For the scanned images, the system can automatically archive the images to the corresponding variety category directory according to the naming rules in the file name or the subfolder name, and generate an index mapping table in the background to facilitate subsequent batch management and statistics. Then, the following preprocessing procedures are performed on each image:

[0049] Uniform size adjustment: in the training stage, the short side is scaled to 256, and then randomly cropped to 224x224; in the verification / test stage, the short side is scaled to 256, and then center-cropped to 224x224.

[0050] Pixel value normalization: based on the RGB channel mean [0.485, 0.456, 0.406] and variance [0.229, 0.224, 0.225] of the ImageNet dataset, the pixel values are normalized to make images under different lighting and color conditions have comparable numerical ranges;

[0051] Data augmentation: in the training stage, the input image is first scaled to 256 pixels on the short side, and then randomly cropped to 224x224; then, with a probability of 50%, it is horizontally flipped, and independently color jittered by ±10% in brightness, contrast, saturation and hue. All augmentation operations are independent of each other to ensure the diversity of samples in shape, direction and color, effectively preventing overfitting and improving the generalization ability of the model in complex environments. In the verification / test stage, only scaling and center cropping are performed, without random augmentation.

[0052] Step 2, build a lightweight cross-layer network structure

[0053] The GraphCross-ViT U-Net network structure maintains the classic three-section layout of Encoder-Bridge-Decoder: Encoder-Bridge-Decoder. Specifically:

[0054] Encoder: the input image is processed by four levels of depthwise separable convolution (Depthwise Separable Conv) + CBAM attention module, and multi-scale features e1, e2, e3, e4 are extracted and downsampled.

[0055] Bottleneck: the deepest layer feature e4 is first flattened and position encoded, and then fed into two layers of lightweight multi-head self-attention Transformer Encoder to generate global semantic sequence T.

[0056] Decoder: Recover spatial resolution by upsampling modules Up4→Up3→Up2→Up1 sequentially; After each upsampling, instead of directly concatenating with the encoder features, the features first go through the “cross-layer GCN-ViT fusion module” (Fusionk) to obtain the fused features F fused , and then give it to the decoding convolution d k Continue processing; Finally, output the segmentation / classification result through 1x1 convolution + Softmax.

[0057] In this way, the decoding process of each level integrates local structure information and global context, making detail recovery and semantic understanding equally important.

[0058] S2.1 Cross-layer GCN-ViT fusion module (Fusion k module)

[0059] Before decoding at the k-th level, the Fusion k module receives two inputs: multi-scale features e k (shape CxHxW) from the k-th level output of the encoder and global semantic sequence T (shape BxLxC) generated by the bridging layer (or the fusion of the previous level). This module mainly consists of three steps:

[0060] S2.1.1 GCN branch: local topological structure modeling

[0061] In this module, we first convert the feature map into a graph structure, then extract local topological information based on graph convolution, and finally reconstruct it into spatial features for subsequent fusion.

[0062] Composition of the graph: Graph is composed of a node set and an edge set ε. Among them, the node definition: in this case, each pixel (or superpixel) of the feature map e k ∈R C×H×W is regarded as a node, with a total of N = HxW nodes; The meaning of the edge: the connection between nodes represents their similarity in feature space or image space, which is used to capture local structure.

[0063] Construct an adjacency matrix and a degree matrix, the adjacency matrix is used to represent which nodes are “adjacent” in the feature space and weighted, ensuring that graph convolution only propagates information in related areas; The degree matrix is used for normalization when graph convolution is performed to prevent numerical explosion or excessive smoothing caused by feature accumulation.

[0064] The adjacency matrix is represented as A, A ∈ R N×N , specifically,

[0065] where f i , f j are node features, k-neighbor of the ith node, The scale parameter is learnable.

[0066] The degree matrix is denoted as D, D ∈ R N×N , specifically, D ii = ∑ j A ij .

[0067] The feature map convolution operation is performed based on the adjacency matrix and the degree matrix:

[0068]

[0069] where F flat ∈ R N×C is the flattened node feature matrix, W g ∈ R C×C’ , b g are learnable parameters, σ is an activation function, which can be ReLU or GELU, and c' is the channel dimension of the output features after convolution (linear projection).

[0070] After convolution, information is aggregated, and each node "absorbs" features from its similar neighbors, strengthening local consistency; topological modeling is achieved, and the G flat after convolution contains the geometric and texture relationships between pixels or superpixels.

[0071] Reshape G flat back to the feature map form for spatial shape reconstruction, so that it can be fused with the output of the cross-layer ViT branch at the same spatial resolution:

[0072] G = reshape(G flat , C' × H × W)

[0073] The reshaped feature G restores the position distribution of the graph convolution result in the two-dimensional image space, allowing the subsequent fusion module to consider both local topology and global semantics.

[0074] S2.1.2 ViT branch: cross-layer global semantic injection

[0075] The global semantic sequence T with a size of B × L × C is output by the two-layer TransformerEncoder in the bridge layer, which encodes the flattening of the deepest layer e4 and is output after position encoding. Project the global sequence T as Query, denoted as Q, Q = T flat · W q , Project the flattened GCN output G as Key and Value, K = G flat · W k , V = G flat · Wv , (multi-head grouping can be h heads, each dimension d k =C" / h).

[0076] The multi-head self-attention mechanism is used to establish cross-layer interaction between Query→Key→Value, so that the graph convolution features of the current level are fused with the global context of the highest layer to obtain reconstructed spatial features T'.

[0077] In the cross-layer multi-head attention mechanism: where W o ∈R c”×c” , and c" is the number of projection channels.

[0078] After completing the multi-head attention calculation, the shape of the output tensor E is: E∈R B×L×c” , L=H×W, in order to interface with the subsequent convolution operation, it is necessary to remap the "sequence" form of L tokens back to the spatial pattern of H×W, that is, reshape the tensor to T'∈R B×c”×H×W .

[0079] In the tensor reshaping process, first call the dimension permutation permute(0,2,1) to move the channel dimension from the last dimension to the middle

[0080] Then use reshape(B,\,C”,\,H,\,W)(or equivalent view) to split the dimension of length L=H×W into height H and width W in row-major order:

[0081]

[0082] This does not change the element order in memory (contiguous), and also ensures that each sequence position (token) is one-to-one mapped with its corresponding spatial coordinates, providing the correct 2D feature map format for subsequent convolution or skip connection.

[0083] S2.1.3 Feature Fusion and CBAM Refinement

[0084] Concatenate GCN output G and cross-layer attention output M in the channel dimension, reduce the number of channels to the original C through 1×1 convolution, and then apply CBAM's channel attention A C and spatial attention A S in turn to remove redundant activations and highlight key areas, and finally generate fusion features F fused .

[0085] M=concat(G,T′,dim=channel)∈R (C′+C″)×H×W

[0086] U = Conv1x1(M, (C' + C") -> C) e R C×H×W

[0087] A c = sigma(MLP(Pool avg (U)) + MLP(Pool max (U)))

[0088] A s = sigma(f 7×7 ([Pool avg (U); Pool max (U)]))

[0089]

[0090] Pseudocode example:

[0091]

[0092]

[0093] S2.2 Optimization Strategy and Learning Rate Scheduling

[0094] The optimizer uses Adam combined with weight decay technology to enhance model generalization ability; the learning rate scheduling uses ReduceLROnPlateau, which reduces the learning rate by a preset ratio when the validation set index (such as Top-1 accuracy) does not improve for several rounds; the training process enables mixed precision (Mixed Precision) to switch between 16-bit and 32-bit modes to reduce memory usage, and the batch size is set to 16 by default, which can be adjusted flexibly according to the data size; during the training process, the performance is evaluated on the validation set every several epochs, and early stopping is triggered when the performance stops improving to save the current optimal model weight, ensuring that the optimal model is always called in the inference stage.

[0095] S2.3 Model Saving and Deployment Preparation

[0096] After training is completed, the system will automatically export the best weight file (.pth or.pt) to the specified directory and generate the corresponding model configuration file (such as network structure definition, normalization parameters, class mapping table, etc.). This automated export module ensures seamless integration of the model and inference code, allowing online inference units or external applications to directly load and call the trained lightweight model.

[0097] Step three, variety inference

[0098] S3.1 Static Image Inference

[0099] In the inference unit, the system provides both single-image mode and batch mode for offline inference. Referring to Figure 7 , in single-image mode, the user clicks "Load Image" in the client "Inference" module, selects a local single flower image, the system pre-processes the image and sends it to the loaded lightweight model for forward inference, then superimposes the detection box and variety label on the original image, generates a labeled result image and saves it as "Original filename_result.jpg", and outputs a JSON report with the same name, recording all detection box coordinates, corresponding variety label and confidence. The client instantly displays the labeled image and prediction results, supporting user saving or exporting; in batch mode, the user specifies a folder containing multiple images, the system automatically scans all JPG / JPEG / PNG files, starts multi-threaded parallel processing, and each image completes preprocessing and model inference in turn, and outputs "Original filename_result.jpg" and the corresponding JSON report. After all reports are processed, a batch statistical report is also generated, containing file name, predicted variety, confidence and processing time, etc. The client displays the overall progress and time, and provides a package download function to facilitate users to obtain all labeled images, reports and summary forms at once.

[0100] S3.2 Dynamic video real-time inference

[0101] Referring to Figure 8 , video mode: the user imports.mp4 or.avi video, sets the frame rate (default 5fps) and output resolution, the system calls the model for detection and rendering of annotations frame by frame, and finally uses OpenCV VideoWriter to recombine the processed frames into an annotated video, which can be previewed on the client or saved as an MP4 file, as shown in the (a) subgraph of Figure 8 ; real-time mode: the system automatically lists local and USB camera device lists, the user selects and clicks "Start detection", the system captures video stream at a maximum of 30fps, real-time inference and superimposes detection boxes and labels on the screen, as shown in the (b) subgraph of Figure 8 , while dynamically outputting per-frame statistical information in the log area, and supporting user online adjustment of confidence threshold or switching of resolution.

[0102] Step four, visualization and export

[0103] In the "Result Visualization" tab, the user can view the loss and accuracy curves during training, as well as the FPS statistics chart and per-batch latency distribution chart of the current inference session at any time. Click the "Export" button, the system can export: the current curve and visualized labeled image as PNG format; batch recognition report saved as JSON or CSV file; processed video one-key generated MP4 and packaged for download.

[0104] In summary, the system core adopts a lightweight cross-layer network model, ensuring high-precision recognition while achieving fast inference. It integrates single-image recognition, batch processing, video analysis, and real-time camera modes to adapt to various needs such as laboratory batch data processing, popular science display, and on-site monitoring. In addition, the system provides a graphical desktop client based on Tkinter and a RESTful interface based on FastAPI. Users can flexibly configure parameters, view real-time recognition results through the visual interface, or easily integrate into third-party applications through standard HTTP requests, significantly improving overall ease of use and scalability.

[0105] This system not only processes static single images but also supports multi-mode inference of batch images, pre-recorded videos, and real-time camera streams, widely applicable to scenarios such as horticultural variety management, agricultural pest monitoring, ecological environment assessment, and online education and research platforms. By introducing image preprocessing modules, CBAM-Transformer-UNet models, and visual client and RESTful service interfaces, the invention effectively improves the computational efficiency and deployment flexibility of flower recognition and significantly enhances the user's visual interaction experience with the experimental process and results.

[0106] This application constructs a lightweight cross-layer network model, which adopts lightweight configuration, and through adjacent pruning k-nearest neighbors and optional superpixel clustering, cross-layer ViT head reduction or dimensionality reduction, 1x1Conv channel can be adjusted as needed, and all new modules support switching, and the downstream can start different levels according to performance / efficiency requirements. Thus, while improving IoU / precision, the overall model parameters are increased by ≤5%, and the inference time is increased by ≤10%.

[0107] Dynamic adjacency learning is performed in the GCN branch, and the adjacency weight is based on the Gaussian kernel of the feature distance, with automatic updating of the learnable parameters Only k neighbors (k ≈ 8-16) are retained, and the node number of clustering dimension reduction after optional SLIC superpixel is reduced, so as to capture irregular deformation, avoid uniform smoothing of fixed grid convolution, and make edge details more sharp. Convolution operation deepens the expression of local topological features and improves the sensitivity to curved boundaries and winding structures. Cross-layer multi-head attention makes up for the lack of shallow semantic information, the Query comes from deeper or globally fused features, so that each level can "see" the global context; the Key / Value comes from the GCN output, improving the attention focus on structured areas; the number of heads h can be set differently at each level (such as h = 4 for the middle layer and h = 2 for the shallow layer) to improve the recognition accuracy of small targets (such as flower stamens and flower bud tips). A layer-by-layer fusion strategy is used to insert Fusion at each level, rather than only at the Bottleneck; CBAM is performed after fusion to ensure dual optimization of channels and space; channel dimension reduction 1x1Conv ensures that parameter growth is controllable (about +3% or so). It ensures multi-level interaction between details and the whole, and avoids information bottlenecks caused by single-level fusion.

[0108] Based on the above ideal embodiments according to the present application, through the above description, relevant personnel can make various changes and modifications without deviating from the technical idea of the present application. The technical scope of the present application is not limited to the contents of the specification, and must be determined by the scope of the claims.

Claims

1. A flower intelligent classification method based on a lightweight cross-layer network structure, characterized in that, Comprising, Step one, data normalization processing and image enhancement; Step two, construct a lightweight cross-layer network structure, including an encoder, a bridge layer, and a decoder, the bridge layer first flattens and position encodes the deepest layer of features in the encoder, then sends it to two layers of lightweight multi-head self-attention TransformerEncoder to generate global semantic sequence T; the decoder restores the spatial resolution through the upsampling module in turn; after each upsampling, first enter the cross-layer GCN-ViT fusion module to obtain the fusion features F fused , and then give it to the decoding convolution d k Continue processing; finally output the classification result through 1x1 convolution + Softmax; Step three, reasoning annotation of image classification results, and export, visualization display. 2.The flower intelligent classification method based on the lightweight cross-layer network structure according to claim 1, characterized in that, In the step one, the unified file format, image size, pixel value normalization, and independent adjustment of image brightness, contrast, saturation and hue are performed. 3.The flower intelligent classification method based on the lightweight cross-layer network structure according to claim 1, characterized in that, In the step two, the GCN branch in the cross-layer GCN-ViT fusion module converts the feature map into a graph structure, extracts local topological information based on graph convolution, and finally reconstructs the spatial features to the ViT branch for subsequent fusion.

4. The flower intelligent classification method based on the lightweight cross-layer network structure according to claim 3, characterized in that, The feature map convolution operation is performed based on an adjacency matrix and a degree matrix in the GCN branch: Wherein, A is an adjacency matrix, D is a degree matrix, F flat ∈R N×C is a flattened node feature matrix, W g ∈R C×C’ , b g are learnable parameters, σ is an activation function, and C' is a channel dimension of the output feature after convolution.

5. The method according to claim 4, wherein, G flat Reshape back to feature map form to reshape the spatial shape to form spatial features G = reshape(G flat , C' x H x W), the reshaped features G restores the location distribution of the graph convolution result in the two-dimensional image space. 6.The flower intelligent classification method based on the lightweight cross-layer network structure according to claim 5, characterized in that, In the ViT branch, the multi-head self-attention mechanism is used to establish cross-layer interaction between Query→Key→Value, so that the current level of graph convolution feature fusion is combined with the highest level of global context to obtain the reconstructed spatial feature T'.

7. The method according to claim 6, wherein, In the cross-layer multi-head attention mechanism: where W o ∈R c”×c” , c” is the number of projection channels, and the shape of the output tensor after completing the multi-head attention calculation is: E∈R B×L×C″ , L = H x W. In order to be connected with the subsequent convolution operation, it is necessary to remap the L tokens in the form of "sequence" back to the spatial pattern of H x W, that is, to reshape the tensor as T'∈R B×C″×H×W .

8. The method according to claim 7, wherein, Concatenate GCN output G and cross-layer attention output M in channel dimension, reduce the channel number back to the original C through 1x1 convolution, and then apply the channel attention A of CBAM in turn C With spatial attention A S , remove redundant activations and highlight key regions, and finally generate fusion features F fused . 9.The flower intelligent classification method based on the lightweight cross-layer network structure according to claim 1, characterized in that, In the step three, image reasoning includes static image reasoning and dynamic image reasoning. For static images, a selected image is preprocessed and fed into the loaded lightweight model for forward reasoning. Then the detection box and variety label are superimposed on the original image to generate a labeled result image and save it as "original file name_result.jpg". At the same time, a JSON report with the same name is output, recording all detection box coordinates, corresponding variety label and confidence. The client instantly displays the annotated image and prediction results, supporting user saving or exporting.

10. The method according to claim 9, wherein, The dynamic image reasoning includes: the system automatically lists the local and USB camera device list, the user selects and clicks "start detection", the system captures video stream at the highest 30fps, performs real-time reasoning and superimposes detection box and label on the screen, while dynamically outputting each frame statistical information in the log area. The system calls the model for detection and rendering of labels by frame, and finally recombines the processed frames into a labeled video.