Below is a “research menu” you can use to move from today’s labor-intensive Photoshop clean-up to a largely automated, reliable, and repeatable deep-learning pipeline.
It is organized from “quick-win baselines” to “state-of-the-art + domain constraints”, so you can pick what matches your time, data size, and risk tolerance.
- Understand & Formalize the Target Distribution
• Discrete palette: 𝑁 pre-defined yarn colors (often ≤ 256).
• Perfect grid alignment: Each pixel ⇒ 1 yarn intersection.
• Hard color boundaries: no anti-aliasing, no semi-transparent edges.
• Topological rules: same-color regions should be 4-connected, no 1-pixel “islands”, symmetry along warp/weft axes, etc.
Turn these into automatic validators; they will become loss terms and offline evaluation metrics.
- Expand the Training Signal
Your paired set is small. Squeeze more information out of what you already have.
A. Synthetic “noise” maker
- Take every clean design.
- Apply a scanner noise model: blur, slight scaling, perspective warp, pencil jitter, missing pixels, brightness drift.
- Output “fake-hand-drawn” ↔ original pixel-perfect pair.
➜ Turns the large unpaired clean corpus into almost unlimited paired data.
B. Heavy classical augmentations
Rotation, flip, elastic deformation (but keep grid resolution), gamma/brightness, random palette swaps.
- Baseline Model (Paired Supervision)
Architecture
• Standard U-Net or Res-U-Net (small; 4M–8M params).
• Input: 3-channel RGB (or scanner’s CMYK).
• Output: logits over N palette classes (softmax).
Loss
- Cross-entropy per pixel (forces valid palette).
- Smooth-L1 on down-sampled images (preserves structure).
- Edge consistency loss (Sobel on input vs. output).
Training
• Start with synthetic pairs 5-10 epochs.
• Fine-tune on the real paired set.
What you get
Fast baseline (≈90 %–95 % pixel accuracy) but still produces small artifacts.
- “Pix2Pix++” (GAN with paired data)
Pix2Pix (Isola et al. 2017) is exactly “paired image→image”, but add domain-specific tricks:
Generator = previous U-Net.
Discriminator = PatchGAN (70×70) looking at real vs. fake local patches.
Extra losses
• Palette quantization loss: ∑‖softmax(p) − one-hot(p)‖₁ (encourages one 1.0, rest 0).
• Symmetry loss: ‖G(x) − flip(G(x))‖₁ on axes where pattern is symmetric.
• Connected-component penalty: differentiable approximation of “tiny islands” [see Liang et al. 2021 – topology-aware loss].
Pros: Much crisper edges, cleaner color blocks.
Cons: Overfits if the paired set is truly tiny → rely on synthetic pairs heavily.
- Semi-/Unpaired Learning Routes
Scenario: want to leverage the huge clean corpus w/out labels.
5.1 CycleGAN-with-a-prior
Goal: Learn forward F: hand-drawn → pixel-perfect, but use G: pixel-perfect → “pseudo hand-drawn” for cyclic consistency.
Key modifications
• Identity loss (Zhu et al. 2017) to preserve palette if input already looks clean.
• Histogram matching in the cycle to avoid color drift.
Training schedule
Step 1: Pre-train F on synthetic pairs.
Step 2: Run full CycleGAN with tied-weights warm-start.
Empirically stabilizes faster than vanilla CycleGAN.
5.2 VQ-VAE + Conditional Prior
Train a VQ-VAE on the clean corpus only → learns discrete codebook of pattern patches.
Then train a transformer/pixelCNN prior conditioned on the noisy input to predict the latent codes.
Pros: Naturally outputs palette-correct, grid-aligned images.
Cons: More engineering; decoding speed slower (unless you do convolutional autoregressive parallelization).
5.3 Diffusion with Hard Palette Projection
Train an unconditional diffusion model on clean designs (discrete color diffusion, e.g. Palette-Diffusion, Hoogeboom 2022).
At inference, run classifier-free guidance using the scanned image as a “conditioning image embedding” (Denoising Diffusion Implicit Models + ControlNet).
After each denoise step, project to nearest palette color.
State-of-the-art quality if you have 100k+ clean images.
- Hybrid Deep + Rule-based Post-Processing
A lightweight, very practical pipeline:
- CNN predicts per-pixel palette logits.
- Take argmax (hard palette).
- Run morphological closing to remove 1-pixel holes.
- Enforce connectivity with a union-find: merge components < K pixels into nearest larger component (color-aware).
- Symmetry fix: mirror average halves, choose majority vote.
Adds near-zero extra training but buys large quality jumps.
- Evaluation & Automated Acceptance
Metrics
• Pixel accuracy & mean Intersection-over-Union (per palette color).
• Boundary F1 score (1-pixel tolerance).
• Symmetry error (MSE between halves).
• Rule violation counts (# islands, # off-grid pixels, # palette mistakes).
Create an automatic “weaving readiness” checker. Production will only look at images passing 100 % rule compliance.
- Implementation Pointers
Frameworks
• PyTorch + torchvision; Lightning or HuggingFace Accelerate for multi-GPU.
• Albumentations for scanner/photocopy augmentations.
• kornia or diffusers for diffusion paths.
Hardware
A single modern GPU (RTX 4090 / A6000) handles 512² U-Net training easily.
Diffusion needs more VRAM but can be patch-based.
Timeline (agile)
Week 1-2 Noise model + synthetic paired generator.
Week 3-4 Baseline U-Net + rule-based post-processing → internal demo.
Week 5-7 Pix2Pix++ with palette/symmetry losses.
Week 8-12 Experiment with CycleGAN / VQ-VAE depending on results; integrate validator + GUI.
- References to Start Reading
• “Image-to-Image Translation with Conditional Adversarial Networks” – Isola et al. 2017 (Pix2Pix)
• “Unpaired Image-to-Image Translation using Cycle-Consistent Adversarial Networks” – Zhu et al. 2017 (CycleGAN)
• “Taming Transformers for High-Resolution Image Synthesis” – Esser et al. 2020 (VQ-GAN)
• “Palette-based Image Generation with Diffusion Models” – Hoogeboom et al. 2022
• “Topology-Preserving Deep Image Segmentation” – Chen et al. 2019 (for connectedness losses)
• “ControlNet: Adding Conditional Control to Text-to-Image Diffusion Models” – Zhang & Agrawala 2023 (conditioning tricks)
- Recommended Roll-out
- Ship the U-Net+rules MVP to designers; measure manual touch-up time.
- Iterate on GAN/diffusion variants only if ROI > threshold.
- Gradually retrain with new human corrections (active learning loop).
Good luck weaving pixels into yarn! 🧶🖼️