A multimodal fashion search model that structures CLIP's 512-D embedding into dedicated color, category, and semantic subspaces through direct alignment with frozen-CLIP specialist models.
Using frozen CLIP backbones gives the specialist models the same visual-semantic understanding as the baseline, while the compact projection heads learn attribute-specific representations.
Main Model Training
The main CLIP model is fine-tuned end-to-end with an enhanced contrastive loss that combines:
Triple contrastive loss (text-image, text-attributes, image-attributes)
Alignment loss — MSE + cosine similarity between the main model's subspace dimensions and the specialist model embeddings (both text and image sides)
Reference loss — optional regularization to stay close to the base CLIP text space
1import torch.nn.functional as F
23# Compare specialist vs main-model subspace4color_from_specialist = models['color_model'].get_text_embeddings(["red"])5color_from_main = text_features[:,:16]67similarity = F.cosine_similarity(color_from_specialist, color_from_main, dim=1)8print(f"Color alignment: {similarity.item():.4f}")
CLI
bash
1# Load from HuggingFace and run example search2python example_usage.py --repo-id Leacb4/gap-clip --text "red summer dress"34# With an image5python example_usage.py --repo-id Leacb4/gap-clip --image path/to/image.jpg
Training
1. Train the Color Model
python
1# From the repository root:2python -m training.color_model
Trains ColorCLIP: frozen CLIP ViT-B/32 + trainable Linear(512, 16) projection. Converges in ~30 min on Apple Silicon MPS. Saves checkpoint to models/color_model.pt.
2. Train the Hierarchy Model
python -m training.hierarchy_model
Trains HierarchyModel: frozen CLIP ViT-B/32 + trainable MLP(512 -> 128 -> 64) + classifier heads. Multi-objective loss (classification + contrastive + consistency). Converges in ~60 min on MPS. Saves checkpoint to models/hierarchy_model.pth.
Steps 1 and 2 can run in parallel.
3. Train the Main GAP-CLIP Model
python -m training.main_model
Fine-tunes laion/CLIP-ViT-B-32-laion2B-s34B-b79K with the enhanced contrastive loss using specialist models as alignment targets. Training features:
Enhanced data augmentation (rotation, color jitter, blur, affine transforms)
All evaluations compare GAP-CLIP against the patrickjohncyh/fashion-clip baseline across three datasets: an internal fashion catalogue, KAGL Marqo (HuggingFace), and Fashion-MNIST.