How cotton6/cotton-size-does-matter works
Project type and purpose
• This is an academic / open-source research codebase implementing a PyTorch-based high-resolution virtual try-on system (“COTTON”).
• It consists of (a) a large preprocessing toolkit to prepare human parsing, pose, skeleton, segmentation masks and (b) a main stage that trains or runs inference of the size-aware Clothing-Oriented Transformation Try-On Network.
File structure
• Top-level directories:
• code/ – contains main training/inference modules, configs, data loaders, model definitions, utilities, result exporters
• preprocessing/ – many submodules for preparing datasets: human-parsing (CIHP), cloth segmentation, cloth2skeleton, U2Net human segmentation, sleeve classifier, etc.
• TryOn_results/ – sample outputs and banner images
• root config and scripts: download_weights.sh, requirements.txt
• Within code/main/:
• configs/ – YAML files for different garment experiments
• data/1024x768/Example_top/ – precomputed human & product images, masks, parsing, poses
• model_end2end.py, main.py – orchestrate training/inference
• dataLoader.py – unifies loading of human & cloth inputs
• util/, unet/ – network parts, warping utilities, visualization
README for additional insights
• COTTON warps clothes via landmark-guided transformation, uses a clothing segmentation network to eliminate worn garments, supports multi‐size and tucked/untucked try-on.
• Relies on PyTorch, YAML configs, DiffAugment, Focal Loss, HTML visualizer.
Main components & interactions
A. Data Preprocessing (preprocessing/)
• Sub-pipelines: Human parsing (CIHP_PARSING), skeleton heatmap generation (Cloth2Skeleton), cloth segmentation (ClothSegmentation), U2Net human mask, sleeve classifier, etc.
• Outputs: standardized datasets of human images, product images, masks, parsing maps, keypoints, skeletons. Stored under code/main/data.
B. Configuration & Weight Management
• YAML configs drive experiment parameters.
• download_weights.sh fetches pretrained backbones/weights.
C. DataLoader & Augmentation (code/main/dataLoader.py + DiffAugment)
• Reads processed dataset (images + metadata), applies augmentations, bundles batches.
D. Model Forward Pass (code/main/model_end2end.py)
• Landmark-guided cloth warping module
• Clothing segmentation network module
• UNet refinements
E. Loss & Optimization
• Focal_Loss.py for classification components
• other losses (e.g., pixel L1, perceptual) embedded in main.py
F. Visualization & Evaluation
• util/html.py exports results to browsable HTML
• mean_iou_evaluate.py for parsing metrics
• final images written to code/main/result/…
G. External Frameworks & Libraries
• PyTorch, torchvision
• (In preprocessing) detectron2 for segmentation/parsing
Relationships and data‐flow
• Raw images → Preprocessing step(s) → Processed dataset files
• Config & weights loaded into Training/Inference pipeline
• Processed dataset → DataLoader → Model → Warping + Segmentation → Loss computation (training) or direct output (inference)
• Outputs → Visualizer/Evaluator → Result folders / HTML pages
Architectural patterns & design principles
• Modular pipeline separation: preprocessing modules are independent from main training/inference stage.
• Config-driven experiments: allows swapping of garment types, sizes, backbones via YAML.
• Clear separation of concerns: data loading, model definition, loss computation, visualization.
Key takeaways
• Essential modules by grouping related scripts under single logical blocks (e.g., “Human Parsing Preprocessor”).
• How configs/weights influence both preprocessing and the core ML pipeline.
• Make data flows explicit, from raw inputs through multiple transformations, to final outputs.