Skip to content

Comments

Swin upgrade#223

Open
TeddyLiang01 wants to merge 27 commits intoPatBall1:masterfrom
TeddyLiang01:Swin-Upgrade
Open

Swin upgrade#223
TeddyLiang01 wants to merge 27 commits intoPatBall1:masterfrom
TeddyLiang01:Swin-Upgrade

Conversation

@TeddyLiang01
Copy link

Summary

This PR adds opt-in Swin Transformer (SwinT) backbone support to detectree2 training + inference, with the SwinT_detectron2 implementation vendored under detectree2/third_party so users don’t need to manually clone/install extra repos. When Swin is enabled, detectree2 can merge the Swin config, load/download compatible weights, and run training/inference without ResNet-specific assumptions.

Key changes

New Swin utilities: detectree2/models/backbones_swin.py

  • prepare_swint_config(...): makes vendored swint importable, registers Swin config nodes, returns YAML to merge.
  • ensure_swint_weights(...): uses provided weights path or auto-downloads default weights to a user cache dir.

Training config support: detectree2/models/train.py

  • Adds use_swint_backbone, swint_config_path, swint_weights_path to setup_cfg.
  • If Swin is selected: merges Swin config and sets cfg.MODEL.WEIGHTS to Swin weights, otherwise preserves existing model-zoo behavior.

Trainer resume/load compatibility: detectree2/models/train.py

  • resume_or_load now skips ResNet stem.conv1 logic when Swin is enabled (no conv1/stem assumptions).

Inference channel handling (Swin-only): detectree2/models/predict.py

  • Adds _using_swint_backbone(predictor) and only when Swin is active, forces inputs to 3 channels (repeat 1-band, drop >3, pad <3) to match Swin weights expectations.

Vendored third-party + packaging: setup.py includes vendored YAMLs + swint/*.py in package_data; .gitignore avoids committing .pth files.

Usage

Example training:

cfg = setup_cfg(
    trains=(train_name,),
    tests=(val_name,),
    use_swint_backbone=True,
    swint_config_path=None,          # optional override
    swint_weights_path=None,         # optional override
)
  • Omitting swint_weights_path auto-downloads default Swin weights to cache.
  • If use_swint_backbone=False, behavior is unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant