A method for detecting out-of-distribution patterns in few-sample pathological images based on a basic model
By constructing a virtual ID feature set and synthesizing boundary-aware virtual OOD features, and combining a multi-source information fusion scoring strategy, the problem of unstable OOD detection performance in pathological image analysis is solved, and efficient and reliable out-of-distribution detection of pathological images is achieved under conditions of few samples.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- QILU UNIVERSITY OF TECHNOLOGY (SHANDONG ACADEMY OF SCIENCES)
- Filing Date
- 2026-07-02
- Publication Date
- 2026-07-31
AI Technical Summary
Existing technologies in pathological image analysis face the challenge of effectively identifying out-of-distribution (OOD) samples under limited sample conditions, leading to the risk of misdiagnosis. Furthermore, existing methods rely on large amounts of labeled data or directly use raw limited sample features, resulting in blurred decision boundaries and making it difficult to meet the reliability requirements of clinical AI systems.
By constructing a virtual ID feature set and designing a boundary-aware virtual OOD feature synthesis and optimization mechanism, combined with a multi-source information fusion scoring strategy, and utilizing basic models such as CONCH, the distributed representation is expanded and the decision boundary is explicitly modeled, thereby improving OOD detection performance.
In the analysis of few-sample pathological images, the performance stability and reliability of OOD detection have been improved, providing a safe and reliable technical solution for clinical AI-assisted diagnostic systems, and significantly improving detection accuracy and false alarm rate control.
Smart Images

Figure CN122492707A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the technical field of out-of-distribution detection, and more specifically, relates to a method for out-of-distribution detection of few-sample pathological images based on a basic model. Background Technology
[0002] In digital pathology diagnosis, model deployment often faces the problem of inconsistency between the distribution of input images and training data. Actual pathological slides are easily affected by staining batches, scanning equipment, or tissue processing procedures, leading to covariate shifts such as color and contrast. Simultaneously, new diseases not encountered during the training phase may be encountered in clinical practice, constituting semantic shifts. These two types of shifts often coexist, making it difficult to effectively identify out-of-distribution (OOD) samples. If the model still outputs high-confidence predictions for such samples, it will lead to the risk of misdiagnosis. Most existing OOD detection methods are validated on natural images, assuming relatively simple shift forms and relying on a large amount of labeled data to model a normal distribution.
[0003] Chinese patent document CN120744746A discloses a robust out-of-distribution detection method based on adversarial virtual outliers. The method includes collecting and preprocessing in-distribution data to obtain a reliable in-distribution dataset; using adversarial training to obtain a robust feature extractor, inputting all in-distribution datasets after adversarial propagation into the robust feature extractor to obtain an in-distribution robust feature set; obtaining boundary points of the in-distribution data, and sampling virtual out-of-distribution data points in the low-likelihood regions surrounding these boundary points; logit normalizing and training a neural ODE module; passing the input data through the robust feature extractor, the neural ODE module, and the out-of-distribution detection module, and using the maximum softmax confidence score as the out-of-distribution detection score to distinguish between in-distribution and out-of-distribution samples.
[0004] However, in pathological scenarios, new categories typically have only a very small number of labeled samples (e.g., 1–5 cases per category), making it difficult for traditional methods to stably estimate distribution boundaries. Some works have attempted to introduce general-purpose large-scale visual models (such as CLIP) for few-sample detection, but their OOD discrimination performance is limited due to the lack of pathological specificity in their pre-training data and insufficient modeling of key features such as cell structure and tissue morphology. In contrast, foundational models customized for the pathology domain (such as CONCH) have learned semantic representations highly relevant to medical tasks through pre-training on large-scale pathological images and texts, exhibiting stronger feature discrimination capabilities under few-sample conditions. However, there is currently a lack of OOD detection methods that can effectively utilize the prior knowledge of such specialized models and are specifically designed for the complex offset characteristics of pathological images. Summary of the Invention
[0005] This invention aims to overcome at least one of the defects of the prior art and provide a method for out-of-distribution detection of pathological images based on a basic model. In real-world scenarios where pathological image annotation data is extremely scarce, this method utilizes existing pathological basic models (such as CONCH) to improve out-of-distribution detection. This addresses the problem that existing methods either rely on a large amount of annotation data or directly use raw few-sample features for detection, resulting in blurred decision boundaries, inaccurate discrimination of OOD samples, and difficulty in meeting the reliability requirements of clinical AI systems.
[0006] The detailed technical solution of this invention is as follows: A method for detecting out-of-distribution patterns in few-sample pathological images based on a base model, the method comprising: S1. Obtain publicly available pathological image data of different types of distribution offset scenes to form the original dataset, and divide it into the original training set and the original test set; S2. Generate enhanced views from the original samples in the original training set using a strong augmentation strategy. Then, input them into the visual base model to extract high-dimensional feature vectors and perform L2 normalization. After obtaining the corresponding candidate virtual ID features, perform feature filtering to form a virtual ID feature set. S3. Input the original samples from the original training set into the visual base model and perform L2 normalization to obtain the original ID feature set; calculate the k nearest neighbor distance of each feature in the original ID feature set to the original ID feature set, and select the Top-K features with the largest distance values as the boundary sample set. For each boundary sample, an isotropic Gaussian perturbation is applied in its local neighborhood to generate multiple virtual OOD candidate features. The virtual OOD candidate features are iteratively optimized using the gradient descent method to obtain the optimized virtual OOD features, which constitute the virtual OOD feature set. S4. Based on the original test set, input the test image to be detected into the visual base model, extract its original feature vector, and perform L2 normalization to obtain the normalized query features. Then, the test image to be detected is scored based on the distances from the query features to the original ID feature set, the distances to the virtual ID feature set, and the distances to the virtual OOD feature set.
[0007] Furthermore, S2 specifically includes: S21, Original Training Set A small sample of pathological images from C known categories are used for subsequent ID feature construction, where each category contains K labeled original samples. ; Original sample The input is fed into the pre-trained visual base model VFM and processed by the built-in feature extraction function. Forward propagation is performed to extract high-dimensional feature vectors, and L2 normalization is then applied to obtain the normalized original features. This is used to construct a normalized original ID feature set. ; Then based on the original ID feature set Calculate each category The characteristic prototype, i.e., the characteristic centroid ; S22, For the original training set of few sample pathological images Each original sample in Apply a stochastic enhancement strategy consisting of random combinations of various basic image transformations. ,generate Enhanced view ; The generated enhanced view will then be Input to the visual base model Then, L2 normalization is performed to obtain the corresponding candidate virtual ID features. ; S23. Regarding the candidate virtual ID features Implement a dual filtering mechanism to ensure semantic fidelity: One method is prototype similarity filtering, which calculates the features of candidate virtual IDs. Its category prototype The cosine similarity, or inner product, is only valid if a threshold condition is met: (1) Only items that meet the requirements will be retained; items that do not meet the requirements will be removed. S24. Second, density filtering within the distribution further ensures the characteristics of candidate virtual IDs. High-density regions located within the original distribution are introduced Nearest neighbor distance measures its local density; First, define the input features to be judged as: candidate virtual ID features generated by a strong data augmentation strategy and filtered by prototype similarity. Calculate input features Compared to the original ID feature set of Nearest neighbor distance for: (2) In formula (2), Representation of feature set Mid-range features Recent A set of eigenvectors Represents the L2 norm; Then select The distance value of the first Percentile as density threshold ; Finally, the candidate virtual ID features that have passed the prototype similarity filtering are analyzed. It will only be retained if it meets the following density determination criteria: (3) This ensures that it is within the core support domain of the ID distribution.
[0008] In summary, through the collaborative screening of the above dual filtering mechanisms, a virtual ID feature set is finally constructed. Its definition is as follows: (4) This feature set effectively expands the feature space covered by the original few samples while maintaining the semantic fidelity of the categories, providing a discriminative in-distribution prior for subsequent OOD detection tasks.
[0009] Furthermore, the basic image transformation includes random grayscale conversion, color dithering, and horizontal flipping.
[0010] Furthermore, S3 specifically includes: S31. For the original ID feature set Each feature in Calculate its to k-nearest neighbor distance Defined as: (5) In formula (5), Indicates in Zhongyu Recent Of the neighbors, the one furthest away is... The Euclidean distance. This distance reflects the "outlierness" of the feature within the distribution.
[0011] S32, Select all The top-K features with the largest values are used as the boundary sample set. This set represents the marginal region of the original ID distribution and is a key location for distinguishing IDs from OODs.
[0012] Secondly, for each boundary sample An isotropic Gaussian perturbation is applied within its local neighborhood to generate virtual OOD candidate features.
[0013] Furthermore, the specific steps for generating virtual OOD candidate features are as follows: For the boundary samples ,generate The candidate features, of which the first one is the 1st candidate feature. Virtual OOD candidate features ,in =1, 2, ..., : (6) In formula (6), To control the hyperparameters of the disturbance amplitude, This is a noise vector sampled from a standard normal distribution. for The identity matrix, and all generated virtual OOD candidate features constitute the initial set. This is used as input for subsequent optimization.
[0014] S33. To enhance the diversity among virtual OOD features and prevent them from being overly concentrated in a small area, a diversity loss is introduced. Its objective is to minimize the feature matrix composed of the virtual OOD candidate features. Average similarity of diagonal elements between China and Africa: (7) In formula (7), Its similarity matrix, elements Corresponding to the The and the first A virtual Cosine similarity of features (since all features are L2 normalized).
[0015] S34. To ensure that the generated virtual OOD features can be accurately located near the decision boundary of the ID data, thereby achieving boundary awareness, a contrastive loss is introduced. This loss forces the similarity between any virtual OOD feature and any ID feature to fall within a predefined target range. Inside, among which An adjustable lower bound is defined: the contrast loss is defined using a hinged loss form. (8) In formula (8), For the number of categories, The number of training samples for each class, Number of virtual OOD features. Loss term. Defined as: (9) In formula (9): (10) The ID feature matrix With virtual OOD feature matrix The similarity matrix between them; in this matrix, Representing the The ID feature and the first Cosine similarity between virtual OOD features. For ID features, This is a transpose of the virtual OOD feature.
[0016] Constructing a set of virtual OOD features Optimization objective function It consists of diversity loss and contrast loss: (11) Virtual OOD feature set is analyzed using gradient descent method. Perform iterative optimization to minimize This allows the optimized virtual OOD features (boundary-aware virtual OOD features) to have good internal diversity and maintain a reasonable similarity interval with ID features, thereby more effectively calibrating the ID / OOD decision boundary.
[0017] Furthermore, S4 specifically includes: The test images to be detected are based on the original test set. The input is fed into the visual base model to extract its original feature vector. Then, L2 normalization is performed to obtain normalized query features. Then, calculate its k-nearest neighbor distances to the following three reference feature sets: Distance 1: Distance to the original ID feature set: (12) in The feature set within the original distribution; Distance 2: Distance to the virtual ID feature set: (13) in This is a set of virtual ID features generated through a dual filtering mechanism; Distance 3: Distance to the virtual OOD feature set: (14) in This is the virtual OOD feature set after joint optimization using diversity and contrast loss; The three types of distances mentioned above together constitute the criteria for multi-source discrimination, reflecting the positional relationship of query samples in different feature spaces.
[0018] Based on the three distances mentioned above, the final OOD score is defined as follows: (15) In formula (15), the negative sign reflects the inverse relationship of "ID likelihood": If the query sample is in the feature space when ≤ When the sample to be tested tends to be within the distribution, it is determined to belong to the normal pathological category; when > When the sample to be tested tends to be outside the distribution, it is determined to be an abnormal sample; a scoring threshold is set. The scoring threshold is a constant pre-set based on the validation set data. It is usually calculated by taking different values on the validation set, such as maximizing the precision when AUROC is maximized or fixing FPR95, and then selecting the value that makes the discrimination effect optimal as the threshold.
[0019] In another aspect of the invention, an electronic device is also provided, comprising: At least one processor; and The memory stores instructions that, when executed by the at least one processor, cause the at least one processor to perform a method for detecting out-of-distribution distributions of few-sample pathological images based on a base model as described above.
[0020] In another aspect of the invention, a computer-readable storage medium is also provided, which stores executable instructions that, when executed, cause the machine to perform a method for detecting out-of-distribution distributions of few-sample pathological images based on a base model as described above.
[0021] Compared with the prior art, the beneficial effects of the present invention are as follows: This invention provides a method for out-of-distribution (OOD) detection in few-sample pathological images based on a fundamental model. By constructing a virtual ID feature set to expand the in-distribution representation, and innovatively designing a boundary-aware virtual OOD feature synthesis and optimization mechanism to explicitly model the decision boundary, combined with a multi-source information fusion scoring strategy, this method solves the problems of unstable performance and poor reliability of out-of-distribution (OOD) detection caused by data distribution shift in few-sample pathological image analysis, as well as the difficulty of existing methods in effectively utilizing the prior knowledge of the fundamental model. This provides an efficient and practical technical solution for deploying safe and reliable AI-assisted diagnostic systems in clinical practice. Attached Figure Description
[0022] Figure 1 This is a schematic diagram of the out-of-distribution detection method described in this invention.
[0023] Figure 2It is a schematic diagram of the virtual ID feature synthesis process in Embodiment 1 of the present invention.
[0024] Figure 3 It is a schematic diagram of the boundary-aware virtual OOD feature synthesis process in Embodiment 1 of the present invention.
[0025] Figure 4 It is a schematic diagram of the scoring mechanism based on a multi-source reference set in Embodiment 1 of the present invention. Detailed implementation manners
[0026] The present invention will be further described below in conjunction with the accompanying drawings and embodiments.
[0027] It should be noted that the following detailed description is exemplary and intended to provide further illustration of the present invention. Unless otherwise specified, all technical and scientific terms used herein have the same meaning as commonly understood by those of ordinary skill in the technical field to which the present invention belongs.
[0028] It should be noted that the terms used herein are only for describing specific implementation manners and are not intended to limit the exemplary embodiments according to the present invention. As used herein, unless the context clearly indicates otherwise, the singular form is also intended to include the plural form. In addition, it should be understood that when the terms "comprising" and / or "including" are used in this specification, they indicate the presence of features, steps, operations, devices, components, and / or combinations thereof.
[0029] In the case of no conflict, the embodiments in the present invention and the features in the embodiments can be combined with each other.
[0030] Embodiment 1 Refer Figure 1 , this embodiment provides a few-shot pathological image out-of-distribution detection method based on a base model, and the method includes: S1. Obtain public pathological image data covering different types of distribution shift scenarios to form an original data set, and divide it into an original training set and an original test set.
[0031] Data preparation: To verify the effectiveness and robustness of the method of the present invention, experimental evaluations were carried out on multiple representative public pathological image data sets, covering different types of distribution shift scenarios, including semantic shift (unknown disease categories).
[0032] Specifically, the data sets used include: NCT-CRC: It contains pathological images of 9 types of H&E-stained colorectal tissue types, and is used to evaluate near / far OOD detection at the semantic level; BreakHis: It contains 40x magnified pathological images of 8 breast cancer subtypes, and is used to evaluate OOD recognition under fine-grained classification; MIDOG consists of 503 full-slice H&E images, covering 10 different imaging domains, and includes covariate shifts (such as staining and device differences) and semantic shifts, used to comprehensively evaluate the model's cross-domain robustness. Skin Tissue Dataset: Contains images of 16 skin tissue patches, with melanoma and basal cell carcinoma (BCC) as known categories (IDs) and the remaining 14 as unknown OOD categories, used to simulate the scenario of distinguishing between rare and common diseases in clinical practice.
[0033] All experiments were conducted under a uniform few-sample setting (16 training samples per class by default). The results show that the method of the present invention can stably improve the OOD detection performance on the above-mentioned diverse pathological datasets, proving that it has good applicability and generalization ability in real clinical environments.
[0034] S2. Virtual ID Feature Synthesis (including candidate generation and dual filtering): Based on the original dataset, a small number of pathological images with multiple categories are obtained as the original training set. An enhanced view input visual base model is generated through a strong augmentation strategy and L2 normalization is performed to obtain the corresponding candidate virtual ID features. After feature selection, a virtual ID feature set is formed. A dual filtering mechanism is used to select high-quality candidate samples that meet the requirements of semantic consistency and distribution density. Finally, a virtual ID feature set with good robustness is constructed.
[0035] Specifically, the virtual ID feature synthesis is as follows: Figure 2 As shown, it specifically includes: S21, Original Training Set A small sample of pathological images from C known categories are used for subsequent ID feature construction, where each category contains K labeled original samples. ; Then, the original sample The input is fed into a pre-trained Vision Foundation Model (VFM) and processed through a built-in feature extraction function. Perform forward propagation to extract high-dimensional feature vectors and then perform L2 normalization to obtain the normalized original ID feature set. Each original sample in the training set Normalized original features obtained by extracting from the visual basic model VFM and performing L2 normalization constitute.
[0036] Specifically, for any original sample Its normalized original characteristics It can be represented as: (16) In formula (16), The original feature vector output by the visual base model. This represents the L2 norm; by dividing it by its own norm, the feature vector can be mapped onto the unit hypersphere, thereby eliminating the influence of the absolute numerical magnitude of the features on subsequent similarity calculations and ensuring the semantic purity of subsequent feature comparisons.
[0037] Next, to ensure semantic consistency of subsequent synthesized samples, based on the original ID feature set... Calculate each category The feature prototype (i.e., the feature centroid) : , (17) In formula (17), Indicates the sample index. Original sample Corresponding category tags, This represents the set of sample indices for category c. This indicates that the original training set belongs to category The sample index set.
[0038] S22. First, for each original training set of pathological images from a small sample... The original samples Apply a stochastic enhancement strategy consisting of random combinations of various basic image transformations. ,generate Enhanced view Preferably, the basic image transformations include, but are not limited to, random grayscale conversion, color jitter, and horizontal flipping.
[0039] Subsequently, the generated enhanced view The input is fed into the aforementioned Visual Foundation Model (VFM) and processed through its feature extraction function. Then, L2 normalization is performed to obtain the corresponding candidate virtual ID features. This step aims to effectively expand the feature space covered by the original small sample size by simulating staining differences and imaging perspective changes in clinical scenarios.
[0040] S23. To prevent over-enhancement from causing the generated samples to deviate from the true distribution, the candidate virtual ID features need to be adjusted. Implement a dual filtering mechanism to ensure semantic fidelity: compute candidate virtual ID features Its category prototype The cosine similarity (i.e., inner product) is only valid if the threshold condition is met. (1) Only samples that meet the criteria are retained; those that do not are discarded. This filtering mechanism effectively excludes invalid samples with semantic shifts.
[0041] Secondly, the features of the enhanced view are extracted, and the pre-calculated feature prototypes are used. Samples with large semantic offsets are removed by prototype similarity filtering (FPS) to ensure the quality of virtual ID features.
[0042] S24. To further ensure the characteristics of candidate virtual IDs High-density regions located within the original distribution (In-Distribution, ID) are introduced. Neighbors ( -Nearest Neighbor, -NN) distance metric to measure its local density. First, define the input features to be judged as the candidate virtual ID features generated above. ) is to calculate this feature. Compared to the original ID feature set k-nearest neighbor distance for: (2) In formula (2), Representation of feature set Mid-range features Recent A set of eigenvectors This represents the L2 norm.
[0043] Here, the original ID feature set ,in This represents the total number of known classes in the training set. This indicates the number of labeled samples corresponding to each category. It is the set of original feature vectors obtained by extracting and normalizing all the original few-sample pathological images in the aforementioned steps; then, each original feature in the original ID feature set is calculated. to the set itself Nearest neighbor distance And select the first of these distance values Percentiles (in this embodiment, A value of 90 was used as the density threshold. ; Finally, the candidate virtual ID features that have passed the prototype similarity filter (FPS) are analyzed. It will only be retained if it meets the following density determination criteria: (3) This ensures that it is within the core support domain of the ID distribution.
[0044] In summary, through the synergistic screening of the aforementioned dual filtering mechanism (i.e., prototype similarity filtering and intra-distribution density filtering), a virtual ID feature set is finally constructed. Its definition is as follows: (4) This feature set effectively expands the feature space covered by the original few samples while maintaining the semantic fidelity of the categories, providing a discriminative in-distribution prior for subsequent OOD detection tasks.
[0045] S3 boundary-aware virtual OOD feature synthesis inputs the original samples from the original training set into the visual base model and performs L2 normalization to obtain the original ID feature set; for each feature in the original ID feature set, calculates its k nearest neighbor distance to the original ID feature set, and selects the Top-K features with the largest distance values as the boundary sample set. For each boundary sample, an isotropic Gaussian perturbation is applied to its local neighborhood to generate multiple virtual OOD candidate features. These virtual OOD candidate features are then iteratively optimized using gradient descent to obtain the optimized virtual OOD features, which constitute the virtual OOD feature set. Figure 3 As shown; specifically including: S31. First, for the original ID feature set Each feature in Calculate its to k-nearest neighbor distance Defined as: (5) Specifically, in practice, for each feature in the training set... ∈ The above distance calculations are performed iteratively to assess the "outlierness" of each original feature within its distribution.
[0046] In formula (5), Indicates in Zhongyu Recent Of the neighbors, the one furthest away is... The Euclidean distance. This distance reflects the "outlierness" of the feature within the distribution.
[0047] S32. Next, select all The top-K features with the largest values are used as the boundary sample set. This set represents the marginal region of the original ID distribution and is a key location for distinguishing IDs from OODs.
[0048] Secondly, for each boundary sample An isotropic Gaussian perturbation is applied within its local neighborhood to generate multiple virtual OOD candidate features. Specifically, for the ... boundary samples ,generate The candidate features, of which the first one is the 1st candidate feature. Virtual OOD candidate features (in =1, 2, ..., The formula for calculating ) is defined as follows: (6) In formula (6), To control the hyperparameters of the disturbance amplitude, This is a noise vector sampled from a standard normal distribution. for The identity matrix. All generated virtual OOD candidate features constitute the initial set. This is used as input for subsequent optimization.
[0049] S33. To enhance the diversity among virtual OOD features and prevent them from being overly concentrated in a small area, a diversity loss is introduced. Its objective is to minimize the feature matrix composed of the virtual OOD candidate features. Average similarity of diagonal elements between China and Africa: (7) In formula (7), Its similarity matrix, elements Corresponding to the The and the first A virtual Cosine similarity of features (since all features are L2 normalized).
[0050] S34. To ensure that the generated virtual OOD features can be accurately located near the decision boundary of the ID data, thereby achieving boundary awareness, a contrastive loss is introduced. This loss forces the similarity between any virtual OOD feature and any ID feature to fall within a predefined target range. Inside, among which An adjustable lower bound is defined: the contrast loss is defined using a hinged loss form. (8) In formula (8), For the number of categories, The number of training samples for each class, Number of virtual OOD features. Loss term. Defined as: (9) In formula (9): (10) The ID feature matrix With virtual OOD feature matrix The similarity matrix between them; in this matrix, Representing the The ID feature and the first Cosine similarity between virtual OOD features. For ID features, This is a transpose of the virtual OOD feature.
[0051] A feature set for virtual OOD was constructed. Optimization objective function It consists of diversity loss and contrast loss: (11) Virtual OOD feature set is analyzed using gradient descent method. Perform iterative optimization to minimize This allows the optimized virtual OOD features (boundary-aware virtual OOD features) to have good internal diversity and maintain a reasonable similarity interval with ID features, thereby more effectively calibrating the ID / OOD decision boundary.
[0052] S4, Multi-source OOD scoring mechanism, specifically including: During the testing phase, this invention proposes an OOD scoring mechanism based on a multi-source reference set, such as... Figure 4 As shown, based on the original test set, the test image to be detected is first... Input to the pre-trained visual base model Extract its original feature vector. Then, L2 normalization is performed to obtain normalized query features: (18) Using the above query features Calculate the k-nearest neighbor distances to the following three reference feature sets respectively: Distance to the original ID feature set: (12) in This is the feature set within the original distribution.
[0053] Distance to the virtual ID feature set: (13) in This is a set of virtual ID features generated through a dual filtering mechanism.
[0054] Distance to the virtual OOD feature set: (14) in This is the virtual OOD feature set after joint optimization using diversity and contrast loss.
[0055] The three types of distances mentioned above together constitute the criteria for multi-source discrimination, reflecting the positional relationship of query samples in different feature spaces.
[0056] Based on the three distances mentioned above, the final OOD score is defined as follows: (15) In formula (15), the negative sign reflects the inverse relationship of "ID likelihood": If the query sample is in the feature space when ≤ When the sample to be tested tends to be within the distribution (ID), it is determined to belong to the normal pathological category; when > When the sample to be tested tends to be out of distribution (OOD), it is considered an abnormal sample. The scoring threshold is a constant pre-set based on the validation set data. It is usually calculated by taking different values on the validation set, such as maximizing the precision when AUROC is maximized or fixing FPR95, and then selecting the value that makes the discrimination effect optimal as the threshold.
[0057] like Figure 4 As shown, the scoring mechanism based on a multi-source reference set constructed in this invention calculates distance metrics between the features of the test image to be detected and the original ID feature set, the virtual ID feature set, and the boundary-aware virtual OOD feature set, respectively. , and And based on this, reliable out-of-distribution discrimination can be achieved.
[0058] As shown in Table 1, the FOOD method proposed in this invention exhibits excellent out-of-distribution (OOD) detection performance on the NCT-CRC dataset.
[0059] In terms of detection capability: the AUROC index achieved by the method of this invention reaches 94.35%, which is 17.69% higher than the existing MCM method, demonstrating the powerful generalization ability of this invention to accurately distinguish between ID and OOD samples under complex pathological distributions.
[0060] Regarding false alarm control: The method of this invention significantly reduces the FPR95 index to 32.00%, which is 61.79% lower than the LSN method, thus significantly reducing the false alarm rate. This demonstrates the significant advantage of the dual virtual feature synthesis strategy proposed in this invention in improving the robustness of pathological diagnosis decisions.
[0061] Table 1: Comparison of the effects of the present invention and existing methods
[0062] Example 2 This embodiment also provides an electronic device, including: At least one processor; and The memory stores instructions that, when executed by the at least one processor, cause the at least one processor to perform the wire foreign object detection method based on the improved YOLOv11 as described above.
[0063] In this embodiment, the electronic device may include, but is not limited to: personal computer, server computer, workstation, desktop computer, laptop computer, notebook computer, mobile computing device, smartphone, tablet computer, cellular phone, personal digital assistant (PDA), handheld device, messaging device, wearable computing device, consumer electronic device, etc.
[0064] Example 3 This embodiment also provides a machine-readable storage medium storing executable instructions that, when executed, cause the machine to perform the wire foreign object detection method based on the improved YOLOv11 as described above.
[0065] Specifically, a system or apparatus equipped with a readable storage medium may be provided, on which software program code implementing the functions of any of the embodiments described above is stored, and the computer or processor of the system or apparatus can read and execute the instructions stored in the readable storage medium.
[0066] In this case, the program code read from the readable medium itself can perform the functions of any of the above embodiments, and therefore the machine-readable code and the readable storage medium storing the machine-readable code constitute a part of this specification.
[0067] Examples of readable storage media include floppy disks, hard disks, magneto-optical disks, optical disks (such as CD-ROM, CD-R, CD-RW, DVD-ROM, DVD-RAM, DVD-RW, DVD-RW), magnetic tapes, non-volatile memory cards, and ROMs. Alternatively, program code can be downloaded from a server computer or the cloud via a communication network.
[0068] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0069] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0070] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0071] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0072] Obviously, the above embodiments of the present invention are merely examples for clearly illustrating the technical solutions of the present invention, and are not intended to limit the specific implementation of the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the claims of the present invention should be included within the protection scope of the claims of the present invention.
Claims
1. A method for detecting out-of-distribution patterns in few-sample pathological images based on a basic model, characterized in that, The method includes: S1. Obtain publicly available pathological image data of different types of distribution offset scenes to form the original dataset, and divide it into the original training set and the original test set; S2. Generate enhanced views from the original samples in the original training set using a strong augmentation strategy. Then, input them into the visual base model to extract high-dimensional feature vectors and perform L2 normalization. After obtaining the corresponding candidate virtual ID features, perform feature filtering to form a virtual ID feature set. S3. Input the original samples from the original training set into the visual base model and perform L2 normalization to obtain the original ID feature set; calculate the k nearest neighbor distance of each feature in the original ID feature set to the original ID feature set, and select the Top-K features with the largest distance values as the boundary sample set. For each boundary sample, an isotropic Gaussian perturbation is applied in its local neighborhood to generate multiple virtual OOD candidate features. The virtual OOD candidate features are iteratively optimized using the gradient descent method to obtain the optimized virtual OOD features, which constitute the virtual OOD feature set. S4. Based on the original test set, input the test image to be detected into the visual base model, extract its original feature vector, and perform L2 normalization to obtain the normalized query features. Then, the test image to be detected is scored based on the distances from the query features to the original ID feature set, the distances to the virtual ID feature set, and the distances to the virtual OOD feature set.
2. The method for detecting out-of-distribution patterns in few-sample pathological images based on a basic model according to claim 1, characterized in that, S2 specifically includes: S21, Original Training Set Includes a small sample of pathological images in C known categories, where each category contains K labeled samples. ; Original sample The input is fed into the pre-trained visual base model VFM and processed by the built-in feature extraction function. Forward propagation is performed to extract high-dimensional feature vectors, and L2 normalization is then applied to obtain the normalized original features. This is used to construct a normalized original ID feature set. ; Then, based on the original ID feature set Calculate each category The characteristic prototype, i.e., the characteristic centroid ; S22, Regarding the original training set Each original sample in Apply a stochastic enhancement strategy consisting of random combinations of various basic image transformations. ,generate Enhanced view ; The generated enhanced view will then be Input to the visual base model Then, L2 normalization is performed to obtain the corresponding candidate virtual ID features. ; S23. Regarding the candidate virtual ID features Implement a dual filtering mechanism: One method is prototype similarity filtering, which calculates the features of candidate virtual IDs. Its category prototype The cosine similarity, or inner product, is only valid if a threshold condition is met: (1) Only items that meet the requirements will be retained; items that do not meet the requirements will be removed. S24. The second method is density filtering within the distribution. First, the input features to be judged are defined as: candidate virtual ID features generated by a strong data augmentation strategy and filtered by prototype similarity. Calculate input features Compared to the original ID feature set of Nearest neighbor distance for: (2) In formula (2), Representation of feature set Mid-range features Recent A set of eigenvectors Represents the L2 norm; Then select The distance value of the first Percentile as density threshold ; Finally, for the candidate virtual ID features that have passed the prototype similarity filtering... It will only be retained if it meets the following density determination criteria: (3) In summary, through the collaborative screening of the above dual filtering mechanisms, a virtual ID feature set is finally constructed. Its definition is as follows: (4)。 3. The method for detecting out-of-distribution patterns in few-sample pathological images based on a basic model according to claim 2, characterized in that, S3 specifically includes: S31. For the original ID feature set Each feature in Calculate its to k-nearest neighbor distance Defined as: (5) In formula (5), Indicates in Zhongyu Recent Of the neighbors, the one furthest away is... The Euclidean distance; S32, Select all The top-K features with the largest values are used as the boundary sample set. ; Secondly, for each boundary sample An isotropic Gaussian perturbation is applied within its local neighborhood to generate virtual OOD candidate features: For the boundary samples ,generate The candidate features, of which the first one is the 1st candidate feature. Virtual OOD candidate features ,in =1, 2, ..., : (6) In formula (6), To control the hyperparameters of the disturbance amplitude, This is a noise vector sampled from a standard normal distribution. for The identity matrix, and all generated virtual OOD candidate features constitute the initial set. ; S33, Introducing Diversity Loss Minimize the feature matrix composed of the virtual OOD candidate features. Average similarity of diagonal elements between China and Africa: (7) In formula (7), Its similarity matrix, elements Corresponding to the The and the first A virtual Cosine similarity of features; S34. Introducing Contrast Loss This loss ensures that the generated virtual OOD features can be accurately located near the decision boundary of the ID data. It forces the similarity between any virtual OOD feature and any ID feature to fall within a preset target range. Inside, among which An adjustable lower bound is defined, and the contrast loss is defined in the form of hinge loss: (8) In formula (8), For the number of categories, The number of training samples for each class, The number of virtual OOD features, and the loss term. Defined as: (9) In formula (9): (10) The ID feature matrix With virtual OOD feature matrix The similarity matrix between them; in this matrix, Representing the The ID feature and the first Cosine similarity between virtual OOD features For ID features, Transpose the virtual OOD feature; Constructing a set of virtual OOD features Optimization objective function It consists of diversity loss and contrast loss: (11) Virtual OOD feature set is analyzed using gradient descent method. Perform iterative optimization to minimize .
4. The method for detecting out-of-distribution patterns in few-sample pathological images based on a basic model according to claim 3, characterized in that, Specifically, S4 is: Test image to be detected The input is fed into the visual base model to extract its original feature vector. Then, L2 normalization is performed to obtain normalized query features. Then, calculate its k-nearest neighbor distances to the following three reference feature sets: Distance 1: Distance to the original ID feature set: (12) Distance 2: Distance to the virtual ID feature set: (13) Distance 3: Distance to the virtual OOD feature set: (14) Based on the three distances mentioned above, the final OOD score is defined as follows: (15) Set a rating threshold If the query sample is in the feature space when ≤ When the sample to be tested tends to be within the distribution, it is determined to belong to the normal pathological category; when > When the sample to be tested tends to be outside the distribution, it is determined to be an abnormal sample.
5. The method for detecting out-of-distribution patterns in few-sample pathological images based on a basic model according to claim 2, characterized in that, The basic image transformations include random grayscale conversion, color jitter, and horizontal flipping.