Research Paper:
R2-Net: A Hybrid Meta-Learning Framework for Cross-Domain Few-Shot Industrial Defect Detection
Ziyi Huang*,**, Xinyu Ouyang*, Haigang Zhang**
, and Jinfeng Yang**
*School of Electronic and Information Engineering, University of Science and Technology Liaoning
No.189 Qianshan Middle Road, Lishan District, Anshan, Liaoning 114051, China
**Institute of Applied Artificial Intelligence of the Guangdong–Hong Kong–Macao Greater Bay Area, Shenzhen Polytechnic University
No.7098 Liuxian Avenue, Nanshan District, Shenzhen, Guangdong 518055, China
Few-shot industrial defect detection is critically challenged by poor cross-domain generalization, where models often fail to adapt from a source domain to new target domains. Existing meta-learning paradigms also face significant constraints in addressing this. Metric-based methods are prone to overfitting, while optimization-based approaches often suffer from high computational costs and training instability. To this end, we propose R2-Net, a hybrid meta-learning framework that balances performance and efficiency. Its core contribution lies in resolving the aforementioned dilemma through a synergy of optimization and inference: we employ the efficient first-order meta-optimizer Reptile to learn a high-quality set of meta-initial parameters. Building on this foundation, the model utilizes a backbone network integrated with an attention mechanism to extract high-quality features, which are then fed into a relation network for rapid and fine-grained relational defect inference. Experimental results on the MVTec AD and NEU-CLS datasets demonstrate that our framework significantly outperforms a range of strong baseline models in cross-domain few-shot tasks, validating its effectiveness.
The R2-Net architecture, illustrating the bi-level meta-learning process
1. Introduction
Industrial defect detection is a critical process for ensuring product quality and manufacturing efficiency. The technological evolution in this field can be broadly categorized into three stages. The initial phase relied on low-efficiency manual inspection, which later advanced to traditional machine vision that utilized fixed algorithms like filters and template matching 1,2. Although these traditional methods provide a degree of automation, they are highly sensitive to environmental variations such as lighting and object pose, and are associated with high development and maintenance costs. This paradigm involves manual feature engineering (e.g., scale-invariant feature transform (SIFT), local binary pattern (LBP) 3,4) followed by classification using models like support vector machines (SVM) 5. While this approach substantially improves system performance, it was limited by the quality of handcrafted features and the complexity of feature engineering, which heavily depends on expert knowledge.
The advent of deep learning, particularly the widespread adoption of convolutional neural networks (CNNs) 6, has revolutionized industrial defect detection. CNNs unify feature extraction and classifier training through an end-to-end learning paradigm, significantly streamlining the development process. Foundational models such as AlexNet, VGGNet, GoogLeNet, and ResNet 7,8,9,10 have laid a solid foundation for industrial applications. However, the success of these deep learning models is critically dependent on large-scale, diverse, and meticulously labeled training datasets. This dependency presents a fundamental conflict with the inherent domain-specific characteristics of industrial defect samples.
Unlike readily available natural image datasets, industrial samples are highly domain-specific, presenting three core issues. First, the scarcity and high acquisition cost of these samples lead to small dataset sizes and a severe imbalance between normal and defective classes, fundamentally challenging the data-hungry nature of supervised learning. Second, defects often appear as subtle, fine-grained anomalies—such as minor scratches or cracks—that are difficult to detect. This is compounded by the high intra-class diversity, where defects of the same type can vary significantly in shape and size, demanding exceptional feature learning capabilities. Finally, the significant cross-domain differences 11 in material, texture, lighting, and background across products or production batches hinder a model’s ability to generalize knowledge from a source domain to a new, unseen target domain. These challenges collectively underscore the need for new methodologies that are less dependent on large, perfectly labeled datasets.
To address the unique challenges of industrial defect samples, few-shot learning (FSL) 12 has emerged as a promising solution. FSL aims to enable models to learn and generalize effectively from only a handful of training samples. However, FSL methods also face their own set of difficulties in industrial defect detection. Metric-learning-based approaches, such as Relation Networks 13, demonstrate a strong ability to model intra-class relationships. However, without effective meta-optimization, they are prone to overfitting in cross-domain tasks. Among optimization methods, model-agnostic meta-learning (MAML) 14 is a groundbreaking work with excellent theoretical generalization potential. However, its high computational cost, substantial memory overhead, and training instability—stemming from second-order optimization—have limited its practical industrial application. Consequently, more efficient and robust first-order meta-learning algorithms like Reptile 15 have been developed. While Reptile achieves similar objectives to MAML through a clever first-order approximation, it often struggles to effectively handle the fine-grained features and high intra-class diversity inherent in industrial defect samples.
This paper introduces a novel hybrid meta-learning framework, R\(^2\)-Net, that synergistically integrates the efficient first-order meta-optimizer Reptile with a powerful Relation Network. The core idea is to leverage Reptile to learn a robust, domain-agnostic meta-initialization, providing an ideal starting point for a model to rapidly adapt to new domains. Building upon this, the enhanced Relation Network employs a “compare-then-aggregate” strategy to perform precise, task-specific inference. This approach preserves the rich morphological diversity within defect classes, leading to more robust classification decisions compared to methods that rely on simple feature averaging. Furthermore, we employ ResNet-18 as the feature extractor to balance representational power with computational efficiency in few-shot scenarios, and we integrate a squeeze-and-excitation (SE) 16 module to enhance the model’s ability to capture subtle defects. The main contributions of this paper are as follows:
-
(1)
A novel hybrid meta-learning framework: We design and implement R\(^2\)-Net, a framework for cross-domain few-shot defect detection that integrates efficient first-order meta-optimization (Reptile), advanced metric learning (Relation Network), and a SE module.
-
(2)
An improved cross-domain adaptation strategy: Our method utilizes Reptile to learn a robust, domain-agnostic meta-initialization. This is combined with a Relation Network for fine-grained, task-specific inference, which effectively addresses the challenging cross-domain generalization problem in industrial defect detection.
-
(3)
Enhanced fine-grained feature capture: By integrating an SE module and adopting a “compare-then-aggregate” strategy within the Relation Network, our framework is better equipped to capture and leverage subtle defect features, thereby tackling the complexities of high intra-class diversity.
3. Method
3.1. Problem Formulation
We formulate the problem of cross-domain few-shot industrial defect detection as follows. Let \({C} = \{C_1, C_2, \dots, C_m\}\) be the universal set of all industrial product categories, where each category \(C_i\) is treated as a distinct domain with a unique feature distribution. To facilitate meta-learning, we partition \({C}\) into two disjoint subsets: a meta-training set \({C}_{\text{train}} = \{C_1, C_2, \dots, C_k\}\) and a meta-testing set \({C}_{\text{test}} = \{C_{k+1}, \dots, C_m\}\), where \(k < m\) and their intersection is the null set (\({C}_{\text{train}} \cap {C}_{\text{test}} = \emptyset\)). The learning process is structured around a series of episodic tasks, \(\{T_j\}\). Each task \(T_j\) is designed as an \(n\)-way, \(k\)-shot classification problem and comprises a support set \(S_j\) and a query set \(Q_j\). The support set \(S_j\) consists of \(n \times k\) labeled examples, with \(k\) examples for each of the \(n\) sampled classes. The query set \(Q_j\) contains unlabeled examples from the same \(n\) classes, for which the model must generate predictions. The objective is to train a model \(M\) on tasks sampled from \({C}_{\text{train}}\) such that it learns a transferable meta-knowledge. Subsequently, when presented with a new task from an unseen domain in \({C}_{\text{test}}\), the model must rapidly adapt using only the support set \(S_j\) and demonstrate strong generalization performance on the corresponding query set \(Q_j\).
3.2. Model Architecture
3.2.1. Feature Extractor with Attention Mechanism
Given that industrial defects typically manifest as subtle variations in texture or shape, the selection of a powerful feature extractor, denoted as \(f_{\varphi}\), is crucial. We selected ResNet-18 as our backbone network because it offers an effective balance between representational capacity and computational efficiency, thereby mitigating the risk of overfitting common in few-shot scenarios with deeper networks. To enhance the model’s sensitivity to discriminative features, we integrated a SE module within each residual block of the ResNet-18 architecture. As depicted in Fig. 1, the SE module first applies global average pooling to each channel to produce a channel-wise statistic. This is followed by two fully connected (FC) layers that learn non-linear inter-channel dependencies, generating a set of attention weights for each channel. These weights are then used to rescale the original feature maps, adaptively recalibrating channel-wise feature responses to emphasize informative features and suppress less useful ones. The integration of residual connections and the SE module not only helps mitigate the vanishing or exploding gradient problem but also enables dynamic feature recalibration, contributing to more stable model training.

Fig. 1. The detailed structure of the residual block with the SE module.
3.2.2. Relation Network for Relational Reasoning
Addressing the challenge of cross-domain industrial defect detection necessitates not only high-quality feature representations but also a robust mechanism to measure and reason about the relationships between these features. This constitutes the core task of the Relation Network, denoted as \(g_{\phi}\). Departing from few-shot methods that rely on fixed, predefined distance metrics (e.g., Euclidean distance or cosine similarity), the fundamental principle of the Relation Network is to “learning to compare.” It employs a dedicated, learnable deep neural network that functions as a non-linear, dynamic metric, enabling it to capture more complex, high-level similarities between samples. In this work, we introduce a key modification to the conventional Relation Network, specifically designed to better capture the intra-class morphological diversity prevalent in industrial defects. Our proposed reasoning process departs from the traditional “aggregate-then-compare” paradigm and instead adopts a “compare-then-aggregate” strategy. This process unfolds in three stages:
-
(1)
Pairwise feature matching: For a given \(n\)-way, \(k\)-shot task, to evaluate the relationship between a sample \(x_q\) and a specific class \(n\), we first perform pairwise matching between its feature map \(f_{\varphi}(x_q)\) and the feature maps of all \(k\) support samples from class \(n\), i.e., \(\{f_{\varphi}(x_{s_1}), f_{\varphi}(x_{s_2}), \dots, f_{\varphi}(x_{s_k})\}\).
-
(2)
Individual relation score generation: Each resulting feature pair is concatenated along the channel dimension and subsequently fed into the Relation Network module, \(g_{\phi}\). This module computes an individual relation score, \(r_{n,i}\), for each pair. Consequently, for class \(n\), we obtain \(k\) independent relation scores: \(\{r_{n,1}, r_{n,2}, \dots, r_{n,k}\}\). The relation score is calculated as follows:
\begin{equation} r_{n,i} = g_{\phi}\left(C\left(f_{\varphi}\left(x_q\right), f_{\varphi}\left(x_{s_i}\right)\right)\right), \label{eq:relation_score} \end{equation}where \(C(\cdot,\cdot)\) represents the concatenation operation that joins the feature maps of two samples along the channel dimension.
-
(3)
Relation score aggregation: The final stage aggregates the individual relation scores to produce a single score for each class. Specifically, the set of \(k\) independent relation scores \(\{r_{n,1}, \dots, r_{n,k}\}\) is combined, typically by averaging, to yield the final relation score, \(R_n\). This score quantifies the overall relationship between the query sample \(x_q\) and class \(n\), and is computed as follows:
\begin{equation} R_n = \frac{1}{k}\displaystyle\sum\limits_{i=1}^{k}r_{n,i}. \label{eq:aggregate_score} \end{equation}
This compare-then-aggregate paradigm offers a significant advantage over the traditional aggregate-then-compare approach. In industrial defect detection, defects of the same class (e.g., scratches) often exhibit significant morphological variations, such as differences in length, width, or curvature. Conventional methods like Prototypical Networks, which average the features of all support samples to create a single class prototype, inevitably lose this valuable intra-class diversity. This can result in a vague and potentially unrepresentative prototype—an “average scratch” that may not accurately represent any specific instance. In contrast, our approach preserves this diversity by independently comparing the query sample against each support sample. This allows the model to capture similarities to various defect morphologies within the class, leading to more robust and nuanced classification decisions.
3.2.3. Meta-Learning Algorithm of R\(^2\)-Net
The novelty of our approach lies in the synergistic fusion of Reptile, an efficient first-order meta-optimization algorithm, with a modified Relation Network tailored for capturing fine-grained inter-sample relationships. This hybrid architecture is designed to learn a meta-initialization that exhibits strong cross-domain generalization, thereby enabling rapid and precise inference on few-shot tasks from unseen domains. The model is parameterized by \(\theta = \{\phi, \varphi\}\), where \(\phi\) and \(\varphi\) denote the parameters of the feature extractor and the Relation Network, respectively. Our meta-learning algorithm optimizes the global parameters \(\theta\) through a bi-level loop structure. Algorithm 1 provides a detailed description of the specific learning process for R\(^2\)-Net. As detailed in Algorithm 1, the R\(^2\)-Net training procedure is structured into two nested phases: an inner loop for task-specific adaptation and an outer loop for meta-optimization. The primary objective of the inner loop is to adapt the model to a specific few-shot task, \(T_i\), sampled from the source domains. To this end, temporary model parameters, \(\theta'\), are fine-tuned using the support set \(S_i\). This adaptation is achieved by computing the task-specific loss \(\mathcal{L}_{T_i}(f_{\theta'})\) on the support set and subsequently updating \(\theta'\) via standard mini-batch stochastic gradient descent (SGD). The update rule is defined as follows:

Fig. 2. The R\(^2\)-Net architecture, illustrating the bi-level meta-learning process. The inner loop performs rapid task adaptation using a feature extractor and a classifier module centered on our modified Relation Network. The outer loop then computes a generalization loss on the query set to update the meta-model’s parameters via backpropagation, thereby enhancing its generalization capabilities.
The learning process can be interpreted as seeking a meta-initialization within the parameter space that is not specialized for any single task, but is instead positioned to be rapidly adaptable across a distribution of tasks. Through iterative training on diverse tasks, the model gradually learns a transferable, task-agnostic meta-knowledge. As a result, when confronted with a new few-shot task from an unseen domain, it can leverage this meta-learned starting point to converge to a high-performance solution with only a few steps of inner-loop adaptation.
As illustrated in Fig. 2, the efficacy of the R\(^2\)-Net framework stems from the synergy between its two core components: the Reptile meta-optimizer and the Relation Network. Reptile is responsible for learning a robust meta-initialization for the entire model—encompassing both the feature extractor and the Relation Network—that exhibits strong cross-domain potential. Building upon this advantageous starting point, our modified Relation Network then performs precise, task-specific reasoning by leveraging its powerful, fine-grained metric based on instance-level comparisons. This symbiotic relationship enables R\(^2\)-Net to achieve both high training stability and superior classification performance on the challenging task of cross-domain industrial defect detection.
4. Experiments and Result Analysis
4.1. Datasets
To systematically evaluate the performance of our proposed R\(^2\)-Net framework, we conducted experiments on the publicly available MVTec and NEU-CLS benchmark datasets. The MVTec dataset is particularly well-suited for our study, as it comprises 15 distinct industrial product categories, each featuring multiple fine-grained, real-world defect types and their corresponding defect-free counterparts. This diversity enables a rigorous assessment of both fine-grained recognition and cross-domain generalization capabilities. For our experimental setup, we selected 13 categories with multiple defect types and partitioned them into 6 distinct folds. Each fold was split into a meta-training set (\({C}_{\text{train}}\)) and a meta-testing set (\({C}_{\text{test}}\)), ensuring that the product categories in \({C}_{\text{test}}\) were entirely unseen during the meta-training phase. To determine the optimal hyperparameter configuration, we employed a 5-fold cross-validation strategy within the meta-training set of each fold. Fig. 3 visualizes sample images of both defect-free and various defective products from the dataset. The NEU-CLS dataset is a collection of surface defects specific to hot-rolled steel strips, encompassing six typical defect types: rolled-in scale, patches, crazing, pitted surface, inclusion, and scratches. This dataset presents a distinct set of challenges, characterized by significant intra-class morphological variations and high inter-class visual similarities, which provides a rigorous test for fine-grained classification. We include the NEU-CLS dataset in our evaluation to assess the generalizability of our method to a different industrial material and defect taxonomy. Since all defects in this dataset belong to the same product category, it serves as a benchmark for intra-domain few-shot learning. Consequently, for each task, we directly sample \(n\) distinct defect types to construct the classification problem without the need for domain-level partitioning.

Fig. 3. Sample images from the MVTec dataset used to construct tasks during the meta-training phase. The tasks are sampled from \({C}_{\text{train}}\) and include both defect-free and various defective samples.
4.2. Experimental Setup
Table 1. Hardware and software configuration.
The R\(^2\)-Net framework was implemented in PyTorch and trained on a single graphics processing unit (GPU). Additional hardware and software specifications are detailed in Table 1. Our training process adhered to the standard episodic paradigm for few-shot learning. Each task was formulated as an \(n\)-way, \(k\)-shot problem, where we sampled \(n \in \{2,3,4,5\}\) and \(k \in \{1,2,3,4,5\}\). The query set for each task contained 10 samples per class. All input images were resized to \(128 \times 128\) pixels. We employed the SGD optimizer for both the inner and outer loops, with learning rates (\(\alpha\)) of 0.01 and meta-learning rates (\(\varepsilon\)) of 0.001, respectively. The meta-learning rate was selected based on empirical tuning; we observed that higher rates led to training instability, while significantly lower rates resulted in slow convergence. The inner-loop adaptation consisted of seven gradient update steps. To mitigate overfitting, a dropout layer with a rate of 0.5 was applied within the relation module. The model was trained for 100 epochs with a meta-batch size of 16 tasks. During the meta-testing phase, we assessed the model’s generalization performance on three mutually exclusive product domains randomly sampled from \({C}_{\text{test}}\). For each unseen domain, the final performance was reported as the average accuracy over 50 randomly generated evaluation tasks. Each task required the model to classify \(n\) distinct defect types from the same product category.
Table 2. Our R\(^2\)-Net model was compared to seven baseline methods with six independent experiments and 3-way classifier learning on the MVTec dataset. Of all the methods that participated in the comparison, our model performed the best. Each result was calculated by averaging the experimental performance of 1-shot, 3-shot, and 5-shot. For better comparison, we report both the normalized accuracy (Norm.) and the corresponding standard accuracy (Std.).
4.3. Result Analysis
To comprehensively evaluate the performance of R\(^2\)-Net, we benchmark it against seven representative few-shot learning methods, which are described below. (1) Training from scratch: As a fundamental baseline, a standard CNN is trained from scratch using only the \(k\) samples from the support set of a given task. The model starts with randomly initialized weights and is immediately evaluated on the query set. (2) ResNet-12 (fine-tuning): This baseline represents a simple transfer learning approach. A ResNet-12 backbone is first pre-trained on all classes in the meta-training set. During evaluation, the feature extractor is frozen, and a new linear classifier is trained using only the \(k\) support samples. (3) Prototypical Networks (ProtoNet): A classic metric-learning method. ProtoNet computes a class prototype by calculating the mean embedding (centroid) of the support samples for each class. Classification is then performed by assigning a query sample to the class of its nearest prototype in the embedding space based on a distance metric like Euclidean distance. (4) Relation Network (RN): An advancement over methods with fixed distance metrics. RN employs a learnable deep neural network as a non-linear comparator to compute a relation score between a query sample and support samples, allowing it to learn more complex similarity measures. (5) MAML: A seminal optimization-based meta-learning algorithm. MAML aims to find a set of initial model parameters that are highly sensitive to new tasks, such that only a few steps of gradient descent are needed to achieve high performance on a new task. (6) Reptile: An efficient, first-order approximation of MAML. Reptile also learns a meta-initialization but updates the meta-parameters by linearly moving them toward the task-adapted parameters, thereby circumventing the costly second-order derivatives required by MAML. (7) ALFA: An advanced MAML variant that shifts the optimization focus from the initial parameters to the adaptation process itself. It employs a meta-network to dynamically generate task-adaptive hyperparameters (e.g., learning rates) for the inner-loop updates, enabling more effective and efficient adaptation.
To ensure a fair comparison across tasks with a varying number of classes (\(n\)) and to account for the effect of random guessing, we report all results using a normalized accuracy metric. This metric is defined as:
Table 3. On the NEU-CLS dataset, the performance comparison of 1-shot and 5-shot in a 3-way setting. Standard accuracy (Std.) is reported alongside normalized accuracy (Norm.) for direct comparison.
On the MVTec dataset, our evaluation followed a rigorous 6-fold cross-validation protocol, with the final results reported as the average normalized accuracy across the six independent runs. As shown in Table 2, our R\(^2\)-Net model achieves a mean accuracy of 0.5192, outperforming all other compared methods. Notably, it surpasses the next-best baseline, ALFA (0.4840), by a significant margin of 3.5%, demonstrating a substantial advance in overall performance. Furthermore, R\(^2\)-Net not only outperforms advanced optimization-based methods like ALFA but also shows a considerable lead over the classic MAML (0.3569). This suggests that our meta-optimization strategy using Reptile is more effective in practice for finding a generalizable initialization than more complex second-order methods. When compared to metric-based approaches, our model’s performance is also markedly superior to that of Prototypical Networks (0.3910) and a standalone Relation Network (0.1611). This highlights that the potential of metric learning in complex domains is significantly amplified when guided by a meta-optimizer like Reptile. The performance of R\(^2\)-Net (0.5192) is not merely an additive combination of its components; it substantially exceeds the sum of the individual performances of Reptile (0.2565) and the Relation Network (0.1611). This result strongly attests to the synergistic nature of our framework: Reptile provides an advantageous and readily adaptable meta-initialization, which the Relation Network then leverages to realize its full relational reasoning capabilities.
To validate the robustness of our framework beyond the multi-domain setting of MVTec, we conducted further evaluations on the NEU-CLS dataset, which focuses on intra-domain defect classification. This dataset, characterized by a relatively uniform background, presents a distinct challenge due to the subtle and often ambiguous boundaries between defect classes. As reported in Table 3, R\(^2\)-Net again demonstrated superior performance. Specifically, it achieved an accuracy of 0.8233 in the demanding 1-shot setting, which increased to 0.8250 in the 5-shot setting. In the 1-shot scenario, our model surpasses the strong ALFA baseline (0.8000) and outperforms MAML (0.6416) by a substantial margin of nearly 18 percentage points. This superior performance extends to comparisons against its core components, significantly exceeding the results of a standalone Relation Network (0.6361) and Reptile (0.6028). The consistent, top-tier performance across two industrial datasets with disparate visual characteristics and challenges strongly validates the generality and robustness of the R\(^2\)-Net framework. This demonstrates its ability to learn effective, transferable meta-knowledge applicable to both complex cross-domain scenarios and fine-grained, intra-domain classification tasks.
4.4. Ablation Experiments
To systematically investigate the contribution of each core component within the R\(^2\)-Net framework and to validate our choice of backbone network, we conducted a comprehensive set of ablation studies. These studies were performed on the MVTec AD dataset, adhering to the same 3-way, 5-shot protocol as our main experiments. The performance for each configuration is reported as the average normalized accuracy from the 6-fold cross-validation. Specifically, we analyzed the impact of the three primary components of our framework: the Reptile meta-optimizer, the Relation Network metric learner, and the SE attention module. The results of this analysis are presented in Table 4.
Table 4. Ablation experiments to verify the necessity of each core component. From the experimental results, it can be seen that three core components are indispensable.
Our analysis begins with a baseline ResNet-12 backbone. A simple transfer learning strategy (fine-tuning) yields a normalized accuracy of 0.3036. Interestingly, when the core meta-learning components are applied individually, their performance falls short of this baseline; a standalone Reptile optimizer achieves 0.2565, and a standalone Relation Network scores 0.1611. This finding underscores that these components must be integrated correctly to unlock their potential. The synergy between our chosen components becomes evident when we combine the Reptile meta-optimizer with the Relation Network. As shown in Table 4, this combination boosts the performance to 0.3639, surpassing the fine-tuning baseline. This significant improvement, which is greater than the sum of the individual parts, strongly validates the central hypothesis of our framework; the synergistic fusion of a meta-optimizer and a metric learner is crucial. We further investigated the contribution of the SE module. Integrating the SE module into the Reptile+RN architecture on the ResNet-12 backbone results in a substantial performance leap to 0.4968. This effect is consistent on our final ResNet-18 backbone, where the full R\(^2\)-Net model achieves 0.5048, while removing the SE module causes the performance to drop to 0.4875. This clearly demonstrates that the SE module’s channel attention mechanism is integral to the model’s success, effectively enhancing its ability to capture fine-grained, discriminative features in industrial defects.
Table 5. The performance of R\(^2\)-Net under 4 different backbone networks was compared in six independent experiments on the MVTec dataset and 3-way classifier learning. In several sets of experiments that included in the comparison, it can be seen that the backbone network achieves the best performance when it is ResNet-18. Standard accuracy (Std.) is reported alongside normalized accuracy (Norm.) for direct comparison.
Having established the synergy of the core components, we next investigate the impact of the backbone architecture on performance. An ideal backbone for few-shot learning must strike a delicate trade-off between powerful representational capacity and efficient task adaptability. To this end, we evaluated the R\(^2\)-Net framework with four ResNet backbones of varying depths: ResNet-12, ResNet-18, ResNet-50, and ResNet-101. The results, presented in Table 5, reveal a clear trend. Performance improves as the network depth increases from ResNet-12 (0.4824) to ResNet-18, which achieves the peak normalized accuracy of 0.5192. However, further increasing the depth leads to a significant and sustained decline in performance, with ResNet-50 and ResNet-101 scoring 0.4435 and 0.4171, respectively. This outcome provides strong evidence that, within our few-shot learning framework, simply increasing network depth beyond a certain threshold is detrimental to generalization performance.
The performance degradation of deeper networks like ResNet-50 and ResNet-101 can be attributed to their pre-training on large-scale datasets such as ImageNet. This process entrenches highly abstract and specialized features in the deeper layers that are specific to the source domain (i.e., natural images). In a few-shot cross-domain scenario, adapting this large and relatively rigid parameter space using only a handful of samples presents two significant challenges. First, the optimization becomes exceedingly difficult; the Reptile algorithm may fail to find an effective optimization trajectory within the limited inner-loop steps. Second, the risk of overfitting to the source domain increases, as the model’s high capacity gives it a propensity to rely on its memorized ImageNet features rather than learning to generalize from the few new samples, leading to negative transfer. In contrast, ResNet-18 achieves the optimal trade-off. It is sufficiently deep to offer superior representational capacity compared to ResNet-12, providing the foundation for its performance gains. Simultaneously, it is not so deep as to exhibit the significant parameter inertia seen in ResNet-50 and ResNet-101. Consequently, its parameter space retains sufficient plasticity, making it highly suitable for rapid and effective adaptation. The choice of backbone depth, therefore, directly governs the efficacy of our framework’s synergistic design. Our experimental results confirm that ResNet-18 is the optimal choice for the “Reptile+Relation Network+SE” combination, as it provides powerful feature representation while retaining the necessary flexibility for effective meta-learning.
4.5. Model Behavior Analysis
Having established the overall superiority of the R\(^2\)-Net framework, we now further investigate its behavioral properties under varying conditions of task difficulty (\(n\)-way) and sample availability (\(k\)-shot). The following experiments are designed to probe the model’s performance boundaries, providing both qualitative and quantitative insights into the effectiveness of our design philosophy.
-
(1)
Impact of task difficulty (\(n\)-way): As illustrated in Fig. 4, we evaluated the model on the MVTec dataset with a fixed 5-shot setting while increasing the number of classes from \(n=2\) to \(n=5\). The results show a graceful degradation in performance across all categories as \(n\) increases, with no sudden collapses. This indicates the inherent stability of our framework. We also observe performance variations linked to class characteristics; categories with distinct visual features, such as “Capsule” and “Cable,” consistently maintain high accuracy with a flatter decline. This suggests that performance is correlated with the inherent class separability of the task, offering a valuable reference for assessing the model’s applicability to specific industrial products.

Fig. 4. The effect of \(n\)-way on model performance.
-
(2)
Impact of sample availability (\(k\)-shot): A key finding, made apparent by the clear performance gap between categories in Fig. 5, is the model’s differing performance on shape-based versus texture-based defects. The results indicate a clear difference in the model’s ability to handle different types of visual features. The model demonstrates significantly higher proficiency on shape-based tasks compared to texture-based ones. For categories like “Cable” and “Hazelnut,” the model achieves high levels of accuracy, whereas for texture-rich categories such as “Grid” and “Carpet,” the overall accuracy is noticeably lower. This observation is a significant contribution, as it reveals the performance characteristics of our meta-learning framework on tasks with different visual properties. It not only explains performance variations but also informs future methodological refinements (e.g., designing specialized modules for texture analysis).

Fig. 5. The effect of \(k\)-shot on model performance.
5. Conclusion
To address the dual challenges of sample scarcity and poor cross-domain adaptability in industrial defect detection, this paper proposed and validated R\(^2\)-Net, a novel hybrid meta-learning framework. Our approach synergistically integrates the efficient first-order meta-optimizer, Reptile, with a modified Relation Network capable of powerful non-linear reasoning. Within this framework, Reptile learns a generalizable meta-initialization for the entire model, which includes a ResNet-18 feature extractor with a SE attention mechanism. The Relation Network then leverages this advantageous starting point to perform accurate inference on few-shot tasks. Extensive experiments on two standard industrial defect datasets (MVTec AD and NEU-CLS) confirmed the superiority of our framework. R\(^2\)-Net consistently outperformed a wide range of strong few-shot learning baselines. Furthermore, our ablation studies revealed the keys to its success: a strong synergy between Reptile and the Relation Network, the critical role of the SE module in capturing fine-grained features, and the selection of ResNet-18 as the optimal balance between representational capacity and adaptive plasticity. Although our framework has achieved good results, there are still some areas worth exploring. We plan to design and integrate a meta-learning module specifically aimed at enhancing texture feature representation, which could improve performance on texture-based defect types. Additionally, although our current experiments focused on MVTec AD and NEU-CLS, the proposed R\(^2\)-Net is designed as a general-purpose framework applicable to various industrial defect detection tasks. We intend to evaluate the framework on a broader and more diverse range of industrial datasets to further verify its versatility. This will allow for a more comprehensive assessment of its cross-domain transferability across different manufacturing environments and material types.
Acknowledgments
This work was supported by the Research Projects of Department of Education of Guangdong Province (2025ZDZX3068, 2023ZDZX1081, 2023KCXTD077), University-Enterprise Joint Research and Development Center (602431007PQ, 602531009PQ), the Phase III Program of the Economic and Social Development Research Institute at Shenzhen Polytechnic University (6025310002Q), National Natural Science Foundation of China (62076166), Shenzhen Polytechnic University Research Fund (6025310044K), and Shenzhen Science and Technology Program (JCYJ20240813093102004).
- [1] K. L. Mak, P. Peng, and K. F. C. Yiu, “Fabric defect detection using morphological filters,” Image and Vision Computing, Vol.27, Issue 10, pp. 1585-1592, 2009. https://doi.org/10.1016/j.imavis.2009.03.007
- [2] R. Brunelli, “Template Matching Techniques in Computer Vision: Theory and Practice,” John Wiley & Sons, 2009. https://doi.org/10.1002/9780470744055
- [3] L. Zheng, Y. Yang, and Q. Tian, “SIFT Meets CNN: A Decade Survey of Instance Retrieval,” IEEE Trans. on Pattern Analysis and Machine Intelligence, Vol.40, Issue 5, pp. 1224-1244, 2018. https://doi.org/10.1109/TPAMI.2017.2709749
- [4] L. Li, X. Mu, S. Li, and H. Peng, “A Review of Face Recognition Technology,” IEEE Access, Vol.8, pp. 139110-139120, 2020. https://doi.org/10.1109/ACCESS.2020.3011028
- [5] S. Suthaharan, “Machine Learning Models and Algorithms for Big Data Classification: Thinking with Examples for Effective Learning,” Springer, 2016. https://doi.org/10.1007/978-1-4899-7641-3
- [6] Z. Li, F. Liu, W. Yang, S. Peng, and J. Zhou, “A Survey of Convolutional Neural Networks: Analysis, Applications, and Prospects,” IEEE Trans. on Neural Networks and Learning Systems, Vol.33, Issue 12, pp. 6999-7019, 2021. https://doi.org/10.1109/TNNLS.2021.3084827
- [7] X. Zhao, L. Wang, Y. Zhang, X. Han, M. Deveci, and M. Parmar, “A review of convolutional neural networks in computer vision,” Artificial Intelligence Review, Vol.57, No.4, Article No.99, 2024. https://doi.org/10.1007/s10462-024-10721-6
- [8] S. Tammina, “Transfer Learning Using VGG-16 with Deep Convolutional Neural Network for Classifying Images,” Int. J. of Scientific and Research Publications (IJSRP), Vol.9, Issue 10, pp. 143-150, 2019. https://doi.org/10.29322/IJSRP.9.10.2019.p9420
- [9] P. Ballester and R. Araujo, “On the Performance of GoogLeNet and AlexNet Applied to Sketches,” Proc. of the AAAI Conf. on Artificial Intelligence, Vol.30, No.1, 2016. https://doi.org/10.1609/aaai.v30i1.10171
- [10] K. He, X. Zhang, S. Ren, and J. Sun, “Deep Residual Learning for Image Recognition,” 2016 IEEE Conf. on Computer Vision and Pattern Recognition (CVPR), pp. 770-778, 2016. https://doi.org/10.1109/CVPR.2016.90
- [11] Y. Song, T. Wang, P. Cai, S. K. Mondal, and J. P. Sahoo, “A Comprehensive Survey of Few-shot Learning: Evolution, Applications, Challenges, and Opportunities,” ACM Computing Surveys, Vol.55, Issue 13s, Article No.271, 2023. https://doi.org/10.1145/3582688
- [12] J. Beck, R. Vuorio, E. Z. Liu, Z. Xiong, L. Zintgraf, C. Finn, and S. Whiteson, “A Tutorial on Meta-Reinforcement Learning,” Foundations and Trends in Machine Learning, Vol.18, Issues 2-3, pp. 224-384, 2025. https://doi.org/10.1561/2200000080
- [13] F. Sung, Y. Yang, L. Zhang, T. Xiang, P. H. S. Torr, and T. M. Hospedales, “Learning to Compare: Relation Network for Few-Shot Learning,” 2018 IEEE/CVF Conf. on Computer Vision and Pattern Recognition, pp. 1199-1208, 2018. https://doi.org/10.1109/CVPR.2018.00131
- [14] C. Finn, P. Abbeel, and S. Levine, “Model-agnostic meta-learning for fast adaptation of deep networks,” Proc. of Int. Conf. on Machine Learning (ICML’17), Vol.70, pp. 1126-1135, 2017.
- [15] A. Nichol, J. Achiam, and J. Schulman, “On First-Order Meta-Learning Algorithms,” arXiv preprint, arXiv:1803.02999, 2018. https://doi.org/10.48550/arXiv.1803.02999
- [16] J. Hu, L. Shen, and G. Sun, “Squeeze-and-Excitation Networks,” 2018 IEEE/CVF Conf. on Computer Vision and Pattern Recognition, pp. 7132-7141, 2018. https://doi.org/10.1109/CVPR.2018.00745
- [17] T. T. Khoei, H. O. Slimane, and N. Kaabouch, “Deep learning: Systematic review, models, challenges, and research directions,” Neural Computing and Applications, Vol.35, No.31, pp. 23103-23124, 2023. https://doi.org/10.1007/s00521-023-08957-4
- [18] R. Archana and P. S. E. Jeevaraj, “Deep learning models for digital image processing: A review,” Artificial Intelligence Review, Vol.57, No.1, Article No.11, 2024. https://doi.org/10.1007/s10462-023-10631-z
- [19] Z. Zou, K. Chen, Z. Shi, Y. Guo, and J. Ye, “Object Detection in 20 Years: A Survey,” Proc. of the IEEE, Vol.111, Issue 3, pp. 257-276, 2023. https://doi.org/10.1109/JPROC.2023.3238524
- [20] Z. Chen and Q. Sun, “Weakly-supervised Semantic Segmentation with Image-level Labels: From Traditional Models to Foundation Models,” ACM Computing Surveys, Vol.57, Issue 5, Article No.111, 2025. https://doi.org/10.1145/3707447
- [21] J. Zhou, C. Xie, S. Gong, Z. Wen, X. Zhao, Q. Xuan, and X. Yang, “Data Augmentation on Graphs: A Technical Survey,” ACM Computing Surveys, Vol.57, Issue 11, Article No.274, 2025. https://doi.org/10.1145/3732282
- [22] A. Bansal, R. Sharma, and M. Kathuria, “A Systematic Review on Data Scarcity Problem in Deep Learning: Solution and Applications,” ACM Computing Surveys (CSUR), Vol.54, Issue 10s, Article No.208, 2022. https://doi.org/10.1145/3502287
- [23] W. Jiang, K. Huang, J. Geng, and X. Deng, “Multi-Scale Metric Learning for Few-Shot Learning,” IEEE Trans. on Circuits and Systems for Video Technology, Vol.31, Issue 3, pp. 1091-1102, 2020. https://doi.org/10.1109/TCSVT.2020.2995754
- [24] X. Li, X. Yang, Z. Ma, and J.-H. Xue, “Deep metric learning for few-shot image classification: A review of recent developments,” Pattern Recognition, Vol.138, Article No.109381, 2023. https://doi.org/10.1016/j.patcog.2023.109381
- [25] H. Gharoun, F. Momenifar, F. Chen, and A. H. Gandomi, “Meta-learning Approaches for Few-Shot Learning: A Survey of Recent Advances,” ACM Computing Surveys, Vol.56, Issue 12, Article No.294, 2024. https://doi.org/10.1145/3659943
- [26] J. Snell, K. Swersky, and R. S. Zemel, “Prototypical Networks for Few-shot Learning,” Advances in Neural Information Processing Systems, Vol.30, 2017.
- [27] O. Vinyals, C. Blundell, T. Lillicrap, K. Kavukcuoglu, and D. Wierstra, “Matching Networks for One Shot Learning,” Advances in Neural Information Processing Systems, Vol.29, 2016.
- [28] S. Baik, M. Choi, J. Choi, H. Kim, and K. M. Lee, “Learning to Learn Task-Adaptive Hyperparameters for Few-Shot Learning,” IEEE Trans. on Pattern Analysis and Machine Intelligence, Vol.46, Issue 3, pp. 1441-1454, 2023. https://doi.org/10.1109/TPAMI.2023.3261387
- [29] H. Zhang, D. Wang, Z. Chen, and R. Pan, “Adaptive visual detection of industrial product defects,” PeerJ Computer Science, Vol.9, Article No.e1264, 2023. https://doi.org/10.7717/peerj-cs.1264
- [30] J. Feng, H. Zhang, and Z. Wang, “Eternal-MAML: A meta-learning framework for cross-domain defect recognition,” PeerJ Computer Science, Vol.11, Article No.e2757, 2025. https://doi.org/10.7717/peerj-cs.2757
- [31] A. Santoro, S. Bartunov, M. Botvinick, D. Wierstra, and T. Lillicrap, “Meta-learning with memory-augmented neural networks,” Proc. of the 33rd Int. Conf. on Machine Learning, Vol.48, pp. 1842-1850, 2016.
- [32] T. Munkhdalai and H. Yu, “Meta Networks,” Proc. of the 34th Int. Conf. on Machine Learning, Vol.70, pp. 2554-2563, 2017.
- [33] Y. Zhao, T. Zhang, J. Li, and Y. Tian, “Dual Adaptive Representation Alignment for Cross-Domain Few-Shot Learning,” IEEE Trans. on Pattern Analysis and Machine Intelligence, Vol.45, Issue 10, pp. 11720-11732, 2023. https://doi.org/10.1109/TPAMI.2023.3272697
- [34] X. Yue, Z. Zheng, S. Zhang, Y. Gao, T. Darrell, K. Keutzer, and A. S. Vincentelli, “Prototypical Cross-domain Self-supervised Learning for Few-shot Unsupervised Domain Adaptation,” 2021 IEEE/CVF Conf. on Computer Vision and Pattern Recognition (CVPR), pp. 13829-13839, 2021. https://doi.org/10.1109/CVPR46437.2021.01362
- [35] J. Du, S. Zhang, Q. Chen, H. Le, Y. Sun, Y. Ni, J. Wang, B. He, and J. Wang, “σ-Adaptive Decoupled Prototype for Few-Shot Object Detection,” 2023 IEEE/CVF Int. Conf. on Computer Vision (ICCV), pp. 18904-18914, 2023. https://doi.org/10.1109/ICCV51070.2023.01737
This article is published under a Creative Commons Attribution-NoDerivatives 4.0 Internationa License.