CatV2TON: Vision-Based Virtual Try-On

repository·main·Indexed 42 days ago

https://github.com/zheng-chong/catv2ton

A Diffusion Transformer (DiT) based method for Vision-Based Virtual Try-On (V2TON) that utilizes Temporal Concatenation of video frames and garment conditions. It supports high-quality image and video try-on tasks, including inference and evaluation for datasets such as VITONHD, DressCode, ViViD-S-Test, and VVT.

Tokens
7.1K
Snippets
22
Records
33
Agent score
53%

What's inside CatV2TON

  1. Understand differences between Detectron2 and Detectron

    main

    Detectron2's model zoo uses several experimental settings and implementation details that differ from the original Detectron. If you need to replicate Detectron's behavior exactly for a fair comparison, use the configurations provided in the Detectron1-Comparisons directory.

    Key differences in standard Detectron2 settings:

    • Scale Augmentation: Used during training to improve AP with lower training cost.
    • Loss Function: Uses L1 loss instead of smooth L1 loss for simplicity (may improve box AP but can affect other AP).
    • Pooling: Uses POOLER_SAMPLING_RATIO=0 instead of 2 (no significant AP effect).
    • ROI Alignment: Uses ROIAlignV2 (no significant AP effect).

    To achieve a fair comparison of accuracy and speed against Detectron, use the configs in detectron2/model_zoo/configs/Detectron1-Comparisons/ which omit these changes.

  2. Data structure for common datasets

    main
    When implementing datasets in this repository, avoid loading full data into the final format (e.g., do not read image files directly into memory). Instead, provide the minimal data structure required for usage to ensure efficiency. For image datasets, you should only provide file names and labels, allowing downstream processes to handle the actual reading of the images.
  3. Export Detectron2 models for deployment

    main

    Use the tools in this directory to prepare Detectron2 models for deployment. The current supported export formats are:

    • TorchScript: For deployment in environments that support TorchScript.
    • ONNX: For cross-platform deployment using the ONNX runtime.
    • Caffe2: (Deprecated)

    For detailed usage instructions and tutorials, refer to the official Detectron2 deployment documentation.

  4. Prepare video datasets for processing

    main

    Organize your downloaded videos into the datasets/ directory. Avoid nested structures, as video filenames are used as unique IDs during processing.

    Example structure for the Panda-70M dataset:

    📦 datasets/
    ├── 📂 panda_70m/
    │   ├── 📂 videos/
    │   │   ├── 📂 data/
    │   │   │   ├── 📄 --C66yU3LjM_2.mp4
    │   │   │   └── ...
    📦 datasets/
    ├── 📂 panda_70m/
    │   ├── 📂 videos/
    │   │   ├── 📂 data/
    │   │   │   ├── 📄 --C66yU3LjM_2.mp4
    │   │   │   └── ...
  5. Install the EasyAnimate video_caption environment

    main

    The recommended way to install the environment is using Docker or Aliyun DSW. For local installation, you can follow the Dockerfile.ds build process to set up a Conda environment.

    Hardware Requirement: To generate video descriptions efficiently and save VRAM, the process relies on llm-awq. You must use an NVIDIA GPU with CUDA Compute Capability >= 8.0 (e.g., RTX 3060 or A2 and above).

    # pull image
    docker pull mybigpai-public-registry.cn-beijing.cr.aliyuncs.com/easycv/torch_cuda:asyanimate
    
    # enter image
    docker run -it -p 7860:7860 --network host --gpus all --security-opt seccomp:unconfined --shm-size 200g mybigpai-public-registry.cn-beijing.cr.aliyuncs.com/easycv/torch_cuda:asyanimate
    
    # clone code
    git clone https://github.com/aigc-apps/EasyAnimate.git
    
    # enter video_caption
    cd EasyAnimate/easyanimate/video_caption
  6. Perform Video Filtering

    main

    Filters high-quality videos using a three-stage pipeline:

    1. Aesthetic filtering: Uses aesthetic-predictor-v2-5 to score content.
    2. Text filtering: Uses EasyOCR to remove videos with excessive text.
    3. Motion filtering: Uses interframe optical flow to filter extreme motion.

    Run the following script to save aesthetic, text, and motion scores to meta files in easyanimate/video_caption/datasets/<dataset_name>/videos_clips/:

    Note: If you cannot access huggingface.com, prefix the command with HF_ENDPOINT=https://hf-mirror.com.

    # If huggingface.com is inaccessible:
    HF_ENDPOINT=https://hf-mirror.com sh scripts/stage_2_video_filtering.sh
    
    # Standard run:
    sh scripts/stage_2_video_filtering.sh
  7. Filter videos for quality

    main

    The filtering process removes low-quality videos using three criteria:

    1. Aesthetic Filtering: Uses aesthetic-predictor-v2-5 to score 4 sampled frames.
    2. Text Filtering: Uses EasyOCR to detect and filter videos with large text areas.
    3. Motion Filtering: Uses optical flow to filter out videos with too little or too much motion.

    Run the filtering script:

    sh scripts/stage_2_video_filtering.sh

    Note: If you cannot access huggingface.com, prefix the command with HF_ENDPOINT=https://hf-mirror.com. Metadata (aesthetic, text, and motion scores) is saved in easyanimate/video_caption/datasets/<dataset_name>/videos_clips/.

    # If huggingface.com is inaccessible:
    HF_ENDPOINT=https://hf-mirror.com sh scripts/stage_2_video_filtering.sh
  8. Generate video descriptions (Recaptioning)

    main

    This stage uses VILA1.5 to generate descriptions, an LLM to rewrite them for video generation tasks, and a custom VideoCLIPXL model to ensure consistency between video and text.

    1. Download VILA1.5: Choose a model size appropriate for your VRAM (e.g., VILA1.5-40b-AWQ for A100 40G).
    2. Download LLM (Optional): Download a model like Meta-Llama-3-8B-Instruct for rewriting.
    3. Run the script:
    VILA_MODEL_PATH=/PATH/TO/VILA_MODEL REWRITE_MODEL_PATH=/PATH/TO/REWRITE_MODEL sh scripts/stage_3_video_recaptioning.sh

    Final training files are saved to: easyanimate/video_caption/datasets/<dataset_name>/videos_clips/meta_train_info.json.

    # Example: Download VILA1.5-40b-AWQ
    huggingface-cli download Efficient-Large-Model/VILA1.5-40b-AWQ --local-dir-use-symlinks False --local-dir /PATH/TO/VILA_MODEL
    
    # Example: Download Llama-3-8B-Instruct
    huggingface-cli download NousResearch/Meta-Llama-3-8B-Instruct --local-dir-use-symlinks False --local-dir /PATH/TO/REWRITE_MODEL
    
    # Run recaptioning
    VILA_MODEL_PATH=/PATH/TO/VILA_MODEL REWRITE_MODEL_PATH=/PATH/TO/REWRITE_MODEL sh scripts/stage_3_video_recaptioning.sh
  9. Use common models, dataloaders, and schedulers via model_zoo

    main

    The detectron2/model_zoo/configs/common/ directory contains definitions for common models, dataloaders, schedulers, and optimizers used in training. These objects are defined using lazy instantiation, meaning you can modify their arguments in your configuration before the objects are actually constructed.

    You can access these common definitions in two ways:

    1. Importing them directly into your code.
    2. Loading them via the model_zoo.get_config API within your own configuration files.
  10. Beautify prompts via OpenAI-compatible API

    main

    You can beautify prompts by requesting an OpenAI-compatible server (either a remote service or a local vLLM deployment).

    Option 1: Direct API Request Set OPENAI_API_KEY and OPENAI_BASE_URL environment variables and run beautiful_prompt.py.

    Option 2: Local vLLM Server

    1. Deploy your local LLM using vLLM to create an OpenAI-compatible server.
    2. Run beautiful_prompt.py pointing to your local endpoint.

    Arguments for beautiful_prompt.py:

    • --model: The model name/ID.
    • --prompt: The raw prompt string.
    • --base_url: The API endpoint (e.g., http://localhost:8000/v1).
    • --api_key: Your API key.
    # Option 1: Using environment variables
    OPENAI_API_KEY="your_openai_api_key" OPENAI_BASE_URL="your_openai_base_url" python beautiful_prompt.py \
        --model "your_model_name" \
        --prompt "your_prompt"
    
    # Option 2: Using a local vLLM server
    python -m beautiful_prompt.py \
        --model /path/to/your_llm \
        --prompt "your_prompt" \
        --base_url "http://localhost:8000/v1" \
        --api_key "your_api_key"
  11. Evaluate Image Try-On performance

    main

    Use eval_image_metrics.py to evaluate the performance of CatV2TON on the VITONHD and DressCode datasets. You can either download the pre-generated results from the provided Google Drive links or run inference on your own data first. The script requires paths to ground truth and predicted image folders.

    CUDA_VISIBLE_DEVICES=0 python eval_image_metrics.py \
    --gt_folder YOUR_GT_FOLDER \
    --pred_folder YOUR_PRED_FOLDER \
    --batch_size 16 \
    --num_workers 16 \
    --paired