πŸŽ‰ 75% of content is free forever β€” Unlock Premium from $10/mo β†’
CW
Search courses…
πŸ’Ό Servicesℹ️ Aboutβœ‰οΈ ContactView Pricing Plansfrom $10

ControlNet: Spatial Conditioning

Generative AIControlNet: Spatial Conditioning🟒 Free Lesson

Advertisement

ControlNet: Spatial Conditioning

Module: Generative AI | Difficulty: Advanced

ControlNet Architecture

Zero Conolutions

Ensures ControlNet starts as identity, preserving pre-trained weights.

Training Strategy

  1. Lock pre-trained U-Net
  2. Train ControlNet with zero-init
  3. Gradually increase scale from 0 to 1

Supported Conditions

ConditionExamplesParams
EdgeCanny, HED, MLSD361M
DepthMiDaS, DPT, ZoeDepth361M
PoseOpenPose, DWPose361M
SegmentationOneFormer, SAM361M
TileDetail enhancer361M
class ZeroConv(nn.Module):
    def __init__(self, channels):
        super().__init__()
        self.conv = nn.Conv2d(channels, channels, 3, padding=1)
        nn.init.zeros_(self.conv.weight)
        nn.init.zeros_(self.conv.bias)
    def forward(self, x):
        return self.conv(x)

class ControlNet(nn.Module):
    def __init__(self, unet):
        super().__init__()
        self.zero_convs = nn.ModuleList([ZeroConv(c) for c in unet.channels])
        self.condition_encoder = nn.Sequential(
            nn.Conv2d(3, 64, 3, padding=1), nn.ReLU(),
            nn.Conv2d(64, 128, 3, 2, 1), nn.ReLU(),
            nn.Conv2d(128, 256, 3, 2, 1), nn.ReLU())

Research Insight: Zero convolutions are essential β€” without them, ControlNet can destabilize the pre-trained U-Net in the first few training steps, leading to mode collapse.

Need Expert Generative AI Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement