원시데이터 수집 시스템
선정목록으로

Knitting Robots: A Deep Learning Approach for Reverse-Engineering Fabric Patterns

관련 모빌리티 소재 · (3) 자동차 인테리어 소재

기본 정보

저자
  1. Sheng, Haoliang
  2. Cai, Songpu
  3. Zheng Xingyu
  4. Lau Meng Cheng
DOI
10.48550/arxiv.2504.14007
저널
arXiv (Cornell University)
발행년도
2025
발행기관
Cornell University
피인용수
0
라이선스
0
논문 유형
–
언어
–
원문 페이지
https://doi.org/10.48550/arxiv.2504.14007
토픽
Textile materials and evaluations
OpenAlex ID
W6910801101

평가 내용

관련도
관련
사업분야
모빌리티 소재 · (3) 자동차 인테리어 소재
부 분야
–
R&D 측면
–
확신도
–
근거 용어
–
판단 근거
임베딩 유사도 기반 평가로 '모빌리티 소재 > 자동차 인테리어 소재' 분야에 선정된 논문입니다.
R&D 활용 포인트
–
평가 입력
–

초록

Knitting, a cornerstone of textile manufacturing, is uniquely challenging to automate, particularly in terms of converting fabric designs into precise, machine-readable instructions. This research bridges the gap between textile production and robotic automation by proposing a novel deep learning-based pipeline for reverse knitting to integrate vision-based robotic systems into textile manufacturing. The pipeline employs a two-stage architecture, enabling robots to first identify front labels before inferring complete labels, ensuring accurate, scalable pattern generation. By incorporating diverse yarn structures, including single-yarn (sj) and multi-yarn (mj) patterns, this study demonstrates how our system can adapt to varying material complexities. Critical challenges in robotic textile manipulation, such as label imbalance, underrepresented stitch types, and the need for fine-grained control, are addressed by leveraging specialized deep-learning architectures. This work establishes a foundation for fully automated robotic knitting systems, enabling customizable, flexible production processes that integrate perception, planning, and actuation, thereby advancing textile manufacturing through intelligent robotic automation.

본문 66,453자

본문 펼치기
_Article_ ## Knitting Robots: A Deep Learning Approach for Reverse-Engineering Fabric Patterns Haoliang Sheng <sup>1</sup> , Songpu Cai <sup>1</sup> , Xingyu Zheng <sup>1,2</sup> and Mengcheng Lau <sup>1,</sup> * 1 Bharti School of Engineering and Computer Science, Laurentian University, Sudbury, ON P3E 2C6, Canada; hsheng@laurentian.ca (H.S.); scai1@laurentian.ca (S.C.); xzheng2@laurentian.ca (X.Z.) 2 Shanghai International Fashion Education Centre, Shanghai 200060, China * Correspondence: mclau@laurentian.ca; Tel.: +1-705-675-1151 Academic Editor: Giuseppe Prencipe Received: 23 February 2025 Revised: 3 April 2025 Accepted: 10 April 2025 Published: Citation: Sheng, H.; Cai, S.; Zheng, X.; Lau, M. Knitting Robots: A Deep Learning Approach for Reverse-Engineering Fabric Patterns. _Electronics_ 2025, _1_, 0. [https://](https://doi.org/10.3390/electronics1010000) [doi.org/](https://doi.org/10.3390/electronics1010000) Copyright: © 2025 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license [(https://creativecommons.org/](https://creativecommons.org/licenses/by/4.0/) [licenses/by/4.0/).](https://creativecommons.org/licenses/by/4.0/) Abstract: Knitting, a cornerstone of textile manufacturing, is uniquely challenging to automate, particularly in terms of converting fabric designs into precise, machine-readable instructions. This research bridges the gap between textile production and robotic automation by proposing a novel deep learning-based pipeline for reverse knitting to integrate vision-based robotic systems into textile manufacturing. The pipeline employs a two-stage architecture, enabling robots to first identify _front_ _labels_ before inferring _complete_ _labels_, ensuring accurate, scalable pattern generation. By incorporating diverse yarn structures, including single-yarn ( _sj_ ) and multi-yarn ( _mj_ ) patterns, this study demonstrates how our system can adapt to varying material complexities. Critical challenges in robotic textile manipulation, such as label imbalance, underrepresented stitch types, and the need for finegrained control, are addressed by leveraging specialized deep-learning architectures. This work establishes a foundation for fully automated robotic knitting systems, enabling customizable, flexible production processes that integrate perception, planning, and actuation, thereby advancing textile manufacturing through intelligent robotic automation. Keywords: automated knitting; deep learning; GAN; ResNet; fabric engineering 1. Introduction Knitting has long been a cornerstone of textile manufacturing, from traditional handcrafted designs to industrial whole-garment knitting machines. In conventional processes, a predefined _stitch_ _label_ serves as the input for knitting machines like those controlled by the _m1plus_ [1] programming language. These inputs generate corresponding fabrics (outputs), which can be visualized or verified through images of the resulting physical objects. However, the process of creating knittable programs or _stitch labels_ from existing images of knitted patterns remains a complex challenge. This gap defines the scope of _reverse_ _knitting_, as shown in Figure 1, which is an emerging paradigm that utilizes real images of knitted fabrics as its input and outputs knittable stitch labels through deep learning models. Such systems hold immense potential to transform the design and manufacturing pipeline, especially in terms of customization and replication tasks. _Electronics_ 2025, _1_, 0 2 of 23 Figure 1. Reverse knitting. The primary objective of this project is to develop a two-stage pipeline for _reverse_ _knitting_, leveraging deep learning to transform real images of knitted fabrics into knittable stitch labels. This pipeline includes a _generation_ _phase_ for predicting _front_ _labels_ and an _inference phase_ for generating _complete labels_ . This research aims to improve the accuracy of label prediction for diverse yarn structures, addressing the challenges of single-yarn ( _sj_ ) and multi-yarn ( _mj_ ) knitting patterns through specialized architectures. Additionally, this study evaluates the pipeline’s performance across realistic scenarios, focusing on its ability to handle imbalanced datasets and generalize effectively. This research explores three key questions. The first focuses on pipeline design, investigating how a two-stage deep learning pipeline can be effectively structured to transform real fabric images into knittable stitch labels. The second addresses performance optimization, examining the impact of design choices such as stricter loss functions, yarn-specific training, and different model architectures on the accuracy and robustness of _front label_ and _complete label_ predictions. Lastly, this research evaluates the pipeline’s ability to handle realistic constraints, such as imbalanced datasets and unknown yarn types, while maintaining high performance across various application scenarios. Early efforts, such as those of Kaspar et al. [2], introduced the Refiner+Img2prog architecture using a SimGAN framework [3] to refine _real images_ into synthetic _rendering_ _images_ for _front_ _label_ prediction. However, challenges like dataset imbalance (e.g., FK dominance) and the “one-to-many” problem—where identical instructions yield varied visuals—limit precision and are often exacerbated by multiple-instance learning (MIL) strategies [2]. Stricter loss functions have since been explored to enhance accuracy. Trunz et al. [4] and Melnyk [5] extended GAN-based approaches [6–8] to model yarn properties and fabric styles, while CNNs [9] excel at capturing spatial stitch relationships and LSTMs [10] address row dependencies [11]. However, these works focus more on creatively generating stitches, unlike Kaspar’s Inverse Knitting, which only translates fabric images into _stitch_ _labels_ . For the _inference phase_, inter-stitch logic is critical. Yuksel et al. [12] pioneered stitch meshes, which were later refined by Wu et al. [13,14] for knittability. Conditional Random Fields (CRFs) [15] model probabilistic dependencies, though long-range limitations persist [16]. Residual architectures [16] and 3D-to-instruction methods [17] further enhance _complete label_ generation. Yet, gaps remain: imbalanced datasets underrepresent rare labels (e.g., “E”, “V”) [2,4,5], multi-yarn scalability is limited [12,13], and computational efficiency lags are common with resource-heavy models [10,11,15]. Unlike Transformers, which favor global features but demand a large amount of resources, our residual CNNs, UNets, and multi-layer CNNs prioritize local dependencies, as _stitch labels_ must work with their neighbors [12], using 3 _×_ 3 kernels effectively. GANs [2] remain cost-efficient, while GNNs, though relational, face convergence issues in dense grids and CNNs favor stability. The rest of this paper is organized as follows: Section 2 details the data collection and preparation process, including the acquisition of ground truth data and the categorization of yarn and stitch types. Section 3 presents the proposed two-stage deep learning archi _Electronics_ 2025, _1_, 0 3 of 23 tecture, describing the _generation phase_ for _front label_ prediction and the _inference phase_ for _complete label_ generation. Section 4 describes the experimental setup, including the four key usage scenarios, and evaluates the model’s performance across different yarn types and stitch patterns. Section 5 discusses the results, highlighting the model’s strengths and limitations, while Section 6 concludes the study and outlines future research directions. Finally, Appendices A and B provide additional details about the model’s implementation and the experimental environment setup. 2. Data Collection and Preparation The data collection and preparation process involves acquiring ground truth data and defining yarn and stitch concepts. As illustrated in Figure 2, the ground truth data consist of four key components: the _complete label_, designed by textile experts as the foundation for other data types; the _front label_, which is derived from the _complete label_ through mapping; the _rendering image_, generated by rendering the _complete label_ ; and the real image, produced by knitting the _complete_ _label_ into physical fabric. These data types are systematically derived through processes such as mapping the _complete label_ to the _front label_, rendering these into images, and knitting these into physical fabrics. Figure 2. Data processing workflow. Our dataset is categorized by yarn types and stitch patterns. The yarn types include single-yarn samples ( _sj_ ) and multi-yarn samples ( _mj_ ), which are further divided into 2 _j_, 3 _j_, and 4 _j_ for fabrics containing two, three, and four yarn colors, respectively. However, practical limitations restrict structures to less than four colors. Each dataset sample consists of a 20 _×_ 20 grid of stitches labeled with stitch types like _FK_, _BK_, and others, which represent the structural details of the fabric. To address the limited availability of _real images_ in the Kaspar dataset, which contains only 1043 front-facing fabric images, data augmentation is performed using transfer images (Figure 3). Both rendering images and transfer images are generated from the _complete label_ using the _m1plus_ software provided by Stoll [1]. These _transfer images_ serve as substitutes for _real images_ captured through physical knitting and photography, allowing for a larger and more balanced dataset. This augmentation strategy significantly enhances the dataset’s consistency and availability, ensuring the more reliable training and evaluation of the models. The _complete label_ is not provided by the designers as raw data but is derived from the _colored complete label_ through label aggregation. It incorporates both structure and color tags. For example, in multi-yarn ( _mj_ ) cases containing two yarns ( _2j_ ), labels such as _(1/2j)FK,MAK_ and _(2/2j)FK,MAK_ are aggregated into _FK,MAK_ . Here, _1/2j_ indicates the first yarn in a twoyarn structure, while _2j_ specifies the yarn type. This label aggregation simplifies structure recognition by focusing on _stitch_ _labels_ without considering color-specific information. _Electronics_ 2025, _1_, 0 4 of 23 Notably, color recognition is outside the scope of this project, which centers on identifying the stitch structures required for knitting instructions. Figure 3. Comparison of transfer image with real image. _2.1._ _Front Label Acquisition_ The _front label_ is obtained using predefined mappings, as illustrated in Figure 4. These contain the label number (numerical values used for training), label name (technical stitch types such as _FK_ and _BK_ ), and label color and are employed for intuitive visualization of the 20 _×_ 20 stitch grid during testing. Additionally, the front label provides a representation within the _rendering image_, ensuring easy identification. In contrast, the _complete label_ focuses on generating knittable instructions and includes the label number, label name, and label color, emphasizing the structural information required for producing feasible patterns. ( a ) ( b ) Figure 4. Mapping from front label to complete label. The "No" column represents the numerical identifiers assigned to each stitch type. The "name" column lists the abbreviated names of the stitch types. The "color" column indicates the encoded colors associated with each stitch type, which are used for visualization purposes. The "image" column (left table) is reserved for displaying physical representations or diagrams of the corresponding stitch types. ( a ) _sj_ map; ( b ) _mj_ map. A key distinction exists between the _front label_ and the _complete label_ . The _front label_ simplifies the recognition of visual patterns in _real images_ or _rendering images_, enabling a _Electronics_ 2025, _1_, 0 5 of 23 model to map directly from the visual domain. Meanwhile, the _complete label_ requires an inference step to generate knittable instructions, making it more suited to logical reasoning tasks rather than visual recognition. To ensure effective model training, separate mappings are provided for single-yarn ( _sj_ ) and multi-yarn ( _mj_ ) structures, as shown in Figure 4a,b. However, because the _front label_ exhibits minimal structural differences between _sj_ and _mj_ cases, combined training is feasible when using front labels. _2.2._ _Rendering Image Acquisition_ _Rendering_ _images_ were synthesized using the _m1plus_ software by Stoll [1], which simulates virtual fabric structures using _complete_ _labels_ . The process involves inputting the _complete_ _label_ into the _m1plus_ software, which generates a corresponding _rendering_ _image_ . These images serve as intermediary outputs for downstream tasks, bridging the gap between virtual designs and real-world knitting data. _2.3._ _Real Image Acquisition_ _Real images_ were generated using Stoll’s computerized flat knitting machines, which are programmed with outputs from the _m1plus_ software. To improve efficiency, multiple samples were knitted together on a single sheet, as illustrated in Figure 5. The Region of Interest (ROI) for each sample was then manually marked to distinguish between the different patterns within the sheet. Finally, physical images were captured using an iPhone 15 Pro Max in RAWMAX photo mode within a controlled lightbox environment, ensuring high-quality imaging for further processing and analysis. Figure 5. Physical sheet. _2.4._ _Distribution of Yarn Types and Stitches_ The _distribution of yarn types_, illustrated in Figure 6, includes a total of 4950 samples. The dataset consists of 3000 single-yarn ( _sj_ ) samples, evenly distributed across 10 subcategories, Hem, Move1, Miss, Cable1, Links2, Move2, Cable2, Mesh, Tuck, and Links1, with approximately 300 samples in each category. Additionally, there are 1950 multi-yarn ( _mj_ ) samples. Although a larger dataset of 12,392 _sj_ samples from Kaspar et al. [2] was available, the decision to limit the _sj_ samples to 3000 was made to maintain a balance with the smaller number of _mj_ samples. This curated subset ensures a representative distribution of both categories for effective model training. _Electronics_ 2025, _1_, 0 6 of 23 Figure 6. Yarn type distribution. The _stitch distribution_ of the dataset reveals a significant label imbalance, as depicted in Figure 7. For the _front labels_, the _FK_ label dominates the dataset, accounting for approximately 75% of the samples, while other labels remain underrepresented. Similarly, for the _complete labels_, _FK_ makes up about 46.5% of the samples, followed by _FK_, with _MAK_ at approximately 27.1% and the other labels being comparatively rare. This imbalance reflects the real-world variability in textile patterns and highlights the need for robust training strategies to mitigate its impact on model performance. ( a ) ( b ) Figure 7. Stitch distribution for ( a ) front labels and ( b ) complete labels. 3. Model Architecture The architecture we propose for generating knitting instructions from fabric images is structured to address the key limitations identified in previous methods, particularly in the approach used by Kaspar et al. (2019) [2]. In contrast to Kaspar et al., who utilized a single _generation phase_ to directly predict 17 single-yarn ( _sj_ ) labels, our methodology introduces an additional _inference_ _phase_ that significantly enhances the scope and precision of the generated knitting instructions. In our approach, the _generation phase_ initially predicts 14 distinct _front labels_ instead of final _sj_ labels. These _front labels_ are carefully chosen to capture the visual differences that are more discernible in the fabric images, making them easier for the model to identify accurately. By focusing on these foundational features, we simplify the initial prediction task, which improves the robustness and accuracy of _front label_ generation. The _inference phase_ then takes these 14 _front labels_ and processes them through a _residual_ _model_ to generate a comprehensive set of 34 _complete labels_ . This _complete label_ set is not only compatible with single-yarn knitting ( _sj_ ) but is also designed to support multi-yarn ( _mj_ ) knitting applications, enabling the production of more intricate and multi-colored patterns. This two-step approach—starting with visually distinctive front labels and refining them into complete knittable labels—represents a major advancement in automated knitting _Electronics_ 2025, _1_, 0 7 of 23 instruction generation. This architecture thus enhances both the scalability and flexibility of the model, making it suitable for a broader range of textile applications. The overall architecture can be visualized in the schematic provided below (Figure 8), which illustrates the flow from _real image_ to _front label_ and finally to _complete label_ through the proposed _generation and inference phases_ . ( a ) ( b ) Figure 8. Overall architecture: ( a ) architecture diagram; ( b ) input and output. _3.1._ _Front Label Generation:_ _Refiner and Img2prog_ The _generation phase_ of our model processes the input _real images_ into _front labels_ in two steps: a _refiner_ is used to produce intermediate _rendering_ _images_ and an Img2prog module to map these images to _front labels_ (Figure 9). While the refiner acts as the _generator_, and Img2prog as the _encoder_, their specific roles are enhanced with innovations that improve the accuracy and robustness of the label prediction pipeline. This approach builds upon and improves Kaspar et al.’s work [2]. This study improves upon Kaspar et al. [2] in two key areas. First, the precise mapping from _real images_ to _rendering images_ replaces Kaspar’s indirect transfer approach, which aligns _real images_ to the rendering domain without creating specific one-to-one mappings. In contrast, our refiner directly maps each _real image_ to a corresponding predefined _rendering_ _image_, reducing ambiguity and improving the accuracy of downstream label predictions. Second, this work introduces a stricter cross-entropy loss by eliminating the multipleinstance learning (MIL) tolerance used by Kaspar et al., which allowed neighboring labels to be considered correct. While MIL provided flexibility, it compromised precision, especially on imbalanced datasets where labels like _FK_ dominate (accounting for 75% of data points). By enforcing stricter accuracy, our approach avoids overfitting to dominant labels and ensures improved performance across all classes [2]. _Electronics_ 2025, _1_, 0 8 of 23 ( a ) ( b ) Figure 9. Refiner+Img2prog architecture: ( a ) refiner+Img2prog diagram; ( b ) input and output. The refiner is a GAN model introduced by Shrivastava et al. (2017) [3]. Their work proposed the idea of refining synthetic images into realistic ones using adversarial training. This foundational concept inspired the design of the _refiner_ used in our pipeline, which adapts their approach to refine residual images into accurate _rendering images_ . The _refiner_, implemented as _oper_img2img_bottleneck_, refines _residual images_ derived from _real images_ into _rendering images_, which serve as intermediary representations. Acting as the _generator_ in the pipeline, the _refiner_ operates through a series of distinct stages. Initially, during input preprocessing, a _residual_ image is generated by subtracting a mean value from the _real_ _image_, which normalizes the input and highlights key patterns for further processing. The encoder process then extracts features from the _residual image_ using convolutional layers and a stride of two to progressively downsample and encode essential information, aided by ReLU activations to ensure non-linearity. At the model’s core, the bottleneck comprises residual blocks that preserve spatial dimensions while capturing deeper and more intricate features, crucial for generating accurate _rendering images_ . Finally, the decoder process reconstructs the processed features into a refined _rendering image_ using upsampling techniques, such as bilinear interpolation followed by convolutional layers. The output is a _rendering image_ that closely matches the ground truth, offering clear visual cues for subsequent tasks like label prediction. _Electronics_ 2025, _1_, 0 9 of 23 The Img2prog module, implemented as _oper_img2prog_final_complex_, transforms the refined _rendering images_ output from the _refiner_ into _front labels_ that encode knitting instructions. Acting as the encoder in the pipeline, Img2prog begins with feature extraction, where convolutional layers reduce the spatial dimensions of the input while capturing its essential features. During this stage, intermediate outputs are preserved for use in skip connections. These skip connections integrate intermediate features, by transforming them through space-to-depth operations, reducing them via convolution, and then concatenating them to form a combined feature map. This approach ensures the fusion of both low-level and high-level information for enhanced feature learning. The residual blocks, similar to those in the refiner, further refine the combined features by processing the local and global dependencies within the knitting patterns. Finally, the output layer uses convolutional layers to map the refined features into _logits_ corresponding to the 14 _front labels_ . The predicted labels are derived through an _argmax_ operation, which determines the most probable class for each label. By refining specific _rendering images_ with the _refiner_ and mapping them to _front labels_ with Img2prog, our method achieves significant improvements in precision and robustness. These two steps form the backbone of our _generation phase_, addressing key shortcomings in Kaspar et al.’s approach and laying the foundation for subsequent _inference-phase_ processing. Our project employs multiple loss functions to guide the training process effectively. These losses include cross-entropy, adversarial, perceptual, and style losses. Each loss component contributes uniquely to the generation of accurate and realistic knitting instructions and images. Cross-entropy loss is a standard metric used in classification tasks to quantify the difference between the predicted probability distribution and the ground truth labels. The formula for cross-entropy loss is _L_ CE = _−_ _N_ ### ∑ _i_ =1 _yi_ log( ˆ _yi_ ) (1) where _yi_ represents the ground truth label for class _i_, _y_ ˆ _i_ is the predicted probability for class _i_, and _N_ denotes the total number of classes. In this project, cross-entropy loss is applied to the _logits_ generated by the _Img2prog_ module to compare the predicted _front labels_ with the ground truth instructions. This loss is computed for both real and synthetic data. Unlike Kaspar et al. [2], who implemented a multiple-instance learning (MIL) strategy to allow label tolerance, our approach strictly evaluates exact matches between predictions and the ground truth. This stricter evaluation avoids inflating accuracy metrics and ensures precise predictions, particularly for imbalanced datasets. Overall, cross-entropy loss is crucial for improving the model’s ability to generate accurate knitting instructions as it effectively aligns the model’s predictions with the target labels. Adversarial loss, inspired by Generative Adversarial Networks (GANs) [6], is employed to enhance the realism of the generated _rendering images_ . We utilize a Conditional GAN (cGAN) framework [7], where the discriminator distinguishes between real and generated images based on the input instructions. The adversarial loss of a generator is computed using the least squares GAN approach [8]: _L_ adv = E _x_ [( _D_ ( _G_ ( _x_ ), _y_ ) _−_ 1) <sup>2</sup> ] (2) where _x_ represents the input image, _y_ is the conditioning information (instructions), _G_ ( _x_ ) is the image generated by the refiner, and _D_ is the discriminator. _Electronics_ 2025, _1_, 0 10 of 23 In our method, the _refiner_ serves as the generator, producing _rendering images_ from _real_ _images_, while the discriminator evaluates their authenticity. Specifically, the discriminator compares ground truth rendering images, or positive samples, to the generated _rendering_ _images_ or ground truth _real images_, which are considered negative samples. Adversarial loss forces the _refiner_ to generate _rendering images_ that are indistinguishable from real ones, ensuring they achieve a higher degree of visual realism. This improved realism enhances the quality of the generated outputs, making them more suitable for subsequent tasks such as accurate _front label_ prediction. Perceptual loss evaluates the similarity between the generated and ground truth _ren-_ _dering images_ in the feature space of a pre-trained VGG network [18]. This loss builds upon the work of Gatys et al. (2016) [19] on neural style transfers. Perceptual loss, specifically when focusing on style similarity, is defined as follows: _L_ style = ∑ _l_ _wl∥G_ <sup>_l_</sup> ( ˆ _x_ ) _−_ _G_ <sup>_l_</sup> ( _x_ ) _∥_ <sup>2</sup> _F_ (3) where _G_ <sup>_l_</sup> ( _·_ ) represents the Gram matrix of the feature maps from layer _l_, _x_ ˆ and _x_ are the generated and ground truth images, _wl_ denotes the weight assigned to each layer, and _∥· ∥F_ is the Frobenius norm. In our method, perceptual loss evaluates the features extracted from layers of the VGG network. By comparing these features, the loss ensures that the generated _rendering images_ maintain their structural and textural consistency with the ground truth. This encourages the model to produce outputs that not only visually resemble the target images but also retain the stylistic and structural details necessary for accurate instruction generation. Syntax loss is designed to enforce syntactic correctness in the predicted knitting instructions. It penalizes invalid transitions between stitches based on a predefined syntax of knitting patterns. This loss function does not have a straightforward mathematical formula but operates by referencing a transition matrix that defines valid stitch combinations. In our method, the predicted instruction logits are compared against these allowable transitions to ensure logical and structural compliance with knitting patterns. This approach guarantees that the generated instructions are not only accurate at the individual stitch level but also syntactically valid. By adhering to these constraints, the syntax loss ensures that the resulting instructions can be feasibly manufactured, making them both practical and consistent with real-world knitting requirements. The total loss function for the _generator phase_ combines several components to ensure the generated _front labels_ are accurate, realistic, and syntactically valid. The total loss can be expressed as follows: _L_ total = _L_ CE + _L_ adv + _L_ style + _L_ syntax (4) These components work together to achieve high-quality _front label_ predictions that not only align with the knitting patterns but are also realistic and compliant with knitting syntax. _3.2._ _Complete Label Inference:_ _Residual Model_ The _inference phase_ focuses on transforming the 20 _×_ 20 _front label_, generated by the _generator_ ( _refiner+Img2prog_ ), into a 20 _×_ 20 _complete label_ . This step is essential for producing knittable instructions, as the _front label_ only represents the visible front side of the fabric, omitting the back layers necessary to create comprehensive knitting instructions. The _residual model_ transforms the _front label_ into a _complete label_ using a three-stage architecture that includes an _encoder_, _bottleneck_, and _decoder_ (Figure 10). The _encoder_ begins by extracting features from the input using an initial convolution layer with Conv2D, BatchNorm, and ReLU activations, ensuring efficient feature representation. Residual blocks are then applied to process these features while preserving their _Electronics_ 2025, _1_, 0 11 of 23 spatial consistency, followed by max pooling to reduce their spatial resolution. Intermediate outputs are retained through skip connections, enabling the decoder to access earlier feature maps for precise reconstruction. The _bottleneck_ stage refines these features further using a deep residual block and includes dilated convolutions to expand the receptive field without increasing the number of parameters, capturing the long-range dependencies critical for accurate predictions. Finally, the _decoder_ reconstructs the _complete label_ by gradually upsampling the features to restore spatial resolution. It combines the earlier encoder outputs via skip connections to ensure that both high-level and low-level features contribute to the final output. A final convolution layer produces the 20 _×_ 20 _complete label_, encoding comprehensive knitting instructions with structural consistency. The _residual model_ leverages residual blocks, skip connections, and dilated convolutions to ensure precise and efficient transformation of the _front label_ into a fully knittable _complete label_ . ( a ) ( b ) Figure 10. Residual model architecture: ( a ) residual diagram; ( b ) input and output. _Electronics_ 2025, _1_, 0 12 of 23 The _front label_ exclusively contains information about the front-facing stitches, leaving out the structural details of the back side. A _complete label_ combines the information from both the front and back stitches, ensuring that the generated instructions are machinecompatible and create knittable outcomes. As demonstrated by Yuksel et al. (2012), in traditional stitch patterning, the label of the current stitch is strongly correlated with its four neighboring stitches (up, down, left, and right) [12]. This intrinsic relationship validates our choice to incorporate 3 _×_ 3 kernels in the network architecture, as they effectively capture local spatial dependencies. The _residual model_ utilizes residual blocks inspired by He et al.’s ResNet architecture, which addresses the vanishing gradient problem in deep networks [16]. Each block consists of convolutional layers with skip connections, enabling gradients to flow directly through the network and allowing the model to learn more effectively. This architecture is particularly well suited to tasks requiring spatial consistency, such as inferring _complete labels_ from _front labels_, where minor errors can propagate throughout the knitting instruction set. To train the _inference_ _phase_, we employed a cross-entropy loss function (Equation (1)). Unlike the _generator_ _phase_, where pixel-level differences in _real_ _images_ and _front_ _labels_ have a minimal impact on accuracy, the _inference_ _phase_ demands precise stitchlevel predictions. Introducing multiple-instance learning (MIL) techniques, as done by Kaspar et al. (2019) [2], would exacerbate the prediction error by neglecting the fine-grained differences between adjacent stitches. Given the small input resolution (a 20 _×_ 20 _front label_ ), such approximations lead to substantial inaccuracies in the _complete label_ . By strictly adhering to a standard cross-entropy loss, our model effectively balances the interdependencies between adjacent stitches and enforces stricter accuracy requirements. 4. Experimental Setup and Results Our model supports four key usage scenarios, as detailed in Appendix A. The first scenario focuses on _front label_ generation, where real knitting images are processed using the _refiner_ and Img2prog modules to produce _front labels_ . The second scenario, _complete_ _label generation (unknown yarn type)_, generates a _complete label_ without prior knowledge of the input yarn type by utilizing the full pipeline, including inference. The third scenario, _complete_ _label_ _generation_ _(known_ _yarn_ _type)_, further optimizes this process by leveraging yarn-specific residual models, distinguishing between the single-yarn ( _sj_ ) and multi-yarn ( _mj_ ) categories. Finally, the fourth scenario, _complete label generation (using ground truth front_ _label)_, directly uses ground truth _front labels_ as input to produce _complete labels_, reducing the model’s dependence on the _front label generation_ step. Each scenario includes detailed commands for execution and training, with TensorBoard support for monitoring the model’s performance and visualizing its results. For more information, see Appendix A. The experiments carried out for this project were conducted on a system configured with an NVIDIA RTX 2070 GPU running on Windows 11 with WSL2. The Ubuntu 18.04.6 operating system was installed within WSL2 to set up the necessary Linux-based environment. The deep learning framework used for this project was TensorFlow 1.11, with Python 3.6, CUDA Toolkit 9.0, and cuDNN 7.1 used for GPU acceleration. The following sections detail the environment configuration process and essential software installations. The full setup process, with detailed and reproducible commands, is documented in Appendix B. To evaluate the model’s performance comprehensively, we designed four scenarios, each reflecting varying levels of input information and output requirements. The first scenario focuses on generating _front labels_ from _real images_ using the _generation phase_ ( _refiner_ + Img2prog), which forms the basis for subsequent tasks. The second scenario generates _complete labels_ without prior knowledge of yarn types by first producing the _front label_ and then inferring the _complete label_ . In the third scenario, in which yarn type information ( _sj_ or _Electronics_ 2025, _1_, 0 13 of 23 _mj_ ) is known, the process uses a yarn-specific residual model for _complete label_ generation. Finally, the fourth scenario bypasses _front label_ generation entirely by directly inputting a ground truth _front label_ into the residual model to predict the _complete label_ . These scenarios provide a structured framework for analyzing the model’s adaptability and performance across a diverse range of tasks. _4.1._ _Generation Phase Evaluation—Scenario 1_ Table 1 summarizes the results from different models used in the _generation_ _phase_ . The metrics evaluated include _sample size_, _parameter count_ (indicating model complexity), _training time_ (in hours), and _F1-score_, which acts as the performance indicator. The _F1-score_ was chosen due to the highly imbalanced label distribution in the dataset, ensuring a robust evaluation of the model’s performance across all classes. Table 1. Results of models used for generation phase. Model Sample Size Params Count <u>*</u> Time (h) F1-Score RFI_complex_a0.5 12,392 2,934,605 6.50 90.2% RFINet_notran_noaug_newinst 12,392 2,934,398 5.00 97.3% RFINet_front_xferln_MIL_160k 4950 2,934,398 3.00 82.1% RFINet_front_xferln_160k ** 4950 2,934,398 3.00 83.1% - Params Count indicates the model’s complexity. ** This is the selected model. The first two models, _RFI_complex_a0.5_ and _RFI_notran_noaug_newinst_, were trained on Kaspar’s dataset of 12,392 single-yarn ( _sj_ ) samples. The baseline model, _RFI_complex_a0.5_, used a label space with 17 classes, which made visual differentiation challenging and reduced its flexibility in generating extended knittable instructions. In contrast, _RFI_notran_noaug_newinst_ addressed these issues by reducing the label space to 14 _front_ _labels_, simplifying the classification task and improving its adaptability for _complete label_ generation. Additionally, it used paired input–output data, explicitly mapping _real images_ to _rendering images_, and introduced _transfer images_ generated with m1plus software as augmented data to compensate for the scarcity of real images. These improvements increased the _F1-score_ from 90.2% to 97.3% while reducing the model’s complexity and training time. The next two models, _RFINet_front_xferln_MIL_160k_ and _RFINet_front_xferln_160k_, were trained on a curated dataset of 4950 samples, consisting of 3000 _sj_ and 1950 _mj_ samples. Both models leveraged transfer learning, using pretrained weights from _RFI_notran_noaug_newinst_ to enable faster convergence. The _RFINet_front_xferln_MIL_160k_ model incorporated MIL into its cross-entropy loss, allowing tolerance for neighboring labels. While this approach improved its fault tolerance, it reduced precision due to overgeneralization, achieving an _F1-score_ of 82.1%. By eliminating MIL and enforcing stricter label predictions, the _RFINet_front_xferln_160k_ model achieved a higher _F1-score_ of 83.1%, particularly improving its predictions for underrepresented labels. We selected _RFINet_front_xferln_160k_ as the _generation phase_ model for Scenario 1 ( _front_ _label_ prediction) based on three factors. First, it was trained on a balanced dataset of 4950 samples, ensuring compatibility with multi-yarn ( _mj_ ) data, which were limited in number. Second, its stricter cross-entropy loss resulted in improved accuracy when handling the imbalanced label distribution. Finally, the use of 14 _front_ _labels_ provided the flexibility needed for generating _complete labels_, making this model a robust and versatile solution for downstream tasks. The performance of the _RFINet_front_xferln_160k_ model in predicting each stitch in Scenario 1 ( _sj_ + _mj_ ) is presented in Table 2. The results demonstrate the model’s success in identifying frequently occurring labels, such as _FK_ and _BK_, for which it achieved _F1-score_ s _Electronics_ 2025, _1_, 0 14 of 23 of 90.5% and 78.2%, respectively. These high scores can be attributed to the dominance of these stitches in the dataset, allowing the model to make robust predictions. Table 2. Results from generation phase for each stitch. Stitch Scenario 1 ( _sj_ + _mj_ ) Count F1-Score FK 1,484,133 90.5% BK 209,577 78.2% T 87,510 53.6% H 41,059 67.8% M 37,223 35.5% E 166 0.0% V 1471 34.9% VR 25,359 69.1% VL 25,733 64.1% X(R) 7031 68.5% X(L) 7043 59.8% O 18,933 43.0% Y 22,904 63.3% FO 11,858 30.8% - Stitch labels and images can be observed in Figure 4. However, the analysis highlights significant challenges encountered with underrepresented labels. For instance, stitch E, for which there were only 166 samples, achieved an _F1-score_ of 0.0%, showing the model’s inability to predict this rare label. Similarly, stitch V, for which there were only 1,471 samples, achieved a low _F1-score_ of 34.9%, indicating the adverse impact of insufficient training data. In contrast, labels such as VR, VL, and X(R), which had moderate sample counts, achieved _F1-scores_ of 69.1%, 64.1%, and 68.5%, respectively, reflecting the model’s ability to generalize when the distribution of data is relatively balanced. These findings emphasize the importance of addressing data imbalances to improve predictions for less common labels. Increasing the sample size for stitches like E and V through targeted data augmentation or rebalancing efforts could enhance the model’s performance on these stitches. Overall, the model shows strong results for common stitches and lays a promising foundation for further improvements in handling underrepresented labels. _4.2._ _Inference Phase Evaluation—Scenarios 2, 3, and 4_ Table 3 presents the results for various models used in the _inference phase_ across three scenarios: Scenario 2 (unknown yarn type), Scenario 3 (known yarn type), and Scenario 4 (ground truth _front label_ ). The columns are similar to those in the _generation phase_ table, detailing sample size, parameter count, training time, and _F1-score_ . This table highlights several trends and key observations about the performance of the _inference phase_ models. _Electronics_ 2025, _1_, 0 15 of 23 Table 3. Results for models used in inference phase. Model Sample Size Params Count Time (h) F1-Score RFINet_complete_MIL 4950 2,935,778 4.67 71.6% RFINet_complete 4950 2,935,778 4.67 80.8% xfer_complete_frompred_2lyr_MIL 4950 21,026 2.75 39.4% xfer_complete_frompred_2lyr 4950 21,026 2.75 52.7% xfer_complete_frompred_5lyr 4950 1,585,422 3.00 78.1% xfer_complete_frompred_residual * 4950 872,034 3.00 85.9% <u>xfer_complete_frompred_unet</u> <u>4950</u> <u>279,138</u> <u>3.00</u> <u>83.9%</u> xfer_complete_frompred_2lyr_sj 3000 21,026 1.75 95.0% xfer_complete_frompred_residual_sj * 3000 872,034 1.75 97.0% xfer_complete_frompred_unet_sj 3000 279,138 1.75 96.2% xfer_complete_frompred_2lyr_mj 1950 21,026 1.00 74.0% xfer_complete_frompred_residual_mj * 1950 872,034 1.00 90.2% <u>xfer_complete_frompred_unet_mj</u> <u>1950</u> <u>279,138</u> <u>1.00</u> <u>84.2%</u> xfer_complete_fromtrue_2lyr_sj 3000 21,026 1.75 98.4% xfer_complete_fromtrue_residual_sj * 3000 872,034 1.75 99.8% xfer_complete_fromtrue_unet_sj 3000 279,138 1.75 99.3% xfer_complete_fromtrue_2lyr_mj 1950 21,026 1.00 86.3% xfer_complete_fromtrue_residual_mj * 1950 872,034 1.00 96.0% xfer_complete_fromtrue_unet_mj 1950 279,138 1.00 95.4% - These are the selected models for each scenario. 4.2.1. Scenario 2: Complete Label Generation (Unknown Yarn Type) In this scenario, where predicted _front labels_ are used as input without prior knowledge of the yarn type ( _sj_ or _mj_ ), two key observations emerge. First, the impact of MIL techniques is notable. Models incorporating MIL, such as _RFINet_complete_MIL_ and _xfer_complete_frompred_2lyr_MIL_, underperform compared to their non-MIL counterparts. For instance, _RFINet_complete_MIL_ achieves an _F1-score_ of only 71.6%, while the stricter _RFINet_complete_ has an improved score of 80.8%. Similarly, _xfer_complete_frompred_2lyr_MIL_ scores 39.4%, whereas its non-MIL variant achieves 52.7%. This discrepancy highlights the unsuitability of MIL for the _inference phase_, where precise stitch-level predictions are essential, aligning with previous findings on MIL’s limitations in handling fine-grained spatial dependencies at a 20 _×_ 20 resolution. Second, the effectiveness of the new CNN architectures becomes evident. Models using CNN-based architectures, such as the 2-layer, 5-layer, residual, and UNet variants, demonstrate varying levels of performance. Among these, the residual model ( _xfer_complete_frompred_residual_ ) achieves the best balance between accuracy and complexity, with an _F1-score_ of 85.9%. It outperforms _RFINet_complete_ (80.8%) and delivers comparable results to more complex models like _xfer_complete_frompred_5lyr_ (78.1%). These results emphasize the residual model’s efficiency and effectiveness in this task. 4.2.2. Scenario 3: Complete Label Generation (Known Yarn Type) In this scenario, knowing the yarn type ( _sj_ or _mj_ ) enables the use of yarn-specific models, resulting in significant performance improvements. _Residual_ models, such as _xfer_complete_frompred_residual_sj_ and _xfer_complete_frompred_residual_mj_, achieve _F1-scores_ of 97.0% and 90.2%, respectively, outperforming their Scenario 2 counterparts. This highlights the advantage of yarn-specific training in enhancing prediction accuracy. UNet models, including _xfer_complete_frompred_unet_sj_ and _xfer_complete_frompred_unet_mj_, also perform well; however, the residual models maintain a slight edge in terms of accuracy, demonstrating their efficiency and robustness in this task. _Electronics_ 2025, _1_, 0 16 of 23 4.2.3. Scenario 4: Complete Label Generation (Using Ground Truth Front Label) In this ideal scenario, where the input is the ground truth _front label_, bypassing the _generation_ _phase_, the _inference_ _phase_ achieves its best theoretical performance. Residual models excel, with _xfer_complete_fromtrue_residual_sj_ achieving an _F1-score_ of 99.8% and _xfer_complete_fromtrue_residual_mj_ reaching 96.0%. These results validate the effectiveness of CNN-based approaches in capturing the spatial dependencies between neighboring stitches using 3 _×_ 3 kernels, consistent with previous theoretical insights [12]. Key observations further highlight the pipeline’s robustness. The incremental improvement from Scenario 2 to Scenario 4 demonstrates the _inference_ _phase’s_ capacity to leverage additional input information, with its accuracy consistently increasing as more precise data are provided. Notably, despite the _generation phase_ achieving an _F1-score_ of 83.1% in _front label_ prediction, the _inference phase_ compensates for these errors, achieving higher _F1-scores_ even in less favorable conditions, such as Scenario 2. Moreover, the _residual_ model ( _xfer_complete_frompred_residual_ ) consistently balances complexity and performance, outperforming 5-layer CNN models and achieving comparable results to UNet models with fewer parameters. This analysis underscores the _inference_ _phase’s_ critical role in ensuring the pipeline’s overall accuracy and robustness by compensating for errors and leveraging spatial correlations to produce knittable _complete labels_ . Table 4 presents the performance of the _inference phase_ models across Scenarios 2, 3, and 4, offering several insights. In Scenario 2, where the yarn type is unknown, common stitches like FK and BK perform well, with _F1-scores_ of 95.9% and 82.6%, respectively. However, rare stitches such as AO(2) (31.8%) and FO(2) (32.3%) struggle due to insufficient data. Additionally, multi-yarn-specific labels like V,HM achieve a modest accuracy (46.1%), further underscoring the challenges posed by data scarcity. Table 4. Results from inference phase for each stitch. Stitch Scenario 2 ( _sj_ + _mj_ ) Scenario 3 ( _sj_ ) Scenario 3 ( _mj_ ) Scenario 4 ( _sj_ ) Scenario 4 ( _mj_ ) Count F1-Score Count F1-Score Count F1-Score Count F1-Score Count F1-Score FK 920,228 95.9% 90,474 98.5% - 0.0% 90,474 100.0% - 0.0% BK 183,030 82.6% 13,375 95.2% 11,366 81.8% 13,375 99.7% 11,366 92.8% T 87,698 65.2% 11,366 89.1% - 0.0% 3207 98.9% - 0.0% H,M 15,618 66.2% - 0.0% - 0.0% 1001 97.1% - 0.0% M 22,342 65.0% 885 97.1% 2308 80.4% 885 97.1% 2308 96.0% E,V(L) 15,901 64.5% 158 84.9% 158 94.8% 158 94.8% - 0.0% V,HM 1179 46.1% - 0.0% - 0.0% - 0.0% - 0.0% VR 8214 84.0% 809 92.1% 809 92.1% 809 99.7% 809 99.7% VL 7919 82.0% 864 91.9% 864 91.9% 864 99.5% 864 99.5% X(R) 7031 90.1% 741 95.9% 741 95.9% 741 99.6% 741 99.6% X(L) 7043 90.0% 713 95.9% 713 95.9% 713 99.6% 713 99.6% T(F) 25,024 78.5% 3207 89.1% - 0.0% 3207 98.9% - 0.0% V,M 265 80.0% - 0.0% 6 80.0% - 0.0% - 0.0% E,V(R) 15,703 85.0% 1747 89.1% - 0.0% 1747 99.7% - 0.0% FK,MAK 536,224 88.9% - 0.0% 107,069 94.6% - 0.0% 107,069 99.0% FT,FMAK 65,413 88.9% - 0.0% 13,106 92.1% - 0.0% 13,106 92.6% Y,MATBK 22,904 63.3% 4741 98.9% - 0.0% 4741 99.6% - 0.0% FO(2) 7324 32.3% - 0.0% 1924 82.3% - 0.0% 1,924 69.4% O(5),BK 7774 43.6% - 0.0% 1500 51.9% - 0.0% 1500 67.9% VR,FMAK 23,014 88.8% 4,419 95.9% - 0.0% 4419 99.9% - 0.0% AO(2) 7767 31.8% - 0.0% 1441 64.7% - 0.0% 1441 64.0% - Stitch labels and images can be observed in Figure 4. In Scenario 3, where the yarn type is known, separating the single-yarn ( _sj_ ) and multiyarn ( _mj_ ) datasets leads to significant performance improvements. For instance, FK leads to a 98.5% accuracy on the _sj_ dataset, while FK,MAK reaches 94.6% on the _mj_ dataset. The _Electronics_ 2025, _1_, 0 17 of 23 separation allows the model to specialize in stitches exclusive to either _sj_ or _mj_, capturing their unique structural characteristics. In the ideal case of Scenario 4, where ground truth _front labels_ are provided, the model achieves near-perfect results. _FK_ achieves 100% accuracy with the _sj_ dataset, and _FK,MAK_ reaches 99.0% accuracy with the _mj_ dataset, validating the theoretical feasibility of inferring _complete labels_ from accurate _front labels_ . The key takeaways from this analysis include the benefits of separating yarn types during training, which significantly boosts stitch-specific accuracy, and the potential for near-ideal performance with perfect _front label_ inputs. Nonetheless, rare stitches remain challenging, highlighting the need for targeted data augmentation to improve the model’s predictions of these stitches. The results also reinforce the importance of the structural insights gained from yarn type separation in enhancing the model’s specialization and performance. _4.3._ _Case Study_ Figure 11 provides a detailed visualization of the results from multiple scenarios and yarn types, showcasing two samples each from the 4 _j_, 3 _j_, 2 _j_, and _sj_ categories. The figure is organized into columns that represent various stages: the ground truth ( _real image, rendering_ _image, front label, and complete label_ ), predictions from Scenario 1 ( _rendering image_ and _front_ _label_ ), predictions from Scenario 3 ( _complete label_, obtained using the predicted _front label_ and yarn-specific _inference_ models), and predictions from Scenario 4 ( _complete label_ obtained using the ground truth _front label_ ). Figure 11. Case study. This analysis reveals several key observations. The model demonstrates a strong overall performance, accurately predicting _front_ and _complete labels_ across all yarn types. _Electronics_ 2025, _1_, 0 18 of 23 Notably, Scenario 3 highlights the model’s ability to correct errors in _front label_ predictions, as seen in samples from the 4 _j_ and 2 _j_ yarn types. The model’s predictions for _sj_ samples are near-perfect for both the front and complete labels, while _mj_ samples achieve high accuracy despite their more complex patterns. Finally, Scenario 4 serves as a benchmark, producing near-perfect _complete labels_, underscoring the model’s potential when given ideal inputs. This case study highlights the system’s robustness and adaptability, demonstrating its ability to handle diverse yarn types and patterns while effectively correcting errors, making it highly applicable to real-world knitting tasks. 5. Discussion The results demonstrate a clear progression in accuracy across the four scenarios, with Scenario 4 achieving near-perfect results while using ground truth _front labels_ . The _generation_ _phase_, powered by the _RFINet_front_xferln_160k_ model, performs well on common stitches but struggles with rare ones, highlighting the importance of balanced datasets. The _inference_ _phase_ compensates for _generation phase_ errors, showing a state-of-the-art performance with yarn-specific models and ground truth inputs. Our case study reinforces these findings, showcasing the model’s consistent performance across single-yarn ( _sj_ ) and multi-yarn ( _mj_ ) samples, with effective error correction in complex cases like 4 _j_ and 2 _j_ patterns. Key insights include the benefits of yarn type separation, strict loss functions, and residual CNN architectures, which enhance accuracy and robustness. However, data imbalance remains a challenge, particularly for rare stitches. This research puts emphasis on the creation of structurally complete labels over colored complete labels, meaning the labels have true knittability. While the ultimate goal of reverse knitting includes full visual and structural fidelity, this research is limited to non-color-encoding structural outputs. Furthermore, challenges related to 3D garment shaping and material variability are beyond the scope of this study. 6. Conclusions This study addresses critical challenges in _reverse knitting_ by introducing a modular two-stage pipeline that separates _front label_ generation from _complete label_ inference. The pipeline leverages residual CNN models to capture spatial dependencies and generate precise knitting instructions, achieving _F1-scores_ of 83.1% in Scenario 1 ( _generation phase_ ) and of up to 97.0% in Scenario 3 ( _inference_ _phase_ ). The _inference_ _phase’s_ ability to correct errors in the _front label_ predictions ensures the production of knittable instructions. Future research should focus on expanding the relevant datasets, particularly those for multi-yarn samples; addressing label imbalance; and implementing data augmentation (e.g., rotation, brightness adjustments). Incorporating color recognition, flexible input– output dimensions, and advanced loss functions like focal loss could further enhance the system. Optimizing the pipeline for industrial knitting machines and extending it to 3D garment shaping and cross-domain textile processes (e.g., weaving, embroidery) will broaden its applicability and scalability. The current pipeline is constrained by fixed input dimensions (160 _×_ 160 pixels) and stitch grids (20 _×_ 20). Future research should explore handling variable input and output dimensions, leveraging object detection models like YOLO [20] to dynamically detect and label individual stitches, potentially supported by fine-grained stitch-level annotations. These advancements lay the foundation for fully automated, customizable textile manufacturing systems, meeting modern design and production demands. Author Contributions: Conceptualization, X.Z. and H.S.; methodology, H.S. and M.L.; software, H.S.; validation, H.S., M.L., and S.C.; formal analysis, H.S.; investigation, X.Z. and M.L.; resources, X.Z.; _Electronics_ 2025, _1_, 0 19 of 23 data curation, S.C. and X.Z.; writing—original draft preparation, H.S.; writing—review and editing, M.L.; visualization, H.S.; supervision, M.L.; project administration, H.S. and M.L. All authors have read and agreed to the published version of the manuscript. Funding: This research received no external funding. Institutional Review Board Statement: Not applicable Informed Consent Statement: Not applicable Data Availability Statement: The original data presented in the study are openly available on [FigShare at https://doi.org/10.6084/m9.figshare.28333379.v2, accessed on 18 February 2025.](https://doi.org/10.6084/m9.figshare.28333379.v2) The [complete source code required for reproducing the results is available on GitHub at https://github.](https://github.com/SHolic/neural_inverse_knitting/tree/main) [com/SHolic/neural_inverse_knitting/tree/main,](https://github.com/SHolic/neural_inverse_knitting/tree/main) accessed on 18 February 2025. Additionally, a demonstration video showcasing the inference procedure can be viewed on YouTube at [https://](https://www.youtube.com/watch?v=GYR-Pck013s) [www.youtube.com/watch?v=GYR-Pck013s, accessed on 1 April 2025.](https://www.youtube.com/watch?v=GYR-Pck013s) Acknowledgments: We would like to extend our heartfelt gratitude to Xingyu Zheng, Jiahui Shu, Tong Zhou, Ying Teng, and other summer interns from Shanghai Sanda University for their invaluable assistance throughout this project. Our deepest thanks also go to STOLL, created by KARL MAYER and SHIMASEIKI, for generously providing equipment, technical support, and expertise that were critical to the success of this research. Conflicts of Interest: The authors declare no conflicts of interest. Abbreviations The following abbreviations are used in this manuscript: _sj_ single-yarn _mj_ multi-yarn MIL multiple-instance learning CNN Convolutional Neural Network Appendix A Our model supports four distinct use cases: 1. Scenario 1: Front Label Generation - Goal: Obtain a front label from a real image. - Components Used: Generation phase (refiner + Img2prog). - Command: ``` python main.py --checkpoint_dir=./checkpoint/RFINet_front_xferln_160k --training=False ``` - Input: Real image. - Output: Front label. - Training Command: ``` ./run.sh -g 0 -c ./checkpoint/RFINet_front_xferln_160k --learning_rate 0.0005 --params discr_img=1,bvggloss=1,gen_passes=1, bloss_unsup=0,decay_steps=50000, decay_rate=0.3,bunet_test=3, use_tran=0,augment=0,bMILloss=0 --weights loss_D*=1.0,loss_G*=0.2 --max_iter 160000 ``` _Electronics_ 2025, _1_, 0 20 of 23 - TensorBoard: We can use TensorBoard to view various loss changes, generated images, multi-class confusion matrices, etc. ``` tensorboard --logdir "./checkpoint/RFINet_front_xferln_160k/val" ``` 2. Scenario 2: Complete Label Generation (Unknown Yarn Type) - Goal: Obtain a complete label from a real image without prior knowledge of its _sj/mj_ classification. - Components Used: – Generation phase (refiner + Img2prog) for front label generation. – Inference phase for complete label prediction. - Command: ``` python xfernet.py test --checkpoint_dir ./checkpoint/xfer_complete_frompred _residual --model_type residual --dataset default --input_source frompred ``` - Input: Real image. - Output: Complete label. 3. Scenario 3: Complete Label Generation (Known Yarn Type) - Goal: Obtain a complete label with knowledge of the _sj/mj_ classification of the input image. - Components Used: – Generation phase (refiner + Img2prog). – Yarn-specific residual model for inference phase. - Command: ``` python xfernet.py test --checkpoint_dir ./checkpoint/xfer_complete_frompred_sj --model_type residual --dataset sj --input_source frompred ``` Or for _mj_ data: ``` python xfernet.py test --checkpoint_dir ./checkpoint/xfer_complete_frompred_mj --model_type residual --dataset mj --input_source frompred ``` - Input: Real image. - Output: Complete label. 4. Scenario 4: Complete Label Generation (Using Ground Truth Front Label) - Goal: Generate complete labels using a ground truth front label and knowledge of yarn type. - Components Used: Yarn-specific residual model. - Command: ``` python xfernet.py test --checkpoint_dir ./checkpoint/xfer_complete_fromtrue_sj ``` _Electronics_ 2025, _1_, 0 21 of 23 ``` --model_type residual --dataset sj --input_source fromtrue ``` Or for _mj_ data: ``` python xfernet.py test --checkpoint_dir ./checkpoint/xfer_complete_fromtrue_mj --model_type residual --dataset mj --input_source fromtrue ``` - Input: Ground truth front label. - Output: Complete label. For Scenario 2 through to Scenario 4, if you wish to execute the training process, you simply need to change the parameter _test_ to _train_ . Additionally, you can utilize TensorBoard to monitor the loss progression and view the confusion matrix by specifying the given _checkpoint_dir_ . Appendix B The experimental environment was set up using Miniconda for dependency management and package installation. The following steps outline the configuration process, with all commands provided for reproducibility: 1. Install Miniconda ``` wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux -x86_64.sh bash Miniconda3-latest-Linux-x86_64.sh source ~/.bashrc ``` 2. Create and Activate Python 3.6 Environment ``` conda create -n tf1.11 python=3.6 conda activate tf1.11 ``` 3. Install GPU-Compatible TensorFlow and Its Dependencies. Install TensorFlow 1.11 and its associated dependencies, ensuring compatibility with the RTX 2070 and CUDA 9.0. ``` conda install tensorflow-gpu=1.11.0 conda install numpy=1.15.3 conda install scipy=1.1.0 ``` 4. Install CUDA Toolkit and cuDNN ``` conda install cudatoolkit=9.0 cudnn=7.1 ``` 5. Install Python Package Requirements. The required Python packages were installed using the _requirements.txt_ file provided in the project repository. ``` pip install -r requirements.txt ``` 6. Install ImageMagick for Image Processing. ImageMagick was used for image manipulation during the preprocessing stage. The following commands were used: ``` sudo apt update sudo apt install imagemagick sudo apt install zip unzip ``` _Electronics_ 2025, _1_, 0 22 of 23 7. Set Up Jupyter Notebook 6.4.3 for Interactive Development. Jupyter Notebook was installed to facilitate interactive code testing and experimentation. ``` conda install jupyter jupyter notebook --ip=0.0.0.0 --no-browser ``` 8. Install Additional Libraries. For additional functionalities, the Scikit-learn library was installed. ``` conda install scikit-learn ``` The experimental environment was designed to leverage the computational power of the RTX 2070 GPU and the stability of TensorFlow 1.11, ensuring compatibility with older dependencies and toolkits. The use of Miniconda allowed for efficient dependency resolutions, while WSL2 provided a seamless bridge between the Windows and Linux environments. By documenting the environmental setup with reproducible commands, this configuration can be easily replicated for future experiments or debugging purposes. References 1. Bohm, G.; Suteu, M.D.; Doble, L. Study on knitting with 3D drawings using the technology offered by Stoll. _Fascicle_ _Text._ _Leatherwork_ 2022, _23_, 5–9. 2. Kaspar, A.; Oh, T.-H.; Makatura, L.; Kellnhofer, P.; Matusik, W. Neural inverse knitting: From images to manufacturing instructions. In Proceedings of the 36th International Conference on Machine Learning, Long Beach, CA, USA, 9–15 June 2019; pp 3272–3281. 3. Shrivastava, A.; Pfister, T.; Tuzel, O.; Susskind, J.; Wang, W.; Webb, R. Learning from simulated and unsupervised images through adversarial training. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, Honolulu, HI, USA, 21–26 July 2017; pp 2107–2116. 4. Trunz, E.; Klein, J.; Müller, J.; Bode, L.; Sarlette, R.; Weinmann, M.; Klein, R. Neural inverse procedural modeling of knitting yarns from images. _Comput._ _Graph._ 2024, _118_, 161–172. 5. Melnyk, V.E. Punch card patterns designed with GAN. In _Proceedings of the 2021 DigitalFUTURES_ ; Springer: Singapore, 2022; pp 83–94. 6. Goodfellow, I.; Pouget-Abadie, J.; Mirza, M.; Xu, B.; Warde-Farley, D.; Ozair, S.; Courville, A.; Bengio, Y. Generative adversarial nets. _Adv._ _Neural Inf._ _Process._ _Syst._ 2014, _27_, 2672–2680. 7. Mirza, M.; Osindero, S. Conditional generative adversarial nets. _arXiv_ 2014, arXiv:1411.1784. 8. Mao, X.; Li, Q.; Xie, H.; Lau, R.Y.K.; Wang, Z.; Smolley, S.P. Least squares generative adversarial networks. In Proceedings of the IEEE International Conference on Computer Vision, Venice, Italy, 22–29 October 2017; pp 2794–2802. 9. LeCun, Y.; Boser, B.; Denker, J.S.; Henderson, D.; Howard, R.E.; Hubbard, W.; Jackel, L.D. Backpropagation applied to handwritten zip code recognition. _Neural Comput._ 1989, _1_, 541–551. 10. Hochreiter, S.; Schmidhuber, J. Long short-term memory. _Neural Comput._ 1997, _9_, 1735–1780. 11. Scheidt, F.; Ou, J.; Ishii, H.; Meisen, T. deepKnit: Learning-based generation of machine knitting code. _Procedia Manuf._ 2020, _51_, 485–492. 12. Yuksel, C.; Kaldor, J.M.; James, D.L.; Marschner, S. Stitch meshes for modeling knitted clothing with yarn-level detail. _ACM Trans._ _Graph._ 2012, _31_, 37:1–37:12. 13. Wu, K.; Swan, H.; Yuksel, C. Knittable stitch meshes. _ACM Trans._ _Graph._ 2018, _37_, 121:1–121:14. 14. Wu, K.; Gao, X.; Ferguson, Z.; Panozzo, D.; Yuksel, C. Stitch meshing. _ACM Trans._ _Graph._ 2018, _37_, 130:1–130:14. 15. Lafferty, J.; McCallum, A.; Pereira, F. Conditional random fields: Probabilistic models for segmenting and labeling sequence data. In Proceedings of the 18th International Conference on Machine Learning, Williamstown, MA, USA, 28 June–1 July 2001; pp 282–289. 16. He, K.; Zhang, X.; Ren, S.; Sun, J. Deep residual learning for image recognition. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, Las Vegas, NV, USA, 37–30 June 2016; pp 770–778. 17. Narayanan, V.; Albaugh, L.; Hodgins, J.; Coros, S.; McCann, J. Automatic knitting of 3D meshes. _ACM Trans._ _Graph._ 2018, _37_, 109:1–109:14. 18. Simonyan, K.; Zisserman, A. Very deep convolutional networks for large-scale image recognition. _arXiv_ 2015, arXiv:1409.1556. 19. Gatys, L.A.; Ecker, A.S.; Bethge, M. Image style transfer using convolutional neural networks. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, Las Vegas, NV, USA, 27–30 June 2016; pp 2414–2423. _Electronics_ 2025, _1_, 0 23 of 23 20. Redmon, J.; Divvala, S.; Girshick, R.; Farhadi, A. You only look once: Unified, real-time object detection. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, Las Vegas, NV, USA, 37–30 June 2016; pp 779–788. Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.

섹션 본문

섹션 본문이 없습니다.

참고문헌

참고문헌 정보가 없습니다.