Full Code of zhihou7/BatchFormer for AI

main 305efaa6c54a cached
770 files
96.6 MB
5.0M tokens
2960 symbols
1 requests
Copy disabled (too large) Download .txt
Showing preview only (20,171K chars total). Download the full file to get everything.
Repository: zhihou7/BatchFormer
Branch: main
Commit: 305efaa6c54a
Files: 770
Total size: 96.6 MB

Directory structure:
gitextract_s7um03j7/

├── README.md
├── batchformer-v2/
│   ├── deformable-detr/
│   │   ├── LICENSE
│   │   ├── README.md
│   │   ├── benchmark.py
│   │   ├── configs/
│   │   │   ├── r101_deformable_detr.sh
│   │   │   ├── r50_deformable_detr.sh
│   │   │   ├── r50_deformable_detr_plus_iterative_bbox_refinement.sh
│   │   │   ├── r50_deformable_detr_plus_iterative_bbox_refinement_plus_plus_two_stage.sh
│   │   │   ├── r50_deformable_detr_single_scale.sh
│   │   │   └── r50_deformable_detr_single_scale_dc5.sh
│   │   ├── datasets/
│   │   │   ├── __init__.py
│   │   │   ├── coco.py
│   │   │   ├── coco_eval.py
│   │   │   ├── coco_panoptic.py
│   │   │   ├── data_prefetcher.py
│   │   │   ├── panoptic_eval.py
│   │   │   ├── samplers.py
│   │   │   ├── torchvision_datasets/
│   │   │   │   ├── __init__.py
│   │   │   │   └── coco.py
│   │   │   └── transforms.py
│   │   ├── docs/
│   │   │   └── changelog.md
│   │   ├── engine.py
│   │   ├── main.py
│   │   ├── models/
│   │   │   ├── __init__.py
│   │   │   ├── backbone.py
│   │   │   ├── deformable_detr.py
│   │   │   ├── deformable_transformer.py
│   │   │   ├── matcher.py
│   │   │   ├── ops/
│   │   │   │   ├── functions/
│   │   │   │   │   ├── __init__.py
│   │   │   │   │   └── ms_deform_attn_func.py
│   │   │   │   ├── make.sh
│   │   │   │   ├── modules/
│   │   │   │   │   ├── __init__.py
│   │   │   │   │   └── ms_deform_attn.py
│   │   │   │   ├── setup.py
│   │   │   │   ├── src/
│   │   │   │   │   ├── cpu/
│   │   │   │   │   │   ├── ms_deform_attn_cpu.cpp
│   │   │   │   │   │   └── ms_deform_attn_cpu.h
│   │   │   │   │   ├── cuda/
│   │   │   │   │   │   ├── ms_deform_attn_cuda.cu
│   │   │   │   │   │   ├── ms_deform_attn_cuda.h
│   │   │   │   │   │   └── ms_deform_im2col_cuda.cuh
│   │   │   │   │   ├── ms_deform_attn.h
│   │   │   │   │   └── vision.cpp
│   │   │   │   └── test.py
│   │   │   ├── position_encoding.py
│   │   │   └── segmentation.py
│   │   ├── requirements.txt
│   │   ├── tools/
│   │   │   ├── launch.py
│   │   │   ├── run_dist_launch.sh
│   │   │   └── run_dist_slurm.sh
│   │   └── util/
│   │       ├── __init__.py
│   │       ├── box_ops.py
│   │       ├── misc.py
│   │       ├── plot_utils.py
│   │       └── visualizer.py
│   ├── deit_share/
│   │   ├── .circleci/
│   │   │   └── config.yml
│   │   ├── .github/
│   │   │   ├── CODE_OF_CONDUCT.md
│   │   │   └── CONTRIBUTING.md
│   │   ├── .gitignore
│   │   ├── .idea/
│   │   │   ├── .gitignore
│   │   │   ├── deit_share.iml
│   │   │   ├── inspectionProfiles/
│   │   │   │   └── profiles_settings.xml
│   │   │   ├── misc.xml
│   │   │   ├── modules.xml
│   │   │   └── vcs.xml
│   │   ├── LICENSE
│   │   ├── README.md
│   │   ├── README_cait.md
│   │   ├── README_resmlp.md
│   │   ├── bt.py
│   │   ├── cait_models.py
│   │   ├── datasets.py
│   │   ├── engine.py
│   │   ├── gpu.pbs
│   │   ├── hubconf.py
│   │   ├── losses.py
│   │   ├── main.py
│   │   ├── models.py
│   │   ├── optimizer.py
│   │   ├── requirements.txt
│   │   ├── resmlp_models.py
│   │   ├── run_with_submitit.py
│   │   ├── samplers.py
│   │   ├── temp.txt
│   │   ├── tiny_img.py
│   │   ├── tox.ini
│   │   └── utils.py
│   └── detr/
│       ├── .circleci/
│       │   └── config.yml
│       ├── .github/
│       │   ├── CODE_OF_CONDUCT.md
│       │   ├── CONTRIBUTING.md
│       │   └── ISSUE_TEMPLATE/
│       │       ├── bugs.md
│       │       ├── questions-help-support.md
│       │       └── unexpected-problems-bugs.md
│       ├── .gitignore
│       ├── Dockerfile
│       ├── LICENSE
│       ├── README.md
│       ├── configs/
│       │   ├── base.sh
│       │   ├── panoptic.sh
│       │   ├── panoptic_1.sh
│       │   ├── panoptic_2.sh
│       │   └── swin.sh
│       ├── d2/
│       │   ├── README.md
│       │   ├── configs/
│       │   │   ├── detr_256_6_6_torchvision.yaml
│       │   │   └── detr_segm_256_6_6_torchvision.yaml
│       │   ├── converter.py
│       │   ├── detr/
│       │   │   ├── __init__.py
│       │   │   ├── config.py
│       │   │   ├── dataset_mapper.py
│       │   │   └── detr.py
│       │   └── train_net.py
│       ├── datasets/
│       │   ├── __init__.py
│       │   ├── coco.py
│       │   ├── coco_eval.py
│       │   ├── coco_panoptic.py
│       │   ├── panoptic_eval.py
│       │   └── transforms.py
│       ├── detr.pbs
│       ├── engine.py
│       ├── hubconf.py
│       ├── main.py
│       ├── models/
│       │   ├── __init__.py
│       │   ├── backbone.py
│       │   ├── detr.py
│       │   ├── matcher.py
│       │   ├── position_encoding.py
│       │   ├── segmentation.py
│       │   └── transformer.py
│       ├── requirements.txt
│       ├── run.py
│       ├── run_with_submitit.py
│       ├── test_all.py
│       ├── tools/
│       │   ├── launch.py
│       │   ├── run_dist_launch.sh
│       │   └── run_dist_slurm.sh
│       ├── tox.ini
│       └── util/
│           ├── __init__.py
│           ├── box_ops.py
│           ├── misc.py
│           └── plot_utils.py
├── czsl/
│   ├── LICENSE
│   ├── README.md
│   ├── configs/
│   │   ├── baselines/
│   │   │   ├── cgqa/
│   │   │   │   ├── aopp.yml
│   │   │   │   ├── le+.yml
│   │   │   │   ├── symnet.yml
│   │   │   │   └── tmn.yml
│   │   │   ├── mit/
│   │   │   │   ├── aopp.yml
│   │   │   │   ├── le+.yml
│   │   │   │   ├── symnet.yml
│   │   │   │   └── tmn.yml
│   │   │   └── utzppos/
│   │   │       ├── aopp.yml
│   │   │       ├── le+.yml
│   │   │       ├── symnet.yml
│   │   │       └── tmn.yml
│   │   ├── cge/
│   │   │   ├── cgqa.yml
│   │   │   ├── mit.yml
│   │   │   └── utzappos.yml
│   │   └── compcos/
│   │       ├── cgqa/
│   │       │   ├── compcos.yml
│   │       │   └── compcos_cw.yml
│   │       ├── mit/
│   │       │   ├── compcos.yml
│   │       │   └── compcos_cw.yml
│   │       └── utzppos/
│   │           ├── compcos.yml
│   │           └── compcos_cw.yml
│   ├── data/
│   │   ├── __init__.py
│   │   └── dataset.py
│   ├── environment.yml
│   ├── flags.py
│   ├── models/
│   │   ├── __init__.py
│   │   ├── common.py
│   │   ├── compcos.py
│   │   ├── gcn.py
│   │   ├── graph_method.py
│   │   ├── image_extractor.py
│   │   ├── manifold_methods.py
│   │   ├── modular_methods.py
│   │   ├── svm.py
│   │   ├── symnet.py
│   │   ├── visual_product.py
│   │   └── word_embedding.py
│   ├── notebooks/
│   │   └── analysis.ipynb
│   ├── test.py
│   ├── train.py
│   └── utils/
│       ├── __init__.py
│       ├── config_model.py
│       ├── download_data.sh
│       ├── download_embeddings.py
│       ├── reorganize_utzap.py
│       └── utils.py
├── domain_generalization/
│   ├── README.md
│   ├── Transfer-Learning-Library/
│   │   ├── .github/
│   │   │   └── ISSUE_TEMPLATE/
│   │   │       ├── bug_report.md
│   │   │       ├── custom.md
│   │   │       └── feature_request.md
│   │   ├── .gitignore
│   │   ├── CONTRIBUTING.md
│   │   ├── LICENSE
│   │   ├── README.md
│   │   ├── common/
│   │   │   ├── __init__.py
│   │   │   ├── loss/
│   │   │   │   └── __init__.py
│   │   │   ├── modules/
│   │   │   │   ├── __init__.py
│   │   │   │   ├── classifier.py
│   │   │   │   └── regressor.py
│   │   │   ├── utils/
│   │   │   │   ├── __init__.py
│   │   │   │   ├── analysis/
│   │   │   │   │   ├── __init__.py
│   │   │   │   │   ├── a_distance.py
│   │   │   │   │   └── tsne.py
│   │   │   │   ├── data.py
│   │   │   │   ├── logger.py
│   │   │   │   ├── meter.py
│   │   │   │   ├── metric/
│   │   │   │   │   ├── __init__.py
│   │   │   │   │   ├── keypoint_detection.py
│   │   │   │   │   └── reid.py
│   │   │   │   └── scheduler.py
│   │   │   └── vision/
│   │   │       ├── __init__.py
│   │   │       ├── datasets/
│   │   │       │   ├── __init__.py
│   │   │       │   ├── _util.py
│   │   │       │   ├── aircrafts.py
│   │   │       │   ├── coco70.py
│   │   │       │   ├── cub200.py
│   │   │       │   ├── digits.py
│   │   │       │   ├── domainnet.py
│   │   │       │   ├── dtd.py
│   │   │       │   ├── eurosat.py
│   │   │       │   ├── imagelist.py
│   │   │       │   ├── imagenet_r.py
│   │   │       │   ├── imagenet_sketch.py
│   │   │       │   ├── keypoint_detection/
│   │   │       │   │   ├── __init__.py
│   │   │       │   │   ├── freihand.py
│   │   │       │   │   ├── hand_3d_studio.py
│   │   │       │   │   ├── human36m.py
│   │   │       │   │   ├── keypoint_dataset.py
│   │   │       │   │   ├── lsp.py
│   │   │       │   │   ├── rendered_hand_pose.py
│   │   │       │   │   ├── surreal.py
│   │   │       │   │   └── util.py
│   │   │       │   ├── office31.py
│   │   │       │   ├── officecaltech.py
│   │   │       │   ├── officehome.py
│   │   │       │   ├── openset/
│   │   │       │   │   └── __init__.py
│   │   │       │   ├── oxfordflowers.py
│   │   │       │   ├── oxfordpet.py
│   │   │       │   ├── pacs.py
│   │   │       │   ├── partial/
│   │   │       │   │   ├── __init__.py
│   │   │       │   │   ├── caltech_imagenet.py
│   │   │       │   │   └── imagenet_caltech.py
│   │   │       │   ├── patchcamelyon.py
│   │   │       │   ├── regression/
│   │   │       │   │   ├── __init__.py
│   │   │       │   │   ├── dsprites.py
│   │   │       │   │   ├── image_regression.py
│   │   │       │   │   └── mpi3d.py
│   │   │       │   ├── reid/
│   │   │       │   │   ├── __init__.py
│   │   │       │   │   ├── basedataset.py
│   │   │       │   │   ├── convert.py
│   │   │       │   │   ├── dukemtmc.py
│   │   │       │   │   ├── market1501.py
│   │   │       │   │   ├── msmt17.py
│   │   │       │   │   ├── personx.py
│   │   │       │   │   └── unreal.py
│   │   │       │   ├── resisc45.py
│   │   │       │   ├── retinopathy.py
│   │   │       │   ├── segmentation/
│   │   │       │   │   ├── __init__.py
│   │   │       │   │   ├── cityscapes.py
│   │   │       │   │   ├── gta5.py
│   │   │       │   │   ├── segmentation_list.py
│   │   │       │   │   └── synthia.py
│   │   │       │   ├── stanford_cars.py
│   │   │       │   ├── stanford_dogs.py
│   │   │       │   └── visda2017.py
│   │   │       ├── models/
│   │   │       │   ├── __init__.py
│   │   │       │   ├── digits.py
│   │   │       │   ├── ibn.py
│   │   │       │   ├── keypoint_detection/
│   │   │       │   │   ├── __init__.py
│   │   │       │   │   ├── loss.py
│   │   │       │   │   └── pose_resnet.py
│   │   │       │   ├── reid/
│   │   │       │   │   ├── __init__.py
│   │   │       │   │   ├── identifier.py
│   │   │       │   │   ├── loss.py
│   │   │       │   │   └── resnet.py
│   │   │       │   ├── resnet.py
│   │   │       │   └── segmentation/
│   │   │       │       ├── __init__.py
│   │   │       │       └── deeplabv2.py
│   │   │       └── transforms/
│   │   │           ├── __init__.py
│   │   │           ├── keypoint_detection.py
│   │   │           └── segmentation.py
│   │   ├── dalib/
│   │   │   ├── __init__.py
│   │   │   ├── adaptation/
│   │   │   │   ├── __init__.py
│   │   │   │   ├── adda.py
│   │   │   │   ├── advent.py
│   │   │   │   ├── afn.py
│   │   │   │   ├── bsp.py
│   │   │   │   ├── cdan.py
│   │   │   │   ├── dan.py
│   │   │   │   ├── dann.py
│   │   │   │   ├── fda.py
│   │   │   │   ├── idm/
│   │   │   │   │   ├── __init__.py
│   │   │   │   │   ├── loss.py
│   │   │   │   │   ├── models/
│   │   │   │   │   │   ├── __init__.py
│   │   │   │   │   │   ├── dsbn.py
│   │   │   │   │   │   ├── identifier.py
│   │   │   │   │   │   ├── idm.py
│   │   │   │   │   │   └── resnet.py
│   │   │   │   │   ├── utils.py
│   │   │   │   │   └── xbm.py
│   │   │   │   ├── iwan.py
│   │   │   │   ├── jan.py
│   │   │   │   ├── mcc.py
│   │   │   │   ├── mcd.py
│   │   │   │   ├── mdd.py
│   │   │   │   ├── osbp.py
│   │   │   │   ├── pada.py
│   │   │   │   ├── regda.py
│   │   │   │   ├── rsd.py
│   │   │   │   └── self_ensemble.py
│   │   │   ├── modules/
│   │   │   │   ├── __init__.py
│   │   │   │   ├── domain_discriminator.py
│   │   │   │   ├── entropy.py
│   │   │   │   ├── gl.py
│   │   │   │   ├── grl.py
│   │   │   │   └── kernels.py
│   │   │   └── translation/
│   │   │       ├── __init__.py
│   │   │       ├── cycada.py
│   │   │       ├── cyclegan/
│   │   │       │   ├── __init__.py
│   │   │       │   ├── discriminator.py
│   │   │       │   ├── generator.py
│   │   │       │   ├── loss.py
│   │   │       │   ├── transform.py
│   │   │       │   └── util.py
│   │   │       ├── fourier_transform.py
│   │   │       └── spgan/
│   │   │           ├── __init__.py
│   │   │           ├── loss.py
│   │   │           └── siamese.py
│   │   ├── dglib/
│   │   │   ├── __init__.py
│   │   │   ├── generalization/
│   │   │   │   ├── __init__.py
│   │   │   │   ├── coral.py
│   │   │   │   ├── groupdro.py
│   │   │   │   ├── irm.py
│   │   │   │   └── mixstyle/
│   │   │   │       ├── __init__.py
│   │   │   │       ├── models/
│   │   │   │       │   ├── __init__.py
│   │   │   │       │   ├── mixstyle.py
│   │   │   │       │   └── resnet.py
│   │   │   │       └── sampler.py
│   │   │   └── modules/
│   │   │       ├── __init__.py
│   │   │       ├── classifier.py
│   │   │       └── sampler.py
│   │   ├── docs/
│   │   │   ├── Makefile
│   │   │   ├── common/
│   │   │   │   ├── loss.rst
│   │   │   │   ├── modules.rst
│   │   │   │   ├── utils/
│   │   │   │   │   ├── analysis.rst
│   │   │   │   │   ├── base.rst
│   │   │   │   │   └── metric.rst
│   │   │   │   └── vision/
│   │   │   │       ├── datasets.rst
│   │   │   │       ├── models.rst
│   │   │   │       └── transforms.rst
│   │   │   ├── conf.py
│   │   │   ├── dalib/
│   │   │   │   ├── adaptation/
│   │   │   │   │   ├── domain_adversarial.rst
│   │   │   │   │   ├── domain_translation.rst
│   │   │   │   │   ├── hypothesis_adversarial.rst
│   │   │   │   │   ├── others.rst
│   │   │   │   │   └── statistics_matching.rst
│   │   │   │   ├── benchmarks/
│   │   │   │   │   ├── image_classification.rst
│   │   │   │   │   ├── image_regression.rst
│   │   │   │   │   ├── keypoint_detection.rst
│   │   │   │   │   ├── multi_source_domain_adaptation.rst
│   │   │   │   │   ├── openset_domain_adaptation.rst
│   │   │   │   │   ├── partial_domain_adaptation.rst
│   │   │   │   │   ├── re_identification.rst
│   │   │   │   │   └── semantic_segmentation.rst
│   │   │   │   └── modules.rst
│   │   │   ├── dglib/
│   │   │   │   ├── benchmarks/
│   │   │   │   │   ├── image_classification.rst
│   │   │   │   │   └── re_identification.rst
│   │   │   │   ├── generalization/
│   │   │   │   │   ├── architecture_design.rst
│   │   │   │   │   ├── data_manipulation.rst
│   │   │   │   │   ├── learning_strategy.rst
│   │   │   │   │   └── representation_learning.rst
│   │   │   │   └── modules.rst
│   │   │   ├── get_started/
│   │   │   │   ├── faq.rst
│   │   │   │   ├── installing.rst
│   │   │   │   ├── introduction.rst
│   │   │   │   ├── quickstart.rst
│   │   │   │   └── visualization.rst
│   │   │   ├── index.rst
│   │   │   ├── make.bat
│   │   │   ├── requirements.txt
│   │   │   └── talib/
│   │   │       ├── benchmarks/
│   │   │       │   └── image_classification.rst
│   │   │       └── finetune.rst
│   │   ├── examples/
│   │   │   ├── domain_adaptation/
│   │   │   │   ├── image_classification/
│   │   │   │   │   ├── README.md
│   │   │   │   │   ├── adda.py
│   │   │   │   │   ├── adda.sh
│   │   │   │   │   ├── addagrl.py
│   │   │   │   │   ├── addagrl.sh
│   │   │   │   │   ├── afn.py
│   │   │   │   │   ├── afn.sh
│   │   │   │   │   ├── bsp.py
│   │   │   │   │   ├── bsp.sh
│   │   │   │   │   ├── cdan.py
│   │   │   │   │   ├── cdan.sh
│   │   │   │   │   ├── dan.py
│   │   │   │   │   ├── dan.sh
│   │   │   │   │   ├── dann.py
│   │   │   │   │   ├── dann.sh
│   │   │   │   │   ├── gpu_dann.pbs
│   │   │   │   │   ├── gpu_mcc.pbs
│   │   │   │   │   ├── gpu_mdd.pbs
│   │   │   │   │   ├── jan.py
│   │   │   │   │   ├── jan.sh
│   │   │   │   │   ├── mcc.py
│   │   │   │   │   ├── mcc.sh
│   │   │   │   │   ├── mcd.py
│   │   │   │   │   ├── mcd.sh
│   │   │   │   │   ├── mdd.py
│   │   │   │   │   ├── mdd.sh
│   │   │   │   │   ├── requirements.txt
│   │   │   │   │   ├── self_ensemble.py
│   │   │   │   │   ├── self_ensemble.sh
│   │   │   │   │   ├── source_only.py
│   │   │   │   │   ├── source_only.sh
│   │   │   │   │   └── utils.py
│   │   │   │   ├── image_regression/
│   │   │   │   │   ├── README.md
│   │   │   │   │   ├── dann.py
│   │   │   │   │   ├── dann.sh
│   │   │   │   │   ├── dd.py
│   │   │   │   │   ├── dd.sh
│   │   │   │   │   ├── rsd.py
│   │   │   │   │   ├── rsd.sh
│   │   │   │   │   ├── source_only.py
│   │   │   │   │   ├── source_only.sh
│   │   │   │   │   └── utils.py
│   │   │   │   ├── keypoint_detection/
│   │   │   │   │   ├── README.md
│   │   │   │   │   ├── regda.py
│   │   │   │   │   ├── regda.sh
│   │   │   │   │   ├── regda_fast.py
│   │   │   │   │   ├── regda_fast.sh
│   │   │   │   │   ├── source_only.py
│   │   │   │   │   └── source_only.sh
│   │   │   │   ├── openset_domain_adaptation/
│   │   │   │   │   ├── README.md
│   │   │   │   │   ├── dann.py
│   │   │   │   │   ├── dann.sh
│   │   │   │   │   ├── osbp.py
│   │   │   │   │   ├── osbp.sh
│   │   │   │   │   ├── source_only.py
│   │   │   │   │   ├── source_only.sh
│   │   │   │   │   └── utils.py
│   │   │   │   ├── partial_domain_adaptation/
│   │   │   │   │   ├── README.md
│   │   │   │   │   ├── afn.py
│   │   │   │   │   ├── afn.sh
│   │   │   │   │   ├── dann.py
│   │   │   │   │   ├── dann.sh
│   │   │   │   │   ├── iwan.py
│   │   │   │   │   ├── iwan.sh
│   │   │   │   │   ├── pada.py
│   │   │   │   │   ├── pada.sh
│   │   │   │   │   ├── requirements.txt
│   │   │   │   │   ├── source_only.py
│   │   │   │   │   ├── source_only.sh
│   │   │   │   │   └── utils.py
│   │   │   │   ├── re_identification/
│   │   │   │   │   ├── README.md
│   │   │   │   │   ├── baseline.py
│   │   │   │   │   ├── baseline.sh
│   │   │   │   │   ├── baseline_cluster.py
│   │   │   │   │   ├── baseline_cluster.sh
│   │   │   │   │   ├── ibn.sh
│   │   │   │   │   ├── idm.py
│   │   │   │   │   ├── idm.sh
│   │   │   │   │   ├── mmt.py
│   │   │   │   │   ├── mmt.sh
│   │   │   │   │   ├── requirements.txt
│   │   │   │   │   ├── spgan.py
│   │   │   │   │   ├── spgan.sh
│   │   │   │   │   └── utils.py
│   │   │   │   └── semantic_segmentation/
│   │   │   │       ├── README.md
│   │   │   │       ├── advent.py
│   │   │   │       ├── advent.sh
│   │   │   │       ├── cycada.py
│   │   │   │       ├── cycada.sh
│   │   │   │       ├── cycle_gan.py
│   │   │   │       ├── cycle_gan.sh
│   │   │   │       ├── fda.py
│   │   │   │       ├── fda.sh
│   │   │   │       ├── source_only.py
│   │   │   │       └── source_only.sh
│   │   │   ├── domain_generalization/
│   │   │   │   ├── image_classification/
│   │   │   │   │   ├── README.md
│   │   │   │   │   ├── baseline.py
│   │   │   │   │   ├── baseline.sh
│   │   │   │   │   ├── coral.py
│   │   │   │   │   ├── coral.sh
│   │   │   │   │   ├── gpu_base.pbs
│   │   │   │   │   ├── gpu_coral.pbs
│   │   │   │   │   ├── gpu_irm.pbs
│   │   │   │   │   ├── groupdro.py
│   │   │   │   │   ├── groupdro.sh
│   │   │   │   │   ├── ibn.sh
│   │   │   │   │   ├── irm.py
│   │   │   │   │   ├── irm.sh
│   │   │   │   │   ├── mixstyle.py
│   │   │   │   │   ├── mixstyle.sh
│   │   │   │   │   ├── mldg.py
│   │   │   │   │   ├── mldg.sh
│   │   │   │   │   ├── requirements.txt
│   │   │   │   │   ├── utils.py
│   │   │   │   │   ├── vrex.py
│   │   │   │   │   └── vrex.sh
│   │   │   │   └── re_identification/
│   │   │   │       ├── README.md
│   │   │   │       ├── baseline.py
│   │   │   │       ├── baseline.sh
│   │   │   │       ├── ibn.sh
│   │   │   │       ├── mixstyle.py
│   │   │   │       ├── mixstyle.sh
│   │   │   │       ├── requirements.txt
│   │   │   │       └── utils.py
│   │   │   └── task_adaptation/
│   │   │       └── image_classification/
│   │   │           ├── README.md
│   │   │           ├── baseline.py
│   │   │           ├── baseline.sh
│   │   │           ├── bi_tuning.py
│   │   │           ├── bi_tuning.sh
│   │   │           ├── bss.py
│   │   │           ├── bss.sh
│   │   │           ├── co_tuning.py
│   │   │           ├── co_tuning.sh
│   │   │           ├── convert_moco_to_pretrained.py
│   │   │           ├── delta.py
│   │   │           ├── delta.sh
│   │   │           ├── lwf.py
│   │   │           ├── lwf.sh
│   │   │           ├── requirements.txt
│   │   │           ├── stochnorm.py
│   │   │           ├── stochnorm.sh
│   │   │           └── utils.py
│   │   ├── requirements.txt
│   │   ├── setup.py
│   │   └── talib/
│   │       ├── __init__.py
│   │       └── finetune/
│   │           ├── __init__.py
│   │           ├── bi_tuning.py
│   │           ├── bss.py
│   │           ├── co_tuning.py
│   │           ├── delta.py
│   │           ├── lwf.py
│   │           └── stochnorm.py
│   ├── baseline.py
│   ├── coral.py
│   ├── irm.py
│   ├── mixstyle.py
│   └── swad/
│       ├── .gitignore
│       ├── LICENSE
│       ├── README.md
│       ├── config.yaml
│       ├── domainbed/
│       │   ├── algorithms/
│       │   │   ├── __init__.py
│       │   │   └── algorithms.py
│       │   ├── datasets/
│       │   │   ├── __init__.py
│       │   │   ├── datasets.py
│       │   │   └── transforms.py
│       │   ├── evaluator.py
│       │   ├── hparams_registry.py
│       │   ├── lib/
│       │   │   ├── fast_data_loader.py
│       │   │   ├── logger.py
│       │   │   ├── misc.py
│       │   │   ├── query.py
│       │   │   ├── swa_utils.py
│       │   │   ├── wide_resnet.py
│       │   │   └── writers.py
│       │   ├── lr_scheduler/
│       │   │   ├── __init__.py
│       │   │   └── lr_scheduler.py
│       │   ├── misc/
│       │   │   └── domain_net_duplicates.txt
│       │   ├── models/
│       │   │   ├── mixstyle.py
│       │   │   ├── resnet_mixstyle.py
│       │   │   └── resnet_mixstyle2.py
│       │   ├── networks.py
│       │   ├── optimizers.py
│       │   ├── scripts/
│       │   │   └── download.py
│       │   ├── swad.py
│       │   └── trainer.py
│       ├── requirements.txt
│       └── train_all.py
├── long-tailed_recognition/
│   ├── BalancedSoftmax/
│   │   ├── .gitignore
│   │   ├── CODE_OF_CONDUCT.md
│   │   ├── CONTRIBUTING.md
│   │   ├── LICENSE
│   │   ├── README.md
│   │   ├── cls_freq/
│   │   │   ├── CIFAR-10-LT_IMBA100.json
│   │   │   ├── CIFAR-10-LT_IMBA200.json
│   │   │   ├── CIFAR-100-LT_IMBA1.json
│   │   │   ├── CIFAR-100-LT_IMBA100.json
│   │   │   ├── CIFAR-100-LT_IMBA200.json
│   │   │   ├── ImageNet_LT.json
│   │   │   ├── Places_LT.json
│   │   │   └── iNaturalist18.json
│   │   ├── config/
│   │   │   ├── CIFAR100_LT/
│   │   │   │   ├── balanced_softmax_imba100.yaml
│   │   │   │   ├── balanced_softmax_imba200.yaml
│   │   │   │   ├── balms_imba100.yaml
│   │   │   │   ├── balms_imba200.yaml
│   │   │   │   ├── decouple_balanced_softmax_imba100.yaml
│   │   │   │   ├── decouple_balanced_softmax_imba200.yaml
│   │   │   │   ├── softmax_imba.yaml
│   │   │   │   ├── softmax_imba100.yaml
│   │   │   │   └── softmax_imba200.yaml
│   │   │   ├── CIFAR10_LT/
│   │   │   │   ├── balanced_softmax_imba200.yaml
│   │   │   │   ├── balms_imba200.yaml
│   │   │   │   ├── decouple_balanced_softmax_imba200.yaml
│   │   │   │   └── softmax_imba200.yaml
│   │   │   ├── ImageNet_LT/
│   │   │   │   ├── balanced_softmax_resnet10.yaml
│   │   │   │   ├── balanced_softmax_resnet50.yaml
│   │   │   │   ├── balms_resnet10.yaml
│   │   │   │   ├── balms_resnet50.yaml
│   │   │   │   ├── cls_crt.yaml
│   │   │   │   ├── cls_lws.yaml
│   │   │   │   ├── decouple_balanced_softmax_resnet10.yaml
│   │   │   │   ├── feat_balance.yaml
│   │   │   │   ├── feat_shift.yaml
│   │   │   │   ├── feat_squareroot.yaml
│   │   │   │   ├── feat_uniform.yaml
│   │   │   │   ├── feat_uniform_resnet10.yaml
│   │   │   │   ├── feat_uniform_resnet50.yaml
│   │   │   │   ├── softmax_resnet10.yaml
│   │   │   │   └── softmax_resnet50_feat.yaml
│   │   │   ├── Places_LT/
│   │   │   │   ├── balanced_softmax.yaml
│   │   │   │   ├── balms.yaml
│   │   │   │   ├── cls_crt.yaml
│   │   │   │   ├── cls_lws.yaml
│   │   │   │   ├── decouple_balanced_softmax.yaml
│   │   │   │   └── feat_unifrom.yaml
│   │   │   └── iNaturalist18/
│   │   │       ├── balanced_softmax.yaml
│   │   │       ├── cls_crt.yaml
│   │   │       ├── cls_lws.yaml
│   │   │       └── feat_unifrom.yaml
│   │   ├── data/
│   │   │   ├── ClassAwareSampler.py
│   │   │   ├── ClassPrioritySampler.py
│   │   │   ├── ImageNet/
│   │   │   │   ├── ImageNet_train.txt
│   │   │   │   ├── ImageNet_val.txt
│   │   │   │   └── gen_txt.py
│   │   │   ├── ImageNet_LT/
│   │   │   │   ├── ImageNet_LT_test.txt
│   │   │   │   ├── ImageNet_LT_train.txt
│   │   │   │   ├── ImageNet_LT_val.txt
│   │   │   │   └── class_labels
│   │   │   ├── ImbalanceCIFAR.py
│   │   │   ├── MetaSampler.py
│   │   │   ├── MixedPrioritizedSampler.py
│   │   │   ├── Places_LT/
│   │   │   │   ├── Places_LT_test.txt
│   │   │   │   ├── Places_LT_train.txt
│   │   │   │   └── Places_LT_val.txt
│   │   │   ├── autoaugment.py
│   │   │   ├── dataloader.py
│   │   │   └── iNaturalist18/
│   │   │       ├── gen_lists.py
│   │   │       ├── iNaturalist18_train.txt
│   │   │       └── iNaturalist18_val.txt
│   │   ├── encoder_network.py
│   │   ├── grads_analysis.py
│   │   ├── layers/
│   │   │   └── ModulatedAttLayer.py
│   │   ├── logger.py
│   │   ├── loss/
│   │   │   ├── BalancedSoftmaxLoss.py
│   │   │   ├── DiscCentroidsLoss.py
│   │   │   └── SoftmaxLoss.py
│   │   ├── main.py
│   │   ├── models/
│   │   │   ├── CosNormClassifier.py
│   │   │   ├── DotProductClassifier.py
│   │   │   ├── KNNClassifier.py
│   │   │   ├── MetaEmbeddingClassifier.py
│   │   │   ├── ResNet101Feature.py
│   │   │   ├── ResNet10Feature.py
│   │   │   ├── ResNet152Feature.py
│   │   │   ├── ResNet152FeatureCaffe.py
│   │   │   ├── ResNet32Feature.py
│   │   │   ├── ResNet50Feature.py
│   │   │   ├── ResNetFeature.py
│   │   │   ├── ResNext101Feature.py
│   │   │   ├── ResNext152Feature.py
│   │   │   ├── ResNext50Feature.py
│   │   │   ├── ResNextFeature.py
│   │   │   └── TauNormClassifier.py
│   │   ├── run_networks.py
│   │   └── utils.py
│   ├── README.md
│   └── RIDE-LongTailRecognition/
│       ├── .flake8
│       ├── .github/
│       │   └── ISSUE_TEMPLATE/
│       │       ├── conceptual-questions.md
│       │       ├── error-report.md
│       │       ├── feature_request.md
│       │       └── other-problems.md
│       ├── .gitignore
│       ├── FAQ.md
│       ├── LICENSE
│       ├── README.md
│       ├── base/
│       │   ├── __init__.py
│       │   ├── base_data_loader.py
│       │   ├── base_model.py
│       │   └── base_trainer.py
│       ├── config.json
│       ├── configs/
│       │   ├── config_iNaturalist_resnet50_distill_ride.json
│       │   ├── config_iNaturalist_resnet50_distill_ride_dist.json
│       │   ├── config_iNaturalist_resnet50_ride.json
│       │   ├── config_iNaturalist_resnet50_ride_dist.json
│       │   ├── config_iNaturalist_resnet50_ride_dist1.json
│       │   ├── config_iNaturalist_resnet50_ride_ea.json
│       │   ├── config_imagenet_lt_resnet10_distill_ride.json
│       │   ├── config_imagenet_lt_resnet10_ride.json
│       │   ├── config_imagenet_lt_resnet10_ride1.json
│       │   ├── config_imagenet_lt_resnet10_ride_base.json
│       │   ├── config_imagenet_lt_resnet10_ride_base1.json
│       │   ├── config_imagenet_lt_resnet10_ride_base_dist.json
│       │   ├── config_imagenet_lt_resnet10_ride_ea.json
│       │   ├── config_imagenet_lt_resnet50_distill_ride.json
│       │   ├── config_imagenet_lt_resnet50_distill_ride_dist.json
│       │   ├── config_imagenet_lt_resnet50_ride.json
│       │   ├── config_imagenet_lt_resnet50_ride_base.json
│       │   ├── config_imagenet_lt_resnet50_ride_base_dist.json
│       │   ├── config_imagenet_lt_resnet50_ride_cos.json
│       │   ├── config_imagenet_lt_resnet50_ride_dist.json
│       │   ├── config_imagenet_lt_resnet50_ride_dist_cos.json
│       │   ├── config_imagenet_lt_resnet50_ride_ea.json
│       │   ├── config_imagenet_lt_resnext50_distill_ride.json
│       │   ├── config_imagenet_lt_resnext50_ride.json
│       │   ├── config_imagenet_lt_resnext50_ride_dist.json
│       │   ├── config_imagenet_lt_resnext50_ride_ea.json
│       │   ├── config_imbalance_cifar100_distill_ride.json
│       │   ├── config_imbalance_cifar100_ldam_drw.json
│       │   ├── config_imbalance_cifar100_ride.json
│       │   ├── config_imbalance_cifar100_ride_base.json
│       │   ├── config_imbalance_cifar100_ride_ea.json
│       │   └── config_imbalance_cifar100_ride_teacher.json
│       ├── contributing.md
│       ├── data_loader/
│       │   ├── __init__.py
│       │   ├── cifar_data_loaders.py
│       │   ├── data_loaders.py
│       │   ├── imagenet_lt_data_loaders.py
│       │   ├── imbalance_cifar.py
│       │   └── inaturalist_data_loaders.py
│       ├── logger/
│       │   ├── __init__.py
│       │   ├── logger.py
│       │   ├── logger_config.json
│       │   └── visualization.py
│       ├── model/
│       │   ├── fb_resnets/
│       │   │   ├── EAResNeXt.py
│       │   │   ├── EAResNet.py
│       │   │   ├── RIDEResNeXt.py
│       │   │   ├── RIDEResNet.py
│       │   │   ├── ResNeXt.py
│       │   │   ├── ResNet.py
│       │   │   └── __init__.py
│       │   ├── ldam_drw_resnets/
│       │   │   ├── __init__.py
│       │   │   ├── ea_resnet_cifar.py
│       │   │   ├── resnet_cifar.py
│       │   │   └── ride_resnet_cifar.py
│       │   ├── loss.py
│       │   ├── metric.py
│       │   └── model.py
│       ├── new_project.py
│       ├── parse_config.py
│       ├── requirements.txt
│       ├── run.py
│       ├── run_imagenet.py
│       ├── t-normalization.py
│       ├── test.py
│       ├── test_lt.sh
│       ├── train.py
│       ├── train_dist.py
│       ├── trainer/
│       │   ├── __init__.py
│       │   └── trainer.py
│       └── utils/
│           ├── __init__.py
│           ├── gflops.py
│           └── util.py
└── moco-v3/
    ├── CODE_OF_CONDUCT.md
    ├── CONFIG.md
    ├── CONTRIBUTING.md
    ├── LICENSE
    ├── README.md
    ├── main_lincls.py
    ├── main_moco.py
    ├── moco/
    │   ├── __init__.py
    │   ├── builder.py
    │   ├── builder_v2.py
    │   ├── loader.py
    │   └── optimizer.py
    ├── transfer/
    │   ├── README.md
    │   ├── datasets.py
    │   ├── oxford_flowers_dataset.py
    │   └── oxford_pets_dataset.py
    └── vits.py

================================================
FILE CONTENTS
================================================

================================================
FILE: README.md
================================================
# BatchFormer: Learning to Explore Sample Relationships for Robust Representation Learning

## Introduction

This is the official PyTorch implementation of [BatchFormer](https://arxiv.org/abs/2203.01522) for Long-Tailed Recognition, Domain Generalization, Compositional Zero-Shot Learning, Contrastive Learning.

<p align="center">
  <img src="rela_illu.png" width="320">
</p>

<p align="center">
Sample Relationship Exploration for Robust Representation Learning
  </p>

**Please also refer to [BatchFormerV2](https://arxiv.org/abs/2204.01254), in which we introduce a BatchFormerV2 module for vision Transformers.**


<p align="center">
  <img src="BT_illu_dim.png" width="480">
</p>

## Main Results

### Long-Tailed Recognition

##### ImageNet-LT
<table><tbody>
<!-- START TABLE -->
<!-- TABLE HEADER -->
<th valign="bottom"></th>
<th valign="bottom">All(R10)</th>
<th valign="bottom">Many(R10)</th>
<th valign="bottom">Med(R10)</th>
<th valign="bottom">Few(R10)</th>
<th valign="bottom">All(R50)</th>
<th valign="bottom">Many(R50)</th>
<th valign="bottom">Med(R50)</th>
<th valign="bottom">Few(R50)</th>
<!-- TABLE BODY -->
<tr><td align="left">RIDE(3 experts)[1]</td>
<td align="center">44.7</td>
<td align="center">57.0</td>
<td align="center">40.3</td>
<td align="center">25.5</td>
<td align="center">53.6</td>
<td align="center">64.9</td>
<td align="center">50.4</td>
<td align="center">33.2</td>
</tr>

<tr><td align="left">+BatchFormer</td>
<td align="center"><b>45.7</b></td>
<td align="center">56.3</td>
<td align="center"><b>42.1</b></td>
<td align="center"><b>28.3</b></td>
<td align="center"><b>54.1</b></td>
<td align="center">64.3</td>
<td align="center"><b>51.4</b></td>
<td align="center"><b>35.1</b></td>

<tr><td align="left">PaCo[2]</td>
<td align="center">-</td>
<td align="center">-</td>
<td align="center">-</td>
<td align="center">-</td>
<td align="center">57.0</td>
<td align="center">64.8</td>
<td align="center">55.9</td>
<td align="center">39.1</td>
</tr>

<tr><td align="left">+BatchFormer</td>
<td align="center">-</td>
<td align="center">-</td>
<td align="center">-</td>
<td align="center">-</td>
<td align="center"><b>57.4</b></td>
<td align="center">62.7</td>
<td align="center"><b>56.7</b></td>
<td align="center"><b>42.1</b></td>
</tbody></table>

Here, we demonstrate the result on one-stage RIDE (ResNext-50)
<table><tbody>
<!-- START TABLE -->
<!-- TABLE HEADER -->
<th valign="bottom"></th>
<th valign="bottom">All</th>
<th valign="bottom">Many</th>
<th valign="bottom">Medium</th>
<th valign="bottom">Few</th>

<!-- TABLE BODY -->
<tr><td align="left">RIDE(3 experts)*</td>
<td align="center">55.9</td>
<td align="center">67.3</td>
<td align="center">52.8</td>
<td align="center">34.6</td>
</tr>
    <tr><td align="left">+BatchFormer</td>
<td align="center"><b>56.5</b></td>
<td align="center">66.6</td>
<td align="center"><b>54.2</b></td>
<td align="center"><b>36.0</b></td>
</tbody></table>


##### iNaturalist 2018
<table><tbody>
<!-- START TABLE -->
<!-- TABLE HEADER -->
<th valign="bottom"></th>
<th valign="bottom">All</th>
<th valign="bottom">Many</th>
<th valign="bottom">Medium</th>
<th valign="bottom">Few</th>

<!-- TABLE BODY -->
<tr><td align="left">RIDE(3 experts)</td>
<td align="center">72.5</td>
<td align="center">68.1</td>
<td align="center">72.7</td>
<td align="center">73.2</td>
</tr>
    <tr><td align="left">+BatchFormer</td>
<td align="center"><b>74.1</b></td>
<td align="center">65.5</td>
<td align="center"><b>74.5</b></td>
<td align="center"><b>75.8</b></td>
</tbody></table>


#### Object Detection (V2)

<table><tbody>
<!-- START TABLE -->
<!-- TABLE HEADER -->
<th valign="bottom"></th>
<th valign="bottom">AP</th>
<th valign="bottom">AP50</th>
<th valign="bottom">AP75</th>
<th valign="bottom">APS</th>
<th valign="bottom">APM</th>
<th valign="bottom">APL</th>
<th valign="bottom">Model</th>

<!-- TABLE BODY -->
<tr><td align="left">DETR</td>
<td align="center">34.8</td>
<td align="center">55.6</td>
<td align="center">35.8</td>
<td align="center">14.0</td>
<td align="center">37.2</td>
<td align="center">54.6</td>
</tr>
    <tr><td align="left">+BatchFormerV2</td>
<td align="center"><b>36.9</b></td>
<td align="center"><b>57.9</b></td>
<td align="center"><b>38.5</b></td>
<td align="center"><b>15.6</b></td>
<td align="center"><b>40.0</b></td>
<td align="center"><b>55.9</b></td>
<td align="center"><a href="https://unisydneyedu-my.sharepoint.com/:u:/g/personal/zhou9878_uni_sydney_edu_au/EUn-InXA-ClMpGaN2emuwpgBarc-_B-IYlYuKs6dvwVn8g?e=dzmX8l">download</a></td>


<tr><td align="left">Conditional DETR</td>
<td align="center">40.9</td>
<td align="center">61.8</td>
<td align="center">43.3</td>
<td align="center">20.8</td>
<td align="center">44.6</td>
<td align="center">59.2</td>
</tr>
    <tr><td align="left">+BatchFormerV2</td>
<td align="center"><b>42.3</b></td>
<td align="center"><b>63.2</b></td>
<td align="center"><b>45.1</b></td>
<td align="center"><b>21.9</b></td>
<td align="center"><b>46.0</b></td>
<td align="center"><b>60.7</b></td>
<td align="center"><a href="https://unisydneyedu-my.sharepoint.com/:u:/g/personal/zhou9878_uni_sydney_edu_au/EX2ulrdzhQBFhOr9mYyLCq0BFONL8IV4QFltr1Sn5RJCcQ?e=cXR2DL">download</a></td>



<tr><td align="left">Deformable DETR</td>
<td align="center">43.8</td>
<td align="center">62.6</td>
<td align="center">47.7</td>
<td align="center">26.4</td>
<td align="center">47.1</td>
<td align="center">58.0</td>
</tr>
    <tr><td align="left">+BatchFormerV2</td>
<td align="center"><b>45.5</b></td>
<td align="center"><b>64.3</b></td>
<td align="center"><b>49.8</b></td>
<td align="center"><b>28.3</b></td>
<td align="center"><b>48.6</b></td>
<td align="center"><b>59.4</b></td>
<td align="center"><a href="https://unisydneyedu-my.sharepoint.com/:f:/g/personal/zhou9878_uni_sydney_edu_au/Em284ufvPkBHi5Eh_vbM4_ABP3c4eXPg_RANRfos2VmO8Q?e=2PhkUs">download</a></td>


</tbody></table>

The backbone is ResNet-50. The training epoch is 50.


#### Panoptic segmentation (V2)

<table><tbody>
<!-- START TABLE -->
<!-- TABLE HEADER -->
<th valign="bottom"></th>
<th valign="bottom">PQ</th>
<th valign="bottom">SQ</th>
<th valign="bottom">RQ</th>
<th valign="bottom">PQ(th)</th>
<th valign="bottom">SQ(th)</th>
<th valign="bottom">RQ(th)</th>
<th valign="bottom">PQ(st)</th>
<th valign="bottom">SQ(st)</th>
<th valign="bottom">RQ(st)</th>
<th valign="bottom">AP</th>
<!-- TABLE BODY -->
<tr><td align="left">DETR</td>
<td align="center">43.4</td>
<td align="center">79.3</td>
<td align="center">53.8</td>
<td align="center">48.2</td>
<td align="center">79.8</td>
<td align="center">59.5</td>
<td align="center">36.3</td>
<td align="center">78.5</td>
<td align="center">45.3</td>
<td align="center">31.1</td>

</tr>
    <tr><td align="left">+BatchFormerV2</td>
<td align="center"><b>45.1</b></td>
<td align="center"><b>80.3</b></td>
<td align="center"><b>55.3</b></td>
<td align="center"><b>50.5</b></td>
<td align="center"><b>81.1</b></td>
<td align="center"><b>61.5</b></td>

<td align="center"><b>37.1</b></td>
<td align="center"><b>79.1</b></td>
<td align="center"><b>46.0</b></td>
<td align="center"><b>33.4</b></td>
</tbody></table>


#### Contrastive Learning
<table><tbody>
<!-- START TABLE -->
<!-- TABLE HEADER -->
<th valign="bottom"></th>
<th valign="bottom">Epochs</th>
<th valign="bottom">Top-1</th>
<th valign="bottom">Pretrained</th>
<!-- TABLE BODY -->
<tr><td align="left">MoCo-v2[3]</td>
<td align="center">200</td>
<td align="center">67.5</td>
<td align="center"></td>
</tr>
<tr><td align="left">+BatchFormer</td>
<td align="center">200</td>
<td align="center"><b>68.4</b></td>
  <td align="center"><a href="https://cloudstor.aarnet.edu.au/plus/s/nnepE6cPmEPMOkv">download</a></td>

<tr><td align="left">MoCo-v3[4]</td>
<td align="center">100</td>
<td align="center">68.9</td>
</tr>
<tr><td align="left">+BatchFormer</td>
<td align="center">100</td>
<td align="center"><b>70.1</b></td>
    <td align="center"><a href="https://unisydneyedu-my.sharepoint.com/:u:/g/personal/zhou9878_uni_sydney_edu_au/ETBR82PULkNMuUeyrxXZkVcBndgYylYnyRjmDQxOn_TUfQ?e=3rPRu4">download</a></td>
</tbody></table>

Here, we provide the pretrained MoCo-V3 model corresponding to [this strategy](https://github.com/zhihou7/BatchFormer/blob/cc7a060c6395cb1dc8a7c577df77f52a44deaf9d/moco-v3/moco/builder.py#L139).

#### Domain Generalization

##### ResNet-18

<table><tbody>
<!-- START TABLE -->
<!-- TABLE HEADER -->
<th valign="bottom"></th>
<th valign="bottom">PACS</th>
<th valign="bottom">VLCS</th>
<th valign="bottom">OfficeHome</th>
<th valign="bottom">Terra</th>

<!-- TABLE BODY -->
<tr><td align="left">SWAD[5]</td>
<td align="center">82.9</td>
<td align="center">76.3</td>
<td align="center">62.1</td>
<td align="center">42.1</td>
</tr>
    <tr><td align="left">+BatchFormer</td>
<td align="center"><b>83.7</b></td>
<td align="center"><b>76.9</b></td>
<td align="center"><b>64.3</b></td>
<td align="center"><b>44.8</b></td>
</tbody></table>


#### Compositional Zero-Shot Learning
<table><tbody>
<!-- START TABLE -->
<!-- TABLE HEADER -->
<th valign="bottom"></th>
<th valign="bottom">MIT-States(AUC)</th>
<th valign="bottom">MIT-States(HM)</th>
<th valign="bottom">UT-Zap50K(AUC)</th>
<th valign="bottom">UT-Zap50K(HM)</th>
<th valign="bottom">C-GQA(AUC)</th>
<th valign="bottom">C-GQA(HM)</th>
<!-- TABLE BODY -->
<tr><td align="left">CGE*[6]</td>
<td align="center">6.3</td>
<td align="center">20.0</td>
<td align="center">31.5</td>
<td align="center">46.5</td>
<td align="center">3.7</td>
<td align="center">14.9</td>
</tr>
    <tr><td align="left">+BatchFormer</td>
<td align="center"><b>6.7</b></td>
<td align="center"><b>20.6</b></td>
<td align="center"><b>34.6</b></td>
<td align="center"><b>49.0</b></td>
<td align="center"><b>3.8</b></td>
<td align="center"><b>15.5</b></td>
</tbody></table>

#### Few-Shot Learning
Experiments on CUB.

<table><tbody>
<!-- START TABLE -->
<!-- TABLE HEADER -->
<th valign="bottom"></th>
<th valign="bottom">Unseen</th>
<th valign="bottom">Seen</th>
<th valign="bottom">Harmonic mean</th>

<!-- TABLE BODY -->
<tr><td align="left">CUB[7]*</td>
<td align="center">67.5</td>
<td align="center">65.1</td>
<td align="center">66.3</td>
</tr>
    <tr><td align="left">+BatchFormer</td>
<td align="center"><b>68.2</b></td>
<td align="center"><b>65.8</b></td>
<td align="center"><b>67.0</b></td>
</tbody></table>


#### Image Classification (V2)

<table><tbody>
<!-- START TABLE -->
<!-- TABLE HEADER -->
<th valign="bottom"></th>
<th valign="bottom">Top-1</th>
<th valign="bottom">Top-5</th>
<!-- TABLE BODY -->
<tr><td align="left">DeiT-T</td>
<td align="center">72.2</td>
<td align="center">91.1</td>
</tr>
    <tr><td align="left">+BatchFormerV2</td>
<td align="center"><b>72.7</b></td>
<td align="center"><b>91.5</b></td>

<tr><td align="left">DeiT-S</td>
<td align="center">79.8</td>
<td align="center">95.0</td>
</tr>
    <tr><td align="left">+BatchFormerV2</td>
<td align="center"><b>80.4</b></td>
<td align="center"><b>95.2</b></td>

<tr><td align="left">DeiT-B</td>
<td align="center">81.7</td>
<td align="center">95.5</td>
</tr>
    <tr><td align="left">+BatchFormerV2</td>
<td align="center"><b>82.2</b></td>
<td align="center"><b>95.8</b></td>
</tbody></table>

#### Reference

1. Long-tailed recognition by routing diverse distribution-aware experts. In ICLR, 2021
2. Parametric contrastive learning. In ICCV, 2021
3. Improved baselines with momentum contrastive learning.
4. An empirical study of training self-supervised vision transformers. In CVPR, 2021
5. Domain generalization by seeking flat minima. In NeurIPS, 2021.
6. Learning graph embeddings for compositional zero-shot learning. In CVPR, 2021
7. Contrastive learning based hybrid networks for long- tailed image classification. In CVPR, 2021



## PyTorch Code

The proposed BatchFormer can be implemented with a few lines as follows,

    def BatchFormer(x, y, encoder, is_training):
        # x: input features with the shape [N, C]
        # encoder: TransformerEncoderLayer(C,4,C,0.5)
        if not is_training:
            return x, y
        pre_x = x
        x = encoder(x.unsqueeze(1)).squeeze(1)
        x = torch.cat([pre_x, x], dim=0)
        y = torch.cat([y, y], dim=0)
        return x, y



## Citation
If you find this repository helpful, please consider cite:

    @inproceedings{hou2022batch,
        title={BatchFormer: Learning to Explore Sample Relationships for Robust Representation Learning},
        author={Hou, Zhi and Yu, Baosheng and Tao, Dacheng},
        booktitle={CVPR},
        year={2022}
    }
    @article{hou2022batchformerv2,
       title={BatchFormerV2: Exploring Sample Relationships for Dense Representation Learning},
       author={Hou, Zhi and Yu, Baosheng and Wang, Chaoyue and Zhan, Yibing and Tao, Dacheng},
       journal={arXiv preprint arXiv:2204.01254},
       year={2022}
    }

Feel free to contact "zhou9878 at uni dot sydney dot edu dot au" if you have any questions.


================================================
FILE: batchformer-v2/deformable-detr/LICENSE
================================================
Copyright (c) 2020 SenseTime. All Rights Reserved.

                                 Apache License
                           Version 2.0, January 2004
                        http://www.apache.org/licenses/

   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION

   1. Definitions.

      "License" shall mean the terms and conditions for use, reproduction,
      and distribution as defined by Sections 1 through 9 of this document.

      "Licensor" shall mean the copyright owner or entity authorized by
      the copyright owner that is granting the License.

      "Legal Entity" shall mean the union of the acting entity and all
      other entities that control, are controlled by, or are under common
      control with that entity. For the purposes of this definition,
      "control" means (i) the power, direct or indirect, to cause the
      direction or management of such entity, whether by contract or
      otherwise, or (ii) ownership of fifty percent (50%) or more of the
      outstanding shares, or (iii) beneficial ownership of such entity.

      "You" (or "Your") shall mean an individual or Legal Entity
      exercising permissions granted by this License.

      "Source" form shall mean the preferred form for making modifications,
      including but not limited to software source code, documentation
      source, and configuration files.

      "Object" form shall mean any form resulting from mechanical
      transformation or translation of a Source form, including but
      not limited to compiled object code, generated documentation,
      and conversions to other media types.

      "Work" shall mean the work of authorship, whether in Source or
      Object form, made available under the License, as indicated by a
      copyright notice that is included in or attached to the work
      (an example is provided in the Appendix below).

      "Derivative Works" shall mean any work, whether in Source or Object
      form, that is based on (or derived from) the Work and for which the
      editorial revisions, annotations, elaborations, or other modifications
      represent, as a whole, an original work of authorship. For the purposes
      of this License, Derivative Works shall not include works that remain
      separable from, or merely link (or bind by name) to the interfaces of,
      the Work and Derivative Works thereof.

      "Contribution" shall mean any work of authorship, including
      the original version of the Work and any modifications or additions
      to that Work or Derivative Works thereof, that is intentionally
      submitted to Licensor for inclusion in the Work by the copyright owner
      or by an individual or Legal Entity authorized to submit on behalf of
      the copyright owner. For the purposes of this definition, "submitted"
      means any form of electronic, verbal, or written communication sent
      to the Licensor or its representatives, including but not limited to
      communication on electronic mailing lists, source code control systems,
      and issue tracking systems that are managed by, or on behalf of, the
      Licensor for the purpose of discussing and improving the Work, but
      excluding communication that is conspicuously marked or otherwise
      designated in writing by the copyright owner as "Not a Contribution."

      "Contributor" shall mean Licensor and any individual or Legal Entity
      on behalf of whom a Contribution has been received by Licensor and
      subsequently incorporated within the Work.

   2. Grant of Copyright License. Subject to the terms and conditions of
      this License, each Contributor hereby grants to You a perpetual,
      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
      copyright license to reproduce, prepare Derivative Works of,
      publicly display, publicly perform, sublicense, and distribute the
      Work and such Derivative Works in Source or Object form.

   3. Grant of Patent License. Subject to the terms and conditions of
      this License, each Contributor hereby grants to You a perpetual,
      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
      (except as stated in this section) patent license to make, have made,
      use, offer to sell, sell, import, and otherwise transfer the Work,
      where such license applies only to those patent claims licensable
      by such Contributor that are necessarily infringed by their
      Contribution(s) alone or by combination of their Contribution(s)
      with the Work to which such Contribution(s) was submitted. If You
      institute patent litigation against any entity (including a
      cross-claim or counterclaim in a lawsuit) alleging that the Work
      or a Contribution incorporated within the Work constitutes direct
      or contributory patent infringement, then any patent licenses
      granted to You under this License for that Work shall terminate
      as of the date such litigation is filed.

   4. Redistribution. You may reproduce and distribute copies of the
      Work or Derivative Works thereof in any medium, with or without
      modifications, and in Source or Object form, provided that You
      meet the following conditions:

      (a) You must give any other recipients of the Work or
          Derivative Works a copy of this License; and

      (b) You must cause any modified files to carry prominent notices
          stating that You changed the files; and

      (c) You must retain, in the Source form of any Derivative Works
          that You distribute, all copyright, patent, trademark, and
          attribution notices from the Source form of the Work,
          excluding those notices that do not pertain to any part of
          the Derivative Works; and

      (d) If the Work includes a "NOTICE" text file as part of its
          distribution, then any Derivative Works that You distribute must
          include a readable copy of the attribution notices contained
          within such NOTICE file, excluding those notices that do not
          pertain to any part of the Derivative Works, in at least one
          of the following places: within a NOTICE text file distributed
          as part of the Derivative Works; within the Source form or
          documentation, if provided along with the Derivative Works; or,
          within a display generated by the Derivative Works, if and
          wherever such third-party notices normally appear. The contents
          of the NOTICE file are for informational purposes only and
          do not modify the License. You may add Your own attribution
          notices within Derivative Works that You distribute, alongside
          or as an addendum to the NOTICE text from the Work, provided
          that such additional attribution notices cannot be construed
          as modifying the License.

      You may add Your own copyright statement to Your modifications and
      may provide additional or different license terms and conditions
      for use, reproduction, or distribution of Your modifications, or
      for any such Derivative Works as a whole, provided Your use,
      reproduction, and distribution of the Work otherwise complies with
      the conditions stated in this License.

   5. Submission of Contributions. Unless You explicitly state otherwise,
      any Contribution intentionally submitted for inclusion in the Work
      by You to the Licensor shall be under the terms and conditions of
      this License, without any additional terms or conditions.
      Notwithstanding the above, nothing herein shall supersede or modify
      the terms of any separate license agreement you may have executed
      with Licensor regarding such Contributions.

   6. Trademarks. This License does not grant permission to use the trade
      names, trademarks, service marks, or product names of the Licensor,
      except as required for reasonable and customary use in describing the
      origin of the Work and reproducing the content of the NOTICE file.

   7. Disclaimer of Warranty. Unless required by applicable law or
      agreed to in writing, Licensor provides the Work (and each
      Contributor provides its Contributions) on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
      implied, including, without limitation, any warranties or conditions
      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
      PARTICULAR PURPOSE. You are solely responsible for determining the
      appropriateness of using or redistributing the Work and assume any
      risks associated with Your exercise of permissions under this License.

   8. Limitation of Liability. In no event and under no legal theory,
      whether in tort (including negligence), contract, or otherwise,
      unless required by applicable law (such as deliberate and grossly
      negligent acts) or agreed to in writing, shall any Contributor be
      liable to You for damages, including any direct, indirect, special,
      incidental, or consequential damages of any character arising as a
      result of this License or out of the use or inability to use the
      Work (including but not limited to damages for loss of goodwill,
      work stoppage, computer failure or malfunction, or any and all
      other commercial damages or losses), even if such Contributor
      has been advised of the possibility of such damages.

   9. Accepting Warranty or Additional Liability. While redistributing
      the Work or Derivative Works thereof, You may choose to offer,
      and charge a fee for, acceptance of support, warranty, indemnity,
      or other liability obligations and/or rights consistent with this
      License. However, in accepting such obligations, You may act only
      on Your own behalf and on Your sole responsibility, not on behalf
      of any other Contributor, and only if You agree to indemnify,
      defend, and hold each Contributor harmless for any liability
      incurred by, or claims asserted against, such Contributor by reason
      of your accepting any such warranty or additional liability.

   END OF TERMS AND CONDITIONS

   APPENDIX: How to apply the Apache License to your work.

      To apply the Apache License to your work, attach the following
      boilerplate notice, with the fields enclosed by brackets "[]"
      replaced with your own identifying information. (Don't include
      the brackets!)  The text should be enclosed in the appropriate
      comment syntax for the file format. We also recommend that a
      file or class name and description of purpose be included on the
      same "printed page" as the copyright notice for easier
      identification within third-party archives.

   Copyright 2020 SenseTime

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.


DETR

Copyright 2020 - present, Facebook, Inc

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.


================================================
FILE: batchformer-v2/deformable-detr/README.md
================================================
# BatchFormerV2: Exploring Sample Relationships for Dense Representation Learning

This repository is based on Deformable DETR. One can follow the instructions in Deformable DETR to install Deformable DETR first.

This repository has changed a few lines of the core code based on Deformable DETR. Check the modifications by:
```
diff models/deformable_transformer.py <(curl https://raw.githubusercontent.com/fundamentalvision/Deformable-DETR/main/models/deformable_transformer.py)
```

I mainly changes the two parts of the code: 
1. apply batchformer t get two streams, https://github.com/zhihou7/BatchFormer/blob/e22f5ff895b04d10f3aa4e745f9a226f3d9b7641/batchformer-v2/models/deformable_transformer.py#L278
2. set the labels for batchformerv2 stream. https://github.com/zhihou7/BatchFormer/blob/e22f5ff895b04d10f3aa4e745f9a226f3d9b7641/batchformer-v2/engine.py#L43

## Main Results

| Method      | AP |
| ----------- | ----------- |
| Deformable DETR  | 43.8       |
| + BatchFormerV2   | 45.5        |

## Installation

### Compiling CUDA operators
```bash
cd ./models/ops
sh ./make.sh
# unit test (should see all checking is True)
python test.py
```

## Usage

### Dataset preparation

Please download [COCO 2017 dataset](https://cocodataset.org/) and organize them as following:

```
code_root/
└── data/
    └── coco/
        ├── train2017/
        ├── val2017/
        └── annotations/
        	├── instances_train2017.json
        	└── instances_val2017.json
```

### Training

#### Training on single node

For example, the command for training Deformable DETR on 8 GPUs is as following:

```bash
GPUS_PER_NODE=8 ./tools/run_dist_launch.sh 8 ./configs/r50_deformable_detr.sh --batch-size 3 --share_bf 0 --bf 1 --insert_idx 0
```

"--share_bf 0 --bf 1 --insert_idx 0" is parameters for BatchFormerV2

### Evaluation

You can get the config file and pretrained model of Deformable DETR (the link is in "Main Results" session), then run following command to evaluate it on COCO 2017 validation set:

```bash
<path to config file> --resume <path to pre-trained model> --eval
```

If you find this repository is helpful, please consider to cite


    @inproceedings{hou2022batch,
    	title={BatchFormer: Learning to Explore Sample Relationships for Robust Representation Learning},
	author={Hou, Zhi and Yu, Baosheng and Tao, Dacheng},
    	booktitle={CVPR},
	year={2022}
	}
      @article{hou2022batchformerv2,
 	 title={BatchFormerV2: Exploring Sample Relationships for Dense Representation Learning},
	  author={Hou, Zhi and Yu, Baosheng and Wang, Chaoyue and Zhan, Yibing and Tao, Dacheng},
	  journal={arXiv preprint arXiv:2204.01254},
	  year={2022}
	}
	


================================================
FILE: batchformer-v2/deformable-detr/benchmark.py
================================================
# ------------------------------------------------------------------------
# Deformable DETR
# Copyright (c) 2020 SenseTime. All Rights Reserved.
# Licensed under the Apache License, Version 2.0 [see LICENSE for details]
# ------------------------------------------------------------------------

"""
Benchmark inference speed of Deformable DETR.
"""
import os
import time
import argparse

import torch

from main import get_args_parser as get_main_args_parser
from models import build_model
from datasets import build_dataset
from util.misc import nested_tensor_from_tensor_list


def get_benckmark_arg_parser():
    parser = argparse.ArgumentParser('Benchmark inference speed of Deformable DETR.')
    parser.add_argument('--num_iters', type=int, default=300, help='total iters to benchmark speed')
    parser.add_argument('--warm_iters', type=int, default=5, help='ignore first several iters that are very slow')
    parser.add_argument('--batch_size', type=int, default=1, help='batch size in inference')
    parser.add_argument('--resume', type=str, help='load the pre-trained checkpoint')
    return parser


@torch.no_grad()
def measure_average_inference_time(model, inputs, num_iters=100, warm_iters=5):
    ts = []
    for iter_ in range(num_iters):
        torch.cuda.synchronize()
        t_ = time.perf_counter()
        model(inputs)
        torch.cuda.synchronize()
        t = time.perf_counter() - t_
        if iter_ >= warm_iters:
          ts.append(t)
    print(ts)
    return sum(ts) / len(ts)


def benchmark():
    args, _ = get_benckmark_arg_parser().parse_known_args()
    main_args = get_main_args_parser().parse_args(_)
    assert args.warm_iters < args.num_iters and args.num_iters > 0 and args.warm_iters >= 0
    assert args.batch_size > 0
    assert args.resume is None or os.path.exists(args.resume)
    dataset = build_dataset('val', main_args)
    model, _, _ = build_model(main_args)
    model.cuda()
    model.eval()
    if args.resume is not None:
        ckpt = torch.load(args.resume, map_location=lambda storage, loc: storage)
        model.load_state_dict(ckpt['model'])
    inputs = nested_tensor_from_tensor_list([dataset.__getitem__(0)[0].cuda() for _ in range(args.batch_size)])
    t = measure_average_inference_time(model, inputs, args.num_iters, args.warm_iters)
    return 1.0 / t * args.batch_size


if __name__ == '__main__':
    fps = benchmark()
    print(f'Inference Speed: {fps:.1f} FPS')



================================================
FILE: batchformer-v2/deformable-detr/configs/r101_deformable_detr.sh
================================================
#!/usr/bin/env bash

source /usr/local/anaconda/4.2.0/etc/profile.d/conda.sh
conda activate pyt

set -x

EXP_DIR=exps/r101_deformable_detr
PY_ARGS=${@:1}

python -u main.py \
    --output_dir ${EXP_DIR} \
    ${PY_ARGS}


================================================
FILE: batchformer-v2/deformable-detr/configs/r50_deformable_detr.sh
================================================
#!/usr/bin/env bash

set -x

EXP_DIR=exps/r50_deformable_detr
PY_ARGS=${@:1}

python -u main.py \
    --output_dir ${EXP_DIR} \
    ${PY_ARGS}


================================================
FILE: batchformer-v2/deformable-detr/configs/r50_deformable_detr_plus_iterative_bbox_refinement.sh
================================================
#!/usr/bin/env bash

set -x

EXP_DIR=exps/r50_deformable_detr_plus_iterative_bbox_refinement
PY_ARGS=${@:1}

python -u main.py \
    --output_dir ${EXP_DIR} \
    --with_box_refine \
    ${PY_ARGS}


================================================
FILE: batchformer-v2/deformable-detr/configs/r50_deformable_detr_plus_iterative_bbox_refinement_plus_plus_two_stage.sh
================================================
#!/usr/bin/env bash

set -x

EXP_DIR=exps/r50_deformable_detr_plus_iterative_bbox_refinement_plus_plus_two_stage
PY_ARGS=${@:1}

python -u main.py \
    --output_dir ${EXP_DIR} \
    --with_box_refine \
    --two_stage \
    ${PY_ARGS}


================================================
FILE: batchformer-v2/deformable-detr/configs/r50_deformable_detr_single_scale.sh
================================================
#!/usr/bin/env bash

set -x

EXP_DIR=exps/r50_deformable_detr_single_scale
PY_ARGS=${@:1}

python -u main.py \
    --num_feature_levels 1 \
    --output_dir ${EXP_DIR} \
    ${PY_ARGS}


================================================
FILE: batchformer-v2/deformable-detr/configs/r50_deformable_detr_single_scale_dc5.sh
================================================
#!/usr/bin/env bash

set -x

EXP_DIR=exps/r50_deformable_detr_single_scale_dc5
PY_ARGS=${@:1}

python -u main.py \
    --num_feature_levels 1 \
    --dilation \
    --output_dir ${EXP_DIR} \
    ${PY_ARGS}


================================================
FILE: batchformer-v2/deformable-detr/datasets/__init__.py
================================================
# ------------------------------------------------------------------------
# Deformable DETR
# Copyright (c) 2020 SenseTime. All Rights Reserved.
# Licensed under the Apache License, Version 2.0 [see LICENSE for details]
# ------------------------------------------------------------------------
# Modified from DETR (https://github.com/facebookresearch/detr)
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
# ------------------------------------------------------------------------

import torch.utils.data
from .torchvision_datasets import CocoDetection

from .coco import build as build_coco


def get_coco_api_from_dataset(dataset):
    for _ in range(10):
        # if isinstance(dataset, torchvision.datasets.CocoDetection):
        #     break
        if isinstance(dataset, torch.utils.data.Subset):
            dataset = dataset.dataset
    if isinstance(dataset, CocoDetection):
        return dataset.coco


def build_dataset(image_set, args):
    if args.dataset_file == 'coco':
        return build_coco(image_set, args)
    if args.dataset_file == 'coco_panoptic':
        # to avoid making panopticapi required for coco
        from .coco_panoptic import build as build_coco_panoptic
        return build_coco_panoptic(image_set, args)
    raise ValueError(f'dataset {args.dataset_file} not supported')


================================================
FILE: batchformer-v2/deformable-detr/datasets/coco.py
================================================
# ------------------------------------------------------------------------
# Deformable DETR
# Copyright (c) 2020 SenseTime. All Rights Reserved.
# Licensed under the Apache License, Version 2.0 [see LICENSE for details]
# ------------------------------------------------------------------------
# Modified from DETR (https://github.com/facebookresearch/detr)
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
# ------------------------------------------------------------------------

"""
COCO dataset which returns image_id for evaluation.

Mostly copy-paste from https://github.com/pytorch/vision/blob/13b35ff/references/detection/coco_utils.py
"""
from pathlib import Path

import torch
import torch.utils.data
from pycocotools import mask as coco_mask

from .torchvision_datasets import CocoDetection as TvCocoDetection
from util.misc import get_local_rank, get_local_size
import datasets.transforms as T


class CocoDetection(TvCocoDetection):
    def __init__(self, img_folder, ann_file, transforms, return_masks, cache_mode=False, local_rank=0, local_size=1):
        super(CocoDetection, self).__init__(img_folder, ann_file,
                                            cache_mode=cache_mode, local_rank=local_rank, local_size=local_size)
        self._transforms = transforms
        self.prepare = ConvertCocoPolysToMask(return_masks)

    def __getitem__(self, idx):
        img, target = super(CocoDetection, self).__getitem__(idx)
        image_id = self.ids[idx]
        target = {'image_id': image_id, 'annotations': target}
        img, target = self.prepare(img, target)
        if self._transforms is not None:
            img, target = self._transforms(img, target)
        return img, target


def convert_coco_poly_to_mask(segmentations, height, width):
    masks = []
    for polygons in segmentations:
        rles = coco_mask.frPyObjects(polygons, height, width)
        mask = coco_mask.decode(rles)
        if len(mask.shape) < 3:
            mask = mask[..., None]
        mask = torch.as_tensor(mask, dtype=torch.uint8)
        mask = mask.any(dim=2)
        masks.append(mask)
    if masks:
        masks = torch.stack(masks, dim=0)
    else:
        masks = torch.zeros((0, height, width), dtype=torch.uint8)
    return masks


class ConvertCocoPolysToMask(object):
    def __init__(self, return_masks=False):
        self.return_masks = return_masks

    def __call__(self, image, target):
        w, h = image.size

        image_id = target["image_id"]
        image_id = torch.tensor([image_id])

        anno = target["annotations"]

        anno = [obj for obj in anno if 'iscrowd' not in obj or obj['iscrowd'] == 0]

        boxes = [obj["bbox"] for obj in anno]
        # guard against no boxes via resizing
        boxes = torch.as_tensor(boxes, dtype=torch.float32).reshape(-1, 4)
        boxes[:, 2:] += boxes[:, :2]
        boxes[:, 0::2].clamp_(min=0, max=w)
        boxes[:, 1::2].clamp_(min=0, max=h)

        classes = [obj["category_id"] for obj in anno]
        classes = torch.tensor(classes, dtype=torch.int64)

        if self.return_masks:
            segmentations = [obj["segmentation"] for obj in anno]
            masks = convert_coco_poly_to_mask(segmentations, h, w)

        keypoints = None
        if anno and "keypoints" in anno[0]:
            keypoints = [obj["keypoints"] for obj in anno]
            keypoints = torch.as_tensor(keypoints, dtype=torch.float32)
            num_keypoints = keypoints.shape[0]
            if num_keypoints:
                keypoints = keypoints.view(num_keypoints, -1, 3)

        keep = (boxes[:, 3] > boxes[:, 1]) & (boxes[:, 2] > boxes[:, 0])
        boxes = boxes[keep]
        classes = classes[keep]
        if self.return_masks:
            masks = masks[keep]
        if keypoints is not None:
            keypoints = keypoints[keep]

        target = {}
        target["boxes"] = boxes
        target["labels"] = classes
        if self.return_masks:
            target["masks"] = masks
        target["image_id"] = image_id
        if keypoints is not None:
            target["keypoints"] = keypoints

        # for conversion to coco api
        area = torch.tensor([obj["area"] for obj in anno])
        iscrowd = torch.tensor([obj["iscrowd"] if "iscrowd" in obj else 0 for obj in anno])
        target["area"] = area[keep]
        target["iscrowd"] = iscrowd[keep]

        target["orig_size"] = torch.as_tensor([int(h), int(w)])
        target["size"] = torch.as_tensor([int(h), int(w)])

        return image, target


def make_coco_transforms(image_set):

    normalize = T.Compose([
        T.ToTensor(),
        T.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
    ])

    scales = [480, 512, 544, 576, 608, 640, 672, 704, 736, 768, 800]

    if image_set == 'train':
        return T.Compose([
            T.RandomHorizontalFlip(),
            T.RandomSelect(
                T.RandomResize(scales, max_size=1333),
                T.Compose([
                    T.RandomResize([400, 500, 600]),
                    T.RandomSizeCrop(384, 600),
                    T.RandomResize(scales, max_size=1333),
                ])
            ),
            normalize,
        ])

    if image_set == 'val':
        return T.Compose([
            T.RandomResize([800], max_size=1333),
            normalize,
        ])

    raise ValueError(f'unknown {image_set}')


def build(image_set, args):
    root = Path(args.coco_path)
    assert root.exists(), f'provided COCO path {root} does not exist'
    mode = 'instances'
    PATHS = {
        "train": (root / "train2017", root / "annotations" / f'{mode}_train2017.json'),
        "val": (root / "val2017", root / "annotations" / f'{mode}_val2017.json'),
    }

    img_folder, ann_file = PATHS[image_set]
    dataset = CocoDetection(img_folder, ann_file, transforms=make_coco_transforms(image_set), return_masks=args.masks,
                            cache_mode=args.cache_mode, local_rank=get_local_rank(), local_size=get_local_size())
    return dataset


================================================
FILE: batchformer-v2/deformable-detr/datasets/coco_eval.py
================================================
# ------------------------------------------------------------------------
# Deformable DETR
# Copyright (c) 2020 SenseTime. All Rights Reserved.
# Licensed under the Apache License, Version 2.0 [see LICENSE for details]
# ------------------------------------------------------------------------
# Modified from DETR (https://github.com/facebookresearch/detr)
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
# ------------------------------------------------------------------------

"""
COCO evaluator that works in distributed mode.

Mostly copy-paste from https://github.com/pytorch/vision/blob/edfd5a7/references/detection/coco_eval.py
The difference is that there is less copy-pasting from pycocotools
in the end of the file, as python3 can suppress prints with contextlib
"""
import os
import contextlib
import copy
import numpy as np
import torch

from pycocotools.cocoeval import COCOeval
from pycocotools.coco import COCO
import pycocotools.mask as mask_util

from util.misc import all_gather


class CocoEvaluator(object):
    def __init__(self, coco_gt, iou_types):
        assert isinstance(iou_types, (list, tuple))
        coco_gt = copy.deepcopy(coco_gt)
        self.coco_gt = coco_gt

        self.iou_types = iou_types
        self.coco_eval = {}
        for iou_type in iou_types:
            self.coco_eval[iou_type] = COCOeval(coco_gt, iouType=iou_type)

        self.img_ids = []
        self.eval_imgs = {k: [] for k in iou_types}

    def update(self, predictions):
        img_ids = list(np.unique(list(predictions.keys())))
        self.img_ids.extend(img_ids)

        for iou_type in self.iou_types:
            results = self.prepare(predictions, iou_type)

            # suppress pycocotools prints
            with open(os.devnull, 'w') as devnull:
                with contextlib.redirect_stdout(devnull):
                    coco_dt = COCO.loadRes(self.coco_gt, results) if results else COCO()
            coco_eval = self.coco_eval[iou_type]

            coco_eval.cocoDt = coco_dt
            coco_eval.params.imgIds = list(img_ids)
            img_ids, eval_imgs = evaluate(coco_eval)

            self.eval_imgs[iou_type].append(eval_imgs)

    def synchronize_between_processes(self):
        for iou_type in self.iou_types:
            self.eval_imgs[iou_type] = np.concatenate(self.eval_imgs[iou_type], 2)
            create_common_coco_eval(self.coco_eval[iou_type], self.img_ids, self.eval_imgs[iou_type])

    def accumulate(self):
        for coco_eval in self.coco_eval.values():
            coco_eval.accumulate()

    def summarize(self):
        for iou_type, coco_eval in self.coco_eval.items():
            print("IoU metric: {}".format(iou_type))
            coco_eval.summarize()

    def prepare(self, predictions, iou_type):
        if iou_type == "bbox":
            return self.prepare_for_coco_detection(predictions)
        elif iou_type == "segm":
            return self.prepare_for_coco_segmentation(predictions)
        elif iou_type == "keypoints":
            return self.prepare_for_coco_keypoint(predictions)
        else:
            raise ValueError("Unknown iou type {}".format(iou_type))

    def prepare_for_coco_detection(self, predictions):
        coco_results = []
        for original_id, prediction in predictions.items():
            if len(prediction) == 0:
                continue

            boxes = prediction["boxes"]
            boxes = convert_to_xywh(boxes).tolist()
            scores = prediction["scores"].tolist()
            labels = prediction["labels"].tolist()

            coco_results.extend(
                [
                    {
                        "image_id": original_id,
                        "category_id": labels[k],
                        "bbox": box,
                        "score": scores[k],
                    }
                    for k, box in enumerate(boxes)
                ]
            )
        return coco_results

    def prepare_for_coco_segmentation(self, predictions):
        coco_results = []
        for original_id, prediction in predictions.items():
            if len(prediction) == 0:
                continue

            scores = prediction["scores"]
            labels = prediction["labels"]
            masks = prediction["masks"]

            masks = masks > 0.5

            scores = prediction["scores"].tolist()
            labels = prediction["labels"].tolist()

            rles = [
                mask_util.encode(np.array(mask[0, :, :, np.newaxis], dtype=np.uint8, order="F"))[0]
                for mask in masks
            ]
            for rle in rles:
                rle["counts"] = rle["counts"].decode("utf-8")

            coco_results.extend(
                [
                    {
                        "image_id": original_id,
                        "category_id": labels[k],
                        "segmentation": rle,
                        "score": scores[k],
                    }
                    for k, rle in enumerate(rles)
                ]
            )
        return coco_results

    def prepare_for_coco_keypoint(self, predictions):
        coco_results = []
        for original_id, prediction in predictions.items():
            if len(prediction) == 0:
                continue

            boxes = prediction["boxes"]
            boxes = convert_to_xywh(boxes).tolist()
            scores = prediction["scores"].tolist()
            labels = prediction["labels"].tolist()
            keypoints = prediction["keypoints"]
            keypoints = keypoints.flatten(start_dim=1).tolist()

            coco_results.extend(
                [
                    {
                        "image_id": original_id,
                        "category_id": labels[k],
                        'keypoints': keypoint,
                        "score": scores[k],
                    }
                    for k, keypoint in enumerate(keypoints)
                ]
            )
        return coco_results


def convert_to_xywh(boxes):
    xmin, ymin, xmax, ymax = boxes.unbind(1)
    return torch.stack((xmin, ymin, xmax - xmin, ymax - ymin), dim=1)


def merge(img_ids, eval_imgs):
    all_img_ids = all_gather(img_ids)
    all_eval_imgs = all_gather(eval_imgs)

    merged_img_ids = []
    for p in all_img_ids:
        merged_img_ids.extend(p)

    merged_eval_imgs = []
    for p in all_eval_imgs:
        merged_eval_imgs.append(p)

    merged_img_ids = np.array(merged_img_ids)
    merged_eval_imgs = np.concatenate(merged_eval_imgs, 2)

    # keep only unique (and in sorted order) images
    merged_img_ids, idx = np.unique(merged_img_ids, return_index=True)
    merged_eval_imgs = merged_eval_imgs[..., idx]

    return merged_img_ids, merged_eval_imgs


def create_common_coco_eval(coco_eval, img_ids, eval_imgs):
    img_ids, eval_imgs = merge(img_ids, eval_imgs)
    img_ids = list(img_ids)
    eval_imgs = list(eval_imgs.flatten())

    coco_eval.evalImgs = eval_imgs
    coco_eval.params.imgIds = img_ids
    coco_eval._paramsEval = copy.deepcopy(coco_eval.params)


#################################################################
# From pycocotools, just removed the prints and fixed
# a Python3 bug about unicode not defined
#################################################################


def evaluate(self):
    '''
    Run per image evaluation on given images and store results (a list of dict) in self.evalImgs
    :return: None
    '''
    # tic = time.time()
    # print('Running per image evaluation...')
    p = self.params
    # add backward compatibility if useSegm is specified in params
    if p.useSegm is not None:
        p.iouType = 'segm' if p.useSegm == 1 else 'bbox'
        print('useSegm (deprecated) is not None. Running {} evaluation'.format(p.iouType))
    # print('Evaluate annotation type *{}*'.format(p.iouType))
    p.imgIds = list(np.unique(p.imgIds))
    if p.useCats:
        p.catIds = list(np.unique(p.catIds))
    p.maxDets = sorted(p.maxDets)
    self.params = p

    self._prepare()
    # loop through images, area range, max detection number
    catIds = p.catIds if p.useCats else [-1]

    if p.iouType == 'segm' or p.iouType == 'bbox':
        computeIoU = self.computeIoU
    elif p.iouType == 'keypoints':
        computeIoU = self.computeOks
    self.ious = {
        (imgId, catId): computeIoU(imgId, catId)
        for imgId in p.imgIds
        for catId in catIds}

    evaluateImg = self.evaluateImg
    maxDet = p.maxDets[-1]
    evalImgs = [
        evaluateImg(imgId, catId, areaRng, maxDet)
        for catId in catIds
        for areaRng in p.areaRng
        for imgId in p.imgIds
    ]
    # this is NOT in the pycocotools code, but could be done outside
    evalImgs = np.asarray(evalImgs).reshape(len(catIds), len(p.areaRng), len(p.imgIds))
    self._paramsEval = copy.deepcopy(self.params)
    # toc = time.time()
    # print('DONE (t={:0.2f}s).'.format(toc-tic))
    return p.imgIds, evalImgs

#################################################################
# end of straight copy from pycocotools, just removing the prints
#################################################################


================================================
FILE: batchformer-v2/deformable-detr/datasets/coco_panoptic.py
================================================
# ------------------------------------------------------------------------
# Deformable DETR
# Copyright (c) 2020 SenseTime. All Rights Reserved.
# Licensed under the Apache License, Version 2.0 [see LICENSE for details]
# ------------------------------------------------------------------------
# Modified from DETR (https://github.com/facebookresearch/detr)
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
# ------------------------------------------------------------------------

import json
from pathlib import Path

import numpy as np
import torch
from PIL import Image

from panopticapi.utils import rgb2id
from util.box_ops import masks_to_boxes

from .coco import make_coco_transforms


class CocoPanoptic:
    def __init__(self, img_folder, ann_folder, ann_file, transforms=None, return_masks=True):
        with open(ann_file, 'r') as f:
            self.coco = json.load(f)

        # sort 'images' field so that they are aligned with 'annotations'
        # i.e., in alphabetical order
        self.coco['images'] = sorted(self.coco['images'], key=lambda x: x['id'])
        # sanity check
        if "annotations" in self.coco:
            for img, ann in zip(self.coco['images'], self.coco['annotations']):
                assert img['file_name'][:-4] == ann['file_name'][:-4]

        self.img_folder = img_folder
        self.ann_folder = ann_folder
        self.ann_file = ann_file
        self.transforms = transforms
        self.return_masks = return_masks

    def __getitem__(self, idx):
        ann_info = self.coco['annotations'][idx] if "annotations" in self.coco else self.coco['images'][idx]
        img_path = Path(self.img_folder) / ann_info['file_name'].replace('.png', '.jpg')
        ann_path = Path(self.ann_folder) / ann_info['file_name']

        img = Image.open(img_path).convert('RGB')
        w, h = img.size
        if "segments_info" in ann_info:
            masks = np.asarray(Image.open(ann_path), dtype=np.uint32)
            masks = rgb2id(masks)

            ids = np.array([ann['id'] for ann in ann_info['segments_info']])
            masks = masks == ids[:, None, None]

            masks = torch.as_tensor(masks, dtype=torch.uint8)
            labels = torch.tensor([ann['category_id'] for ann in ann_info['segments_info']], dtype=torch.int64)

        target = {}
        target['image_id'] = torch.tensor([ann_info['image_id'] if "image_id" in ann_info else ann_info["id"]])
        if self.return_masks:
            target['masks'] = masks
        target['labels'] = labels

        target["boxes"] = masks_to_boxes(masks)

        target['size'] = torch.as_tensor([int(h), int(w)])
        target['orig_size'] = torch.as_tensor([int(h), int(w)])
        if "segments_info" in ann_info:
            for name in ['iscrowd', 'area']:
                target[name] = torch.tensor([ann[name] for ann in ann_info['segments_info']])

        if self.transforms is not None:
            img, target = self.transforms(img, target)

        return img, target

    def __len__(self):
        return len(self.coco['images'])

    def get_height_and_width(self, idx):
        img_info = self.coco['images'][idx]
        height = img_info['height']
        width = img_info['width']
        return height, width


def build(image_set, args):
    img_folder_root = Path(args.coco_path)
    ann_folder_root = Path(args.coco_panoptic_path)
    assert img_folder_root.exists(), f'provided COCO path {img_folder_root} does not exist'
    assert ann_folder_root.exists(), f'provided COCO path {ann_folder_root} does not exist'
    mode = 'panoptic'
    PATHS = {
        "train": ("train2017", Path("annotations") / f'{mode}_train2017.json'),
        "val": ("val2017", Path("annotations") / f'{mode}_val2017.json'),
    }

    img_folder, ann_file = PATHS[image_set]
    img_folder_path = img_folder_root / img_folder
    ann_folder = ann_folder_root / f'{mode}_{img_folder}'
    ann_file = ann_folder_root / ann_file

    dataset = CocoPanoptic(img_folder_path, ann_folder, ann_file,
                           transforms=make_coco_transforms(image_set), return_masks=args.masks)

    return dataset


================================================
FILE: batchformer-v2/deformable-detr/datasets/data_prefetcher.py
================================================
# ------------------------------------------------------------------------
# Deformable DETR
# Copyright (c) 2020 SenseTime. All Rights Reserved.
# Licensed under the Apache License, Version 2.0 [see LICENSE for details]
# ------------------------------------------------------------------------

import torch

def to_cuda(samples, targets, device):
    samples = samples.to(device, non_blocking=True)
    targets = [{k: v.to(device, non_blocking=True) for k, v in t.items()} for t in targets]
    return samples, targets

class data_prefetcher():
    def __init__(self, loader, device, prefetch=True):
        self.loader = iter(loader)
        self.prefetch = prefetch
        self.device = device
        if prefetch:
            self.stream = torch.cuda.Stream()
            self.preload()

    def preload(self):
        try:
            self.next_samples, self.next_targets = next(self.loader)
        except StopIteration:
            self.next_samples = None
            self.next_targets = None
            return
        # if record_stream() doesn't work, another option is to make sure device inputs are created
        # on the main stream.
        # self.next_input_gpu = torch.empty_like(self.next_input, device='cuda')
        # self.next_target_gpu = torch.empty_like(self.next_target, device='cuda')
        # Need to make sure the memory allocated for next_* is not still in use by the main stream
        # at the time we start copying to next_*:
        # self.stream.wait_stream(torch.cuda.current_stream())
        with torch.cuda.stream(self.stream):
            self.next_samples, self.next_targets = to_cuda(self.next_samples, self.next_targets, self.device)
            # more code for the alternative if record_stream() doesn't work:
            # copy_ will record the use of the pinned source tensor in this side stream.
            # self.next_input_gpu.copy_(self.next_input, non_blocking=True)
            # self.next_target_gpu.copy_(self.next_target, non_blocking=True)
            # self.next_input = self.next_input_gpu
            # self.next_target = self.next_target_gpu

            # With Amp, it isn't necessary to manually convert data to half.
            # if args.fp16:
            #     self.next_input = self.next_input.half()
            # else:

    def next(self):
        if self.prefetch:
            torch.cuda.current_stream().wait_stream(self.stream)
            samples = self.next_samples
            targets = self.next_targets
            if samples is not None:
                samples.record_stream(torch.cuda.current_stream())
            if targets is not None:
                for t in targets:
                    for k, v in t.items():
                        v.record_stream(torch.cuda.current_stream())
            self.preload()
        else:
            try:
                samples, targets = next(self.loader)
                samples, targets = to_cuda(samples, targets, self.device)
            except StopIteration:
                samples = None
                targets = None
        return samples, targets


================================================
FILE: batchformer-v2/deformable-detr/datasets/panoptic_eval.py
================================================
# ------------------------------------------------------------------------
# Deformable DETR
# Copyright (c) 2020 SenseTime. All Rights Reserved.
# Licensed under the Apache License, Version 2.0 [see LICENSE for details]
# ------------------------------------------------------------------------
# Modified from DETR (https://github.com/facebookresearch/detr)
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
# ------------------------------------------------------------------------

import json
import os

import util.misc as utils

try:
    from panopticapi.evaluation import pq_compute
except ImportError:
    pass


class PanopticEvaluator(object):
    def __init__(self, ann_file, ann_folder, output_dir="panoptic_eval"):
        self.gt_json = ann_file
        self.gt_folder = ann_folder
        if utils.is_main_process():
            if not os.path.exists(output_dir):
                os.mkdir(output_dir)
        self.output_dir = output_dir
        self.predictions = []

    def update(self, predictions):
        for p in predictions:
            with open(os.path.join(self.output_dir, p["file_name"]), "wb") as f:
                f.write(p.pop("png_string"))

        self.predictions += predictions

    def synchronize_between_processes(self):
        all_predictions = utils.all_gather(self.predictions)
        merged_predictions = []
        for p in all_predictions:
            merged_predictions += p
        self.predictions = merged_predictions

    def summarize(self):
        if utils.is_main_process():
            json_data = {"annotations": self.predictions}
            predictions_json = os.path.join(self.output_dir, "predictions.json")
            with open(predictions_json, "w") as f:
                f.write(json.dumps(json_data))
            return pq_compute(self.gt_json, predictions_json, gt_folder=self.gt_folder, pred_folder=self.output_dir)
        return None


================================================
FILE: batchformer-v2/deformable-detr/datasets/samplers.py
================================================
# ------------------------------------------------------------------------
# Deformable DETR
# Copyright (c) 2020 SenseTime. All Rights Reserved.
# Licensed under the Apache License, Version 2.0 [see LICENSE for details]
# ------------------------------------------------------------------------
# Modified from codes in torch.utils.data.distributed
# ------------------------------------------------------------------------

import os
import math
import torch
import torch.distributed as dist
from torch.utils.data.sampler import Sampler


class DistributedSampler(Sampler):
    """Sampler that restricts data loading to a subset of the dataset.
    It is especially useful in conjunction with
    :class:`torch.nn.parallel.DistributedDataParallel`. In such case, each
    process can pass a DistributedSampler instance as a DataLoader sampler,
    and load a subset of the original dataset that is exclusive to it.
    .. note::
        Dataset is assumed to be of constant size.
    Arguments:
        dataset: Dataset used for sampling.
        num_replicas (optional): Number of processes participating in
            distributed training.
        rank (optional): Rank of the current process within num_replicas.
    """

    def __init__(self, dataset, num_replicas=None, rank=None, local_rank=None, local_size=None, shuffle=True):
        if num_replicas is None:
            if not dist.is_available():
                raise RuntimeError("Requires distributed package to be available")
            num_replicas = dist.get_world_size()
        if rank is None:
            if not dist.is_available():
                raise RuntimeError("Requires distributed package to be available")
            rank = dist.get_rank()
        self.dataset = dataset
        self.num_replicas = num_replicas
        self.rank = rank
        self.epoch = 0
        self.num_samples = int(math.ceil(len(self.dataset) * 1.0 / self.num_replicas))
        self.total_size = self.num_samples * self.num_replicas
        self.shuffle = shuffle

    def __iter__(self):
        if self.shuffle:
            # deterministically shuffle based on epoch
            g = torch.Generator()
            g.manual_seed(self.epoch)
            indices = torch.randperm(len(self.dataset), generator=g).tolist()
        else:
            indices = torch.arange(len(self.dataset)).tolist()

        # add extra samples to make it evenly divisible
        indices += indices[: (self.total_size - len(indices))]
        assert len(indices) == self.total_size

        # subsample
        offset = self.num_samples * self.rank
        indices = indices[offset : offset + self.num_samples]
        assert len(indices) == self.num_samples

        return iter(indices)

    def __len__(self):
        return self.num_samples

    def set_epoch(self, epoch):
        self.epoch = epoch


class NodeDistributedSampler(Sampler):
    """Sampler that restricts data loading to a subset of the dataset.
    It is especially useful in conjunction with
    :class:`torch.nn.parallel.DistributedDataParallel`. In such case, each
    process can pass a DistributedSampler instance as a DataLoader sampler,
    and load a subset of the original dataset that is exclusive to it.
    .. note::
        Dataset is assumed to be of constant size.
    Arguments:
        dataset: Dataset used for sampling.
        num_replicas (optional): Number of processes participating in
            distributed training.
        rank (optional): Rank of the current process within num_replicas.
    """

    def __init__(self, dataset, num_replicas=None, rank=None, local_rank=None, local_size=None, shuffle=True):
        if num_replicas is None:
            if not dist.is_available():
                raise RuntimeError("Requires distributed package to be available")
            num_replicas = dist.get_world_size()
        if rank is None:
            if not dist.is_available():
                raise RuntimeError("Requires distributed package to be available")
            rank = dist.get_rank()
        if local_rank is None:
            local_rank = int(os.environ.get('LOCAL_RANK', 0))
        if local_size is None:
            local_size = int(os.environ.get('LOCAL_SIZE', 1))
        self.dataset = dataset
        self.shuffle = shuffle
        self.num_replicas = num_replicas
        self.num_parts = local_size
        self.rank = rank
        self.local_rank = local_rank
        self.epoch = 0
        self.num_samples = int(math.ceil(len(self.dataset) * 1.0 / self.num_replicas))
        self.total_size = self.num_samples * self.num_replicas

        self.total_size_parts = self.num_samples * self.num_replicas // self.num_parts

    def __iter__(self):
        if self.shuffle:
            # deterministically shuffle based on epoch
            g = torch.Generator()
            g.manual_seed(self.epoch)
            indices = torch.randperm(len(self.dataset), generator=g).tolist()
        else:
            indices = torch.arange(len(self.dataset)).tolist()
        indices = [i for i in indices if i % self.num_parts == self.local_rank]

        # add extra samples to make it evenly divisible
        indices += indices[:(self.total_size_parts - len(indices))]
        assert len(indices) == self.total_size_parts

        # subsample
        indices = indices[self.rank // self.num_parts:self.total_size_parts:self.num_replicas // self.num_parts]
        assert len(indices) == self.num_samples

        return iter(indices)

    def __len__(self):
        return self.num_samples

    def set_epoch(self, epoch):
        self.epoch = epoch


================================================
FILE: batchformer-v2/deformable-detr/datasets/torchvision_datasets/__init__.py
================================================
# ------------------------------------------------------------------------
# Deformable DETR
# Copyright (c) 2020 SenseTime. All Rights Reserved.
# Licensed under the Apache License, Version 2.0 [see LICENSE for details]
# ------------------------------------------------------------------------

from .coco import CocoDetection


================================================
FILE: batchformer-v2/deformable-detr/datasets/torchvision_datasets/coco.py
================================================
# ------------------------------------------------------------------------
# Deformable DETR
# Copyright (c) 2020 SenseTime. All Rights Reserved.
# Licensed under the Apache License, Version 2.0 [see LICENSE for details]
# ------------------------------------------------------------------------
# Modified from torchvision
# ------------------------------------------------------------------------

"""
Copy-Paste from torchvision, but add utility of caching images on memory
"""
from torchvision.datasets.vision import VisionDataset
from PIL import Image
import os
import os.path
import tqdm
from io import BytesIO


class CocoDetection(VisionDataset):
    """`MS Coco Detection <http://mscoco.org/dataset/#detections-challenge2016>`_ Dataset.
    Args:
        root (string): Root directory where images are downloaded to.
        annFile (string): Path to json annotation file.
        transform (callable, optional): A function/transform that  takes in an PIL image
            and returns a transformed version. E.g, ``transforms.ToTensor``
        target_transform (callable, optional): A function/transform that takes in the
            target and transforms it.
        transforms (callable, optional): A function/transform that takes input sample and its target as entry
            and returns a transformed version.
    """

    def __init__(self, root, annFile, transform=None, target_transform=None, transforms=None,
                 cache_mode=False, local_rank=0, local_size=1):
        super(CocoDetection, self).__init__(root, transforms, transform, target_transform)
        from pycocotools.coco import COCO
        self.coco = COCO(annFile)
        self.ids = list(sorted(self.coco.imgs.keys()))
        self.cache_mode = cache_mode
        self.local_rank = local_rank
        self.local_size = local_size
        if cache_mode:
            self.cache = {}
            self.cache_images()

    def cache_images(self):
        self.cache = {}
        for index, img_id in zip(tqdm.trange(len(self.ids)), self.ids):
            if index % self.local_size != self.local_rank:
                continue
            path = self.coco.loadImgs(img_id)[0]['file_name']
            with open(os.path.join(self.root, path), 'rb') as f:
                self.cache[path] = f.read()

    def get_image(self, path):
        if self.cache_mode:
            if path not in self.cache.keys():
                with open(os.path.join(self.root, path), 'rb') as f:
                    self.cache[path] = f.read()
            return Image.open(BytesIO(self.cache[path])).convert('RGB')
        return Image.open(os.path.join(self.root, path)).convert('RGB')

    def __getitem__(self, index):
        """
        Args:
            index (int): Index
        Returns:
            tuple: Tuple (image, target). target is the object returned by ``coco.loadAnns``.
        """
        coco = self.coco
        img_id = self.ids[index]
        ann_ids = coco.getAnnIds(imgIds=img_id)
        target = coco.loadAnns(ann_ids)

        path = coco.loadImgs(img_id)[0]['file_name']

        img = self.get_image(path)
        if self.transforms is not None:
            img, target = self.transforms(img, target)

        return img, target

    def __len__(self):
        return len(self.ids)


================================================
FILE: batchformer-v2/deformable-detr/datasets/transforms.py
================================================
# ------------------------------------------------------------------------
# Deformable DETR
# Copyright (c) 2020 SenseTime. All Rights Reserved.
# Licensed under the Apache License, Version 2.0 [see LICENSE for details]
# ------------------------------------------------------------------------
# Modified from DETR (https://github.com/facebookresearch/detr)
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
# ------------------------------------------------------------------------

"""
Transforms and data augmentation for both image + bbox.
"""
import random

import PIL
import torch
import torchvision.transforms as T
import torchvision.transforms.functional as F

from util.box_ops import box_xyxy_to_cxcywh
from util.misc import interpolate


def crop(image, target, region):
    cropped_image = F.crop(image, *region)

    target = target.copy()
    i, j, h, w = region

    # should we do something wrt the original size?
    target["size"] = torch.tensor([h, w])

    fields = ["labels", "area", "iscrowd"]

    if "boxes" in target:
        boxes = target["boxes"]
        max_size = torch.as_tensor([w, h], dtype=torch.float32)
        cropped_boxes = boxes - torch.as_tensor([j, i, j, i])
        cropped_boxes = torch.min(cropped_boxes.reshape(-1, 2, 2), max_size)
        cropped_boxes = cropped_boxes.clamp(min=0)
        area = (cropped_boxes[:, 1, :] - cropped_boxes[:, 0, :]).prod(dim=1)
        target["boxes"] = cropped_boxes.reshape(-1, 4)
        target["area"] = area
        fields.append("boxes")

    if "masks" in target:
        # FIXME should we update the area here if there are no boxes?
        target['masks'] = target['masks'][:, i:i + h, j:j + w]
        fields.append("masks")

    # remove elements for which the boxes or masks that have zero area
    if "boxes" in target or "masks" in target:
        # favor boxes selection when defining which elements to keep
        # this is compatible with previous implementation
        if "boxes" in target:
            cropped_boxes = target['boxes'].reshape(-1, 2, 2)
            keep = torch.all(cropped_boxes[:, 1, :] > cropped_boxes[:, 0, :], dim=1)
        else:
            keep = target['masks'].flatten(1).any(1)

        for field in fields:
            target[field] = target[field][keep]

    return cropped_image, target


def hflip(image, target):
    flipped_image = F.hflip(image)

    w, h = image.size

    target = target.copy()
    if "boxes" in target:
        boxes = target["boxes"]
        boxes = boxes[:, [2, 1, 0, 3]] * torch.as_tensor([-1, 1, -1, 1]) + torch.as_tensor([w, 0, w, 0])
        target["boxes"] = boxes

    if "masks" in target:
        target['masks'] = target['masks'].flip(-1)

    return flipped_image, target


def resize(image, target, size, max_size=None):
    # size can be min_size (scalar) or (w, h) tuple

    def get_size_with_aspect_ratio(image_size, size, max_size=None):
        w, h = image_size
        if max_size is not None:
            min_original_size = float(min((w, h)))
            max_original_size = float(max((w, h)))
            if max_original_size / min_original_size * size > max_size:
                size = int(round(max_size * min_original_size / max_original_size))

        if (w <= h and w == size) or (h <= w and h == size):
            return (h, w)

        if w < h:
            ow = size
            oh = int(size * h / w)
        else:
            oh = size
            ow = int(size * w / h)

        return (oh, ow)

    def get_size(image_size, size, max_size=None):
        if isinstance(size, (list, tuple)):
            return size[::-1]
        else:
            return get_size_with_aspect_ratio(image_size, size, max_size)

    size = get_size(image.size, size, max_size)
    rescaled_image = F.resize(image, size)

    if target is None:
        return rescaled_image, None

    ratios = tuple(float(s) / float(s_orig) for s, s_orig in zip(rescaled_image.size, image.size))
    ratio_width, ratio_height = ratios

    target = target.copy()
    if "boxes" in target:
        boxes = target["boxes"]
        scaled_boxes = boxes * torch.as_tensor([ratio_width, ratio_height, ratio_width, ratio_height])
        target["boxes"] = scaled_boxes

    if "area" in target:
        area = target["area"]
        scaled_area = area * (ratio_width * ratio_height)
        target["area"] = scaled_area

    h, w = size
    target["size"] = torch.tensor([h, w])

    if "masks" in target:
        target['masks'] = interpolate(
            target['masks'][:, None].float(), size, mode="nearest")[:, 0] > 0.5

    return rescaled_image, target


def pad(image, target, padding):
    # assumes that we only pad on the bottom right corners
    padded_image = F.pad(image, (0, 0, padding[0], padding[1]))
    if target is None:
        return padded_image, None
    target = target.copy()
    # should we do something wrt the original size?
    target["size"] = torch.tensor(padded_image[::-1])
    if "masks" in target:
        target['masks'] = torch.nn.functional.pad(target['masks'], (0, padding[0], 0, padding[1]))
    return padded_image, target


class RandomCrop(object):
    def __init__(self, size):
        self.size = size

    def __call__(self, img, target):
        region = T.RandomCrop.get_params(img, self.size)
        return crop(img, target, region)


class RandomSizeCrop(object):
    def __init__(self, min_size: int, max_size: int):
        self.min_size = min_size
        self.max_size = max_size

    def __call__(self, img: PIL.Image.Image, target: dict):
        w = random.randint(self.min_size, min(img.width, self.max_size))
        h = random.randint(self.min_size, min(img.height, self.max_size))
        region = T.RandomCrop.get_params(img, [h, w])
        return crop(img, target, region)


class CenterCrop(object):
    def __init__(self, size):
        self.size = size

    def __call__(self, img, target):
        image_width, image_height = img.size
        crop_height, crop_width = self.size
        crop_top = int(round((image_height - crop_height) / 2.))
        crop_left = int(round((image_width - crop_width) / 2.))
        return crop(img, target, (crop_top, crop_left, crop_height, crop_width))


class RandomHorizontalFlip(object):
    def __init__(self, p=0.5):
        self.p = p

    def __call__(self, img, target):
        if random.random() < self.p:
            return hflip(img, target)
        return img, target


class RandomResize(object):
    def __init__(self, sizes, max_size=None):
        assert isinstance(sizes, (list, tuple))
        self.sizes = sizes
        self.max_size = max_size

    def __call__(self, img, target=None):
        size = random.choice(self.sizes)
        return resize(img, target, size, self.max_size)


class RandomPad(object):
    def __init__(self, max_pad):
        self.max_pad = max_pad

    def __call__(self, img, target):
        pad_x = random.randint(0, self.max_pad)
        pad_y = random.randint(0, self.max_pad)
        return pad(img, target, (pad_x, pad_y))


class RandomSelect(object):
    """
    Randomly selects between transforms1 and transforms2,
    with probability p for transforms1 and (1 - p) for transforms2
    """
    def __init__(self, transforms1, transforms2, p=0.5):
        self.transforms1 = transforms1
        self.transforms2 = transforms2
        self.p = p

    def __call__(self, img, target):
        if random.random() < self.p:
            return self.transforms1(img, target)
        return self.transforms2(img, target)


class ToTensor(object):
    def __call__(self, img, target):
        return F.to_tensor(img), target


class RandomErasing(object):

    def __init__(self, *args, **kwargs):
        self.eraser = T.RandomErasing(*args, **kwargs)

    def __call__(self, img, target):
        return self.eraser(img), target


class Normalize(object):
    def __init__(self, mean, std):
        self.mean = mean
        self.std = std

    def __call__(self, image, target=None):
        image = F.normalize(image, mean=self.mean, std=self.std)
        if target is None:
            return image, None
        target = target.copy()
        h, w = image.shape[-2:]
        if "boxes" in target:
            boxes = target["boxes"]
            boxes = box_xyxy_to_cxcywh(boxes)
            boxes = boxes / torch.tensor([w, h, w, h], dtype=torch.float32)
            target["boxes"] = boxes
        return image, target


class Compose(object):
    def __init__(self, transforms):
        self.transforms = transforms

    def __call__(self, image, target):
        for t in self.transforms:
            image, target = t(image, target)
        return image, target

    def __repr__(self):
        format_string = self.__class__.__name__ + "("
        for t in self.transforms:
            format_string += "\n"
            format_string += "    {0}".format(t)
        format_string += "\n)"
        return format_string


================================================
FILE: batchformer-v2/deformable-detr/docs/changelog.md
================================================
## Changelog

**[2020.12.07]** Fix a bug of sampling offset normalization (see [this issue](https://github.com/fundamentalvision/Deformable-DETR/issues/6)) in the MSDeformAttn module. The final accuracy on COCO is slightly improved. Code and pre-trained models have been updated. This bug only occurs in this released version but not in the original implementation used in our paper.

================================================
FILE: batchformer-v2/deformable-detr/engine.py
================================================
# ------------------------------------------------------------------------
# Deformable DETR
# Copyright (c) 2020 SenseTime. All Rights Reserved.
# Licensed under the Apache License, Version 2.0 [see LICENSE for details]
# ------------------------------------------------------------------------
# Modified from DETR (https://github.com/facebookresearch/detr)
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
# ------------------------------------------------------------------------

"""
Train and eval functions used in main.py
"""
import math
import os
import sys
from typing import Iterable

import torch
import util.misc as utils
from datasets.coco_eval import CocoEvaluator
from datasets.panoptic_eval import PanopticEvaluator
from datasets.data_prefetcher import data_prefetcher


def train_one_epoch(model: torch.nn.Module, criterion: torch.nn.Module,
                    data_loader: Iterable, optimizer: torch.optim.Optimizer,
                    device: torch.device, epoch: int, max_norm: float = 0):
    model.train()
    criterion.train()
    metric_logger = utils.MetricLogger(delimiter="  ")
    metric_logger.add_meter('lr', utils.SmoothedValue(window_size=1, fmt='{value:.6f}'))
    metric_logger.add_meter('class_error', utils.SmoothedValue(window_size=1, fmt='{value:.2f}'))
    metric_logger.add_meter('grad_norm', utils.SmoothedValue(window_size=1, fmt='{value:.2f}'))
    header = 'Epoch: [{}]'.format(epoch)
    print_freq = 10

    prefetcher = data_prefetcher(data_loader, device, prefetch=True)
    samples, targets = prefetcher.next()

    # for samples, targets in metric_logger.log_every(data_loader, print_freq, header):
    for _ in metric_logger.log_every(range(len(data_loader)), print_freq, header):
        outputs = model(samples)
        if len(outputs['pred_logits']) > len(targets): # Here, we need to set the labels for the batchformerv2 stream/batch
            targets = targets + targets # targets is a list
        loss_dict = criterion(outputs, targets)
        weight_dict = criterion.weight_dict
        losses = sum(loss_dict[k] * weight_dict[k] for k in loss_dict.keys() if k in weight_dict)

        # reduce losses over all GPUs for logging purposes
        loss_dict_reduced = utils.reduce_dict(loss_dict)
        loss_dict_reduced_unscaled = {f'{k}_unscaled': v
                                      for k, v in loss_dict_reduced.items()}
        loss_dict_reduced_scaled = {k: v * weight_dict[k]
                                    for k, v in loss_dict_reduced.items() if k in weight_dict}
        losses_reduced_scaled = sum(loss_dict_reduced_scaled.values())

        loss_value = losses_reduced_scaled.item()

        if not math.isfinite(loss_value):
            print("Loss is {}, stopping training".format(loss_value))
            print(loss_dict_reduced)
            sys.exit(1)

        optimizer.zero_grad()
        losses.backward()
        if max_norm > 0:
            grad_total_norm = torch.nn.utils.clip_grad_norm_(model.parameters(), max_norm)
        else:
            grad_total_norm = utils.get_total_grad_norm(model.parameters(), max_norm)
        optimizer.step()

        metric_logger.update(loss=loss_value, **loss_dict_reduced_scaled, **loss_dict_reduced_unscaled)
        metric_logger.update(class_error=loss_dict_reduced['class_error'])
        metric_logger.update(lr=optimizer.param_groups[0]["lr"])
        metric_logger.update(grad_norm=grad_total_norm)

        samples, targets = prefetcher.next()
    # gather the stats from all processes
    metric_logger.synchronize_between_processes()
    print("Averaged stats:", metric_logger)
    return {k: meter.global_avg for k, meter in metric_logger.meters.items()}


@torch.no_grad()
def evaluate(model, criterion, postprocessors, data_loader, base_ds, device, output_dir):
    model.eval()
    criterion.eval()

    metric_logger = utils.MetricLogger(delimiter="  ")
    metric_logger.add_meter('class_error', utils.SmoothedValue(window_size=1, fmt='{value:.2f}'))
    header = 'Test:'

    iou_types = tuple(k for k in ('segm', 'bbox') if k in postprocessors.keys())
    coco_evaluator = CocoEvaluator(base_ds, iou_types)
    # coco_evaluator.coco_eval[iou_types[0]].params.iouThrs = [0, 0.1, 0.5, 0.75]

    panoptic_evaluator = None
    if 'panoptic' in postprocessors.keys():
        panoptic_evaluator = PanopticEvaluator(
            data_loader.dataset.ann_file,
            data_loader.dataset.ann_folder,
            output_dir=os.path.join(output_dir, "panoptic_eval"),
        )

    for samples, targets in metric_logger.log_every(data_loader, 10, header):
        samples = samples.to(device)
        targets = [{k: v.to(device) for k, v in t.items()} for t in targets]

        outputs = model(samples)
        loss_dict = criterion(outputs, targets)
        weight_dict = criterion.weight_dict

        # reduce losses over all GPUs for logging purposes
        loss_dict_reduced = utils.reduce_dict(loss_dict)
        loss_dict_reduced_scaled = {k: v * weight_dict[k]
                                    for k, v in loss_dict_reduced.items() if k in weight_dict}
        loss_dict_reduced_unscaled = {f'{k}_unscaled': v
                                      for k, v in loss_dict_reduced.items()}
        metric_logger.update(loss=sum(loss_dict_reduced_scaled.values()),
                             **loss_dict_reduced_scaled,
                             **loss_dict_reduced_unscaled)
        metric_logger.update(class_error=loss_dict_reduced['class_error'])

        orig_target_sizes = torch.stack([t["orig_size"] for t in targets], dim=0)
        results = postprocessors['bbox'](outputs, orig_target_sizes)
        if 'segm' in postprocessors.keys():
            target_sizes = torch.stack([t["size"] for t in targets], dim=0)
            results = postprocessors['segm'](results, outputs, orig_target_sizes, target_sizes)
        res = {target['image_id'].item(): output for target, output in zip(targets, results)}
        if coco_evaluator is not None:
            coco_evaluator.update(res)

        if panoptic_evaluator is not None:
            res_pano = postprocessors["panoptic"](outputs, target_sizes, orig_target_sizes)
            for i, target in enumerate(targets):
                image_id = target["image_id"].item()
                file_name = f"{image_id:012d}.png"
                res_pano[i]["image_id"] = image_id
                res_pano[i]["file_name"] = file_name

            panoptic_evaluator.update(res_pano)

    # gather the stats from all processes
    metric_logger.synchronize_between_processes()
    print("Averaged stats:", metric_logger)
    if coco_evaluator is not None:
        coco_evaluator.synchronize_between_processes()
    if panoptic_evaluator is not None:
        panoptic_evaluator.synchronize_between_processes()

    # accumulate predictions from all images
    if coco_evaluator is not None:
        coco_evaluator.accumulate()
        coco_evaluator.summarize()
    panoptic_res = None
    if panoptic_evaluator is not None:
        panoptic_res = panoptic_evaluator.summarize()
    stats = {k: meter.global_avg for k, meter in metric_logger.meters.items()}
    if coco_evaluator is not None:
        if 'bbox' in postprocessors.keys():
            stats['coco_eval_bbox'] = coco_evaluator.coco_eval['bbox'].stats.tolist()
        if 'segm' in postprocessors.keys():
            stats['coco_eval_masks'] = coco_evaluator.coco_eval['segm'].stats.tolist()
    if panoptic_res is not None:
        stats['PQ_all'] = panoptic_res["All"]
        stats['PQ_th'] = panoptic_res["Things"]
        stats['PQ_st'] = panoptic_res["Stuff"]
    return stats, coco_evaluator


================================================
FILE: batchformer-v2/deformable-detr/main.py
================================================
# ------------------------------------------------------------------------
# Deformable DETR
# Copyright (c) 2020 SenseTime. All Rights Reserved.
# Licensed under the Apache License, Version 2.0 [see LICENSE for details]
# ------------------------------------------------------------------------
# Modified from DETR (https://github.com/facebookresearch/detr)
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
# ------------------------------------------------------------------------


import argparse
import datetime
import json
import random
import time
from pathlib import Path

import numpy as np
import torch
from torch.utils.data import DataLoader
import datasets
import util.misc as utils
import datasets.samplers as samplers
from datasets import build_dataset, get_coco_api_from_dataset
from engine import evaluate, train_one_epoch
from models import build_model


def get_args_parser():
    parser = argparse.ArgumentParser('Deformable DETR Detector', add_help=False)
    parser.add_argument('--lr', default=2e-4, type=float)
    parser.add_argument('--lr_backbone_names', default=["backbone.0"], type=str, nargs='+')
    parser.add_argument('--lr_backbone', default=2e-5, type=float)
    parser.add_argument('--lr_linear_proj_names', default=['reference_points', 'sampling_offsets'], type=str, nargs='+')
    parser.add_argument('--lr_linear_proj_mult', default=0.1, type=float)
    parser.add_argument('--batch_size', default=2, type=int)
    parser.add_argument('--weight_decay', default=1e-4, type=float)
    parser.add_argument('--epochs', default=50, type=int)
    parser.add_argument('--lr_drop', default=40, type=int)
    parser.add_argument('--lr_drop_epochs', default=None, type=int, nargs='+')
    parser.add_argument('--clip_max_norm', default=0.1, type=float,
                        help='gradient clipping max norm')


    parser.add_argument('--sgd', action='store_true')

    # Variants of Deformable DETR
    parser.add_argument('--with_box_refine', default=False, action='store_true')
    parser.add_argument('--two_stage', default=False, action='store_true')

    # Model parameters
    parser.add_argument('--frozen_weights', type=str, default=None,
                        help="Path to the pretrained model. If set, only the mask head will be trained")

    # * Backbone
    parser.add_argument('--backbone', default='resnet50', type=str,
                        help="Name of the convolutional backbone to use")
    parser.add_argument('--dilation', action='store_true',
                        help="If true, we replace stride with dilation in the last convolutional block (DC5)")
    parser.add_argument('--position_embedding', default='sine', type=str, choices=('sine', 'learned'),
                        help="Type of positional embedding to use on top of the image features")
    parser.add_argument('--position_embedding_scale', default=2 * np.pi, type=float,
                        help="position / size * scale")
    parser.add_argument('--num_feature_levels', default=4, type=int, help='number of feature levels')

    # * Transformer
    parser.add_argument('--enc_layers', default=6, type=int,
                        help="Number of encoding layers in the transformer")
    parser.add_argument('--dec_layers', default=6, type=int,
                        help="Number of decoding layers in the transformer")
    parser.add_argument('--dim_feedforward', default=1024, type=int,
                        help="Intermediate size of the feedforward layers in the transformer blocks")
    parser.add_argument('--hidden_dim', default=256, type=int,
                        help="Size of the embeddings (dimension of the transformer)")
    parser.add_argument('--dropout', default=0.1, type=float,
                        help="Dropout applied in the transformer")
    parser.add_argument('--nheads', default=8, type=int,
                        help="Number of attention heads inside the transformer's attentions")
    parser.add_argument('--num_queries', default=300, type=int,
                        help="Number of query slots")
    parser.add_argument('--dec_n_points', default=4, type=int)
    parser.add_argument('--enc_n_points', default=4, type=int)

    # * Segmentation
    parser.add_argument('--masks', action='store_true',
                        help="Train segmentation head if the flag is provided")

    # Loss
    parser.add_argument('--no_aux_loss', dest='aux_loss', action='store_false',
                        help="Disables auxiliary decoding losses (loss at each layer)")

    # * Matcher
    parser.add_argument('--set_cost_class', default=2, type=float,
                        help="Class coefficient in the matching cost")
    parser.add_argument('--set_cost_bbox', default=5, type=float,
                        help="L1 box coefficient in the matching cost")
    parser.add_argument('--set_cost_giou', default=2, type=float,
                        help="giou box coefficient in the matching cost")

    # * Loss coefficients
    parser.add_argument('--mask_loss_coef', default=1, type=float)
    parser.add_argument('--dice_loss_coef', default=1, type=float)
    parser.add_argument('--cls_loss_coef', default=2, type=float)
    parser.add_argument('--bbox_loss_coef', default=5, type=float)
    parser.add_argument('--giou_loss_coef', default=2, type=float)
    parser.add_argument('--focal_alpha', default=0.25, type=float)

    # dataset parameters
    parser.add_argument('--dataset_file', default='coco')
    parser.add_argument('--coco_path', default='./data/coco', type=str)
    parser.add_argument('--coco_panoptic_path', type=str)
    parser.add_argument('--remove_difficult', action='store_true')

    parser.add_argument('--output_dir', default='',
                        help='path where to save, empty for no saving')
    parser.add_argument('--device', default='cuda',
                        help='device to use for training / testing')
    parser.add_argument('--seed', default=42, type=int)
    parser.add_argument('--resume', default='', help='resume from checkpoint')
    parser.add_argument('--start_epoch', default=0, type=int, metavar='N',
                        help='start epoch')
    parser.add_argument('--eval', action='store_true')
    parser.add_argument('--num_workers', default=2, type=int)
    parser.add_argument('--bf', default=0, type=int)
    parser.add_argument('--share_bf', default=1, type=int)
    parser.add_argument('--bt_num_layers', default=1, type=int)
    parser.add_argument('--insert_idx', action='append', type=int,
                        help='insert idx list')
    parser.add_argument('--eval_bf', action='store_true', help='batch inference with batchformerv2')
    parser.add_argument('--drop_path', default=0., type=float)
    parser.add_argument('--cache_mode', default=False, action='store_true', help='whether to cache images on memory')

    return parser


def main(args):
    utils.init_distributed_mode(args)
    print("git:\n  {}\n".format(utils.get_sha()))

    if args.frozen_weights is not None:
        assert args.masks, "Frozen training is meant for segmentation only"
    print(args)

    device = torch.device(args.device)

    # fix the seed for reproducibility
    seed = args.seed + utils.get_rank()
    torch.manual_seed(seed)
    np.random.seed(seed)
    random.seed(seed)

    model, criterion, postprocessors = build_model(args)
    model.to(device)

    model_without_ddp = model
    n_parameters = sum(p.numel() for p in model.parameters() if p.requires_grad)
    print('number of params:', n_parameters)

    dataset_train = build_dataset(image_set='train', args=args)
    dataset_val = build_dataset(image_set='val', args=args)

    if args.distributed:
        if args.cache_mode:
            sampler_train = samplers.NodeDistributedSampler(dataset_train)
            sampler_val = samplers.NodeDistributedSampler(dataset_val, shuffle=False)
        else:
            sampler_train = samplers.DistributedSampler(dataset_train)
            sampler_val = samplers.DistributedSampler(dataset_val, shuffle=False)
    else:
        sampler_train = torch.utils.data.RandomSampler(dataset_train)
        sampler_val = torch.utils.data.SequentialSampler(dataset_val)

    batch_sampler_train = torch.utils.data.BatchSampler(
        sampler_train, args.batch_size, drop_last=True)

    data_loader_train = DataLoader(dataset_train, batch_sampler=batch_sampler_train,
                                   collate_fn=utils.collate_fn, num_workers=args.num_workers,
                                   pin_memory=True)
    data_loader_val = DataLoader(dataset_val, args.batch_size, sampler=sampler_val,
                                 drop_last=False, collate_fn=utils.collate_fn, num_workers=args.num_workers,
                                 pin_memory=True)

    # lr_backbone_names = ["backbone.0", "backbone.neck", "input_proj", "transformer.encoder"]
    def match_name_keywords(n, name_keywords):
        out = False
        for b in name_keywords:
            if b in n:
                out = True
                break
        return out


    param_dicts = [
        {
            "params":
                [p for n, p in model_without_ddp.named_parameters()
                 if not match_name_keywords(n, args.lr_backbone_names) and not match_name_keywords(n, args.lr_linear_proj_names) and p.requires_grad],
            "lr": args.lr,
        },
        {
            "params": [p for n, p in model_without_ddp.named_parameters() if match_name_keywords(n, args.lr_backbone_names) and p.requires_grad],
            "lr": args.lr_backbone,
        },
        {
            "params": [p for n, p in model_without_ddp.named_parameters() if match_name_keywords(n, args.lr_linear_proj_names) and p.requires_grad],
            "lr": args.lr * args.lr_linear_proj_mult,
        }
    ]
    if args.sgd:
        optimizer = torch.optim.SGD(param_dicts, lr=args.lr, momentum=0.9,
                                    weight_decay=args.weight_decay)
    else:
        optimizer = torch.optim.AdamW(param_dicts, lr=args.lr,
                                      weight_decay=args.weight_decay)
    lr_scheduler = torch.optim.lr_scheduler.StepLR(optimizer, args.lr_drop)

    if args.distributed:
        model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[args.gpu])
        model_without_ddp = model.module

    if args.dataset_file == "coco_panoptic":
        # We also evaluate AP during panoptic training, on original coco DS
        coco_val = datasets.coco.build("val", args)
        base_ds = get_coco_api_from_dataset(coco_val)
    else:
        base_ds = get_coco_api_from_dataset(dataset_val)

    if args.frozen_weights is not None:
        checkpoint = torch.load(args.frozen_weights, map_location='cpu')
        model_without_ddp.detr.load_state_dict(checkpoint['model'])

    output_dir = Path(args.output_dir)
    if args.resume:
        if args.resume.startswith('https'):
            checkpoint = torch.hub.load_state_dict_from_url(
                args.resume, map_location='cpu', check_hash=True)
        else:
            checkpoint = torch.load(args.resume, map_location='cpu')
        missing_keys, unexpected_keys = model_without_ddp.load_state_dict(checkpoint['model'], strict=False)
        unexpected_keys = [k for k in unexpected_keys if not (k.endswith('total_params') or k.endswith('total_ops'))]
        if len(missing_keys) > 0:
            print('Missing Keys: {}'.format(missing_keys))
        if len(unexpected_keys) > 0:
            print('Unexpected Keys: {}'.format(unexpected_keys))
        if not args.eval and 'optimizer' in checkpoint and 'lr_scheduler' in checkpoint and 'epoch' in checkpoint:
            import copy
            p_groups = copy.deepcopy(optimizer.param_groups)
            optimizer.load_state_dict(checkpoint['optimizer'])
            for pg, pg_old in zip(optimizer.param_groups, p_groups):
                pg['lr'] = pg_old['lr']
                pg['initial_lr'] = pg_old['initial_lr']
            print(optimizer.param_groups)
            lr_scheduler.load_state_dict(checkpoint['lr_scheduler'])
            # todo: this is a hack for doing experiment that resume from checkpoint and also modify lr scheduler (e.g., decrease lr in advance).
            args.override_resumed_lr_drop = True
            if args.override_resumed_lr_drop:
                print('Warning: (hack) args.override_resumed_lr_drop is set to True, so args.lr_drop would override lr_drop in resumed lr_scheduler.')
                lr_scheduler.step_size = args.lr_drop
                lr_scheduler.base_lrs = list(map(lambda group: group['initial_lr'], optimizer.param_groups))
            lr_scheduler.step(lr_scheduler.last_epoch)
            args.start_epoch = checkpoint['epoch'] + 1
        # check the resumed model
        if not args.eval:
            test_stats, coco_evaluator = evaluate(
                model, criterion, postprocessors, data_loader_val, base_ds, device, args.output_dir
            )
    
    if args.eval:
        test_stats, coco_evaluator = evaluate(model, criterion, postprocessors,
                                              data_loader_val, base_ds, device, args.output_dir)
        if args.output_dir:
            utils.save_on_master(coco_evaluator.coco_eval["bbox"].eval, output_dir / "eval.pth")
        return

    print("Start training")
    start_time = time.time()
    for epoch in range(args.start_epoch, args.epochs):
        if args.distributed:
            sampler_train.set_epoch(epoch)
        train_stats = train_one_epoch(
            model, criterion, data_loader_train, optimizer, device, epoch, args.clip_max_norm)
        lr_scheduler.step()
        if args.output_dir:
            checkpoint_paths = [output_dir / 'checkpoint.pth']
            # extra checkpoint before LR drop and every 5 epochs
            if (epoch + 1) % args.lr_drop == 0 or (epoch + 1) % 5 == 0:
                checkpoint_paths.append(output_dir / f'checkpoint{epoch:04}.pth')
            for checkpoint_path in checkpoint_paths:
                utils.save_on_master({
                    'model': model_without_ddp.state_dict(),
                    'optimizer': optimizer.state_dict(),
                    'lr_scheduler': lr_scheduler.state_dict(),
                    'epoch': epoch,
                    'args': args,
                }, checkpoint_path)

        test_stats, coco_evaluator = evaluate(
            model, criterion, postprocessors, data_loader_val, base_ds, device, args.output_dir
        )

        log_stats = {**{f'train_{k}': v for k, v in train_stats.items()},
                     **{f'test_{k}': v for k, v in test_stats.items()},
                     'epoch': epoch,
                     'n_parameters': n_parameters}

        if args.output_dir and utils.is_main_process():
            with (output_dir / "log.txt").open("a") as f:
                f.write(json.dumps(log_stats) + "\n")

            # for evaluation logs
            if coco_evaluator is not None:
                (output_dir / 'eval').mkdir(exist_ok=True)
                if "bbox" in coco_evaluator.coco_eval:
                    filenames = ['latest.pth']
                    if epoch % 50 == 0:
                        filenames.append(f'{epoch:03}.pth')
                    for name in filenames:
                        torch.save(coco_evaluator.coco_eval["bbox"].eval,
                                   output_dir / "eval" / name)

    total_time = time.time() - start_time
    total_time_str = str(datetime.timedelta(seconds=int(total_time)))
    print('Training time {}'.format(total_time_str))


if __name__ == '__main__':
    parser = argparse.ArgumentParser('Deformable DETR training and evaluation script', parents=[get_args_parser()])
    args = parser.parse_args()
    if args.output_dir:
        Path(args.output_dir).mkdir(parents=True, exist_ok=True)
    main(args)


================================================
FILE: batchformer-v2/deformable-detr/models/__init__.py
================================================
# ------------------------------------------------------------------------
# Deformable DETR
# Copyright (c) 2020 SenseTime. All Rights Reserved.
# Licensed under the Apache License, Version 2.0 [see LICENSE for details]
# ------------------------------------------------------------------------
# Modified from DETR (https://github.com/facebookresearch/detr)
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
# ------------------------------------------------------------------------

from .deformable_detr import build


def build_model(args):
    return build(args)



================================================
FILE: batchformer-v2/deformable-detr/models/backbone.py
================================================
# ------------------------------------------------------------------------
# Deformable DETR
# Copyright (c) 2020 SenseTime. All Rights Reserved.
# Licensed under the Apache License, Version 2.0 [see LICENSE for details]
# ------------------------------------------------------------------------
# Modified from DETR (https://github.com/facebookresearch/detr)
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
# ------------------------------------------------------------------------

"""
Backbone modules.
"""
from collections import OrderedDict

import torch
import torch.nn.functional as F
import torchvision
from torch import nn
from torchvision.models._utils import IntermediateLayerGetter
from typing import Dict, List

from util.misc import NestedTensor, is_main_process

from .position_encoding import build_position_encoding


class FrozenBatchNorm2d(torch.nn.Module):
    """
    BatchNorm2d where the batch statistics and the affine parameters are fixed.

    Copy-paste from torchvision.misc.ops with added eps before rqsrt,
    without which any other models than torchvision.models.resnet[18,34,50,101]
    produce nans.
    """

    def __init__(self, n, eps=1e-5):
        super(FrozenBatchNorm2d, self).__init__()
        self.register_buffer("weight", torch.ones(n))
        self.register_buffer("bias", torch.zeros(n))
        self.register_buffer("running_mean", torch.zeros(n))
        self.register_buffer("running_var", torch.ones(n))
        self.eps = eps

    def _load_from_state_dict(self, state_dict, prefix, local_metadata, strict,
                              missing_keys, unexpected_keys, error_msgs):
        num_batches_tracked_key = prefix + 'num_batches_tracked'
        if num_batches_tracked_key in state_dict:
            del state_dict[num_batches_tracked_key]

        super(FrozenBatchNorm2d, self)._load_from_state_dict(
            state_dict, prefix, local_metadata, strict,
            missing_keys, unexpected_keys, error_msgs)

    def forward(self, x):
        # move reshapes to the beginning
        # to make it fuser-friendly
        w = self.weight.reshape(1, -1, 1, 1)
        b = self.bias.reshape(1, -1, 1, 1)
        rv = self.running_var.reshape(1, -1, 1, 1)
        rm = self.running_mean.reshape(1, -1, 1, 1)
        eps = self.eps
        scale = w * (rv + eps).rsqrt()
        bias = b - rm * scale
        return x * scale + bias


class BackboneBase(nn.Module):

    def __init__(self, backbone: nn.Module, train_backbone: bool, return_interm_layers: bool):
        super().__init__()
        for name, parameter in backbone.named_parameters():
            if not train_backbone or 'layer2' not in name and 'layer3' not in name and 'layer4' not in name:
                parameter.requires_grad_(False)
        if return_interm_layers:
            # return_layers = {"layer1": "0", "layer2": "1", "layer3": "2", "layer4": "3"}
            return_layers = {"layer2": "0", "layer3": "1", "layer4": "2"}
            self.strides = [8, 16, 32]
            self.num_channels = [512, 1024, 2048]
        else:
            return_layers = {'layer4': "0"}
            self.strides = [32]
            self.num_channels = [2048]
        self.body = IntermediateLayerGetter(backbone, return_layers=return_layers)

    def forward(self, tensor_list: NestedTensor):
        xs = self.body(tensor_list.tensors)
        out: Dict[str, NestedTensor] = {}
        for name, x in xs.items():
            m = tensor_list.mask
            assert m is not None
            mask = F.interpolate(m[None].float(), size=x.shape[-2:]).to(torch.bool)[0]
            out[name] = NestedTensor(x, mask)
        return out


class Backbone(BackboneBase):
    """ResNet backbone with frozen BatchNorm."""
    def __init__(self, name: str,
                 train_backbone: bool,
                 return_interm_layers: bool,
                 dilation: bool):
        norm_layer = FrozenBatchNorm2d
        backbone = getattr(torchvision.models, name)(
            replace_stride_with_dilation=[False, False, dilation],
            pretrained=is_main_process(), norm_layer=norm_layer)
        assert name not in ('resnet18', 'resnet34'), "number of channels are hard coded"
        super().__init__(backbone, train_backbone, return_interm_layers)
        if dilation:
            self.strides[-1] = self.strides[-1] // 2


class Joiner(nn.Sequential):
    def __init__(self, backbone, position_embedding):
        super().__init__(backbone, position_embedding)
        self.strides = backbone.strides
        self.num_channels = backbone.num_channels

    def forward(self, tensor_list: NestedTensor):
        xs = self[0](tensor_list)
        out: List[NestedTensor] = []
        pos = []
        for name, x in sorted(xs.items()):
            out.append(x)

        # position encoding
        for x in out:
            pos.append(self[1](x).to(x.tensors.dtype))

        return out, pos


def build_backbone(args):
    position_embedding = build_position_encoding(args)
    train_backbone = args.lr_backbone > 0
    return_interm_layers = args.masks or (args.num_feature_levels > 1)
    backbone = Backbone(args.backbone, train_backbone, return_interm_layers, args.dilation)
    model = Joiner(backbone, position_embedding)
    return model


================================================
FILE: batchformer-v2/deformable-detr/models/deformable_detr.py
================================================
# ------------------------------------------------------------------------
# Deformable DETR
# Copyright (c) 2020 SenseTime. All Rights Reserved.
# Licensed under the Apache License, Version 2.0 [see LICENSE for details]
# ------------------------------------------------------------------------
# Modified from DETR (https://github.com/facebookresearch/detr)
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
# ------------------------------------------------------------------------

"""
Deformable DETR model and criterion classes.
"""
import torch
import torch.nn.functional as F
from torch import nn
import math

from util import box_ops
from util.misc import (NestedTensor, nested_tensor_from_tensor_list,
                       accuracy, get_world_size, interpolate,
                       is_dist_avail_and_initialized, inverse_sigmoid)

from .backbone import build_backbone
from .matcher import build_matcher
from .segmentation import (DETRsegm, PostProcessPanoptic, PostProcessSegm,
                           dice_loss, sigmoid_focal_loss)
from .deformable_transformer import build_deforamble_transformer
import copy


def _get_clones(module, N):
    return nn.ModuleList([copy.deepcopy(module) for i in range(N)])


class DeformableDETR(nn.Module):
    """ This is the Deformable DETR module that performs object detection """
    def __init__(self, backbone, transformer, num_classes, num_queries, num_feature_levels,
                 aux_loss=True, with_box_refine=False, two_stage=False):
        """ Initializes the model.
        Parameters:
            backbone: torch module of the backbone to be used. See backbone.py
            transformer: torch module of the transformer architecture. See transformer.py
            num_classes: number of object classes
            num_queries: number of object queries, ie detection slot. This is the maximal number of objects
                         DETR can detect in a single image. For COCO, we recommend 100 queries.
            aux_loss: True if auxiliary decoding losses (loss at each decoder layer) are to be used.
            with_box_refine: iterative bounding box refinement
            two_stage: two-stage Deformable DETR
        """
        super().__init__()
        self.num_queries = num_queries
        self.transformer = transformer
        hidden_dim = transformer.d_model
        self.class_embed = nn.Linear(hidden_dim, num_classes)
        self.bbox_embed = MLP(hidden_dim, hidden_dim, 4, 3)
        self.num_feature_levels = num_feature_levels
        if not two_stage:
            self.query_embed = nn.Embedding(num_queries, hidden_dim*2)
        if num_feature_levels > 1:
            num_backbone_outs = len(backbone.strides)
            input_proj_list = []
            for _ in range(num_backbone_outs):
                in_channels = backbone.num_channels[_]
                input_proj_list.append(nn.Sequential(
                    nn.Conv2d(in_channels, hidden_dim, kernel_size=1),
                    nn.GroupNorm(32, hidden_dim),
                ))
            for _ in range(num_feature_levels - num_backbone_outs):
                input_proj_list.append(nn.Sequential(
                    nn.Conv2d(in_channels, hidden_dim, kernel_size=3, stride=2, padding=1),
                    nn.GroupNorm(32, hidden_dim),
                ))
                in_channels = hidden_dim
            self.input_proj = nn.ModuleList(input_proj_list)
        else:
            self.input_proj = nn.ModuleList([
                nn.Sequential(
                    nn.Conv2d(backbone.num_channels[0], hidden_dim, kernel_size=1),
                    nn.GroupNorm(32, hidden_dim),
                )])
        self.backbone = backbone
        self.aux_loss = aux_loss
        self.with_box_refine = with_box_refine
        self.two_stage = two_stage

        prior_prob = 0.01
        bias_value = -math.log((1 - prior_prob) / prior_prob)
        self.class_embed.bias.data = torch.ones(num_classes) * bias_value
        nn.init.constant_(self.bbox_embed.layers[-1].weight.data, 0)
        nn.init.constant_(self.bbox_embed.layers[-1].bias.data, 0)
        for proj in self.input_proj:
            nn.init.xavier_uniform_(proj[0].weight, gain=1)
            nn.init.constant_(proj[0].bias, 0)

        # if two-stage, the last class_embed and bbox_embed is for region proposal generation
        num_pred = (transformer.decoder.num_layers + 1) if two_stage else transformer.decoder.num_layers
        if with_box_refine:
            self.class_embed = _get_clones(self.class_embed, num_pred)
            self.bbox_embed = _get_clones(self.bbox_embed, num_pred)
            nn.init.constant_(self.bbox_embed[0].layers[-1].bias.data[2:], -2.0)
            # hack implementation for iterative bounding box refinement
            self.transformer.decoder.bbox_embed = self.bbox_embed
        else:
            nn.init.constant_(self.bbox_embed.layers[-1].bias.data[2:], -2.0)
            self.class_embed = nn.ModuleList([self.class_embed for _ in range(num_pred)])
            self.bbox_embed = nn.ModuleList([self.bbox_embed for _ in range(num_pred)])
            self.transformer.decoder.bbox_embed = None
        if two_stage:
            # hack implementation for two-stage
            self.transformer.decoder.class_embed = self.class_embed
            for box_embed in self.bbox_embed:
                nn.init.constant_(box_embed.layers[-1].bias.data[2:], 0.0)

    def forward(self, samples: NestedTensor):
        """ The forward expects a NestedTensor, which consists of:
               - samples.tensor: batched images, of shape [batch_size x 3 x H x W]
               - samples.mask: a binary mask of shape [batch_size x H x W], containing 1 on padded pixels

            It returns a dict with the following elements:
               - "pred_logits": the classification logits (including no-object) for all queries.
                                Shape= [batch_size x num_queries x (num_classes + 1)]
               - "pred_boxes": The normalized boxes coordinates for all queries, represented as
                               (center_x, center_y, height, width). These values are normalized in [0, 1],
                               relative to the size of each individual image (disregarding possible padding).
                               See PostProcess for information on how to retrieve the unnormalized bounding box.
               - "aux_outputs": Optional, only returned when auxilary losses are activated. It is a list of
                                dictionnaries containing the two above keys for each decoder layer.
        """
        if not isinstance(samples, NestedTensor):
            samples = nested_tensor_from_tensor_list(samples)
        features, pos = self.backbone(samples)

        srcs = []
        masks = []
        for l, feat in enumerate(features):
            src, mask = feat.decompose()
            srcs.append(self.input_proj[l](src))
            masks.append(mask)
            assert mask is not None
        if self.num_feature_levels > len(srcs):
            _len_srcs = len(srcs)
            for l in range(_len_srcs, self.num_feature_levels):
                if l == _len_srcs:
                    src = self.input_proj[l](features[-1].tensors)
                else:
                    src = self.input_proj[l](srcs[-1])
                m = samples.mask
                mask = F.interpolate(m[None].float(), size=src.shape[-2:]).to(torch.bool)[0]
                pos_l = self.backbone[1](NestedTensor(src, mask)).to(src.dtype)
                srcs.append(src)
                masks.append(mask)
                pos.append(pos_l)

        query_embeds = None
        if not self.two_stage:
            query_embeds = self.query_embed.weight
        hs, init_reference, inter_references, enc_outputs_class, enc_outputs_coord_unact = self.transformer(srcs, masks, pos, query_embeds)

        outputs_classes = []
        outputs_coords = []
        for lvl in range(hs.shape[0]):
            if lvl == 0:
                reference = init_reference
            else:
                reference = inter_references[lvl - 1]
            reference = inverse_sigmoid(reference)
            outputs_class = self.class_embed[lvl](hs[lvl])
            tmp = self.bbox_embed[lvl](hs[lvl])
            if reference.shape[-1] == 4:
                tmp += reference
            else:
                assert reference.shape[-1] == 2
                tmp[..., :2] += reference
            outputs_coord = tmp.sigmoid()
            outputs_classes.append(outputs_class)
            outputs_coords.append(outputs_coord)
        outputs_class = torch.stack(outputs_classes)
        outputs_coord = torch.stack(outputs_coords)

        out = {'pred_logits': outputs_class[-1], 'pred_boxes': outputs_coord[-1]}
        if self.aux_loss:
            out['aux_outputs'] = self._set_aux_loss(outputs_class, outputs_coord)

        if self.two_stage:
            enc_outputs_coord = enc_outputs_coord_unact.sigmoid()
            out['enc_outputs'] = {'pred_logits': enc_outputs_class, 'pred_boxes': enc_outputs_coord}
        return out

    @torch.jit.unused
    def _set_aux_loss(self, outputs_class, outputs_coord):
        # this is a workaround to make torchscript happy, as torchscript
        # doesn't support dictionary with non-homogeneous values, such
        # as a dict having both a Tensor and a list.
        return [{'pred_logits': a, 'pred_boxes': b}
                for a, b in zip(outputs_class[:-1], outputs_coord[:-1])]


class SetCriterion(nn.Module):
    """ This class computes the loss for DETR.
    The process happens in two steps:
        1) we compute hungarian assignment between ground truth boxes and the outputs of the model
        2) we supervise each pair of matched ground-truth / prediction (supervise class and box)
    """
    def __init__(self, num_classes, matcher, weight_dict, losses, focal_alpha=0.25):
        """ Create the criterion.
        Parameters:
            num_classes: number of object categories, omitting the special no-object category
            matcher: module able to compute a matching between targets and proposals
            weight_dict: dict containing as key the names of the losses and as values their relative weight.
            losses: list of all the losses to be applied. See get_loss for list of available losses.
            focal_alpha: alpha in Focal Loss
        """
        super().__init__()
        self.num_classes = num_classes
        self.matcher = matcher
        self.weight_dict = weight_dict
        self.losses = losses
        self.focal_alpha = focal_alpha

    def loss_labels(self, outputs, targets, indices, num_boxes, log=True):
        """Classification loss (NLL)
        targets dicts must contain the key "labels" containing a tensor of dim [nb_target_boxes]
        """
        assert 'pred_logits' in outputs
        src_logits = outputs['pred_logits']

        idx = self._get_src_permutation_idx(indices)
        target_classes_o = torch.cat([t["labels"][J] for t, (_, J) in zip(targets, indices)])
        target_classes = torch.full(src_logits.shape[:2], self.num_classes,
                                    dtype=torch.int64, device=src_logits.device)
        target_classes[idx] = target_classes_o

        target_classes_onehot = torch.zeros([src_logits.shape[0], src_logits.shape[1], src_logits.shape[2] + 1],
                                            dtype=src_logits.dtype, layout=src_logits.layout, device=src_logits.device)
        target_classes_onehot.scatter_(2, target_classes.unsqueeze(-1), 1)

        target_classes_onehot = target_classes_onehot[:,:,:-1]
        loss_ce = sigmoid_focal_loss(src_logits, target_classes_onehot, num_boxes, alpha=self.focal_alpha, gamma=2) * src_logits.shape[1]
        losses = {'loss_ce': loss_ce}

        if log:
            # TODO this should probably be a separate loss, not hacked in this one here
            losses['class_error'] = 100 - accuracy(src_logits[idx], target_classes_o)[0]
        return losses

    @torch.no_grad()
    def loss_cardinality(self, outputs, targets, indices, num_boxes):
        """ Compute the cardinality error, ie the absolute error in the number of predicted non-empty boxes
        This is not really a loss, it is intended for logging purposes only. It doesn't propagate gradients
        """
        pred_logits = outputs['pred_logits']
        device = pred_logits.device
        tgt_lengths = torch.as_tensor([len(v["labels"]) for v in targets], device=device)
        # Count the number of predictions that are NOT "no-object" (which is the last class)
        card_pred = (pred_logits.argmax(-1) != pred_logits.shape[-1] - 1).sum(1)
        card_err = F.l1_loss(card_pred.float(), tgt_lengths.float())
        losses = {'cardinality_error': card_err}
        return losses

    def loss_boxes(self, outputs, targets, indices, num_boxes):
        """Compute the losses related to the bounding boxes, the L1 regression loss and the GIoU loss
           targets dicts must contain the key "boxes" containing a tensor of dim [nb_target_boxes, 4]
           The target boxes are expected in format (center_x, center_y, h, w), normalized by the image size.
        """
        assert 'pred_boxes' in outputs
        idx = self._get_src_permutation_idx(indices)
        src_boxes = outputs['pred_boxes'][idx]
        target_boxes = torch.cat([t['boxes'][i] for t, (_, i) in zip(targets, indices)], dim=0)

        loss_bbox = F.l1_loss(src_boxes, target_boxes, reduction='none')

        losses = {}
        losses['loss_bbox'] = loss_bbox.sum() / num_boxes

        loss_giou = 1 - torch.diag(box_ops.generalized_box_iou(
            box_ops.box_cxcywh_to_xyxy(src_boxes),
            box_ops.box_cxcywh_to_xyxy(target_boxes)))
        losses['loss_giou'] = loss_giou.sum() / num_boxes
        return losses

    def loss_masks(self, outputs, targets, indices, num_boxes):
        """Compute the losses related to the masks: the focal loss and the dice loss.
           targets dicts must contain the key "masks" containing a tensor of dim [nb_target_boxes, h, w]
        """
        assert "pred_masks" in outputs

        src_idx = self._get_src_permutation_idx(indices)
        tgt_idx = self._get_tgt_permutation_idx(indices)

        src_masks = outputs["pred_masks"]

        # TODO use valid to mask invalid areas due to padding in loss
        target_masks, valid = nested_tensor_from_tensor_list([t["masks"] for t in targets]).decompose()
        target_masks = target_masks.to(src_masks)

        src_masks = src_masks[src_idx]
        # upsample predictions to the target size
        src_masks = interpolate(src_masks[:, None], size=target_masks.shape[-2:],
                                mode="bilinear", align_corners=False)
        src_masks = src_masks[:, 0].flatten(1)

        target_masks = target_masks[tgt_idx].flatten(1)

        losses = {
            "loss_mask": sigmoid_focal_loss(src_masks, target_masks, num_boxes),
            "loss_dice": dice_loss(src_masks, target_masks, num_boxes),
        }
        return losses

    def _get_src_permutation_idx(self, indices):
        # permute predictions following indices
        batch_idx = torch.cat([torch.full_like(src, i) for i, (src, _) in enumerate(indices)])
        src_idx = torch.cat([src for (src, _) in indices])
        return batch_idx, src_idx

    def _get_tgt_permutation_idx(self, indices):
        # permute targets following indices
        batch_idx = torch.cat([torch.full_like(tgt, i) for i, (_, tgt) in enumerate(indices)])
        tgt_idx = torch.cat([tgt for (_, tgt) in indices])
        return batch_idx, tgt_idx

    def get_loss(self, loss, outputs, targets, indices, num_boxes, **kwargs):
        loss_map = {
            'labels': self.loss_labels,
            'cardinality': self.loss_cardinality,
            'boxes': self.loss_boxes,
            'masks': self.loss_masks
        }
        assert loss in loss_map, f'do you really want to compute {loss} loss?'
        return loss_map[loss](outputs, targets, indices, num_boxes, **kwargs)

    def forward(self, outputs, targets):
        """ This performs the loss computation.
        Parameters:
             outputs: dict of tensors, see the output specification of the model for the format
             targets: list of dicts, such that len(targets) == batch_size.
                      The expected keys in each dict depends on the losses applied, see each loss' doc
        """
        outputs_without_aux = {k: v for k, v in outputs.items() if k != 'aux_outputs' and k != 'enc_outputs'}

        # Retrieve the matching between the outputs of the last layer and the targets
        indices = self.matcher(outputs_without_aux, targets)

        # Compute the average number of target boxes accross all nodes, for normalization purposes
        num_boxes = sum(len(t["labels"]) for t in targets)
        num_boxes = torch.as_tensor([num_boxes], dtype=torch.float, device=next(iter(outputs.values())).device)
        if is_dist_avail_and_initialized():
            torch.distributed.all_reduce(num_boxes)
        num_boxes = torch.clamp(num_boxes / get_world_size(), min=1).item()

        # Compute all the requested losses
        losses = {}
        for loss in self.losses:
            kwargs = {}
            losses.update(self.get_loss(loss, outputs, targets, indices, num_boxes, **kwargs))

        # In case of auxiliary losses, we repeat this process with the output of each intermediate layer.
        if 'aux_outputs' in outputs:
            for i, aux_outputs in enumerate(outputs['aux_outputs']):
                indices = self.matcher(aux_outputs, targets)
                for loss in self.losses:
                    if loss == 'masks':
                        # Intermediate masks losses are too costly to compute, we ignore them.
                        continue
                    kwargs = {}
                    if loss == 'labels':
                        # Logging is enabled only for the last layer
                        kwargs['log'] = False
                    l_dict = self.get_loss(loss, aux_outputs, targets, indices, num_boxes, **kwargs)
                    l_dict = {k + f'_{i}': v for k, v in l_dict.items()}
                    losses.update(l_dict)

        if 'enc_outputs' in outputs:
            enc_outputs = outputs['enc_outputs']
            bin_targets = copy.deepcopy(targets)
            for bt in bin_targets:
                bt['labels'] = torch.zeros_like(bt['labels'])
            indices = self.matcher(enc_outputs, bin_targets)
            for loss in self.losses:
                if loss == 'masks':
                    # Intermediate masks losses are too costly to compute, we ignore them.
                    continue
                kwargs = {}
                if loss == 'labels':
                    # Logging is enabled only for the last layer
                    kwargs['log'] = False
                l_dict = self.get_loss(loss, enc_outputs, bin_targets, indices, num_boxes, **kwargs)
                l_dict = {k + f'_enc': v for k, v in l_dict.items()}
                losses.update(l_dict)

        return losses


class PostProcess(nn.Module):
    """ This module converts the model's output into the format expected by the coco api"""

    @torch.no_grad()
    def forward(self, outputs, target_sizes):
        """ Perform the computation
        Parameters:
            outputs: raw outputs of the model
            target_sizes: tensor of dimension [batch_size x 2] containing the size of each images of the batch
                          For evaluation, this must be the original image size (before any data augmentation)
                          For visualization, this should be the image size after data augment, but before padding
        """
        out_logits, out_bbox = outputs['pred_logits'], outputs['pred_boxes']

        assert len(out_logits) == len(target_sizes)
        assert target_sizes.shape[1] == 2

        prob = out_logits.sigmoid()
        topk_values, topk_indexes = torch.topk(prob.view(out_logits.shape[0], -1), 100, dim=1)
        scores = topk_values
        topk_boxes = topk_indexes // out_logits.shape[2]
        labels = topk_indexes % out_logits.shape[2]
        boxes = box_ops.box_cxcywh_to_xyxy(out_bbox)
        boxes = torch.gather(boxes, 1, topk_boxes.unsqueeze(-1).repeat(1,1,4))

        # and from relative [0, 1] to absolute [0, height] coordinates
        img_h, img_w = target_sizes.unbind(1)
        scale_fct = torch.stack([img_w, img_h, img_w, img_h], dim=1)
        boxes = boxes * scale_fct[:, None, :]

        results = [{'scores': s, 'labels': l, 'boxes': b} for s, l, b in zip(scores, labels, boxes)]

        return results


class MLP(nn.Module):
    """ Very simple multi-layer perceptron (also called FFN)"""

    def __init__(self, input_dim, hidden_dim, output_dim, num_layers):
        super().__init__()
        self.num_layers = num_layers
        h = [hidden_dim] * (num_layers - 1)
        self.layers = nn.ModuleList(nn.Linear(n, k) for n, k in zip([input_dim] + h, h + [output_dim]))

    def forward(self, x):
        for i, layer in enumerate(self.layers):
            x = F.relu(layer(x)) if i < self.num_layers - 1 else layer(x)
        return x


def build(args):
    num_classes = 20 if args.dataset_file != 'coco' else 91
    if args.dataset_file == "coco_panoptic":
        num_classes = 250
    device = torch.device(args.device)

    backbone = build_backbone(args)

    transformer = build_deforamble_transformer(args)
    model = DeformableDETR(
        backbone,
        transformer,
        num_classes=num_classes,
        num_queries=args.num_queries,
        num_feature_levels=args.num_feature_levels,
        aux_loss=args.aux_loss,
        with_box_refine=args.with_box_refine,
        two_stage=args.two_stage,
    )
    if args.masks:
        model = DETRsegm(model, freeze_detr=(args.frozen_weights is not None))
    matcher = build_matcher(args)
    weight_dict = {'loss_ce': args.cls_loss_coef, 'loss_bbox': args.bbox_loss_coef}
    weight_dict['loss_giou'] = args.giou_loss_coef
    if args.masks:
        weight_dict["loss_mask"] = args.mask_loss_coef
        weight_dict["loss_dice"] = args.dice_loss_coef
    # TODO this is a hack
    if args.aux_loss:
        aux_weight_dict = {}
        for i in range(args.dec_layers - 1):
            aux_weight_dict.update({k + f'_{i}': v for k, v in weight_dict.items()})
        aux_weight_dict.update({k + f'_enc': v for k, v in weight_dict.items()})
        weight_dict.update(aux_weight_dict)

    losses = ['labels', 'boxes', 'cardinality']
    if args.masks:
        losses += ["masks"]
    # num_classes, matcher, weight_dict, losses, focal_alpha=0.25
    criterion = SetCriterion(num_classes, matcher, weight_dict, losses, focal_alpha=args.focal_alpha)
    criterion.to(device)
    postprocessors = {'bbox': PostProcess()}
    if args.masks:
        postprocessors['segm'] = PostProcessSegm()
        if args.dataset_file == "coco_panoptic":
            is_thing_map = {i: i <= 90 for i in range(201)}
            postprocessors["panoptic"] = PostProcessPanoptic(is_thing_map, threshold=0.85)

    return model, criterion, postprocessors


================================================
FILE: batchformer-v2/deformable-detr/models/deformable_transformer.py
================================================

import copy
from typing import Optional, List
import math

import torch
import torch.nn.functional as F
from torch import nn, Tensor
from torch.nn.init import xavier_uniform_, constant_, uniform_, normal_

from util.misc import inverse_sigmoid
from models.ops.modules import MSDeformAttn


class DeformableTransformer(nn.Module):
    def __init__(self, d_model=256, nhead=8,
                 num_encoder_layers=6, num_decoder_layers=6, dim_feedforward=1024, dropout=0.1,
                 activation="relu", return_intermediate_dec=False,
                 num_feature_levels=4, dec_n_points=4,  enc_n_points=4,
                 two_stage=False, two_stage_num_proposals=300, args=None):
        super().__init__()
        assert args is not None

        self.d_model = d_model
        self.nhead = nhead
        self.two_stage = two_stage
        self.two_stage_num_proposals = two_stage_num_proposals

        encoder_layer = DeformableTransformerEncoderLayer(d_model, dim_feedforward,
                                                          dropout, activation,
                                                          num_feature_levels, nhead, enc_n_points)
        self.bf = None
        insert_idx = []
        if args is not None and args.bf:
            def generate_bf(type, args):
                if type == 1:
                    encoder = torch.nn.TransformerEncoderLayer(d_model, 4, d_model, dropout=0.5)
                elif type >= 2:
                    encoder = torch.nn.TransformerEncoder(torch.nn.TransformerEncoderLayer(d_model, 4, d_model, dropout=0.5), type)
                else:
                    encoder = torch.nn.TransformerEncoderLayer(d_model, 4, d_model, dropout=0.5)
                return encoder
            self.bf = generate_bf(args.bt_num_layers, args)
            insert_idx = args.insert_idx
            if not args.share_bf:
                self.bf = torch.nn.ModuleList([generate_bf(args.bt_num_layers, args) if i in insert_idx else torch.nn.Identity() for i in range(0, num_encoder_layers)])
        self.encoder = DeformableTransformerEncoder(encoder_layer, num_encoder_layers, bf=self.bf, bf_idx = args.bf, insert_idx=insert_idx,
                                                    eval_bf=args.eval_bf)

        decoder_layer = DeformableTransformerDecoderLayer(d_model, dim_feedforward,
                                                          dropout, activation,
                                                          num_feature_levels, nhead, dec_n_points)
        self.decoder = DeformableTransformerDecoder(decoder_layer, num_decoder_layers, return_intermediate_dec)

        self.level_embed = nn.Parameter(torch.Tensor(num_feature_levels, d_model))

        if two_stage:
            self.enc_output = nn.Linear(d_model, d_model)
            self.enc_output_norm = nn.LayerNorm(d_model)
            self.pos_trans = nn.Linear(d_model * 2, d_model * 2)
            self.pos_trans_norm = nn.LayerNorm(d_model * 2)
        else:
            self.reference_points = nn.Linear(d_model, 2)

        self._reset_parameters()

    def _reset_parameters(self):
        for p in self.parameters():
            if p.dim() > 1:
                nn.init.xavier_uniform_(p)
        for m in self.modules():
            if isinstance(m, MSDeformAttn):
                m._reset_parameters()
        if not self.two_stage:
            xavier_uniform_(self.reference_points.weight.data, gain=1.0)
            constant_(self.reference_points.bias.data, 0.)
        normal_(self.level_embed)

    def get_proposal_pos_embed(self, proposals):
        num_pos_feats = 128
        temperature = 10000
        scale = 2 * math.pi

        dim_t = torch.arange(num_pos_feats, dtype=torch.float32, device=proposals.device)
        dim_t = temperature ** (2 * (dim_t // 2) / num_pos_feats)
        # N, L, 4
        proposals = proposals.sigmoid() * scale
        # N, L, 4, 128
        pos = proposals[:, :, :, None] / dim_t
        # N, L, 4, 64, 2
        pos = torch.stack((pos[:, :, :, 0::2].sin(), pos[:, :, :, 1::2].cos()), dim=4).flatten(2)
        return pos

    def gen_encoder_output_proposals(self, memory, memory_padding_mask, spatial_shapes):
        N_, S_, C_ = memory.shape
        base_scale = 4.0
        proposals = []
        _cur = 0
        for lvl, (H_, W_) in enumerate(spatial_shapes):
            mask_flatten_ = memory_padding_mask[:, _cur:(_cur + H_ * W_)].view(N_, H_, W_, 1)
            valid_H = torch.sum(~mask_flatten_[:, :, 0, 0], 1)
            valid_W = torch.sum(~mask_flatten_[:, 0, :, 0], 1)

            grid_y, grid_x = torch.meshgrid(torch.linspace(0, H_ - 1, H_, dtype=torch.float32, device=memory.device),
                                            torch.linspace(0, W_ - 1, W_, dtype=torch.float32, device=memory.device))
            grid = torch.cat([grid_x.unsqueeze(-1), grid_y.unsqueeze(-1)], -1)

            scale = torch.cat([valid_W.unsqueeze(-1), valid_H.unsqueeze(-1)], 1).view(N_, 1, 1, 2)
            grid = (grid.unsqueeze(0).expand(N_, -1, -1, -1) + 0.5) / scale
            wh = torch.ones_like(grid) * 0.05 * (2.0 ** lvl)
            proposal = torch.cat((grid, wh), -1).view(N_, -1, 4)
            proposals.append(proposal)
            _cur += (H_ * W_)
        output_proposals = torch.cat(proposals, 1)
        output_proposals_valid = ((output_proposals > 0.01) & (output_proposals < 0.99)).all(-1, keepdim=True)
        output_proposals = torch.log(output_proposals / (1 - output_proposals))
        output_proposals = output_proposals.masked_fill(memory_padding_mask.unsqueeze(-1), float('inf'))
        output_proposals = output_proposals.masked_fill(~output_proposals_valid, float('inf'))

        output_memory = memory
        output_memory = output_memory.masked_fill(memory_padding_mask.unsqueeze(-1), float(0))
        output_memory = output_memory.masked_fill(~output_proposals_valid, float(0))
        output_memory = self.enc_output_norm(self.enc_output(output_memory))
        return output_memory, output_proposals

    def get_valid_ratio(self, mask):
        _, H, W = mask.shape
        valid_H = torch.sum(~mask[:, :, 0], 1)
        valid_W = torch.sum(~mask[:, 0, :], 1)
        valid_ratio_h = valid_H.float() / H
        valid_ratio_w = valid_W.float() / W
        valid_ratio = torch.stack([valid_ratio_w, valid_ratio_h], -1)
        return valid_ratio

    def forward(self, srcs, masks, pos_embeds, query_embed=None):
        assert self.two_stage or query_embed is not None

        # prepare input for encoder
        src_flatten = []
        mask_flatten = []
        lvl_pos_embed_flatten = []
        spatial_shapes = []
        for lvl, (src, mask, pos_embed) in enumerate(zip(srcs, masks, pos_embeds)):
            bs, c, h, w = src.shape
            spatial_shape = (h, w)
            spatial_shapes.append(spatial_shape)
            src = src.flatten(2).transpose(1, 2)
            mask = mask.flatten(1)
            pos_embed = pos_embed.flatten(2).transpose(1, 2)
            lvl_pos_embed = pos_embed + self.level_embed[lvl].view(1, 1, -1)
            lvl_pos_embed_flatten.append(lvl_pos_embed)
            src_flatten.append(src)
            mask_flatten.append(mask)
        src_flatten = torch.cat(src_flatten, 1)
        mask_flatten = torch.cat(mask_flatten, 1)
        lvl_pos_embed_flatten = torch.cat(lvl_pos_embed_flatten, 1)
        spatial_shapes = torch.as_tensor(spatial_shapes, dtype=torch.long, device=src_flatten.device)
        level_start_index = torch.cat((spatial_shapes.new_zeros((1, )), spatial_shapes.prod(1).cumsum(0)[:-1]))
        valid_ratios = torch.stack([self.get_valid_ratio(m) for m in masks], 1)

        # encoder
        memory = self.encoder(src_flatten, spatial_shapes, level_start_index, valid_ratios, lvl_pos_embed_flatten, mask_flatten)

        if len(memory) > len(mask_flatten):
            mask_flatten = torch.cat([mask_flatten, mask_flatten], dim=0)
            valid_ratios = torch.cat([valid_ratios, valid_ratios], dim=0)
        # prepare input for decoder
        bs, _, c = memory.shape
        if self.two_stage:
            output_memory, output_proposals = self.gen_encoder_output_proposals(memory, mask_flatten, spatial_shapes)

            # hack implementation for two-stage Deformable DETR
            enc_outputs_class = self.decoder.class_embed[self.decoder.num_layers](output_memory)
            enc_outputs_coord_unact = self.decoder.bbox_embed[self.decoder.num_layers](output_memory) + output_proposals

            topk = self.two_stage_num_proposals
            topk_proposals = torch.topk(enc_outputs_class[..., 0], topk, dim=1)[1]
            topk_coords_unact = torch.gather(enc_outputs_coord_unact, 1, topk_proposals.unsqueeze(-1).repeat(1, 1, 4))
            topk_coords_unact = topk_coords_unact.detach()
            reference_points = topk_coords_unact.sigmoid()
            init_reference_out = reference_points
            pos_trans_out = self.pos_trans_norm(self.pos_trans(self.get_proposal_pos_embed(topk_coords_unact)))
            query_embed, tgt = torch.split(pos_trans_out, c, dim=2)
        else:
            query_embed, tgt = torch.split(query_embed, c, dim=1)
            query_embed = query_embed.unsqueeze(0).expand(bs, -1, -1)
            tgt = tgt.unsqueeze(0).expand(bs, -1, -1)
            reference_points = self.reference_points(query_embed).sigmoid()
            init_reference_out = reference_points
        # decoder
        hs, inter_references = self.decoder(tgt, reference_points, memory,
                                            spatial_shapes, level_start_index, valid_ratios, query_embed, mask_flatten)

        inter_references_out = inter_references
        if self.two_stage:
            return hs, init_reference_out, inter_references_out, enc_outputs_class, enc_outputs_coord_unact
        return hs, init_reference_out, inter_references_out, None, None


class DeformableTransformerEncoderLayer(nn.Module):
    def __init__(self,
                 d_model=256, d_ffn=1024,
                 dropout=0.1, activation="relu",
                 n_levels=4, n_heads=8, n_points=4):
        super().__init__()

        # self attention
        self.self_attn = MSDeformAttn(d_model, n_levels, n_heads, n_points)
        self.dropout1 = nn.Dropout(dropout)
        self.norm1 = nn.LayerNorm(d_model)

        # ffn
        self.linear1 = nn.Linear(d_model, d_ffn)
        self.activation = _get_activation_fn(activation)
        self.dropout2 = nn.Dropout(dropout)
        self.linear2 = nn.Linear(d_ffn, d_model)
        self.dropout3 = nn.Dropout(dropout)
        self.norm2 = nn.LayerNorm(d_model)

    @staticmethod
    def with_pos_embed(tensor, pos):
        return tensor if pos is None else tensor + pos

    def forward_ffn(self, src):
        src2 = self.linear2(self.dropout2(self.activation(self.linear1(src))))
        src = src + self.dropout3(src2)
        src = self.norm2(src)
        return src

    def forward(self, src, pos, reference_points, spatial_shapes, level_start_index, padding_mask=None):
        # self attention
        src2 = self.self_attn(self.with_pos_embed(src, pos), reference_points, src, spatial_shapes, level_start_index, padding_mask)
        src = src + self.dropout1(src2)
        src = self.norm1(src)

        # ffn
        src = self.forward_ffn(src)

        return src


class DeformableTransformerEncoder(nn.Module):
    def __init__(self, encoder_layer, num_layers, bf=None, bf_idx = 0, insert_idx=2, eval_bf=0):
        super().__init__()
        self.layers = _get_clones(encoder_layer, num_layers)
        self.num_layers = num_layers
        self.insert_idx = insert_idx
        if type(bf) != torch.nn.ModuleList and bf is not None:
            self.bf = [bf]*num_layers
        else:
            self.bf = bf
        self.bf_idx = bf_idx
        self.eval_bf = eval_bf

    @staticmethod
    def get_reference_points(spatial_shapes, valid_ratios, device):
        reference_points_list = []
        for lvl, (H_, W_) in enumerate(spatial_shapes):

            ref_y, ref_x = torch.meshgrid(torch.linspace(0.5, H_ - 0.5, H_, dtype=torch.float32, device=device),
                                          torch.linspace(0.5, W_ - 0.5, W_, dtype=torch.float32, device=device))
            ref_y = ref_y.reshape(-1)[None] / (valid_ratios[:, None, lvl, 1] * H_)
            ref_x = ref_x.reshape(-1)[None] / (valid_ratios[:, None, lvl, 0] * W_)
            ref = torch.stack((ref_x, ref_y), -1)
            reference_points_list.append(ref)
        reference_points = torch.cat(reference_points_list, 1)
        reference_points = reference_points[:, :, None] * valid_ratios[:, None]
        return reference_points

    def forward(self, src, spatial_shapes, level_start_index, valid_ratios, pos=None, padding_mask=None):
        output = src
        reference_points = self.get_reference_points(spatial_shapes, valid_ratios, device=src.device)
        for i, layer in enumerate(self.layers):
            output = layer(output, pos, reference_points, spatial_shapes, level_start_index, padding_mask)

            if i in self.insert_idx and self.bf is not None and self.bf_idx in [1] and (self.training or self.eval_bf):
                old_output = output
                if i != self.insert_idx[0]: # If this is not the first layer, we split the batch into two streams because we have concatenate the two streams.
                    old_output = output[ :len(output)//2, :, :]  # stream without batchformerv2
                    output = output[len(output)//2:, :, :] # strea with batchformerv2
                output = self.bf[i](output) # if this is th first layer, we apply the batchformerv2 on the batch. then concatenate old_output and output
                if self.training:
                    output = torch.cat([old_output, output], dim=0)
                if i == self.insert_idx[0] and self.training: # for other variables, we just share it i the next modules. We thus repeat it.
                    pos = torch.cat([pos, pos], dim=0) 
                    reference_points = torch.cat([reference_points, reference_points], dim=0)
                    padding_mask = torch.cat([padding_mask, padding_mask], dim=0)
            elif i in self.insert_idx and self.bf is not None and self.bf_idx == 7 and self.training:
                # single stream
                output = self.bf[i](output)

        return output


class DeformableTransformerDecoderLayer(nn.Module):
    def __init__(self, d_model=256, d_ffn=1024,
                 dropout=0.1, activation="relu",
                 n_levels=4, n_heads=8, n_points=4):
        super().__init__()

        # cross attention
        self.cross_attn = MSDeformAttn(d_model, n_levels, n_heads, n_points)
        self.dropout1 = nn.Dropout(dropout)
        self.norm1 = nn.LayerNorm(d_model)

        # self attention
        self.self_attn = nn.MultiheadAttention(d_model, n_heads, dropout=dropout)
        self.dropout2 = nn.Dropout(dropout)
        self.norm2 = nn.LayerNorm(d_model)

        # ffn
        self.linear1 = nn.Linear(d_model, d_ffn)
        self.activation = _get_activation_fn(activation)
        self.dropout3 = nn.Dropout(dropout)
        self.linear2 = nn.Linear(d_ffn, d_model)
        self.dropout4 = nn.Dropout(dropout)
        self.norm3 = nn.LayerNorm(d_model)

    @staticmethod
    def with_pos_embed(tensor, pos):
        return tensor if pos is None else tensor + pos

    def forward_ffn(self, tgt):
        tgt2 = self.linear2(self.dropout3(self.activation(self.linear1(tgt))))
        tgt = tgt + self.dropout4(tgt2)
        tgt = self.norm3(tgt)
        return tgt

    def forward(self, tgt, query_pos, reference_points, src, src_spatial_shapes, level_start_index, src_padding_mask=None):
        # self attention
        q = k = self.with_pos_embed(tgt, query_pos)
        tgt2 = self.self_attn(q.transpose(0, 1), k.transpose(0, 1), tgt.transpose(0, 1))[0].transpose(0, 1)
        tgt = tgt + self.dropout2(tgt2)
        tgt = self.norm2(tgt)

        # cross attention
        tgt2 = self.cross_attn(self.with_pos_embed(tgt, query_pos),
                               reference_points,
                               src, src_spatial_shapes, level_start_index, src_padding_mask)
        tgt = tgt + self.dropout1(tgt2)
        tgt = self.norm1(tgt)

        # ffn
        tgt = self.forward_ffn(tgt)

        return tgt


class DeformableTransformerDecoder(nn.Module):
    def __init__(self, decoder_layer, num_layers, return_intermediate=False):
        super().__init__()
        self.layers = _get_clones(decoder_layer, num_layers)
        self.num_layers = num_layers
        self.return_intermediate = return_intermediate
        # hack implementation for iterative bounding box refinement and two-stage Deformable DETR
        self.bbox_embed = None
        self.class_embed = None

    def forward(self, tgt, reference_points, src, src_spatial_shapes, src_level_start_index, src_valid_ratios,
                query_pos=None, src_padding_mask=None):
        output = tgt

        intermediate = []
        intermediate_reference_points = []
        for lid, layer in enumerate(self.layers):
            if reference_points.shape[-1] == 4:
                reference_points_input = reference_points[:, :, None] \
                                         * torch.cat([src_valid_ratios, src_valid_ratios], -1)[:, None]
            else:
                assert reference_points.shape[-1] == 2
                reference_points_input = reference_points[:, :, None] * src_valid_ratios[:, None]
            output = layer(output, query_pos, reference_points_input, src, src_spatial_shapes, src_level_start_index, src_padding_mask)
            # hack implementation for iterative bounding box refinement
            if self.bbox_embed is not None:
                tmp = self.bbox_embed[lid](output)
                if reference_points.shape[-1] == 4:
                    new_reference_points = tmp + inverse_sigmoid(reference_points)
                    new_reference_points = new_reference_points.sigmoid()
                else:
                    assert reference_points.shape[-1] == 2
                    new_reference_points = tmp
                    new_reference_points[..., :2] = tmp[..., :2] + inverse_sigmoid(reference_points)
                    new_reference_points = new_reference_points.sigmoid()
                reference_points = new_reference_points.detach()

            if self.return_intermediate:
                intermediate.append(output)
                intermediate_reference_points.append(reference_points)

        if self.return_intermediate:
            return torch.stack(intermediate), torch.stack(intermediate_reference_points)

        return output, reference_points


def _get_clones(module, N):
    return nn.ModuleList([copy.deepcopy(module) for i in range(N)])


def _get_activation_fn(activation):
    """Return an activation function given a string"""
    if activation == "relu":
        return F.relu
    if activation == "gelu":
        return F.gelu
    if activation == "glu":
        return F.glu
    raise RuntimeError(F"activation should be relu/gelu, not {activation}.")


def build_deforamble_transformer(args):
    return DeformableTransformer(
        d_model=args.hidden_dim,
        nhead=args.nheads,
        num_encoder_layers=args.enc_layers,
        num_decoder_layers=args.dec_layers,
        dim_feedforward=args.dim_feedforward,
        dropout=args.dropout,
        activation="relu",
        return_intermediate_dec=True,
        num_feature_levels=args.num_feature_levels,
        dec_n_points=args.dec_n_points,
        enc_n_points=args.enc_n_points,
        two_stage=args.two_stage,
        two_stage_num_proposals=args.num_queries,
        args=args)




================================================
FILE: batchformer-v2/deformable-detr/models/matcher.py
================================================
# ------------------------------------------------------------------------
# Deformable DETR
# Copyright (c) 2020 SenseTime. All Rights Reserved.
# Licensed under the Apache License, Version 2.0 [see LICENSE for details]
# ------------------------------------------------------------------------
# Modified from DETR (https://github.com/facebookresearch/detr)
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
# ------------------------------------------------------------------------

"""
Modules to compute the matching cost and solve the corresponding LSAP.
"""
import torch
from scipy.optimize import linear_sum_assignment
from torch import nn

from util.box_ops import box_cxcywh_to_xyxy, generalized_box_iou


class HungarianMatcher(nn.Module):
    """This class computes an assignment between the targets and the predictions of the network

    For efficiency reasons, the targets don't include the no_object. Because of this, in general,
    there are more predictions than targets. In this case, we do a 1-to-1 matching of the best predictions,
    while the others are un-matched (and thus treated as non-objects).
    """

    def __init__(self,
                 cost_class: float = 1,
                 cost_bbox: float = 1,
                 cost_giou: float = 1):
        """Creates the matcher

        Params:
            cost_class: This is the relative weight of the classification error in the matching cost
            cost_bbox: This is the relative weight of the L1 error of the bounding box coordinates in the matching cost
            cost_giou: This is the relative weight of the giou loss of the bounding box in the matching cost
        """
        super().__init__()
        self.cost_class = cost_class
        self.cost_bbox = cost_bbox
        self.cost_giou = cost_giou
        assert cost_class != 0 or cost_bbox != 0 or cost_giou != 0, "all costs cant be 0"

    def forward(self, outputs, targets):
        """ Performs the matching

        Params:
            outputs: This is a dict that contains at least these entries:
                 "pred_logits": Tensor of dim [batch_size, num_queries, num_classes] with the classification logits
                 "pred_boxes": Tensor of dim [batch_size, num_queries, 4] with the predicted box coordinates

            targets: This is a list of targets (len(targets) = batch_size), where each target is a dict containing:
                 "labels": Tensor of dim [num_target_boxes] (where num_target_boxes is the number of ground-truth
                           objects in the target) containing the class labels
                 "boxes": Tensor of dim [num_target_boxes, 4] containing the target box coordinates

        Returns:
            A list of size batch_size, containing tuples of (index_i, index_j) where:
                - index_i is the indices of the selected predictions (in order)
                - index_j is the indices of the corresponding selected targets (in order)
            For each batch element, it holds:
                len(index_i) = len(index_j) = min(num_queries, num_target_boxes)
        """
        with torch.no_grad():
            bs, num_queries = outputs["pred_logits"].shape[:2]

            # We flatten to compute the cost matrices in a batch
            out_prob = outputs["pred_logits"].flatten(0, 1).sigmoid()
            out_bbox = outputs["pred_boxes"].flatten(0, 1)  # [batch_size * num_queries, 4]

            # Also concat the target labels and boxes
            tgt_ids = torch.cat([v["labels"] for v in targets])
            tgt_bbox = torch.cat([v["boxes"] for v in targets])

            # Compute the classification cost.
            alpha = 0.25
            gamma = 2.0
            neg_cost_class = (1 - alpha) * (out_prob ** gamma) * (-(1 - out_prob + 1e-8).log())
            pos_cost_class = alpha * ((1 - out_prob) ** gamma) * (-(out_prob + 1e-8).log())
            cost_class = pos_cost_class[:, tgt_ids] - neg_cost_class[:, tgt_ids]

            # Compute the L1 cost between boxes
            cost_bbox = torch.cdist(out_bbox, tgt_bbox, p=1)

            # Compute the giou cost betwen boxes
            cost_giou = -generalized_box_iou(box_cxcywh_to_xyxy(out_bbox),
                                             box_cxcywh_to_xyxy(tgt_bbox))

            # Final cost matrix
            C = self.cost_bbox * cost_bbox + self.cost_class * cost_class + self.cost_giou * cost_giou
            C = C.view(bs, num_queries, -1).cpu()

            sizes = [len(v["boxes"]) for v in targets]
            indices = [linear_sum_assignment(c[i]) for i, c in enumerate(C.split(sizes, -1))]
            return [(torch.as_tensor(i, dtype=torch.int64), torch.as_tensor(j, dtype=torch.int64)) for i, j in indices]


def build_matcher(args):
    return HungarianMatcher(cost_class=args.set_cost_class,
                            cost_bbox=args.set_cost_bbox,
                            cost_giou=args.set_cost_giou)


================================================
FILE: batchformer-v2/deformable-detr/models/ops/functions/__init__.py
================================================
# ------------------------------------------------------------------------------------------------
# Deformable DETR
# Copyright (c) 2020 SenseTime. All Rights Reserved.
# Licensed under the Apache License, Version 2.0 [see LICENSE for details]
# ------------------------------------------------------------------------------------------------
# Modified from https://github.com/chengdazhi/Deformable-Convolution-V2-PyTorch/tree/pytorch_1.0.0
# ------------------------------------------------------------------------------------------------

from .ms_deform_attn_func import MSDeformAttnFunction



================================================
FILE: batchformer-v2/deformable-detr/models/ops/functions/ms_deform_attn_func.py
================================================
# ------------------------------------------------------------------------------------------------
# Deformable DETR
# Copyright (c) 2020 SenseTime. All Rights Reserved.
# Licensed under the Apache License, Version 2.0 [see LICENSE for details]
# ------------------------------------------------------------------------------------------------
# Modified from https://github.com/chengdazhi/Deformable-Convolution-V2-PyTorch/tree/pytorch_1.0.0
# ------------------------------------------------------------------------------------------------

from __future__ import absolute_import
from __future__ import print_function
from __future__ import division

import torch
import torch.nn.functional as F
from torch.autograd import Function
from torch.autograd.function import once_differentiable

import MultiScaleDeformableAttention as MSDA


class MSDeformAttnFunction(Function):
    @staticmethod
    def forward(ctx, value, value_spatial_shapes, value_level_start_index, sampling_locations, attention_weights, im2col_step):
        ctx.im2col_step = im2col_step
        output = MSDA.ms_deform_attn_forward(
            value, value_spatial_shapes, value_level_start_index, sampling_locations, attention_weights, ctx.im2col_step)
        ctx.save_for_backward(value, value_spatial_shapes, value_level_start_index, sampling_locations, attention_weights)
        return output

    @staticmethod
    @once_differentiable
    def backward(ctx, grad_output):
        value, value_spatial_shapes, value_level_start_index, sampling_locations, attention_weights = ctx.saved_tensors
        grad_value, grad_sampling_loc, grad_attn_weight = \
            MSDA.ms_deform_attn_backward(
                value, value_spatial_shapes, value_level_start_index, sampling_locations, attention_weights, grad_output, ctx.im2col_step)

        return grad_value, None, None, grad_sampling_loc, grad_attn_weight, None


def ms_deform_attn_core_pytorch(value, value_spatial_shapes, sampling_locations, attention_weights):
    # for debug and test only,
    # need to use cuda version instead
    N_, S_, M_, D_ = value.shape
    _, Lq_, M_, L_, P_, _ = sampling_locations.shape
    value_list = value.split([H_ * W_ for H_, W_ in value_spatial_shapes], dim=1)
    sampling_grids = 2 * sampling_locations - 1
    sampling_value_list = []
    for lid_, (H_, W_) in enumerate(value_spatial_shapes):
        # N_, H_*W_, M_, D_ -> N_, H_*W_, M_*D_ -> N_, M_*D_, H_*W_ -> N_*M_, D_, H_, W_
        value_l_ = value_list[lid_].flatten(2).transpose(1, 2).reshape(N_*M_, D_, H_, W_)
        # N_, Lq_, M_, P_, 2 -> N_, M_, Lq_, P_, 2 -> N_*M_, Lq_, P_, 2
        sampling_grid_l_ = sampling_grids[:, :, :, lid_].transpose(1, 2).flatten(0, 1)
        # N_*M_, D_, Lq_, P_
        sampling_value_l_ = F.grid_sample(value_l_, sampling_grid_l_,
                                          mode='bilinear', padding_mode='zeros', align_corners=False)
        sampling_value_list.append(sampling_value_l_)
    # (N_, Lq_, M_, L_, P_) -> (N_, M_, Lq_, L_, P_) -> (N_, M_, 1, Lq_, L_*P_)
    attention_weights = attention_weights.transpose(1, 2).reshape(N_*M_, 1, Lq_, L_*P_)
    output = (torch.stack(sampling_value_list, dim=-2).flatten(-2) * attention_weights).sum(-1).view(N_, M_*D_, Lq_)
    return output.transpose(1, 2).contiguous()


================================================
FILE: batchformer-v2/deformable-detr/models/ops/make.sh
================================================
#!/usr/bin/env bash
# ------------------------------------------------------------------------------------------------
# Deformable DETR
# Copyright (c) 2020 SenseTime. All Rights Reserved.
# Licensed under the Apache License, Version 2.0 [see LICENSE for details]
# ------------------------------------------------------------------------------------------------
# Modified from https://github.com/chengdazhi/Deformable-Convolution-V2-PyTorch/tree/pytorch_1.0.0
# ------------------------------------------------------------------------------------------------

python setup.py build install


================================================
FILE: batchformer-v2/deformable-detr/models/ops/modules/__init__.py
================================================
# ------------------------------------------------------------------------------------------------
# Deformable DETR
# Copyright (c) 2020 SenseTime. All Rights Reserved.
# Licensed under the Apache License, Version 2.0 [see LICENSE for details]
# ------------------------------------------------------------------------------------------------
# Modified from https://github.com/chengdazhi/Deformable-Convolution-V2-PyTorch/tree/pytorch_1.0.0
# ------------------------------------------------------------------------------------------------

from .ms_deform_attn import MSDeformAttn


================================================
FILE: batchformer-v2/deformable-detr/models/ops/modules/ms_deform_attn.py
================================================
# ------------------------------------------------------------------------------------------------
# Deformable DETR
# Copyright (c) 2020 SenseTime. All Rights Reserved.
# Licensed under the Apache License, Version 2.0 [see LICENSE for details]
# ------------------------------------------------------------------------------------------------
# Modified from https://github.com/chengdazhi/Deformable-Convolution-V2-PyTorch/tree/pytorch_1.0.0
# ------------------------------------------------------------------------------------------------

from __future__ import absolute_import
from __future__ import print_function
from __future__ import division

import warnings
import math

import torch
from torch import nn
import torch.nn.functional as F
from torch.nn.init import xavier_uniform_, constant_

from ..functions import MSDeformAttnFunction


def _is_power_of_2(n):
    if (not isinstance(n, int)) or (n < 0):
        raise ValueError("invalid input for _is_power_of_2: {} (type: {})".format(n, type(n)))
    return (n & (n-1) == 0) and n != 0


class MSDeformAttn(nn.Module):
    def __init__(self, d_model=256, n_levels=4, n_heads=8, n_points=4):
        """
        Multi-Scale Deformable Attention Module
        :param d_model      hidden dimension
        :param n_levels     number of feature levels
        :param n_heads      number of attention heads
        :param n_points     number of sampling points per attention head per feature level
        """
        super().__init__()
        if d_model % n_heads != 0:
            raise ValueError('d_model must be divisible by n_heads, but got {} and {}'.format(d_model, n_heads))
        _d_per_head = d_model // n_heads
        # you'd better set _d_per_head to a power of 2 which is more efficient in our CUDA implementation
        if not _is_power_of_2(_d_per_head):
            warnings.warn("You'd better set d_model in MSDeformAttn to make the dimension of each attention head a power of 2 "
                          "which is more efficient in our CUDA implementation.")

        self.im2col_step = 64

        self.d_model = d_model
        self.n_levels = n_levels
        self.n_heads = n_heads
        self.n_points = n_points

        self.sampling_offsets = nn.Linear(d_model, n_heads * n_levels * n_points * 2)
        self.attention_weights = nn.Linear(d_model, n_heads * n_levels * n_points)
        self.value_proj = nn.Linear(d_model, d_model)
        self.output_proj = nn.Linear(d_model, d_model)

        self._reset_parameters()

    def _reset_parameters(self):
        constant_(self.sampling_offsets.weight.data, 0.)
        thetas = torch.arange(self.n_heads, dtype=torch.float32) * (2.0 * math.pi / self.n_heads)
        grid_init = torch.stack([thetas.cos(), thetas.sin()], -1)
        grid_init = (grid_init / grid_init.abs().max(-1, keepdim=True)[0]).view(self.n_heads, 1, 1, 2).repeat(1, self.n_levels, self.n_points, 1)
        for i in range(self.n_points):
            grid_init[:, :, i, :] *= i + 1
        with torch.no_grad():
            self.sampling_offsets.bias = nn.Parameter(grid_init.view(-1))
        constant_(self.attention_weights.weight.data, 0.)
        constant_(self.attention_weights.bias.data, 0.)
        xavier_uniform_(self.value_proj.weight.data)
        constant_(self.value_proj.bias.data, 0.)
        xavier_uniform_(self.output_proj.weight.data)
        constant_(self.output_proj.bias.data, 0.)

    def forward(self, query, reference_points, input_flatten, input_spatial_shapes, input_level_start_index, input_padding_mask=None):
        """
        :param query                       (N, Length_{query}, C)
        :param reference_points            (N, Length_{query}, n_levels, 2), range in [0, 1], top-left (0,0), bottom-right (1, 1), including padding area
                                        or (N, Length_{query}, n_levels, 4), add additional (w, h) to form reference boxes
        :param input_flatten               (N, \sum_{l=0}^{L-1} H_l \cdot W_l, C)
        :param input_spatial_shapes        (n_levels, 2), [(H_0, W_0), (H_1, W_1), ..., (H_{L-1}, W_{L-1})]
        :param input_level_start_index     (n_levels, ), [0, H_0*W_0, H_0*W_0+H_1*W_1, H_0*W_0+H_1*W_1+H_2*W_2, ..., H_0*W_0+H_1*W_1+...+H_{L-1}*W_{L-1}]
        :param input_padding_mask          (N, \sum_{l=0}^{L-1} H_l \cdot W_l), True for padding elements, False for non-padding elements

        :return output                     (N, Length_{query}, C)
        """
        N, Len_q, _ = query.shape
        N, Len_in, _ = input_flatten.shape
        assert (input_spatial_shapes[:, 0] * input_spatial_shapes[:, 1]).sum() == Len_in

        value = self.value_proj(input_flatten)
        if input_padding_mask is not None:
            value = value.masked_fill(input_padding_mask[..., None], float(0))
        value = value.view(N, Len_in, self.n_heads, self.d_model // self.n_heads)
        sampling_offsets = self.sampling_offsets(query).view(N, Len_q, self.n_heads, self.n_levels, self.n_points, 2)
        attention_weights = self.attention_weights(query).view(N, Len_q, self.n_heads, self.n_levels * self.n_points)
        attention_weights = F.softmax(attention_weights, -1).view(N, Len_q, self.n_heads, self.n_levels, self.n_points)
        # N, Len_q, n_heads, n_levels, n_points, 2
        if reference_points.shape[-1] == 2:
            offset_normalizer = torch.stack([input_spatial_shapes[..., 1], input_spatial_shapes[..., 0]], -1)
            sampling_locations = reference_points[:, :, None, :, None, :] \
                                 + sampling_offsets / offset_normalizer[None, None, None, :, None, :]
        elif reference_points.shape[-1] == 4:
            sampling_locations = reference_points[:, :, None, :, None, :2] \
                                 + sampling_offsets / self.n_points * reference_points[:, :, None, :, None, 2:] * 0.5
        else:
            raise ValueError(
                'Last dim of reference_points must be 2 or 4, but get {} instead.'.format(reference_points.shape[-1]))
        output = MSDeformAttnFunction.apply(
            value, input_spatial_shapes, input_level_start_index, sampling_locations, attention_weights, self.im2col_step)
        output = self.output_proj(output)
        return output


================================================
FILE: batchformer-v2/deformable-detr/models/ops/setup.py
================================================
# ------------------------------------------------------------------------------------------------
# Deformable DETR
# Copyright (c) 2020 SenseTime. All Rights Reserved.
# Licensed under the Apache License, Version 2.0 [see LICENSE for details]
# ------------------------------------------------------------------------------------------------
# Modified from https://github.com/chengdazhi/Deformable-Convolution-V2-PyTorch/tree/pytorch_1.0.0
# ------------------------------------------------------------------------------------------------

import os
import glob

import torch

from torch.utils.cpp_extension import CUDA_HOME
from torch.utils.cpp_extension import CppExtension
from torch.utils.cpp_extension import CUDAExtension

from setuptools import find_packages
from setuptools import setup

requirements = ["torch", "torchvision"]

def get_extensions():
    this_dir = os.path.dirname(os.path.abspath(__file__))
    extensions_dir = os.path.join(this_dir, "src")

    main_file = glob.glob(os.path.join(extensions_dir, "*.cpp"))
    source_cpu = glob.glob(os.path.join(extensions_dir, "cpu", "*.cpp"))
    source_cuda = glob.glob(os.path.join(extensions_dir, "cuda", "*.cu"))

    sources = main_file + source_cpu
    extension = CppExtension
    extra_compile_args = {"cxx": []}
    define_macros = []

    if torch.cuda.is_available() and CUDA_HOME is not None:
        extension = CUDAExtension
        sources += source_cuda
        define_macros += [("WITH_CUDA", None)]
        extra_compile_args["nvcc"] = [
            "-DCUDA_HAS_FP16=1",
            "-D__CUDA_NO_HALF_OPERATORS__",
            "-D__CUDA_NO_HALF_CONVERSIONS__",
            "-D__CUDA_NO_HALF2_OPERATORS__",
        ]
    else:
        raise NotImplementedError('Cuda is not availabel')

    sources = [os.path.join(extensions_dir, s) for s in sources]
    include_dirs = [extensions_dir]
    ext_modules = [
        extension(
            "MultiScaleDeformableAttention",
            sources,
            include_dirs=include_dirs,
            define_macros=define_macros,
            extra_compile_args=extra_compile_args,
        )
    ]
    return ext_modules

setup(
    name="MultiScaleDeformableAttention",
    version="1.0",
    author="Weijie Su",
    url="https://github.com/fundamentalvision/Deformable-DETR",
    description="PyTorch Wrapper for CUDA Functions of Multi-Scale Deformable Attention",
    packages=find_packages(exclude=("configs", "tests",)),
    ext_modules=get_extensions(),
    cmdclass={"build_ext": torch.utils.cpp_extension.BuildExtension},
)


================================================
FILE: batchformer-v2/deformable-detr/models/ops/src/cpu/ms_deform_attn_cpu.cpp
================================================
/*!
**************************************************************************************************
* Deformable DETR
* Copyright (c) 2020 SenseTime. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 [see LICENSE for details]
**************************************************************************************************
* Modified from https://github.com/chengdazhi/Deformable-Convolution-V2-PyTorch/tree/pytorch_1.0.0
**************************************************************************************************
*/

#include <vector>

#include <ATen/ATen.h>
#include <ATen/cuda/CUDAContext.h>


at::Tensor
ms_deform_attn_cpu_forward(
    const at::Tensor &value, 
    const at::Tensor &spatial_shapes,
    const at::Tensor &level_start_index,
    const at::Tensor &sampling_loc,
    const at::Tensor &attn_weight,
    const int im2col_step)
{
    AT_ERROR("Not implement on cpu");
}

std::vector<at::Tensor>
ms_deform_attn_cpu_backward(
    const at::Tensor &value, 
    const at::Tensor &spatial_shapes,
    const at::Tensor &level_start_index,
    const at::Tensor &sampling_loc,
    const at::Tensor &attn_weight,
    const at::Tensor &grad_output,
    const int im2col_step)
{
    AT_ERROR("Not implement on cpu");
}



================================================
FILE: batchformer-v2/deformable-detr/models/ops/src/cpu/ms_deform_attn_cpu.h
================================================
/*!
**************************************************************************************************
* Deformable DETR
* Copyright (c) 2020 SenseTime. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 [see LICENSE for details]
**************************************************************************************************
* Modified from https://github.com/chengdazhi/Deformable-Convolution-V2-PyTorch/tree/pytorch_1.0.0
**************************************************************************************************
*/

#pragma once
#include <torch/extension.h>

at::Tensor
ms_deform_attn_cpu_forward(
    const at::Tensor &value, 
    const at::Tensor &spatial_shapes,
    const at::Tensor &level_start_index,
    const at::Tensor &sampling_loc,
    const at::Tensor &attn_weight,
    const int im2col_step);

std::vector<at::Tensor>
ms_deform_attn_cpu_backward(
    const at::Tensor &value, 
    const at::Tensor &spatial_shapes,
    const at::Tensor &level_start_index,
    const at::Tensor &sampling_loc,
    const at::Tensor &attn_weight,
    const at::Tensor &grad_output,
    const int im2col_step);




================================================
FILE: batchformer-v2/deformable-detr/models/ops/src/cuda/ms_deform_attn_cuda.cu
================================================
/*!
**************************************************************************************************
* Deformable DETR
* Copyright (c) 2020 SenseTime. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 [see LICENSE for details]
**************************************************************************************************
* Modified from https://github.com/chengdazhi/Deformable-Convolution-V2-PyTorch/tree/pytorch_1.0.0
**************************************************************************************************
*/

#include <vector>
#include "cuda/ms_deform_im2col_cuda.cuh"

#include <ATen/ATen.h>
#include <ATen/cuda/CUDAContext.h>
#include <cuda.h>
#include <cuda_runtime.h>


at::Tensor ms_deform_attn_cuda_forward(
    const at::Tensor &value, 
    const at::Tensor &spatial_shapes,
    const at::Tensor &level_start_index,
    const at::Tensor &sampling_loc,
    const at::Tensor &attn_weight,
    const int im2col_step)
{
    AT_ASSERTM(value.is_contiguous(), "value tensor has to be contiguous");
    AT_ASSERTM(spatial_shapes.is_contiguous(), "spatial_shapes tensor has to be contiguous");
    AT_ASSERTM(level_start_index.is_contiguous(), "level_start_index tensor has to be contiguous");
    AT_ASSERTM(sampling_loc.is_contiguous(), "sampling_loc tensor has to be contiguous");
    AT_ASSERTM(attn_weight.is_contiguous(), "attn_weight tensor has to be contiguous");

    AT_ASSERTM(value.type().is_cuda(), "value must be a CUDA tensor");
    AT_ASSERTM(spatial_shapes.type().is_cuda(), "spatial_shapes must be a CUDA tensor");
    AT_ASSERTM(level_start_index.type().is_cuda(), "level_start_index must be a CUDA tensor");
    AT_ASSERTM(sampling_loc.type().is_cuda(), "sampling_loc must be a CUDA tensor");
    AT_ASSERTM(attn_weight.type().is_cuda(), "attn_weight must be a CUDA tensor");

    const int batch = value.size(0);
    const int spatial_size = value.size(1);
    const int num_heads = value.size(2);
    const int channels = value.size(3);

    const int num_levels = spatial_shapes.size(0);

    const int num_query = sampling_loc.size(1);
    const int num_point = sampling_loc.size(4);

    const int im2col_step_ = std::min(batch, im2col_step);

    AT_ASSERTM(batch % im2col_step_ == 0, "batch(%d) must divide im2col_step(%d)", batch, im2col_step_);
    
    auto output = at::zeros({batch, num_query, num_heads, channels}, value.options());

    const int batch_n = im2col_step_;
    auto output_n = output.view({batch/im2col_step_, batch_n, num_query, num_heads, channels});
    auto per_value_size = spatial_size * num_heads * channels;
    auto per_sample_loc_size = num_query * num_heads * num_levels * num_point * 2;
    auto per_attn_weight_size = num_query * num_heads * num_levels * num_point;
    for (int n = 0; n < batch/im2col_step_; ++n)
    {
        auto columns = output_n.select(0, n);
        AT_DISPATCH_FLOATING_TYPES(value.type(), "ms_deform_attn_forward_cuda", ([&] {
            ms_deformable_im2col_cuda(at::cuda::getCurrentCUDAStream(),
                value.data<scalar_t>() + n * im2col_step_ * per_value_size,
                spatial_shapes.data<int64_t>(),
                level_start_index.data<int64_t>(),
                sampling_loc.data<scalar_t>() + n * im2col_step_ * per_sample_loc_size,
                attn_weight.data<scalar_t>() + n * im2col_step_ * per_attn_weight_size,
                batch_n, spatial_size, num_heads, channels, num_levels, num_query, num_point,
                columns.data<scalar_t>());

        }));
    }

    output = output.view({batch, num_query, num_heads*channels});

    return output;
}


std::vector<at::Tensor> ms_deform_attn_cuda_backward(
    const at::Tensor &value, 
    const at::Tensor &spatial_shapes,
    const at::Tensor &level_start_index,
    const at::Tensor &sampling_loc,
    const at::Tensor &attn_weight,
    const at::Tensor &grad_output,
    const int im2col_step)
{

    AT_ASSERTM(value.is_contiguous(), "value tensor has to be contiguous");
    AT_ASSERTM(spatial_shapes.is_contiguous(), "spatial_shapes tensor has to be contiguous");
    AT_ASSERTM(level_start_index.is_contiguous(), "level_start_index tensor has to be contiguous");
    AT_ASSERTM(sampling_loc.is_contiguous(), "sampling_loc tensor has to be contiguous");
    AT_ASSERTM(attn_weight.is_contiguous(), "attn_weight tensor has to be contiguous");
    AT_ASSERTM(grad_output.is_contiguous(), "grad_output tensor has to be contiguous");

    AT_ASSERTM(value.type().is_cuda(), "value must be a CUDA tensor");
    AT_ASSERTM(spatial_shapes.type().is_cuda(), "spatial_shapes must be a CUDA tensor");
    AT_ASSERTM(level_start_index.type().is_cuda(), "level_start_index must be a CUDA tensor");
    AT_ASSERTM(sampling_loc.type().is_cuda(), "sampling_loc must be a CUDA tensor");
    AT_ASSERTM(attn_weight.type().is_cuda(), "attn_weight must be a CUDA tensor");
    AT_ASSERTM(grad_output.type().is_cuda(), "grad_output must be a CUDA tensor");

    const int batch = value.size(0);
    const int spatial_size = value.size(1);
    const int num_heads = value.size(2);
    const int channels = value.size(3);

    const int num_levels = spatial_shapes.size(0);

    const int num_query = sampling_loc.size(1);
    const int num_point = sampling_loc.size(4);

    const int im2col_step_ = std::min(batch, im2col_step);

    AT_ASSERTM(batch % im2col_step_ == 0, "batch(%d) must divide im2col_step(%d)", batch, im2col_step_);

    auto grad_value = at::zeros_like(value);
    auto grad_sampling_loc = at::zeros_like(sampling_loc);
    auto grad_attn_weight = at::zeros_like(attn_weight);

    const int batch_n = im2col_step_;
    auto per_value_size = spatial_size * num_heads * channels;
    auto per_sample_loc_size = num_query * num_heads * num_levels * num_point * 2;
    auto per_attn_weight_size = num_query * num_heads * num_levels * num_point;
    auto grad_output_n = grad_output.view({batch/im2col_step_, batch_n, num_query, num_heads, channels});
    
    for (int n = 0; n < batch/im2col_step_; ++n)
    {
        auto grad_output_g = grad_output_n.select(0, n);
        AT_DISPATCH_FLOATING_TYPES(value.type(), "ms_deform_attn_backward_cuda", ([&] {
            ms_deformable_col2im_cuda(at::cuda::getCurrentCUDAStream(),
                                    grad_output_g.data<scalar_t>(),
                                    value.data<scalar_t>() + n * im2col_step_ * per_value_size,
                                    spatial_shapes.data<int64_t>(),
                                    level_start_index.data<int64_t>(),
                                    sampling_loc.data<scalar_t>() + n * im2col_step_ * per_sample_loc_size,
                                    attn_weight.data<scalar_t>() + n * im2col_step_ * per_attn_weight_size,
                                    batch_n, spatial_size, num_heads, channels, num_levels, num_query, num_point,
                                    grad_value.data<scalar_t>() +  n * im2col_step_ * per_value_size,
                                    grad_sampling_loc.data<scalar_t>() + n * im2col_step_ * per_sample_loc_size,
                                    grad_attn_weight.data<scalar_t>() + n * im2col_step_ * per_attn_weight_size);

        }));
    }

    return {
        grad_value, grad_sampling_loc, grad_attn_weight
    };
}

================================================
FILE: batchformer-v2/deformable-detr/models/ops/src/cuda/ms_deform_attn_cuda.h
================================================
/*!
**************************************************************************************************
* Deformable DETR
* Copyright (c) 2020 SenseTime. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 [see LICENSE for details]
**************************************************************************************************
* Modified from https://github.com/chengdazhi/Deformable-Convolution-V2-PyTorch/tree/pytorch_1.0.0
**************************************************************************************************
*/

#pragma once
#include <torch/extension.h>

at::Tensor ms_deform_attn_cuda_forward(
    const at::Tensor &value, 
    const at::Tensor &spatial_shapes,
    const at::Tensor &level_start_index,
    const at::Tensor &sampling_loc,
    const at::Tensor &attn_weight,
    const int im2col_step);

std::vector<at::Tensor> ms_deform_attn_cuda_backward(
    const at::Tensor &value, 
    const at::Tensor &spatial_shapes,
    const at::Tensor &level_start_index,
    const at::Tensor &sampling_loc,
    const at::Tensor &attn_weight,
    const at::Tensor &grad_output,
    const int im2col_step);



================================================
FILE: batchformer-v2/deformable-detr/models/ops/src/cuda/ms_deform_im2col_cuda.cuh
================================================
/*!
**************************************************************************
* Deformable DETR
* Copyright (c) 2020 SenseTime. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 [see LICENSE for details]
**************************************************************************
* Modified from DCN (https://github.com/msracver/Deformable-ConvNets)
* Copyright (c) 2018 Microsoft
**************************************************************************
*/

#include <cstdio>
#include <algorithm>
#include <cstring>

#include <ATen/ATen.h>
#include <ATen/cuda/CUDAContext.h>

#include <THC/THCAtomics.cuh>

#define CUDA_KERNEL_LOOP(i, n)                          \
  for (int i = blockIdx.x * blockDim.x + threadIdx.x;   \
      i < (n);                                          \
      i += blockDim.x * gridDim.x)

const int CUDA_NUM_THREADS = 1024;
inline int GET_BLOCKS(const int N, const int num_threads)
{
  return (N + num_threads - 1) / num_threads;
}


template <typename scalar_t>
__device__ scalar_t ms_deform_attn_im2col_bilinear(const scalar_t* &bottom_data, 
                                                   const int &height, const int &width, const int &nheads, const int &channels,
                                                   const scalar_t &h, const scalar_t &w, const int &m, const int &c)
{
  const int h_low = floor(h);
  const int w_low = floor(w);
  const int h_high = h_low + 1;
  const int w_high = w_low + 1;

  const scalar_t lh = h - h_low;
  const scalar_t lw = w - w_low;
  const scalar_t hh = 1 - lh, hw = 1 - lw;

  const int w_stride = nheads * channels;
  const int h_stride = width * w_stride;
  const int h_low_ptr_offset = h_low * h_stride;
  const int h_high_ptr_offset = h_low_ptr_offset + h_stride;
  const int w_low_ptr_offset = w_low * w_stride;
  const int w_high_ptr_offset = w_low_ptr_offset + w_stride;
  const int base_ptr = m * channels + c;

  scalar_t v1 = 0;
  if (h_low >= 0 && w_low >= 0)
  {
    const int ptr1 = h_low_ptr_offset + w_low_ptr_offset + base_ptr;
    v1 = bottom_data[ptr1];
  }
  scalar_t v2 = 0;
  if (h_low >= 0 && w_high <= width - 1)
  {
    const int ptr2 = h_low_ptr_offset + w_high_ptr_offset + base_ptr;
    v2 = bottom_data[ptr2];
  }
  scalar_t v3 = 0;
  if (h_high <= height - 1 && w_low >= 0)
  {
    const int ptr3 = h_high_ptr_offset + w_low_ptr_offset + base_ptr;
    v3 = bottom_data[ptr3];
  }
  scalar_t v4 = 0;
  if (h_high <= height - 1 && w_high <= width - 1)
  {
    const int ptr4 = h_high_ptr_offset + w_high_ptr_offset + base_ptr;
    v4 = bottom_data[ptr4];
  }

  const scalar_t w1 = hh * hw, w2 = hh * lw, w3 = lh * hw, w4 = lh * lw;

  const scalar_t val = (w1 * v1 + w2 * v2 + w3 * v3 + w4 * v4);
  return val;
}


template <typename scalar_t>
__device__ void ms_deform_attn_col2im_bilinear(const scalar_t* &bottom_data, 
                                                   const int &height, const int &width, const int &nheads, const int &channels,
                                                   const scalar_t &h, const scalar_t &w, const int &m, const int &c,
                                                   const scalar_t &top_grad,
                                                   const scalar_t &attn_weight,
                                                   scalar_t* &grad_value, 
                                                   scalar_t* grad_sampling_loc,
                                                   scalar_t* grad_attn_weight)
{
  const int h_low = floor(h);
  const int w_low = floor(w);
  const int h_high = h_low + 1;
  const int w_high = w_low + 1;

  const scalar_t lh = h - h_low;
  const scalar_t lw = w - w_low;
  const scalar_t hh = 1 - lh, hw = 1 - lw;

  const int w_stride = nheads * channels;
  const int h_stride = width * w_stride;
  const int h_low_ptr_offset = h_low * h_stride;
  const int h_high_ptr_offset = h_low_ptr_offset + h_stride;
  const int w_low_ptr_offset = w_low * w_stride;
  const int w_high_ptr_offset = w_low_ptr_offset + w_stride;
  const int base_ptr = m * channels + c;

  const scalar_t w1 = hh * hw, w2 = hh * lw, w3 = lh * hw, w4 = lh * lw;
  const scalar_t top_grad_value = top_grad * attn_weight;
  scalar_t grad_h_weight = 0, grad_w_weight = 0;

  scalar_t v1 = 0;
  if (h_low >= 0 && w_low >= 0)
  {
    const int ptr1 = h_low_ptr_offset + w_low_ptr_offset + base_ptr;
    v1 = bottom_data[ptr1];
    grad_h_weight -= hw * v1;
    grad_w_weight -= hh * v1;
    atomicAdd(grad_value+ptr1, w1*top_grad_value);
  }
  scalar_t v2 = 0;
  if (h_low >= 0 && w_high <= width - 1)
  {
    const int ptr2 = h_low_ptr_offset + w_high_ptr_offset + base_ptr;
    v2 = bottom_data[ptr2];
    grad_h_weight -= lw * v2;
    grad_w_weight += hh * v2;
    atomicAdd(grad_value+ptr2, w2*top_grad_value);
  }
  scalar_t v3 = 0;
  if (h_high <= height - 1 && w_low >= 0)
  {
    const int ptr3 = h_high_ptr_offset + w_low_ptr_offset + base_ptr;
    v3 = bottom_data[ptr3];
    grad_h_weight += hw * v3;
    grad_w_weight -= lh * v3;
    atomicAdd(grad_value+ptr3, w3*top_grad_value); 
  }
  scalar_t v4 = 0;
  if (h_high <= height - 1 && w_high <= width - 1)
  {
    const int ptr4 = h_high_ptr_offset + w_high_ptr_offset + base_ptr;
    v4 = bottom_data[ptr4];
    grad_h_weight += lw * v4;
    grad_w_weight += lh * v4;
    atomicAdd(grad_value+ptr4, w4*top_grad_value);
  }

  const scalar_t val = (w1 * v1 + w2 * v2 + w3 * v3 + w4 * v4);
  *grad_attn_weight = top_grad * val;
  *grad_sampling_loc = width * grad_w_weight * top_grad_value;
  *(grad_sampling_loc + 1) = height * grad_h_weight * top_grad_value;
}


template <typename scalar_t>
__device__ void ms_deform_attn_col2im_bilinear_gm(const scalar_t* &bottom_data, 
                                                   const int &height, const int &width, const int &nheads, const int &channels,
                                                   const scalar_t &h, const scalar_t &w, const int &m, const int &c,
                                                   const scalar_t &top_grad,
                                                   const scalar_t &attn_weight,
                                                   scalar_t* &grad_value, 
                                                   scalar_t* grad_sampling_loc,
                                                   scalar_t* grad_attn_weight)
{
  const int h_low = floor(h);
  const int w_low = floor(w);
  const int h_high = h_low + 1;
  const int w_high = w_low + 1;

  const scalar_t lh = h - h_low;
  const scalar_t lw = w - w_low;
  const scalar_t hh = 1 - lh, hw = 1 - lw;

  const int w_stride = nheads * channels;
  const int h_stride = width * w_stride;
  const int h_low_ptr_offset = h_low * h_stride;
  const int h_high_ptr_offset = h_low_ptr_offset + h_stride;
  const int w_low_ptr_offset = w_low * w_stride;
  const int w_high_ptr_offset = w_low_ptr_offset + w_stride;
  const int base_ptr = m * channels + c;

  const scalar_t w1 = hh * hw, w2 = hh * lw, w3 = lh * hw, w4 = lh * lw;
  const scalar_t top_grad_value = top_grad * attn_weight;
  scalar_t grad_h_weight = 0, grad_w_weight = 0;

  scalar_t v1 = 0;
  if (h_low >= 0 && w_low >= 0)
  {
    const int ptr1 = h_low_ptr_offset + w_low_ptr_offset + base_ptr;
    v1 = bottom_data[ptr1];
    grad_h_weight -= hw * v1;
    grad_w_weight -= hh * v1;
    atomicAdd(grad_value+ptr1, w1*top_grad_value);
  }
  scalar_t v2 = 0;
  if (h_low >= 0 && w_high <= width - 1)
  {
    const int ptr2 = h_low_ptr_offset + w_high_ptr_offset + base_ptr;
    v2 = bottom_data[ptr2];
    grad_h_weight -= lw * v2;
    grad_w_weight += hh * v2;
    atomicAdd(grad_value+ptr2, w2*top_grad_value);
  }
  scalar_t v3 = 0;
  if (h_high <= height - 1 && w_low >= 0)
  {
    const int ptr3 = h_high_ptr_offset + w_low_ptr_offset + base_ptr;
    v3 = bottom_data[ptr3];
    grad_h_weight += hw * v3;
    grad_w_weight -= lh * v3;
    atomicAdd(grad_value+ptr3, w3*top_grad_value); 
  }
  scalar_t v4 = 0;
  if (h_high <= height - 1 && w_high <= width - 1)
  {
    const int ptr4 = h_high_ptr_offset + w_high_ptr_offset + base_ptr;
    v4 = bottom_data[ptr4];
    grad_h_weight += lw * v4;
    grad_w_weight += lh * v4;
    atomicAdd(grad_value+ptr4, w4*top_grad_value);
  }

  const scalar_t val = (w1 * v1 + w2 * v2 + w3 * v3 + w4 * v4);
  atomicAdd(grad_attn_weight, top_grad * val); 
  atomicAdd(grad_sampling_loc, width * grad_w_weight * top_grad_value);
  atomicAdd(grad_sampling_loc + 1, height * grad_h_weight * top_grad_value);
}


template <typename scalar_t>
__global__ void ms_deformable_im2col_gpu_kernel(const int n,
                                                const scalar_t *data_value, 
                                                const int64_t *data_spatial_shapes,
                                                const int64_t *data_level_start_index, 
                                                const scalar_t *data_sampling_loc,
                                                const scalar_t *data_attn_weight,
                                                const int batch_size, 
                                                const int spatial_size, 
                                                const int num_heads,
                                                const int channels, 
                                                const int num_levels,
                                                const int num_query,
                                                const int num_point,
                                                scalar_t *data_col)
{
  CUDA_KERNEL_LOOP(index, n)
  {
    int _temp = index;
    const int c_col = _temp % channels;
    _temp /= channels;
    const int sampling_index = _temp; 
    const int m_col = _temp % num_heads;
    _temp /= num_heads;
    const int q_col = _temp % num_query;
    _temp /= num_query;
    const int b_col = _temp;

    scalar_t *data_col_ptr = data_col + index;
    int data_weight_ptr = sampling_index * num_levels * num_point;
    int data_loc_w_ptr = data_weight_ptr << 1;
    const int qid_stride = num_heads * channels;
    const int data_value_ptr_init_offset = b_col * spatial_size * qid_stride;
    scalar_t col = 0;
    
    for (int l_col=0; l_col < num_levels; ++l_col)
    {
      const int level_start_id = data_level_start_index[l_col];
      const int spatial_h_ptr = l_col << 1;
      const int spatial_h = data_spatial_shapes[spatial_h_ptr];
      const int spatial_w = data_spatial_shapes[spatial_h_ptr + 1];
      const scalar_t *data_value_ptr = data_value + (data_value_ptr_init_offset + level_start_id * qid_stride);
      for (int p_col=0; p_col < num_point; ++p_col)
      {
        const scalar_t loc_w = data_sampling_loc[data_loc_w_ptr];
        const scalar_t loc_h = data_sampling_loc[data_loc_w_ptr + 1];
        const scalar_t weight = data_attn_weight[data_weight_ptr];

        const scalar_t h_im = loc_h * spatial_h - 0.5;
        const scalar_t w_im = loc_w * spatial_w - 0.5;

        if (h_im > -1 && w_im > -1 && h_im < spatial_h && w_im < spatial_w)
        {
          col += ms_deform_attn_im2col_bilinear(data_value_ptr, spatial_h, spatial_w, num_heads, channels, h_im, w_im, m_col, c_col) * weight;
        }

        data_weight_ptr += 1;
        data_loc_w_ptr += 2;
      }
    }
    *data_col_ptr = col;
  }
}

template <typename scalar_t, unsigned int blockSize>
__global__ void ms_deformable_col2im_gpu_kernel_shm_blocksize_aware_reduce_v1(const int n,
                                                const scalar_t *grad_col,
                                                const scalar_t *data_value,
                                                const int64_t *data_spatial_shapes,
                                                const int64_t *data_level_start_index, 
                                                const scalar_t *data_sampling_loc,
                                                const scalar_t *data_attn_weight,
                                                const int batch_size, 
                                                const int spatial_size, 
                                                const int num_heads,
                                                const int channels, 
                                                const int num_levels,
                                                const int num_query,
                                                const int num_point,
                                                scalar_t *grad_value,
                                                scalar_t *grad_sampling_loc,
                                                scalar_t *grad_attn_weight)
{
  CUDA_KERNEL_LOOP(index, n)
  {
    __shared__ scalar_t cache_grad_sampling_loc[blockSize * 2];
    __shared__ scalar_t cache_grad_attn_weight[blockSize];
    unsigned int tid = threadIdx.x;
    int _temp = index;
    const int c_col = _temp % channels;
    _temp /= channels;
    const int sampling_index = _temp; 
    const int m_col = _temp % num_heads;
    _temp /= num_heads;
    const int q_col = _temp % num_query;
    _temp /= num_query;
    const int b_col = _temp;

    const scalar_t top_grad = grad_col[index];

    int data_weight_ptr = sampling_index * num_levels * num_point;
    int data_loc_w_ptr = data_weight_ptr << 1;
    const int grad_sampling_ptr = data_weight_ptr;
    grad_sampling_loc += grad_sampling_ptr << 1;
    grad_attn_weight += grad_sampling_ptr;
    const int grad_weight_stride = 1;
    const int grad_loc_stride = 2;
    const int qid_stride = num_heads * channels;
    const int data_value_ptr_init_offset = b_col * spatial_size * qid_stride;

    for (int l_col=0; l_col < num_levels; ++l_col)
    {
      const int level_start_id = data_level_start_index[l_col];
      const int spatial_h_ptr = l_col << 1;
      const int spatial_h = data_spatial_shapes[spatial_h_ptr];
      const int spatial_w = data_spatial_shapes[spatial_h_ptr + 1];
      const int value_ptr_offset = data_value_ptr_init_offset + level_start_id * qid_stride;
      const scalar_t *data_value_ptr = data_value + value_ptr_offset;
      scalar_t *grad_value_ptr = grad_value + value_ptr_offset;

      for (int p_col=0; p_col < num_point; ++p_col)
      {
        const scalar_t loc_w = data_sampling_loc[data_loc_w_ptr];
        const scalar_t loc_h = data_sampling_loc[data_loc_w_ptr + 1];
        const scalar_t weight = data_attn_weight[data_weight_ptr];

        const scalar_t h_im = loc_h * spatial_h - 0.5;
        const scalar_t w_im = loc_w * spatial_w - 0.5;
        *(cache_grad_sampling_loc+(threadIdx.x << 1)) = 0;
        *(cache_grad_sampling_loc+((threadIdx.x << 1) + 1)) = 0;
        *(cache_grad_attn_weight+threadIdx.x)=0;
        if (h_im > -1 && w_im > -1 && h_im < spatial_h && w_im < spatial_w)
        {
          ms_deform_attn_col2im_bilinear(
            data_value_ptr, spatial_h, spatial_w, num_heads, channels, h_im, w_im, m_col, c_col,
            top_grad, weight, grad_value_ptr, 
            cache_grad_sampling_loc+(threadIdx.x << 1), cache_grad_attn_weight+threadIdx.x);
        }
        
        __syncthreads();
        if (tid == 0)
        {
          scalar_t _grad_w=cache_grad_sampling_loc[0], _grad_h=cache_grad_sampling_loc[1], _grad_a=cache_grad_attn_weight[0];
          int sid=2;
          for (unsigned int tid = 1; tid < blockSize; ++tid)
          {
            _grad_w += cache_grad_sampling_loc[sid];
            _grad_h += cache_grad_sampling_loc[sid + 1];
            _grad_a += cache_grad_attn_weight[tid];
            sid += 2;
          }
          
          
          *grad_sampling_loc = _grad_w;
          *(grad_samplin
Download .txt
gitextract_s7um03j7/

├── README.md
├── batchformer-v2/
│   ├── deformable-detr/
│   │   ├── LICENSE
│   │   ├── README.md
│   │   ├── benchmark.py
│   │   ├── configs/
│   │   │   ├── r101_deformable_detr.sh
│   │   │   ├── r50_deformable_detr.sh
│   │   │   ├── r50_deformable_detr_plus_iterative_bbox_refinement.sh
│   │   │   ├── r50_deformable_detr_plus_iterative_bbox_refinement_plus_plus_two_stage.sh
│   │   │   ├── r50_deformable_detr_single_scale.sh
│   │   │   └── r50_deformable_detr_single_scale_dc5.sh
│   │   ├── datasets/
│   │   │   ├── __init__.py
│   │   │   ├── coco.py
│   │   │   ├── coco_eval.py
│   │   │   ├── coco_panoptic.py
│   │   │   ├── data_prefetcher.py
│   │   │   ├── panoptic_eval.py
│   │   │   ├── samplers.py
│   │   │   ├── torchvision_datasets/
│   │   │   │   ├── __init__.py
│   │   │   │   └── coco.py
│   │   │   └── transforms.py
│   │   ├── docs/
│   │   │   └── changelog.md
│   │   ├── engine.py
│   │   ├── main.py
│   │   ├── models/
│   │   │   ├── __init__.py
│   │   │   ├── backbone.py
│   │   │   ├── deformable_detr.py
│   │   │   ├── deformable_transformer.py
│   │   │   ├── matcher.py
│   │   │   ├── ops/
│   │   │   │   ├── functions/
│   │   │   │   │   ├── __init__.py
│   │   │   │   │   └── ms_deform_attn_func.py
│   │   │   │   ├── make.sh
│   │   │   │   ├── modules/
│   │   │   │   │   ├── __init__.py
│   │   │   │   │   └── ms_deform_attn.py
│   │   │   │   ├── setup.py
│   │   │   │   ├── src/
│   │   │   │   │   ├── cpu/
│   │   │   │   │   │   ├── ms_deform_attn_cpu.cpp
│   │   │   │   │   │   └── ms_deform_attn_cpu.h
│   │   │   │   │   ├── cuda/
│   │   │   │   │   │   ├── ms_deform_attn_cuda.cu
│   │   │   │   │   │   ├── ms_deform_attn_cuda.h
│   │   │   │   │   │   └── ms_deform_im2col_cuda.cuh
│   │   │   │   │   ├── ms_deform_attn.h
│   │   │   │   │   └── vision.cpp
│   │   │   │   └── test.py
│   │   │   ├── position_encoding.py
│   │   │   └── segmentation.py
│   │   ├── requirements.txt
│   │   ├── tools/
│   │   │   ├── launch.py
│   │   │   ├── run_dist_launch.sh
│   │   │   └── run_dist_slurm.sh
│   │   └── util/
│   │       ├── __init__.py
│   │       ├── box_ops.py
│   │       ├── misc.py
│   │       ├── plot_utils.py
│   │       └── visualizer.py
│   ├── deit_share/
│   │   ├── .circleci/
│   │   │   └── config.yml
│   │   ├── .github/
│   │   │   ├── CODE_OF_CONDUCT.md
│   │   │   └── CONTRIBUTING.md
│   │   ├── .gitignore
│   │   ├── .idea/
│   │   │   ├── .gitignore
│   │   │   ├── deit_share.iml
│   │   │   ├── inspectionProfiles/
│   │   │   │   └── profiles_settings.xml
│   │   │   ├── misc.xml
│   │   │   ├── modules.xml
│   │   │   └── vcs.xml
│   │   ├── LICENSE
│   │   ├── README.md
│   │   ├── README_cait.md
│   │   ├── README_resmlp.md
│   │   ├── bt.py
│   │   ├── cait_models.py
│   │   ├── datasets.py
│   │   ├── engine.py
│   │   ├── gpu.pbs
│   │   ├── hubconf.py
│   │   ├── losses.py
│   │   ├── main.py
│   │   ├── models.py
│   │   ├── optimizer.py
│   │   ├── requirements.txt
│   │   ├── resmlp_models.py
│   │   ├── run_with_submitit.py
│   │   ├── samplers.py
│   │   ├── temp.txt
│   │   ├── tiny_img.py
│   │   ├── tox.ini
│   │   └── utils.py
│   └── detr/
│       ├── .circleci/
│       │   └── config.yml
│       ├── .github/
│       │   ├── CODE_OF_CONDUCT.md
│       │   ├── CONTRIBUTING.md
│       │   └── ISSUE_TEMPLATE/
│       │       ├── bugs.md
│       │       ├── questions-help-support.md
│       │       └── unexpected-problems-bugs.md
│       ├── .gitignore
│       ├── Dockerfile
│       ├── LICENSE
│       ├── README.md
│       ├── configs/
│       │   ├── base.sh
│       │   ├── panoptic.sh
│       │   ├── panoptic_1.sh
│       │   ├── panoptic_2.sh
│       │   └── swin.sh
│       ├── d2/
│       │   ├── README.md
│       │   ├── configs/
│       │   │   ├── detr_256_6_6_torchvision.yaml
│       │   │   └── detr_segm_256_6_6_torchvision.yaml
│       │   ├── converter.py
│       │   ├── detr/
│       │   │   ├── __init__.py
│       │   │   ├── config.py
│       │   │   ├── dataset_mapper.py
│       │   │   └── detr.py
│       │   └── train_net.py
│       ├── datasets/
│       │   ├── __init__.py
│       │   ├── coco.py
│       │   ├── coco_eval.py
│       │   ├── coco_panoptic.py
│       │   ├── panoptic_eval.py
│       │   └── transforms.py
│       ├── detr.pbs
│       ├── engine.py
│       ├── hubconf.py
│       ├── main.py
│       ├── models/
│       │   ├── __init__.py
│       │   ├── backbone.py
│       │   ├── detr.py
│       │   ├── matcher.py
│       │   ├── position_encoding.py
│       │   ├── segmentation.py
│       │   └── transformer.py
│       ├── requirements.txt
│       ├── run.py
│       ├── run_with_submitit.py
│       ├── test_all.py
│       ├── tools/
│       │   ├── launch.py
│       │   ├── run_dist_launch.sh
│       │   └── run_dist_slurm.sh
│       ├── tox.ini
│       └── util/
│           ├── __init__.py
│           ├── box_ops.py
│           ├── misc.py
│           └── plot_utils.py
├── czsl/
│   ├── LICENSE
│   ├── README.md
│   ├── configs/
│   │   ├── baselines/
│   │   │   ├── cgqa/
│   │   │   │   ├── aopp.yml
│   │   │   │   ├── le+.yml
│   │   │   │   ├── symnet.yml
│   │   │   │   └── tmn.yml
│   │   │   ├── mit/
│   │   │   │   ├── aopp.yml
│   │   │   │   ├── le+.yml
│   │   │   │   ├── symnet.yml
│   │   │   │   └── tmn.yml
│   │   │   └── utzppos/
│   │   │       ├── aopp.yml
│   │   │       ├── le+.yml
│   │   │       ├── symnet.yml
│   │   │       └── tmn.yml
│   │   ├── cge/
│   │   │   ├── cgqa.yml
│   │   │   ├── mit.yml
│   │   │   └── utzappos.yml
│   │   └── compcos/
│   │       ├── cgqa/
│   │       │   ├── compcos.yml
│   │       │   └── compcos_cw.yml
│   │       ├── mit/
│   │       │   ├── compcos.yml
│   │       │   └── compcos_cw.yml
│   │       └── utzppos/
│   │           ├── compcos.yml
│   │           └── compcos_cw.yml
│   ├── data/
│   │   ├── __init__.py
│   │   └── dataset.py
│   ├── environment.yml
│   ├── flags.py
│   ├── models/
│   │   ├── __init__.py
│   │   ├── common.py
│   │   ├── compcos.py
│   │   ├── gcn.py
│   │   ├── graph_method.py
│   │   ├── image_extractor.py
│   │   ├── manifold_methods.py
│   │   ├── modular_methods.py
│   │   ├── svm.py
│   │   ├── symnet.py
│   │   ├── visual_product.py
│   │   └── word_embedding.py
│   ├── notebooks/
│   │   └── analysis.ipynb
│   ├── test.py
│   ├── train.py
│   └── utils/
│       ├── __init__.py
│       ├── config_model.py
│       ├── download_data.sh
│       ├── download_embeddings.py
│       ├── reorganize_utzap.py
│       └── utils.py
├── domain_generalization/
│   ├── README.md
│   ├── Transfer-Learning-Library/
│   │   ├── .github/
│   │   │   └── ISSUE_TEMPLATE/
│   │   │       ├── bug_report.md
│   │   │       ├── custom.md
│   │   │       └── feature_request.md
│   │   ├── .gitignore
│   │   ├── CONTRIBUTING.md
│   │   ├── LICENSE
│   │   ├── README.md
│   │   ├── common/
│   │   │   ├── __init__.py
│   │   │   ├── loss/
│   │   │   │   └── __init__.py
│   │   │   ├── modules/
│   │   │   │   ├── __init__.py
│   │   │   │   ├── classifier.py
│   │   │   │   └── regressor.py
│   │   │   ├── utils/
│   │   │   │   ├── __init__.py
│   │   │   │   ├── analysis/
│   │   │   │   │   ├── __init__.py
│   │   │   │   │   ├── a_distance.py
│   │   │   │   │   └── tsne.py
│   │   │   │   ├── data.py
│   │   │   │   ├── logger.py
│   │   │   │   ├── meter.py
│   │   │   │   ├── metric/
│   │   │   │   │   ├── __init__.py
│   │   │   │   │   ├── keypoint_detection.py
│   │   │   │   │   └── reid.py
│   │   │   │   └── scheduler.py
│   │   │   └── vision/
│   │   │       ├── __init__.py
│   │   │       ├── datasets/
│   │   │       │   ├── __init__.py
│   │   │       │   ├── _util.py
│   │   │       │   ├── aircrafts.py
│   │   │       │   ├── coco70.py
│   │   │       │   ├── cub200.py
│   │   │       │   ├── digits.py
│   │   │       │   ├── domainnet.py
│   │   │       │   ├── dtd.py
│   │   │       │   ├── eurosat.py
│   │   │       │   ├── imagelist.py
│   │   │       │   ├── imagenet_r.py
│   │   │       │   ├── imagenet_sketch.py
│   │   │       │   ├── keypoint_detection/
│   │   │       │   │   ├── __init__.py
│   │   │       │   │   ├── freihand.py
│   │   │       │   │   ├── hand_3d_studio.py
│   │   │       │   │   ├── human36m.py
│   │   │       │   │   ├── keypoint_dataset.py
│   │   │       │   │   ├── lsp.py
│   │   │       │   │   ├── rendered_hand_pose.py
│   │   │       │   │   ├── surreal.py
│   │   │       │   │   └── util.py
│   │   │       │   ├── office31.py
│   │   │       │   ├── officecaltech.py
│   │   │       │   ├── officehome.py
│   │   │       │   ├── openset/
│   │   │       │   │   └── __init__.py
│   │   │       │   ├── oxfordflowers.py
│   │   │       │   ├── oxfordpet.py
│   │   │       │   ├── pacs.py
│   │   │       │   ├── partial/
│   │   │       │   │   ├── __init__.py
│   │   │       │   │   ├── caltech_imagenet.py
│   │   │       │   │   └── imagenet_caltech.py
│   │   │       │   ├── patchcamelyon.py
│   │   │       │   ├── regression/
│   │   │       │   │   ├── __init__.py
│   │   │       │   │   ├── dsprites.py
│   │   │       │   │   ├── image_regression.py
│   │   │       │   │   └── mpi3d.py
│   │   │       │   ├── reid/
│   │   │       │   │   ├── __init__.py
│   │   │       │   │   ├── basedataset.py
│   │   │       │   │   ├── convert.py
│   │   │       │   │   ├── dukemtmc.py
│   │   │       │   │   ├── market1501.py
│   │   │       │   │   ├── msmt17.py
│   │   │       │   │   ├── personx.py
│   │   │       │   │   └── unreal.py
│   │   │       │   ├── resisc45.py
│   │   │       │   ├── retinopathy.py
│   │   │       │   ├── segmentation/
│   │   │       │   │   ├── __init__.py
│   │   │       │   │   ├── cityscapes.py
│   │   │       │   │   ├── gta5.py
│   │   │       │   │   ├── segmentation_list.py
│   │   │       │   │   └── synthia.py
│   │   │       │   ├── stanford_cars.py
│   │   │       │   ├── stanford_dogs.py
│   │   │       │   └── visda2017.py
│   │   │       ├── models/
│   │   │       │   ├── __init__.py
│   │   │       │   ├── digits.py
│   │   │       │   ├── ibn.py
│   │   │       │   ├── keypoint_detection/
│   │   │       │   │   ├── __init__.py
│   │   │       │   │   ├── loss.py
│   │   │       │   │   └── pose_resnet.py
│   │   │       │   ├── reid/
│   │   │       │   │   ├── __init__.py
│   │   │       │   │   ├── identifier.py
│   │   │       │   │   ├── loss.py
│   │   │       │   │   └── resnet.py
│   │   │       │   ├── resnet.py
│   │   │       │   └── segmentation/
│   │   │       │       ├── __init__.py
│   │   │       │       └── deeplabv2.py
│   │   │       └── transforms/
│   │   │           ├── __init__.py
│   │   │           ├── keypoint_detection.py
│   │   │           └── segmentation.py
│   │   ├── dalib/
│   │   │   ├── __init__.py
│   │   │   ├── adaptation/
│   │   │   │   ├── __init__.py
│   │   │   │   ├── adda.py
│   │   │   │   ├── advent.py
│   │   │   │   ├── afn.py
│   │   │   │   ├── bsp.py
│   │   │   │   ├── cdan.py
│   │   │   │   ├── dan.py
│   │   │   │   ├── dann.py
│   │   │   │   ├── fda.py
│   │   │   │   ├── idm/
│   │   │   │   │   ├── __init__.py
│   │   │   │   │   ├── loss.py
│   │   │   │   │   ├── models/
│   │   │   │   │   │   ├── __init__.py
│   │   │   │   │   │   ├── dsbn.py
│   │   │   │   │   │   ├── identifier.py
│   │   │   │   │   │   ├── idm.py
│   │   │   │   │   │   └── resnet.py
│   │   │   │   │   ├── utils.py
│   │   │   │   │   └── xbm.py
│   │   │   │   ├── iwan.py
│   │   │   │   ├── jan.py
│   │   │   │   ├── mcc.py
│   │   │   │   ├── mcd.py
│   │   │   │   ├── mdd.py
│   │   │   │   ├── osbp.py
│   │   │   │   ├── pada.py
│   │   │   │   ├── regda.py
│   │   │   │   ├── rsd.py
│   │   │   │   └── self_ensemble.py
│   │   │   ├── modules/
│   │   │   │   ├── __init__.py
│   │   │   │   ├── domain_discriminator.py
│   │   │   │   ├── entropy.py
│   │   │   │   ├── gl.py
│   │   │   │   ├── grl.py
│   │   │   │   └── kernels.py
│   │   │   └── translation/
│   │   │       ├── __init__.py
│   │   │       ├── cycada.py
│   │   │       ├── cyclegan/
│   │   │       │   ├── __init__.py
│   │   │       │   ├── discriminator.py
│   │   │       │   ├── generator.py
│   │   │       │   ├── loss.py
│   │   │       │   ├── transform.py
│   │   │       │   └── util.py
│   │   │       ├── fourier_transform.py
│   │   │       └── spgan/
│   │   │           ├── __init__.py
│   │   │           ├── loss.py
│   │   │           └── siamese.py
│   │   ├── dglib/
│   │   │   ├── __init__.py
│   │   │   ├── generalization/
│   │   │   │   ├── __init__.py
│   │   │   │   ├── coral.py
│   │   │   │   ├── groupdro.py
│   │   │   │   ├── irm.py
│   │   │   │   └── mixstyle/
│   │   │   │       ├── __init__.py
│   │   │   │       ├── models/
│   │   │   │       │   ├── __init__.py
│   │   │   │       │   ├── mixstyle.py
│   │   │   │       │   └── resnet.py
│   │   │   │       └── sampler.py
│   │   │   └── modules/
│   │   │       ├── __init__.py
│   │   │       ├── classifier.py
│   │   │       └── sampler.py
│   │   ├── docs/
│   │   │   ├── Makefile
│   │   │   ├── common/
│   │   │   │   ├── loss.rst
│   │   │   │   ├── modules.rst
│   │   │   │   ├── utils/
│   │   │   │   │   ├── analysis.rst
│   │   │   │   │   ├── base.rst
│   │   │   │   │   └── metric.rst
│   │   │   │   └── vision/
│   │   │   │       ├── datasets.rst
│   │   │   │       ├── models.rst
│   │   │   │       └── transforms.rst
│   │   │   ├── conf.py
│   │   │   ├── dalib/
│   │   │   │   ├── adaptation/
│   │   │   │   │   ├── domain_adversarial.rst
│   │   │   │   │   ├── domain_translation.rst
│   │   │   │   │   ├── hypothesis_adversarial.rst
│   │   │   │   │   ├── others.rst
│   │   │   │   │   └── statistics_matching.rst
│   │   │   │   ├── benchmarks/
│   │   │   │   │   ├── image_classification.rst
│   │   │   │   │   ├── image_regression.rst
│   │   │   │   │   ├── keypoint_detection.rst
│   │   │   │   │   ├── multi_source_domain_adaptation.rst
│   │   │   │   │   ├── openset_domain_adaptation.rst
│   │   │   │   │   ├── partial_domain_adaptation.rst
│   │   │   │   │   ├── re_identification.rst
│   │   │   │   │   └── semantic_segmentation.rst
│   │   │   │   └── modules.rst
│   │   │   ├── dglib/
│   │   │   │   ├── benchmarks/
│   │   │   │   │   ├── image_classification.rst
│   │   │   │   │   └── re_identification.rst
│   │   │   │   ├── generalization/
│   │   │   │   │   ├── architecture_design.rst
│   │   │   │   │   ├── data_manipulation.rst
│   │   │   │   │   ├── learning_strategy.rst
│   │   │   │   │   └── representation_learning.rst
│   │   │   │   └── modules.rst
│   │   │   ├── get_started/
│   │   │   │   ├── faq.rst
│   │   │   │   ├── installing.rst
│   │   │   │   ├── introduction.rst
│   │   │   │   ├── quickstart.rst
│   │   │   │   └── visualization.rst
│   │   │   ├── index.rst
│   │   │   ├── make.bat
│   │   │   ├── requirements.txt
│   │   │   └── talib/
│   │   │       ├── benchmarks/
│   │   │       │   └── image_classification.rst
│   │   │       └── finetune.rst
│   │   ├── examples/
│   │   │   ├── domain_adaptation/
│   │   │   │   ├── image_classification/
│   │   │   │   │   ├── README.md
│   │   │   │   │   ├── adda.py
│   │   │   │   │   ├── adda.sh
│   │   │   │   │   ├── addagrl.py
│   │   │   │   │   ├── addagrl.sh
│   │   │   │   │   ├── afn.py
│   │   │   │   │   ├── afn.sh
│   │   │   │   │   ├── bsp.py
│   │   │   │   │   ├── bsp.sh
│   │   │   │   │   ├── cdan.py
│   │   │   │   │   ├── cdan.sh
│   │   │   │   │   ├── dan.py
│   │   │   │   │   ├── dan.sh
│   │   │   │   │   ├── dann.py
│   │   │   │   │   ├── dann.sh
│   │   │   │   │   ├── gpu_dann.pbs
│   │   │   │   │   ├── gpu_mcc.pbs
│   │   │   │   │   ├── gpu_mdd.pbs
│   │   │   │   │   ├── jan.py
│   │   │   │   │   ├── jan.sh
│   │   │   │   │   ├── mcc.py
│   │   │   │   │   ├── mcc.sh
│   │   │   │   │   ├── mcd.py
│   │   │   │   │   ├── mcd.sh
│   │   │   │   │   ├── mdd.py
│   │   │   │   │   ├── mdd.sh
│   │   │   │   │   ├── requirements.txt
│   │   │   │   │   ├── self_ensemble.py
│   │   │   │   │   ├── self_ensemble.sh
│   │   │   │   │   ├── source_only.py
│   │   │   │   │   ├── source_only.sh
│   │   │   │   │   └── utils.py
│   │   │   │   ├── image_regression/
│   │   │   │   │   ├── README.md
│   │   │   │   │   ├── dann.py
│   │   │   │   │   ├── dann.sh
│   │   │   │   │   ├── dd.py
│   │   │   │   │   ├── dd.sh
│   │   │   │   │   ├── rsd.py
│   │   │   │   │   ├── rsd.sh
│   │   │   │   │   ├── source_only.py
│   │   │   │   │   ├── source_only.sh
│   │   │   │   │   └── utils.py
│   │   │   │   ├── keypoint_detection/
│   │   │   │   │   ├── README.md
│   │   │   │   │   ├── regda.py
│   │   │   │   │   ├── regda.sh
│   │   │   │   │   ├── regda_fast.py
│   │   │   │   │   ├── regda_fast.sh
│   │   │   │   │   ├── source_only.py
│   │   │   │   │   └── source_only.sh
│   │   │   │   ├── openset_domain_adaptation/
│   │   │   │   │   ├── README.md
│   │   │   │   │   ├── dann.py
│   │   │   │   │   ├── dann.sh
│   │   │   │   │   ├── osbp.py
│   │   │   │   │   ├── osbp.sh
│   │   │   │   │   ├── source_only.py
│   │   │   │   │   ├── source_only.sh
│   │   │   │   │   └── utils.py
│   │   │   │   ├── partial_domain_adaptation/
│   │   │   │   │   ├── README.md
│   │   │   │   │   ├── afn.py
│   │   │   │   │   ├── afn.sh
│   │   │   │   │   ├── dann.py
│   │   │   │   │   ├── dann.sh
│   │   │   │   │   ├── iwan.py
│   │   │   │   │   ├── iwan.sh
│   │   │   │   │   ├── pada.py
│   │   │   │   │   ├── pada.sh
│   │   │   │   │   ├── requirements.txt
│   │   │   │   │   ├── source_only.py
│   │   │   │   │   ├── source_only.sh
│   │   │   │   │   └── utils.py
│   │   │   │   ├── re_identification/
│   │   │   │   │   ├── README.md
│   │   │   │   │   ├── baseline.py
│   │   │   │   │   ├── baseline.sh
│   │   │   │   │   ├── baseline_cluster.py
│   │   │   │   │   ├── baseline_cluster.sh
│   │   │   │   │   ├── ibn.sh
│   │   │   │   │   ├── idm.py
│   │   │   │   │   ├── idm.sh
│   │   │   │   │   ├── mmt.py
│   │   │   │   │   ├── mmt.sh
│   │   │   │   │   ├── requirements.txt
│   │   │   │   │   ├── spgan.py
│   │   │   │   │   ├── spgan.sh
│   │   │   │   │   └── utils.py
│   │   │   │   └── semantic_segmentation/
│   │   │   │       ├── README.md
│   │   │   │       ├── advent.py
│   │   │   │       ├── advent.sh
│   │   │   │       ├── cycada.py
│   │   │   │       ├── cycada.sh
│   │   │   │       ├── cycle_gan.py
│   │   │   │       ├── cycle_gan.sh
│   │   │   │       ├── fda.py
│   │   │   │       ├── fda.sh
│   │   │   │       ├── source_only.py
│   │   │   │       └── source_only.sh
│   │   │   ├── domain_generalization/
│   │   │   │   ├── image_classification/
│   │   │   │   │   ├── README.md
│   │   │   │   │   ├── baseline.py
│   │   │   │   │   ├── baseline.sh
│   │   │   │   │   ├── coral.py
│   │   │   │   │   ├── coral.sh
│   │   │   │   │   ├── gpu_base.pbs
│   │   │   │   │   ├── gpu_coral.pbs
│   │   │   │   │   ├── gpu_irm.pbs
│   │   │   │   │   ├── groupdro.py
│   │   │   │   │   ├── groupdro.sh
│   │   │   │   │   ├── ibn.sh
│   │   │   │   │   ├── irm.py
│   │   │   │   │   ├── irm.sh
│   │   │   │   │   ├── mixstyle.py
│   │   │   │   │   ├── mixstyle.sh
│   │   │   │   │   ├── mldg.py
│   │   │   │   │   ├── mldg.sh
│   │   │   │   │   ├── requirements.txt
│   │   │   │   │   ├── utils.py
│   │   │   │   │   ├── vrex.py
│   │   │   │   │   └── vrex.sh
│   │   │   │   └── re_identification/
│   │   │   │       ├── README.md
│   │   │   │       ├── baseline.py
│   │   │   │       ├── baseline.sh
│   │   │   │       ├── ibn.sh
│   │   │   │       ├── mixstyle.py
│   │   │   │       ├── mixstyle.sh
│   │   │   │       ├── requirements.txt
│   │   │   │       └── utils.py
│   │   │   └── task_adaptation/
│   │   │       └── image_classification/
│   │   │           ├── README.md
│   │   │           ├── baseline.py
│   │   │           ├── baseline.sh
│   │   │           ├── bi_tuning.py
│   │   │           ├── bi_tuning.sh
│   │   │           ├── bss.py
│   │   │           ├── bss.sh
│   │   │           ├── co_tuning.py
│   │   │           ├── co_tuning.sh
│   │   │           ├── convert_moco_to_pretrained.py
│   │   │           ├── delta.py
│   │   │           ├── delta.sh
│   │   │           ├── lwf.py
│   │   │           ├── lwf.sh
│   │   │           ├── requirements.txt
│   │   │           ├── stochnorm.py
│   │   │           ├── stochnorm.sh
│   │   │           └── utils.py
│   │   ├── requirements.txt
│   │   ├── setup.py
│   │   └── talib/
│   │       ├── __init__.py
│   │       └── finetune/
│   │           ├── __init__.py
│   │           ├── bi_tuning.py
│   │           ├── bss.py
│   │           ├── co_tuning.py
│   │           ├── delta.py
│   │           ├── lwf.py
│   │           └── stochnorm.py
│   ├── baseline.py
│   ├── coral.py
│   ├── irm.py
│   ├── mixstyle.py
│   └── swad/
│       ├── .gitignore
│       ├── LICENSE
│       ├── README.md
│       ├── config.yaml
│       ├── domainbed/
│       │   ├── algorithms/
│       │   │   ├── __init__.py
│       │   │   └── algorithms.py
│       │   ├── datasets/
│       │   │   ├── __init__.py
│       │   │   ├── datasets.py
│       │   │   └── transforms.py
│       │   ├── evaluator.py
│       │   ├── hparams_registry.py
│       │   ├── lib/
│       │   │   ├── fast_data_loader.py
│       │   │   ├── logger.py
│       │   │   ├── misc.py
│       │   │   ├── query.py
│       │   │   ├── swa_utils.py
│       │   │   ├── wide_resnet.py
│       │   │   └── writers.py
│       │   ├── lr_scheduler/
│       │   │   ├── __init__.py
│       │   │   └── lr_scheduler.py
│       │   ├── misc/
│       │   │   └── domain_net_duplicates.txt
│       │   ├── models/
│       │   │   ├── mixstyle.py
│       │   │   ├── resnet_mixstyle.py
│       │   │   └── resnet_mixstyle2.py
│       │   ├── networks.py
│       │   ├── optimizers.py
│       │   ├── scripts/
│       │   │   └── download.py
│       │   ├── swad.py
│       │   └── trainer.py
│       ├── requirements.txt
│       └── train_all.py
├── long-tailed_recognition/
│   ├── BalancedSoftmax/
│   │   ├── .gitignore
│   │   ├── CODE_OF_CONDUCT.md
│   │   ├── CONTRIBUTING.md
│   │   ├── LICENSE
│   │   ├── README.md
│   │   ├── cls_freq/
│   │   │   ├── CIFAR-10-LT_IMBA100.json
│   │   │   ├── CIFAR-10-LT_IMBA200.json
│   │   │   ├── CIFAR-100-LT_IMBA1.json
│   │   │   ├── CIFAR-100-LT_IMBA100.json
│   │   │   ├── CIFAR-100-LT_IMBA200.json
│   │   │   ├── ImageNet_LT.json
│   │   │   ├── Places_LT.json
│   │   │   └── iNaturalist18.json
│   │   ├── config/
│   │   │   ├── CIFAR100_LT/
│   │   │   │   ├── balanced_softmax_imba100.yaml
│   │   │   │   ├── balanced_softmax_imba200.yaml
│   │   │   │   ├── balms_imba100.yaml
│   │   │   │   ├── balms_imba200.yaml
│   │   │   │   ├── decouple_balanced_softmax_imba100.yaml
│   │   │   │   ├── decouple_balanced_softmax_imba200.yaml
│   │   │   │   ├── softmax_imba.yaml
│   │   │   │   ├── softmax_imba100.yaml
│   │   │   │   └── softmax_imba200.yaml
│   │   │   ├── CIFAR10_LT/
│   │   │   │   ├── balanced_softmax_imba200.yaml
│   │   │   │   ├── balms_imba200.yaml
│   │   │   │   ├── decouple_balanced_softmax_imba200.yaml
│   │   │   │   └── softmax_imba200.yaml
│   │   │   ├── ImageNet_LT/
│   │   │   │   ├── balanced_softmax_resnet10.yaml
│   │   │   │   ├── balanced_softmax_resnet50.yaml
│   │   │   │   ├── balms_resnet10.yaml
│   │   │   │   ├── balms_resnet50.yaml
│   │   │   │   ├── cls_crt.yaml
│   │   │   │   ├── cls_lws.yaml
│   │   │   │   ├── decouple_balanced_softmax_resnet10.yaml
│   │   │   │   ├── feat_balance.yaml
│   │   │   │   ├── feat_shift.yaml
│   │   │   │   ├── feat_squareroot.yaml
│   │   │   │   ├── feat_uniform.yaml
│   │   │   │   ├── feat_uniform_resnet10.yaml
│   │   │   │   ├── feat_uniform_resnet50.yaml
│   │   │   │   ├── softmax_resnet10.yaml
│   │   │   │   └── softmax_resnet50_feat.yaml
│   │   │   ├── Places_LT/
│   │   │   │   ├── balanced_softmax.yaml
│   │   │   │   ├── balms.yaml
│   │   │   │   ├── cls_crt.yaml
│   │   │   │   ├── cls_lws.yaml
│   │   │   │   ├── decouple_balanced_softmax.yaml
│   │   │   │   └── feat_unifrom.yaml
│   │   │   └── iNaturalist18/
│   │   │       ├── balanced_softmax.yaml
│   │   │       ├── cls_crt.yaml
│   │   │       ├── cls_lws.yaml
│   │   │       └── feat_unifrom.yaml
│   │   ├── data/
│   │   │   ├── ClassAwareSampler.py
│   │   │   ├── ClassPrioritySampler.py
│   │   │   ├── ImageNet/
│   │   │   │   ├── ImageNet_train.txt
│   │   │   │   ├── ImageNet_val.txt
│   │   │   │   └── gen_txt.py
│   │   │   ├── ImageNet_LT/
│   │   │   │   ├── ImageNet_LT_test.txt
│   │   │   │   ├── ImageNet_LT_train.txt
│   │   │   │   ├── ImageNet_LT_val.txt
│   │   │   │   └── class_labels
│   │   │   ├── ImbalanceCIFAR.py
│   │   │   ├── MetaSampler.py
│   │   │   ├── MixedPrioritizedSampler.py
│   │   │   ├── Places_LT/
│   │   │   │   ├── Places_LT_test.txt
│   │   │   │   ├── Places_LT_train.txt
│   │   │   │   └── Places_LT_val.txt
│   │   │   ├── autoaugment.py
│   │   │   ├── dataloader.py
│   │   │   └── iNaturalist18/
│   │   │       ├── gen_lists.py
│   │   │       ├── iNaturalist18_train.txt
│   │   │       └── iNaturalist18_val.txt
│   │   ├── encoder_network.py
│   │   ├── grads_analysis.py
│   │   ├── layers/
│   │   │   └── ModulatedAttLayer.py
│   │   ├── logger.py
│   │   ├── loss/
│   │   │   ├── BalancedSoftmaxLoss.py
│   │   │   ├── DiscCentroidsLoss.py
│   │   │   └── SoftmaxLoss.py
│   │   ├── main.py
│   │   ├── models/
│   │   │   ├── CosNormClassifier.py
│   │   │   ├── DotProductClassifier.py
│   │   │   ├── KNNClassifier.py
│   │   │   ├── MetaEmbeddingClassifier.py
│   │   │   ├── ResNet101Feature.py
│   │   │   ├── ResNet10Feature.py
│   │   │   ├── ResNet152Feature.py
│   │   │   ├── ResNet152FeatureCaffe.py
│   │   │   ├── ResNet32Feature.py
│   │   │   ├── ResNet50Feature.py
│   │   │   ├── ResNetFeature.py
│   │   │   ├── ResNext101Feature.py
│   │   │   ├── ResNext152Feature.py
│   │   │   ├── ResNext50Feature.py
│   │   │   ├── ResNextFeature.py
│   │   │   └── TauNormClassifier.py
│   │   ├── run_networks.py
│   │   └── utils.py
│   ├── README.md
│   └── RIDE-LongTailRecognition/
│       ├── .flake8
│       ├── .github/
│       │   └── ISSUE_TEMPLATE/
│       │       ├── conceptual-questions.md
│       │       ├── error-report.md
│       │       ├── feature_request.md
│       │       └── other-problems.md
│       ├── .gitignore
│       ├── FAQ.md
│       ├── LICENSE
│       ├── README.md
│       ├── base/
│       │   ├── __init__.py
│       │   ├── base_data_loader.py
│       │   ├── base_model.py
│       │   └── base_trainer.py
│       ├── config.json
│       ├── configs/
│       │   ├── config_iNaturalist_resnet50_distill_ride.json
│       │   ├── config_iNaturalist_resnet50_distill_ride_dist.json
│       │   ├── config_iNaturalist_resnet50_ride.json
│       │   ├── config_iNaturalist_resnet50_ride_dist.json
│       │   ├── config_iNaturalist_resnet50_ride_dist1.json
│       │   ├── config_iNaturalist_resnet50_ride_ea.json
│       │   ├── config_imagenet_lt_resnet10_distill_ride.json
│       │   ├── config_imagenet_lt_resnet10_ride.json
│       │   ├── config_imagenet_lt_resnet10_ride1.json
│       │   ├── config_imagenet_lt_resnet10_ride_base.json
│       │   ├── config_imagenet_lt_resnet10_ride_base1.json
│       │   ├── config_imagenet_lt_resnet10_ride_base_dist.json
│       │   ├── config_imagenet_lt_resnet10_ride_ea.json
│       │   ├── config_imagenet_lt_resnet50_distill_ride.json
│       │   ├── config_imagenet_lt_resnet50_distill_ride_dist.json
│       │   ├── config_imagenet_lt_resnet50_ride.json
│       │   ├── config_imagenet_lt_resnet50_ride_base.json
│       │   ├── config_imagenet_lt_resnet50_ride_base_dist.json
│       │   ├── config_imagenet_lt_resnet50_ride_cos.json
│       │   ├── config_imagenet_lt_resnet50_ride_dist.json
│       │   ├── config_imagenet_lt_resnet50_ride_dist_cos.json
│       │   ├── config_imagenet_lt_resnet50_ride_ea.json
│       │   ├── config_imagenet_lt_resnext50_distill_ride.json
│       │   ├── config_imagenet_lt_resnext50_ride.json
│       │   ├── config_imagenet_lt_resnext50_ride_dist.json
│       │   ├── config_imagenet_lt_resnext50_ride_ea.json
│       │   ├── config_imbalance_cifar100_distill_ride.json
│       │   ├── config_imbalance_cifar100_ldam_drw.json
│       │   ├── config_imbalance_cifar100_ride.json
│       │   ├── config_imbalance_cifar100_ride_base.json
│       │   ├── config_imbalance_cifar100_ride_ea.json
│       │   └── config_imbalance_cifar100_ride_teacher.json
│       ├── contributing.md
│       ├── data_loader/
│       │   ├── __init__.py
│       │   ├── cifar_data_loaders.py
│       │   ├── data_loaders.py
│       │   ├── imagenet_lt_data_loaders.py
│       │   ├── imbalance_cifar.py
│       │   └── inaturalist_data_loaders.py
│       ├── logger/
│       │   ├── __init__.py
│       │   ├── logger.py
│       │   ├── logger_config.json
│       │   └── visualization.py
│       ├── model/
│       │   ├── fb_resnets/
│       │   │   ├── EAResNeXt.py
│       │   │   ├── EAResNet.py
│       │   │   ├── RIDEResNeXt.py
│       │   │   ├── RIDEResNet.py
│       │   │   ├── ResNeXt.py
│       │   │   ├── ResNet.py
│       │   │   └── __init__.py
│       │   ├── ldam_drw_resnets/
│       │   │   ├── __init__.py
│       │   │   ├── ea_resnet_cifar.py
│       │   │   ├── resnet_cifar.py
│       │   │   └── ride_resnet_cifar.py
│       │   ├── loss.py
│       │   ├── metric.py
│       │   └── model.py
│       ├── new_project.py
│       ├── parse_config.py
│       ├── requirements.txt
│       ├── run.py
│       ├── run_imagenet.py
│       ├── t-normalization.py
│       ├── test.py
│       ├── test_lt.sh
│       ├── train.py
│       ├── train_dist.py
│       ├── trainer/
│       │   ├── __init__.py
│       │   └── trainer.py
│       └── utils/
│           ├── __init__.py
│           ├── gflops.py
│           └── util.py
└── moco-v3/
    ├── CODE_OF_CONDUCT.md
    ├── CONFIG.md
    ├── CONTRIBUTING.md
    ├── LICENSE
    ├── README.md
    ├── main_lincls.py
    ├── main_moco.py
    ├── moco/
    │   ├── __init__.py
    │   ├── builder.py
    │   ├── builder_v2.py
    │   ├── loader.py
    │   └── optimizer.py
    ├── transfer/
    │   ├── README.md
    │   ├── datasets.py
    │   ├── oxford_flowers_dataset.py
    │   └── oxford_pets_dataset.py
    └── vits.py
Download .txt
Showing preview only (254K chars total). Download the full file or copy to clipboard to get everything.
SYMBOL INDEX (2960 symbols across 378 files)

FILE: batchformer-v2/deformable-detr/benchmark.py
  function get_benckmark_arg_parser (line 22) | def get_benckmark_arg_parser():
  function measure_average_inference_time (line 32) | def measure_average_inference_time(model, inputs, num_iters=100, warm_it...
  function benchmark (line 46) | def benchmark():

FILE: batchformer-v2/deformable-detr/datasets/__init__.py
  function get_coco_api_from_dataset (line 16) | def get_coco_api_from_dataset(dataset):
  function build_dataset (line 26) | def build_dataset(image_set, args):

FILE: batchformer-v2/deformable-detr/datasets/coco.py
  class CocoDetection (line 26) | class CocoDetection(TvCocoDetection):
    method __init__ (line 27) | def __init__(self, img_folder, ann_file, transforms, return_masks, cac...
    method __getitem__ (line 33) | def __getitem__(self, idx):
  function convert_coco_poly_to_mask (line 43) | def convert_coco_poly_to_mask(segmentations, height, width):
  class ConvertCocoPolysToMask (line 60) | class ConvertCocoPolysToMask(object):
    method __init__ (line 61) | def __init__(self, return_masks=False):
    method __call__ (line 64) | def __call__(self, image, target):
  function make_coco_transforms (line 125) | def make_coco_transforms(image_set):
  function build (line 157) | def build(image_set, args):

FILE: batchformer-v2/deformable-detr/datasets/coco_eval.py
  class CocoEvaluator (line 30) | class CocoEvaluator(object):
    method __init__ (line 31) | def __init__(self, coco_gt, iou_types):
    method update (line 44) | def update(self, predictions):
    method synchronize_between_processes (line 63) | def synchronize_between_processes(self):
    method accumulate (line 68) | def accumulate(self):
    method summarize (line 72) | def summarize(self):
    method prepare (line 77) | def prepare(self, predictions, iou_type):
    method prepare_for_coco_detection (line 87) | def prepare_for_coco_detection(self, predictions):
    method prepare_for_coco_segmentation (line 111) | def prepare_for_coco_segmentation(self, predictions):
    method prepare_for_coco_keypoint (line 146) | def prepare_for_coco_keypoint(self, predictions):
  function convert_to_xywh (line 173) | def convert_to_xywh(boxes):
  function merge (line 178) | def merge(img_ids, eval_imgs):
  function create_common_coco_eval (line 200) | def create_common_coco_eval(coco_eval, img_ids, eval_imgs):
  function evaluate (line 216) | def evaluate(self):

FILE: batchformer-v2/deformable-detr/datasets/coco_panoptic.py
  class CocoPanoptic (line 23) | class CocoPanoptic:
    method __init__ (line 24) | def __init__(self, img_folder, ann_folder, ann_file, transforms=None, ...
    method __getitem__ (line 42) | def __getitem__(self, idx):
    method __len__ (line 78) | def __len__(self):
    method get_height_and_width (line 81) | def get_height_and_width(self, idx):
  function build (line 88) | def build(image_set, args):

FILE: batchformer-v2/deformable-detr/datasets/data_prefetcher.py
  function to_cuda (line 9) | def to_cuda(samples, targets, device):
  class data_prefetcher (line 14) | class data_prefetcher():
    method __init__ (line 15) | def __init__(self, loader, device, prefetch=True):
    method preload (line 23) | def preload(self):
    method next (line 51) | def next(self):

FILE: batchformer-v2/deformable-detr/datasets/panoptic_eval.py
  class PanopticEvaluator (line 21) | class PanopticEvaluator(object):
    method __init__ (line 22) | def __init__(self, ann_file, ann_folder, output_dir="panoptic_eval"):
    method update (line 31) | def update(self, predictions):
    method synchronize_between_processes (line 38) | def synchronize_between_processes(self):
    method summarize (line 45) | def summarize(self):

FILE: batchformer-v2/deformable-detr/datasets/samplers.py
  class DistributedSampler (line 16) | class DistributedSampler(Sampler):
    method __init__ (line 31) | def __init__(self, dataset, num_replicas=None, rank=None, local_rank=N...
    method __iter__ (line 48) | def __iter__(self):
    method __len__ (line 68) | def __len__(self):
    method set_epoch (line 71) | def set_epoch(self, epoch):
  class NodeDistributedSampler (line 75) | class NodeDistributedSampler(Sampler):
    method __init__ (line 90) | def __init__(self, dataset, num_replicas=None, rank=None, local_rank=N...
    method __iter__ (line 115) | def __iter__(self):
    method __len__ (line 135) | def __len__(self):
    method set_epoch (line 138) | def set_epoch(self, epoch):

FILE: batchformer-v2/deformable-detr/datasets/torchvision_datasets/coco.py
  class CocoDetection (line 20) | class CocoDetection(VisionDataset):
    method __init__ (line 33) | def __init__(self, root, annFile, transform=None, target_transform=Non...
    method cache_images (line 46) | def cache_images(self):
    method get_image (line 55) | def get_image(self, path):
    method __getitem__ (line 63) | def __getitem__(self, index):
    method __len__ (line 83) | def __len__(self):

FILE: batchformer-v2/deformable-detr/datasets/transforms.py
  function crop (line 24) | def crop(image, target, region):
  function hflip (line 67) | def hflip(image, target):
  function resize (line 84) | def resize(image, target, size, max_size=None):
  function pad (line 143) | def pad(image, target, padding):
  class RandomCrop (line 156) | class RandomCrop(object):
    method __init__ (line 157) | def __init__(self, size):
    method __call__ (line 160) | def __call__(self, img, target):
  class RandomSizeCrop (line 165) | class RandomSizeCrop(object):
    method __init__ (line 166) | def __init__(self, min_size: int, max_size: int):
    method __call__ (line 170) | def __call__(self, img: PIL.Image.Image, target: dict):
  class CenterCrop (line 177) | class CenterCrop(object):
    method __init__ (line 178) | def __init__(self, size):
    method __call__ (line 181) | def __call__(self, img, target):
  class RandomHorizontalFlip (line 189) | class RandomHorizontalFlip(object):
    method __init__ (line 190) | def __init__(self, p=0.5):
    method __call__ (line 193) | def __call__(self, img, target):
  class RandomResize (line 199) | class RandomResize(object):
    method __init__ (line 200) | def __init__(self, sizes, max_size=None):
    method __call__ (line 205) | def __call__(self, img, target=None):
  class RandomPad (line 210) | class RandomPad(object):
    method __init__ (line 211) | def __init__(self, max_pad):
    method __call__ (line 214) | def __call__(self, img, target):
  class RandomSelect (line 220) | class RandomSelect(object):
    method __init__ (line 225) | def __init__(self, transforms1, transforms2, p=0.5):
    method __call__ (line 230) | def __call__(self, img, target):
  class ToTensor (line 236) | class ToTensor(object):
    method __call__ (line 237) | def __call__(self, img, target):
  class RandomErasing (line 241) | class RandomErasing(object):
    method __init__ (line 243) | def __init__(self, *args, **kwargs):
    method __call__ (line 246) | def __call__(self, img, target):
  class Normalize (line 250) | class Normalize(object):
    method __init__ (line 251) | def __init__(self, mean, std):
    method __call__ (line 255) | def __call__(self, image, target=None):
  class Compose (line 269) | class Compose(object):
    method __init__ (line 270) | def __init__(self, transforms):
    method __call__ (line 273) | def __call__(self, image, target):
    method __repr__ (line 278) | def __repr__(self):

FILE: batchformer-v2/deformable-detr/engine.py
  function train_one_epoch (line 25) | def train_one_epoch(model: torch.nn.Module, criterion: torch.nn.Module,
  function evaluate (line 85) | def evaluate(model, criterion, postprocessors, data_loader, base_ds, dev...

FILE: batchformer-v2/deformable-detr/main.py
  function get_args_parser (line 29) | def get_args_parser():
  function main (line 136) | def main(args):

FILE: batchformer-v2/deformable-detr/models/__init__.py
  function build_model (line 13) | def build_model(args):

FILE: batchformer-v2/deformable-detr/models/backbone.py
  class FrozenBatchNorm2d (line 27) | class FrozenBatchNorm2d(torch.nn.Module):
    method __init__ (line 36) | def __init__(self, n, eps=1e-5):
    method _load_from_state_dict (line 44) | def _load_from_state_dict(self, state_dict, prefix, local_metadata, st...
    method forward (line 54) | def forward(self, x):
  class BackboneBase (line 67) | class BackboneBase(nn.Module):
    method __init__ (line 69) | def __init__(self, backbone: nn.Module, train_backbone: bool, return_i...
    method forward (line 85) | def forward(self, tensor_list: NestedTensor):
  class Backbone (line 96) | class Backbone(BackboneBase):
    method __init__ (line 98) | def __init__(self, name: str,
  class Joiner (line 112) | class Joiner(nn.Sequential):
    method __init__ (line 113) | def __init__(self, backbone, position_embedding):
    method forward (line 118) | def forward(self, tensor_list: NestedTensor):
  function build_backbone (line 132) | def build_backbone(args):

FILE: batchformer-v2/deformable-detr/models/deformable_detr.py
  function _get_clones (line 31) | def _get_clones(module, N):
  class DeformableDETR (line 35) | class DeformableDETR(nn.Module):
    method __init__ (line 37) | def __init__(self, backbone, transformer, num_classes, num_queries, nu...
    method forward (line 114) | def forward(self, samples: NestedTensor):
    method _set_aux_loss (line 190) | def _set_aux_loss(self, outputs_class, outputs_coord):
  class SetCriterion (line 198) | class SetCriterion(nn.Module):
    method __init__ (line 204) | def __init__(self, num_classes, matcher, weight_dict, losses, focal_al...
    method loss_labels (line 220) | def loss_labels(self, outputs, targets, indices, num_boxes, log=True):
    method loss_cardinality (line 247) | def loss_cardinality(self, outputs, targets, indices, num_boxes):
    method loss_boxes (line 260) | def loss_boxes(self, outputs, targets, indices, num_boxes):
    method loss_masks (line 281) | def loss_masks(self, outputs, targets, indices, num_boxes):
    method _get_src_permutation_idx (line 310) | def _get_src_permutation_idx(self, indices):
    method _get_tgt_permutation_idx (line 316) | def _get_tgt_permutation_idx(self, indices):
    method get_loss (line 322) | def get_loss(self, loss, outputs, targets, indices, num_boxes, **kwargs):
    method forward (line 332) | def forward(self, outputs, targets):
  class PostProcess (line 394) | class PostProcess(nn.Module):
    method forward (line 398) | def forward(self, outputs, target_sizes):
  class MLP (line 429) | class MLP(nn.Module):
    method __init__ (line 432) | def __init__(self, input_dim, hidden_dim, output_dim, num_layers):
    method forward (line 438) | def forward(self, x):
  function build (line 444) | def build(args):

FILE: batchformer-v2/deformable-detr/models/deformable_transformer.py
  class DeformableTransformer (line 15) | class DeformableTransformer(nn.Module):
    method __init__ (line 16) | def __init__(self, d_model=256, nhead=8,
    method _reset_parameters (line 67) | def _reset_parameters(self):
    method get_proposal_pos_embed (line 79) | def get_proposal_pos_embed(self, proposals):
    method gen_encoder_output_proposals (line 94) | def gen_encoder_output_proposals(self, memory, memory_padding_mask, sp...
    method get_valid_ratio (line 126) | def get_valid_ratio(self, mask):
    method forward (line 135) | def forward(self, srcs, masks, pos_embeds, query_embed=None):
  class DeformableTransformerEncoderLayer (line 200) | class DeformableTransformerEncoderLayer(nn.Module):
    method __init__ (line 201) | def __init__(self,
    method with_pos_embed (line 221) | def with_pos_embed(tensor, pos):
    method forward_ffn (line 224) | def forward_ffn(self, src):
    method forward (line 230) | def forward(self, src, pos, reference_points, spatial_shapes, level_st...
  class DeformableTransformerEncoder (line 242) | class DeformableTransformerEncoder(nn.Module):
    method __init__ (line 243) | def __init__(self, encoder_layer, num_layers, bf=None, bf_idx = 0, ins...
    method get_reference_points (line 256) | def get_reference_points(spatial_shapes, valid_ratios, device):
    method forward (line 270) | def forward(self, src, spatial_shapes, level_start_index, valid_ratios...
  class DeformableTransformerDecoderLayer (line 295) | class DeformableTransformerDecoderLayer(nn.Module):
    method __init__ (line 296) | def __init__(self, d_model=256, d_ffn=1024,
    method with_pos_embed (line 320) | def with_pos_embed(tensor, pos):
    method forward_ffn (line 323) | def forward_ffn(self, tgt):
    method forward (line 329) | def forward(self, tgt, query_pos, reference_points, src, src_spatial_s...
  class DeformableTransformerDecoder (line 349) | class DeformableTransformerDecoder(nn.Module):
    method __init__ (line 350) | def __init__(self, decoder_layer, num_layers, return_intermediate=False):
    method forward (line 359) | def forward(self, tgt, reference_points, src, src_spatial_shapes, src_...
  function _get_clones (line 396) | def _get_clones(module, N):
  function _get_activation_fn (line 400) | def _get_activation_fn(activation):
  function build_deforamble_transformer (line 411) | def build_deforamble_transformer(args):

FILE: batchformer-v2/deformable-detr/models/matcher.py
  class HungarianMatcher (line 20) | class HungarianMatcher(nn.Module):
    method __init__ (line 28) | def __init__(self,
    method forward (line 45) | def forward(self, outputs, targets):
  function build_matcher (line 99) | def build_matcher(args):

FILE: batchformer-v2/deformable-detr/models/ops/functions/ms_deform_attn_func.py
  class MSDeformAttnFunction (line 21) | class MSDeformAttnFunction(Function):
    method forward (line 23) | def forward(ctx, value, value_spatial_shapes, value_level_start_index,...
    method backward (line 32) | def backward(ctx, grad_output):
  function ms_deform_attn_core_pytorch (line 41) | def ms_deform_attn_core_pytorch(value, value_spatial_shapes, sampling_lo...

FILE: batchformer-v2/deformable-detr/models/ops/modules/ms_deform_attn.py
  function _is_power_of_2 (line 24) | def _is_power_of_2(n):
  class MSDeformAttn (line 30) | class MSDeformAttn(nn.Module):
    method __init__ (line 31) | def __init__(self, d_model=256, n_levels=4, n_heads=8, n_points=4):
    method _reset_parameters (line 62) | def _reset_parameters(self):
    method forward (line 78) | def forward(self, query, reference_points, input_flatten, input_spatia...

FILE: batchformer-v2/deformable-detr/models/ops/setup.py
  function get_extensions (line 23) | def get_extensions():

FILE: batchformer-v2/deformable-detr/models/ops/src/cpu/ms_deform_attn_cpu.cpp
  function ms_deform_attn_cpu_forward (line 17) | at::Tensor
  function ms_deform_attn_cpu_backward (line 29) | std::vector<at::Tensor>

FILE: batchformer-v2/deformable-detr/models/ops/src/ms_deform_attn.h
  function im2col_step (line 27) | int im2col_step)

FILE: batchformer-v2/deformable-detr/models/ops/src/vision.cpp
  function PYBIND11_MODULE (line 13) | PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {

FILE: batchformer-v2/deformable-detr/models/ops/test.py
  function check_forward_equal_with_pytorch_double (line 32) | def check_forward_equal_with_pytorch_double():
  function check_forward_equal_with_pytorch_float (line 48) | def check_forward_equal_with_pytorch_float():
  function check_gradient_numerical (line 63) | def check_gradient_numerical(channels=4, grad_value=True, grad_sampling_...

FILE: batchformer-v2/deformable-detr/models/position_encoding.py
  class PositionEmbeddingSine (line 20) | class PositionEmbeddingSine(nn.Module):
    method __init__ (line 25) | def __init__(self, num_pos_feats=64, temperature=10000, normalize=Fals...
    method forward (line 36) | def forward(self, tensor_list: NestedTensor):
  class PositionEmbeddingLearned (line 59) | class PositionEmbeddingLearned(nn.Module):
    method __init__ (line 63) | def __init__(self, num_pos_feats=256):
    method reset_parameters (line 69) | def reset_parameters(self):
    method forward (line 73) | def forward(self, tensor_list: NestedTensor):
  function build_position_encoding (line 87) | def build_position_encoding(args):

FILE: batchformer-v2/deformable-detr/models/segmentation.py
  class DETRsegm (line 30) | class DETRsegm(nn.Module):
    method __init__ (line 31) | def __init__(self, detr, freeze_detr=False):
    method forward (line 43) | def forward(self, samples: NestedTensor):
  class MaskHeadSmallConv (line 72) | class MaskHeadSmallConv(nn.Module):
    method __init__ (line 78) | def __init__(self, dim, fpn_dims, context_dim):
    method forward (line 105) | def forward(self, x, bbox_mask, fpns):
  class MHAttentionMap (line 146) | class MHAttentionMap(nn.Module):
    method __init__ (line 149) | def __init__(self, query_dim, hidden_dim, num_heads, dropout=0, bias=T...
    method forward (line 164) | def forward(self, q, k, mask=None):
  function dice_loss (line 178) | def dice_loss(inputs, targets, num_boxes):
  function sigmoid_focal_loss (line 196) | def sigmoid_focal_loss(inputs, targets, num_boxes, alpha: float = 0.25, ...
  class PostProcessSegm (line 224) | class PostProcessSegm(nn.Module):
    method __init__ (line 225) | def __init__(self, threshold=0.5):
    method forward (line 230) | def forward(self, results, outputs, orig_target_sizes, max_target_sizes):
  class PostProcessPanoptic (line 247) | class PostProcessPanoptic(nn.Module):
    method __init__ (line 251) | def __init__(self, is_thing_map, threshold=0.85):
    method forward (line 262) | def forward(self, outputs, processed_sizes, target_sizes=None):

FILE: batchformer-v2/deformable-detr/tools/launch.py
  function parse_args (line 116) | def parse_args():
  function main (line 159) | def main():

FILE: batchformer-v2/deformable-detr/util/box_ops.py
  function box_cxcywh_to_xyxy (line 17) | def box_cxcywh_to_xyxy(x):
  function box_xyxy_to_cxcywh (line 24) | def box_xyxy_to_cxcywh(x):
  function box_iou (line 32) | def box_iou(boxes1, boxes2):
  function generalized_box_iou (line 48) | def generalized_box_iou(boxes1, boxes2):
  function masks_to_boxes (line 72) | def masks_to_boxes(masks):

FILE: batchformer-v2/deformable-detr/util/misc.py
  function _check_size_scale_factor (line 33) | def _check_size_scale_factor(dim, size, scale_factor):
  function _output_size (line 44) | def _output_size(dim, input, size, scale_factor):
  class SmoothedValue (line 62) | class SmoothedValue(object):
    method __init__ (line 67) | def __init__(self, window_size=20, fmt=None):
    method update (line 75) | def update(self, value, n=1):
    method synchronize_between_processes (line 80) | def synchronize_between_processes(self):
    method median (line 94) | def median(self):
    method avg (line 99) | def avg(self):
    method global_avg (line 104) | def global_avg(self):
    method max (line 108) | def max(self):
    method value (line 112) | def value(self):
    method __str__ (line 115) | def __str__(self):
  function all_gather (line 124) | def all_gather(data):
  function reduce_dict (line 167) | def reduce_dict(input_dict, average=True):
  class MetricLogger (line 194) | class MetricLogger(object):
    method __init__ (line 195) | def __init__(self, delimiter="\t"):
    method update (line 199) | def update(self, **kwargs):
    method __getattr__ (line 206) | def __getattr__(self, attr):
    method __str__ (line 214) | def __str__(self):
    method synchronize_between_processes (line 222) | def synchronize_between_processes(self):
    method add_meter (line 226) | def add_meter(self, name, meter):
    method log_every (line 229) | def log_every(self, iterable, print_freq, header=None):
  function get_sha (line 284) | def get_sha():
  function collate_fn (line 304) | def collate_fn(batch):
  function _max_by_axis (line 310) | def _max_by_axis(the_list):
  function nested_tensor_from_tensor_list (line 319) | def nested_tensor_from_tensor_list(tensor_list: List[Tensor]):
  class NestedTensor (line 339) | class NestedTensor(object):
    method __init__ (line 340) | def __init__(self, tensors, mask: Optional[Tensor]):
    method to (line 344) | def to(self, device, non_blocking=False):
    method record_stream (line 355) | def record_stream(self, *args, **kwargs):
    method decompose (line 360) | def decompose(self):
    method __repr__ (line 363) | def __repr__(self):
  function setup_for_distributed (line 367) | def setup_for_distributed(is_master):
  function is_dist_avail_and_initialized (line 382) | def is_dist_avail_and_initialized():
  function get_world_size (line 390) | def get_world_size():
  function get_rank (line 396) | def get_rank():
  function get_local_size (line 402) | def get_local_size():
  function get_local_rank (line 408) | def get_local_rank():
  function is_main_process (line 414) | def is_main_process():
  function save_on_master (line 418) | def save_on_master(*args, **kwargs):
  function init_distributed_mode (line 423) | def init_distributed_mode(args):
  function accuracy (line 465) | def accuracy(output, target, topk=(1,)):
  function interpolate (line 483) | def interpolate(input, size=None, scale_factor=None, mode="nearest", ali...
  function get_total_grad_norm (line 505) | def get_total_grad_norm(parameters, norm_type=2):
  function inverse_sigmoid (line 513) | def inverse_sigmoid(x, eps=1e-5):

FILE: batchformer-v2/deformable-detr/util/plot_utils.py
  function plot_logs (line 21) | def plot_logs(logs, fields=('class_error', 'loss_bbox_unscaled', 'mAP'),...
  function plot_precision_recall (line 77) | def plot_precision_recall(files, naming_scheme='iter'):

FILE: batchformer-v2/deit_share/bt.py
  class BlockBF (line 5) | class BlockBF(torch.nn.Module):
    method __init__ (line 7) | def __init__(self, block: Block, fp16_type=0):
    method forward (line 12) | def forward(self, x):
  class BlockWrap32 (line 34) | class BlockWrap32(torch.nn.Module):
    method __init__ (line 36) | def __init__(self, block: Block, fp16_type: int):
    method forward (line 41) | def forward(self, x):
  class BlockWrapDebug (line 57) | class BlockWrapDebug(torch.nn.Module):
    method __init__ (line 59) | def __init__(self, block: Block):
    method forward (line 63) | def forward(self, x):
  class AttentionOnly (line 74) | class AttentionOnly(torch.nn.Module):
    method __init__ (line 76) | def __init__(self, block: Block, drop_path = 0. , add_bt=70):
    method forward (line 85) | def forward(self, x):
  class MLPDecorder (line 93) | class MLPDecorder(torch.nn.Module):
    method __init__ (line 95) | def __init__(self, dim, mlp_dim, skip_mlp=False):
    method forward (line 101) | def forward(self, x):
  class MLPEncoder (line 109) | class MLPEncoder(torch.nn.Module):
    method __init__ (line 111) | def __init__(self, d_model, batch_size, dim_feedforward=2048, dropout=...
    method __setstate__ (line 122) | def __setstate__(self, state):
    method forward (line 128) | def forward(self, src):
  class TransformerDecorator1 (line 147) | class TransformerDecorator1(torch.nn.Module):
    method __init__ (line 148) | def __init__(self, add_bt=3, dim=2048, eval_global=0, args=None, first...
    method forward (line 186) | def forward(self, feature):

FILE: batchformer-v2/deit_share/cait_models.py
  class Class_Attention (line 21) | class Class_Attention(nn.Module):
    method __init__ (line 24) | def __init__(self, dim, num_heads=8, qkv_bias=False, qk_scale=None, at...
    method forward (line 38) | def forward(self, x ):
  class LayerScale_Block_CA (line 57) | class LayerScale_Block_CA(nn.Module):
    method __init__ (line 60) | def __init__(self, dim, num_heads, mlp_ratio=4., qkv_bias=False, qk_sc...
    method forward (line 75) | def forward(self, x, x_cls):
  class Attention_talking_head (line 87) | class Attention_talking_head(nn.Module):
    method __init__ (line 90) | def __init__(self, dim, num_heads=8, qkv_bias=False, qk_scale=None, at...
    method forward (line 111) | def forward(self, x):
  class LayerScale_Block (line 130) | class LayerScale_Block(nn.Module):
    method __init__ (line 133) | def __init__(self, dim, num_heads, mlp_ratio=4., qkv_bias=False, qk_sc...
    method forward (line 147) | def forward(self, x):
  class cait_models (line 155) | class cait_models(nn.Module):
    method __init__ (line 158) | def __init__(self, img_size=224, patch_size=16, in_chans=3, num_classe...
    method _init_weights (line 213) | def _init_weights(self, m):
    method no_weight_decay (line 223) | def no_weight_decay(self):
    method forward_features (line 227) | def forward_features(self, x):
    method forward (line 248) | def forward(self, x):
  function cait_XXS24_224 (line 256) | def cait_XXS24_224(pretrained=False, **kwargs):
  function cait_XXS24 (line 278) | def cait_XXS24(pretrained=False, **kwargs):
  function cait_XXS36_224 (line 299) | def cait_XXS36_224(pretrained=False, **kwargs):
  function cait_XXS36 (line 321) | def cait_XXS36(pretrained=False, **kwargs):
  function cait_XS24 (line 343) | def cait_XS24(pretrained=False, **kwargs):
  function cait_S24_224 (line 368) | def cait_S24_224(pretrained=False, **kwargs):
  function cait_S24 (line 390) | def cait_S24(pretrained=False, **kwargs):
  function cait_S36 (line 412) | def cait_S36(pretrained=False, **kwargs):
  function cait_M36 (line 438) | def cait_M36(pretrained=False, **kwargs):
  function cait_M48 (line 461) | def cait_M48(pretrained=False, **kwargs):

FILE: batchformer-v2/deit_share/datasets.py
  class INatDataset (line 13) | class INatDataset(ImageFolder):
    method __init__ (line 14) | def __init__(self, root, train=True, year=2018, transform=None, target...
  function build_dataset (line 56) | def build_dataset(is_train, args):
  function build_transform (line 78) | def build_transform(is_train, args):

FILE: batchformer-v2/deit_share/engine.py
  function train_one_epoch (line 20) | def train_one_epoch(model: torch.nn.Module, criterion: DistillationLoss,
  function evaluate (line 92) | def evaluate(data_loader, model, device):
  function reduce_tensor (line 127) | def reduce_tensor(acc1, args):
  function validate (line 134) | def validate(val_loader, training_labels, model, device, num_classes, ra...
  function shot_acc (line 164) | def shot_acc(preds, labels, train_data, many_shot_thr=100, low_shot_thr=...

FILE: batchformer-v2/deit_share/losses.py
  class DistillationLoss (line 13) | class DistillationLoss(torch.nn.Module):
    method __init__ (line 18) | def __init__(self, base_criterion: torch.nn.Module, teacher_model: tor...
    method forward (line 28) | def forward(self, inputs, outputs, labels):
  class BalancedSoftmax (line 76) | class BalancedSoftmax(_Loss):
    method __init__ (line 80) | def __init__(self, freq_path):
    method forward (line 87) | def forward(self, inputs, outputs, labels, reduction='mean'):
  function balanced_softmax_loss (line 91) | def balanced_softmax_loss(labels, logits, sample_per_class, reduction):
  function create_loss (line 108) | def create_loss(freq_path):

FILE: batchformer-v2/deit_share/main.py
  function get_args_parser (line 29) | def get_args_parser():
  function main (line 217) | def main(args):

FILE: batchformer-v2/deit_share/models.py
  class DistilledVisionTransformer (line 22) | class DistilledVisionTransformer(VisionTransformer):
    method __init__ (line 23) | def __init__(self, *args, **kwargs):
    method forward_features (line 34) | def forward_features(self, x):
    method forward (line 53) | def forward(self, x):
  function deit_tiny_patch16_224 (line 65) | def deit_tiny_patch16_224(pretrained=False, **kwargs):
  function deit_small_patch16_224 (line 80) | def deit_small_patch16_224(pretrained=False, **kwargs):
  function deit_small_patch16_224_12 (line 101) | def deit_small_patch16_224_12(pretrained=False, **kwargs):
  function deit_base_patch16_224 (line 119) | def deit_base_patch16_224(pretrained=False, **kwargs):
  function deit_tiny_distilled_patch16_224 (line 145) | def deit_tiny_distilled_patch16_224(pretrained=False, **kwargs):
  function deit_small_distilled_patch16_224 (line 160) | def deit_small_distilled_patch16_224(pretrained=False, **kwargs):
  function deit_base_distilled_patch16_224 (line 175) | def deit_base_distilled_patch16_224(pretrained=False, **kwargs):
  function deit_base_patch16_384 (line 190) | def deit_base_patch16_384(pretrained=False, **kwargs):
  function deit_base_distilled_patch16_384 (line 205) | def deit_base_distilled_patch16_384(pretrained=False, **kwargs):

FILE: batchformer-v2/deit_share/optimizer.py
  function add_bt_weight_decay (line 26) | def add_bt_weight_decay(model, weight_decay=1e-5, skip_list=(), second_g...
  function create_bt_optimizer (line 49) | def create_bt_optimizer(args, model, bt_decay, filter_bias_and_bn=True):
  function create_optimizer_v2 (line 62) | def create_optimizer_v2(

FILE: batchformer-v2/deit_share/resmlp_models.py
  class Affine (line 16) | class Affine(nn.Module):
    method __init__ (line 17) | def __init__(self, dim):
    method forward (line 22) | def forward(self, x):
  class layers_scale_mlp_blocks (line 25) | class layers_scale_mlp_blocks(nn.Module):
    method __init__ (line 27) | def __init__(self, dim, drop=0., drop_path=0., act_layer=nn.GELU,init_...
    method forward (line 37) | def forward(self, x):
  class resmlp_models (line 43) | class resmlp_models(nn.Module):
    method __init__ (line 45) | def __init__(self, img_size=224, patch_size=16, in_chans=3, num_classe...
    method _init_weights (line 76) | def _init_weights(self, m):
    method get_classifier (line 87) | def get_classifier(self):
    method reset_classifier (line 90) | def reset_classifier(self, num_classes, global_pool=''):
    method forward_features (line 94) | def forward_features(self, x):
    method forward (line 107) | def forward(self, x):
  function resmlp_12 (line 113) | def resmlp_12(pretrained=False,dist=False, **kwargs):
  function resmlp_24 (line 134) | def resmlp_24(pretrained=False,dist=False,dino=False, **kwargs):
  function resmlp_36 (line 156) | def resmlp_36(pretrained=False,dist=False, **kwargs):
  function resmlpB_24 (line 176) | def resmlpB_24(pretrained=False,dist=False, in_22k = False, **kwargs):

FILE: batchformer-v2/deit_share/run_with_submitit.py
  function parse_args (line 15) | def parse_args():
  function get_shared_folder (line 30) | def get_shared_folder() -> Path:
  function get_init_file (line 39) | def get_init_file():
  class Trainer (line 48) | class Trainer(object):
    method __init__ (line 49) | def __init__(self, args):
    method __call__ (line 52) | def __call__(self):
    method checkpoint (line 58) | def checkpoint(self):
    method _setup_gpu_args (line 70) | def _setup_gpu_args(self):
  function main (line 82) | def main():

FILE: batchformer-v2/deit_share/samplers.py
  class RASampler (line 8) | class RASampler(torch.utils.data.Sampler):
    method __init__ (line 16) | def __init__(self, dataset, num_replicas=None, rank=None, shuffle=True):
    method __iter__ (line 35) | def __iter__(self):
    method __len__ (line 55) | def __len__(self):
    method set_epoch (line 58) | def set_epoch(self, epoch):

FILE: batchformer-v2/deit_share/utils.py
  class SmoothedValue (line 18) | class SmoothedValue(object):
    method __init__ (line 23) | def __init__(self, window_size=20, fmt=None):
    method update (line 31) | def update(self, value, n=1):
    method synchronize_between_processes (line 36) | def synchronize_between_processes(self):
    method median (line 50) | def median(self):
    method avg (line 55) | def avg(self):
    method global_avg (line 60) | def global_avg(self):
    method max (line 64) | def max(self):
    method value (line 68) | def value(self):
    method __str__ (line 71) | def __str__(self):
  class MetricLogger (line 80) | class MetricLogger(object):
    method __init__ (line 81) | def __init__(self, delimiter="\t"):
    method update (line 85) | def update(self, **kwargs):
    method __getattr__ (line 92) | def __getattr__(self, attr):
    method __str__ (line 100) | def __str__(self):
    method synchronize_between_processes (line 108) | def synchronize_between_processes(self):
    method add_meter (line 112) | def add_meter(self, name, meter):
    method log_every (line 115) | def log_every(self, iterable, print_freq, header=None):
  function _load_checkpoint_for_ema (line 162) | def _load_checkpoint_for_ema(model_ema, checkpoint):
  function setup_for_distributed (line 172) | def setup_for_distributed(is_master):
  function is_dist_avail_and_initialized (line 187) | def is_dist_avail_and_initialized():
  function get_world_size (line 195) | def get_world_size():
  function get_rank (line 201) | def get_rank():
  function is_main_process (line 207) | def is_main_process():
  function save_on_master (line 211) | def save_on_master(*args, **kwargs):
  function init_distributed_mode (line 216) | def init_distributed_mode(args):

FILE: batchformer-v2/detr/d2/converter.py
  function parse_args (line 12) | def parse_args():
  function main (line 20) | def main():

FILE: batchformer-v2/detr/d2/detr/config.py
  function add_detr_config (line 6) | def add_detr_config(cfg):

FILE: batchformer-v2/detr/d2/detr/dataset_mapper.py
  function build_transform_gen (line 15) | def build_transform_gen(cfg, is_train):
  class DetrDatasetMapper (line 42) | class DetrDatasetMapper:
    method __init__ (line 55) | def __init__(self, cfg, is_train=True):
    method __call__ (line 73) | def __call__(self, dataset_dict):

FILE: batchformer-v2/detr/d2/detr/detr.py
  class MaskedBackbone (line 31) | class MaskedBackbone(nn.Module):
    method __init__ (line 34) | def __init__(self, cfg):
    method forward (line 41) | def forward(self, images):
    method mask_out_padding (line 53) | def mask_out_padding(self, feature_shapes, image_sizes, device):
  class Detr (line 70) | class Detr(nn.Module):
    method __init__ (line 75) | def __init__(self, cfg):
    method forward (line 158) | def forward(self, batched_inputs):
    method prepare_targets (line 202) | def prepare_targets(self, targets):
    method inference (line 217) | def inference(self, box_cls, box_pred, mask_pred, image_sizes):
    method preprocess_image (line 255) | def preprocess_image(self, batched_inputs):

FILE: batchformer-v2/detr/d2/train_net.py
  class Trainer (line 31) | class Trainer(DefaultTrainer):
    method build_evaluator (line 37) | def build_evaluator(cls, cfg, dataset_name, output_folder=None):
    method build_train_loader (line 49) | def build_train_loader(cls, cfg):
    method build_optimizer (line 57) | def build_optimizer(cls, cfg, model):
  function setup (line 106) | def setup(args):
  function main (line 119) | def main(args):

FILE: batchformer-v2/detr/datasets/__init__.py
  function get_coco_api_from_dataset (line 8) | def get_coco_api_from_dataset(dataset):
  function build_dataset (line 18) | def build_dataset(image_set, args):

FILE: batchformer-v2/detr/datasets/coco.py
  class CocoDetection (line 17) | class CocoDetection(torchvision.datasets.CocoDetection):
    method __init__ (line 18) | def __init__(self, img_folder, ann_file, transforms, return_masks):
    method __getitem__ (line 23) | def __getitem__(self, idx):
  function convert_coco_poly_to_mask (line 33) | def convert_coco_poly_to_mask(segmentations, height, width):
  class ConvertCocoPolysToMask (line 50) | class ConvertCocoPolysToMask(object):
    method __init__ (line 51) | def __init__(self, return_masks=False):
    method __call__ (line 54) | def __call__(self, image, target):
  function make_coco_transforms (line 115) | def make_coco_transforms(image_set):
  function build (line 147) | def build(image_set, args):
  function build_coco2014 (line 160) | def build_coco2014(image_set, args):
  function build_hico (line 173) | def build_hico(image_set, args):

FILE: batchformer-v2/detr/datasets/coco_eval.py
  class CocoEvaluator (line 22) | class CocoEvaluator(object):
    method __init__ (line 23) | def __init__(self, coco_gt, iou_types):
    method update (line 36) | def update(self, predictions):
    method synchronize_between_processes (line 55) | def synchronize_between_processes(self):
    method accumulate (line 60) | def accumulate(self):
    method summarize (line 64) | def summarize(self):
    method prepare (line 69) | def prepare(self, predictions, iou_type):
    method prepare_for_coco_detection (line 79) | def prepare_for_coco_detection(self, predictions):
    method prepare_for_coco_segmentation (line 103) | def prepare_for_coco_segmentation(self, predictions):
    method prepare_for_coco_keypoint (line 138) | def prepare_for_coco_keypoint(self, predictions):
  function convert_to_xywh (line 165) | def convert_to_xywh(boxes):
  function merge (line 170) | def merge(img_ids, eval_imgs):
  function create_common_coco_eval (line 192) | def create_common_coco_eval(coco_eval, img_ids, eval_imgs):
  function evaluate (line 208) | def evaluate(self):

FILE: batchformer-v2/detr/datasets/coco_panoptic.py
  class CocoPanoptic (line 15) | class CocoPanoptic:
    method __init__ (line 16) | def __init__(self, img_folder, ann_folder, ann_file, transforms=None, ...
    method __getitem__ (line 34) | def __getitem__(self, idx):
    method __len__ (line 70) | def __len__(self):
    method get_height_and_width (line 73) | def get_height_and_width(self, idx):
  function build (line 80) | def build(image_set, args):

FILE: batchformer-v2/detr/datasets/panoptic_eval.py
  class PanopticEvaluator (line 13) | class PanopticEvaluator(object):
    method __init__ (line 14) | def __init__(self, ann_file, ann_folder, output_dir="panoptic_eval"):
    method update (line 23) | def update(self, predictions):
    method synchronize_between_processes (line 30) | def synchronize_between_processes(self):
    method summarize (line 37) | def summarize(self):

FILE: batchformer-v2/detr/datasets/transforms.py
  function crop (line 16) | def crop(image, target, region):
  function hflip (line 59) | def hflip(image, target):
  function resize (line 76) | def resize(image, target, size, max_size=None):
  function pad (line 135) | def pad(image, target, padding):
  class RandomCrop (line 148) | class RandomCrop(object):
    method __init__ (line 149) | def __init__(self, size):
    method __call__ (line 152) | def __call__(self, img, target):
  class RandomSizeCrop (line 157) | class RandomSizeCrop(object):
    method __init__ (line 158) | def __init__(self, min_size: int, max_size: int):
    method __call__ (line 162) | def __call__(self, img: PIL.Image.Image, target: dict):
  class CenterCrop (line 169) | class CenterCrop(object):
    method __init__ (line 170) | def __init__(self, size):
    method __call__ (line 173) | def __call__(self, img, target):
  class RandomHorizontalFlip (line 181) | class RandomHorizontalFlip(object):
    method __init__ (line 182) | def __init__(self, p=0.5):
    method __call__ (line 185) | def __call__(self, img, target):
  class RandomResize (line 191) | class RandomResize(object):
    method __init__ (line 192) | def __init__(self, sizes, max_size=None):
    method __call__ (line 197) | def __call__(self, img, target=None):
  class RandomPad (line 202) | class RandomPad(object):
    method __init__ (line 203) | def __init__(self, max_pad):
    method __call__ (line 206) | def __call__(self, img, target):
  class RandomSelect (line 212) | class RandomSelect(object):
    method __init__ (line 217) | def __init__(self, transforms1, transforms2, p=0.5):
    method __call__ (line 222) | def __call__(self, img, target):
  class ToTensor (line 228) | class ToTensor(object):
    method __call__ (line 229) | def __call__(self, img, target):
  class RandomErasing (line 233) | class RandomErasing(object):
    method __init__ (line 235) | def __init__(self, *args, **kwargs):
    method __call__ (line 238) | def __call__(self, img, target):
  class Normalize (line 242) | class Normalize(object):
    method __init__ (line 243) | def __init__(self, mean, std):
    method __call__ (line 247) | def __call__(self, image, target=None):
  class Compose (line 261) | class Compose(object):
    method __init__ (line 262) | def __init__(self, transforms):
    method __call__ (line 265) | def __call__(self, image, target):
    method __repr__ (line 270) | def __repr__(self):

FILE: batchformer-v2/detr/engine.py
  function train_one_epoch (line 17) | def train_one_epoch(model: torch.nn.Module, criterion: torch.nn.Module,
  function evaluate (line 70) | def evaluate(model, criterion, postprocessors, data_loader, base_ds, dev...

FILE: batchformer-v2/detr/hubconf.py
  function _make_detr (line 13) | def _make_detr(backbone_name: str, dilation=False, num_classes=91, mask=...
  function detr_resnet50 (line 26) | def detr_resnet50(pretrained=False, num_classes=91, return_postprocessor...
  function detr_resnet50_dc5 (line 43) | def detr_resnet50_dc5(pretrained=False, num_classes=91, return_postproce...
  function detr_resnet101 (line 62) | def detr_resnet101(pretrained=False, num_classes=91, return_postprocesso...
  function detr_resnet101_dc5 (line 79) | def detr_resnet101_dc5(pretrained=False, num_classes=91, return_postproc...
  function detr_resnet50_panoptic (line 98) | def detr_resnet50_panoptic(
  function detr_resnet50_dc5_panoptic (line 121) | def detr_resnet50_dc5_panoptic(
  function detr_resnet101_panoptic (line 147) | def detr_resnet101_panoptic(

FILE: batchformer-v2/detr/main.py
  function get_args_parser (line 20) | def get_args_parser():
  function main (line 118) | def main(args):

FILE: batchformer-v2/detr/models/__init__.py
  function build_model (line 5) | def build_model(args):

FILE: batchformer-v2/detr/models/backbone.py
  class FrozenBatchNorm2d (line 19) | class FrozenBatchNorm2d(torch.nn.Module):
    method __init__ (line 28) | def __init__(self, n):
    method _load_from_state_dict (line 35) | def _load_from_state_dict(self, state_dict, prefix, local_metadata, st...
    method forward (line 45) | def forward(self, x):
  class BackboneBase (line 58) | class BackboneBase(nn.Module):
    method __init__ (line 60) | def __init__(self, backbone: nn.Module, train_backbone: bool, num_chan...
    method forward (line 74) | def forward(self, tensor_list: NestedTensor):
  class Backbone (line 85) | class Backbone(BackboneBase):
    method __init__ (line 87) | def __init__(self, name: str,
  class Joiner (line 99) | class Joiner(nn.Sequential):
    method __init__ (line 100) | def __init__(self, backbone, position_embedding):
    method forward (line 103) | def forward(self, tensor_list: NestedTensor):
  function build_backbone (line 115) | def build_backbone(args):
  class SwinBackbone (line 124) | class SwinBackbone(nn.Module):
    method __init__ (line 125) | def __init__(self, name: str,
    method forward (line 157) | def forward(self, tensor_list: NestedTensor):
  function build_swin_backbone (line 168) | def build_swin_backbone(args):

FILE: batchformer-v2/detr/models/detr.py
  class DETR (line 21) | class DETR(nn.Module):
    method __init__ (line 23) | def __init__(self, backbone, transformer, num_classes, num_queries, au...
    method forward (line 45) | def forward(self, samples: NestedTensor):
    method _set_aux_loss (line 76) | def _set_aux_loss(self, outputs_class, outputs_coord):
  class SetCriterion (line 84) | class SetCriterion(nn.Module):
    method __init__ (line 90) | def __init__(self, num_classes, matcher, weight_dict, eos_coef, losses...
    method loss_labels (line 111) | def loss_labels(self, outputs, targets, indices, num_boxes, log=True):
    method loss_cardinality (line 141) | def loss_cardinality(self, outputs, targets, indices, num_boxes):
    method loss_boxes (line 154) | def loss_boxes(self, outputs, targets, indices, num_boxes):
    method loss_masks (line 175) | def loss_masks(self, outputs, targets, indices, num_boxes):
    method _get_src_permutation_idx (line 204) | def _get_src_permutation_idx(self, indices):
    method _get_tgt_permutation_idx (line 210) | def _get_tgt_permutation_idx(self, indices):
    method get_loss (line 216) | def get_loss(self, loss, outputs, targets, indices, num_boxes, **kwargs):
    method forward (line 226) | def forward(self, outputs, targets):
  class PostProcess (line 269) | class PostProcess(nn.Module):
    method forward (line 272) | def forward(self, outputs, target_sizes):
  class MLP (line 300) | class MLP(nn.Module):
    method __init__ (line 303) | def __init__(self, input_dim, hidden_dim, output_dim, num_layers):
    method forward (line 309) | def forward(self, x):
  function build (line 315) | def build(args):

FILE: batchformer-v2/detr/models/matcher.py
  class HungarianMatcher (line 12) | class HungarianMatcher(nn.Module):
    method __init__ (line 20) | def __init__(self, cost_class: float = 1, cost_bbox: float = 1, cost_g...
    method forward (line 35) | def forward(self, outputs, targets):
  function build_matcher (line 85) | def build_matcher(args):

FILE: batchformer-v2/detr/models/position_encoding.py
  class PositionEmbeddingSine (line 12) | class PositionEmbeddingSine(nn.Module):
    method __init__ (line 17) | def __init__(self, num_pos_feats=64, temperature=10000, normalize=Fals...
    method forward (line 28) | def forward(self, tensor_list: NestedTensor):
  class PositionEmbeddingLearned (line 51) | class PositionEmbeddingLearned(nn.Module):
    method __init__ (line 55) | def __init__(self, num_pos_feats=256):
    method reset_parameters (line 61) | def reset_parameters(self):
    method forward (line 65) | def forward(self, tensor_list: NestedTensor):
  function build_position_encoding (line 79) | def build_position_encoding(args):

FILE: batchformer-v2/detr/models/segmentation.py
  class DETRsegm (line 24) | class DETRsegm(nn.Module):
    method __init__ (line 25) | def __init__(self, detr, freeze_detr=False):
    method forward (line 37) | def forward(self, samples: NestedTensor):
  function _expand (line 75) | def _expand(tensor, length: int):
  class MaskHeadSmallConv (line 79) | class MaskHeadSmallConv(nn.Module):
    method __init__ (line 85) | def __init__(self, dim, fpn_dims, context_dim):
    method forward (line 112) | def forward(self, x: Tensor, bbox_mask: Tensor, fpns: List[Tensor]):
  class MHAttentionMap (line 150) | class MHAttentionMap(nn.Module):
    method __init__ (line 153) | def __init__(self, query_dim, hidden_dim, num_heads, dropout=0.0, bias...
    method forward (line 168) | def forward(self, q, k, mask: Optional[Tensor] = None):
  function dice_loss (line 182) | def dice_loss(inputs, targets, num_boxes):
  function sigmoid_focal_loss (line 200) | def sigmoid_focal_loss(inputs, targets, num_boxes, alpha: float = 0.25, ...
  class PostProcessSegm (line 228) | class PostProcessSegm(nn.Module):
    method __init__ (line 229) | def __init__(self, threshold=0.5):
    method forward (line 234) | def forward(self, results, outputs, orig_target_sizes, max_target_sizes):
  class PostProcessPanoptic (line 251) | class PostProcessPanoptic(nn.Module):
    method __init__ (line 255) | def __init__(self, is_thing_map, threshold=0.85):
    method forward (line 266) | def forward(self, outputs, processed_sizes, target_sizes=None):

FILE: batchformer-v2/detr/models/transformer.py
  class Transformer (line 18) | class Transformer(nn.Module):
    method __init__ (line 20) | def __init__(self, d_model=512, nhead=8, num_encoder_layers=6,
    method _reset_parameters (line 57) | def _reset_parameters(self):
    method forward (line 62) | def forward(self, src, mask, query_embed, pos_embed):
  class TransformerEncoder (line 97) | class TransformerEncoder(nn.Module):
    method __init__ (line 99) | def __init__(self, encoder_layer, num_layers, norm=None, bf=None, bf_i...
    method forward (line 112) | def forward(self, src,
  class TransformerDecoder (line 160) | class TransformerDecoder(nn.Module):
    method __init__ (line 162) | def __init__(self, decoder_layer, num_layers, norm=None, return_interm...
    method forward (line 170) | def forward(self, tgt, memory,
  class TransformerEncoderLayer (line 210) | class TransformerEncoderLayer(nn.Module):
    method __init__ (line 212) | def __init__(self, d_model, nhead, dim_feedforward=2048, dropout=0.1,
    method with_pos_embed (line 229) | def with_pos_embed(self, tensor, pos: Optional[Tensor]):
    method forward_post (line 232) | def forward_post(self,
    method forward_pre (line 247) | def forward_pre(self, src,
    method forward (line 261) | def forward(self, src,
  class TransformerDecoderLayer (line 270) | class TransformerDecoderLayer(nn.Module):
    method __init__ (line 272) | def __init__(self, d_model, nhead, dim_feedforward=2048, dropout=0.1,
    method with_pos_embed (line 292) | def with_pos_embed(self, tensor, pos: Optional[Tensor]):
    method forward_post (line 295) | def forward_post(self, tgt, memory,
    method forward_pre (line 318) | def forward_pre(self, tgt, memory,
    method forward (line 341) | def forward(self, tgt, memory,
  function _get_clones (line 355) | def _get_clones(module, N):
  function build_transformer (line 359) | def build_transformer(args):
  function _get_activation_fn (line 373) | def _get_activation_fn(activation):

FILE: batchformer-v2/detr/run.py
  function parse_args (line 43) | def parse_args():

FILE: batchformer-v2/detr/run_with_submitit.py
  function parse_args (line 14) | def parse_args():
  function get_shared_folder (line 24) | def get_shared_folder() -> Path:
  function get_init_file (line 33) | def get_init_file():
  class Trainer (line 42) | class Trainer(object):
    method __init__ (line 43) | def __init__(self, args):
    method __call__ (line 46) | def __call__(self):
    method checkpoint (line 52) | def checkpoint(self):
    method _setup_gpu_args (line 65) | def _setup_gpu_args(self):
  function main (line 77) | def main():

FILE: batchformer-v2/detr/test_all.py
  class Tester (line 23) | class Tester(unittest.TestCase):
    method test_box_cxcywh_to_xyxy (line 25) | def test_box_cxcywh_to_xyxy(self):
    method indices_torch2python (line 31) | def indices_torch2python(indices):
    method test_hungarian (line 34) | def test_hungarian(self):
    method test_position_encoding_script (line 63) | def test_position_encoding_script(self):
    method test_backbone_script (line 67) | def test_backbone_script(self):
    method test_model_script_detection (line 71) | def test_model_script_detection(self):
    method test_model_script_panoptic (line 80) | def test_model_script_panoptic(self):
    method test_model_detection_different_inputs (line 90) | def test_model_detection_different_inputs(self):
    method test_warpped_model_script_detection (line 105) | def test_warpped_model_script_detection(self):
  class ONNXExporterTester (line 127) | class ONNXExporterTester(unittest.TestCase):
    method setUpClass (line 129) | def setUpClass(cls):
    method run_model (line 132) | def run_model(self, model, inputs_list, tolerate_small_mismatch=False,...
    method ort_validate (line 151) | def ort_validate(self, onnx_io, inputs, outputs, tolerate_small_mismat...
    method test_model_onnx_detection (line 178) | def test_model_onnx_detection(self):
    method test_model_onnx_detection_panoptic (line 193) | def test_model_onnx_detection_panoptic(self):

FILE: batchformer-v2/detr/tools/launch.py
  function parse_args (line 116) | def parse_args():
  function main (line 162) | def main():

FILE: batchformer-v2/detr/util/box_ops.py
  function box_cxcywh_to_xyxy (line 9) | def box_cxcywh_to_xyxy(x):
  function box_xyxy_to_cxcywh (line 16) | def box_xyxy_to_cxcywh(x):
  function box_iou (line 24) | def box_iou(boxes1, boxes2):
  function generalized_box_iou (line 40) | def generalized_box_iou(boxes1, boxes2):
  function masks_to_boxes (line 64) | def masks_to_boxes(masks):

FILE: batchformer-v2/detr/util/misc.py
  function _check_size_scale_factor (line 26) | def _check_size_scale_factor(dim, size, scale_factor):
  function _output_size (line 37) | def _output_size(dim, input, size, scale_factor):
  class SmoothedValue (line 55) | class SmoothedValue(object):
    method __init__ (line 60) | def __init__(self, window_size=20, fmt=None):
    method update (line 68) | def update(self, value, n=1):
    method synchronize_between_processes (line 73) | def synchronize_between_processes(self):
    method median (line 87) | def median(self):
    method avg (line 92) | def avg(self):
    method global_avg (line 97) | def global_avg(self):
    method max (line 101) | def max(self):
    method value (line 105) | def value(self):
    method __str__ (line 108) | def __str__(self):
  function all_gather (line 117) | def all_gather(data):
  function reduce_dict (line 160) | def reduce_dict(input_dict, average=True):
  class MetricLogger (line 187) | class MetricLogger(object):
    method __init__ (line 188) | def __init__(self, delimiter="\t"):
    method update (line 192) | def update(self, **kwargs):
    method __getattr__ (line 199) | def __getattr__(self, attr):
    method __str__ (line 207) | def __str__(self):
    method synchronize_between_processes (line 215) | def synchronize_between_processes(self):
    method add_meter (line 219) | def add_meter(self, name, meter):
    method log_every (line 222) | def log_every(self, iterable, print_freq, header=None):
  function get_sha (line 277) | def get_sha():
  function collate_fn (line 297) | def collate_fn(batch):
  function _max_by_axis (line 303) | def _max_by_axis(the_list):
  class NestedTensor (line 312) | class NestedTensor(object):
    method __init__ (line 313) | def __init__(self, tensors, mask: Optional[Tensor]):
    method to (line 317) | def to(self, device):
    method decompose (line 328) | def decompose(self):
    method __repr__ (line 331) | def __repr__(self):
  function nested_tensor_from_tensor_list (line 335) | def nested_tensor_from_tensor_list(tensor_list: List[Tensor]):
  function _onnx_nested_tensor_from_tensor_list (line 363) | def _onnx_nested_tensor_from_tensor_list(tensor_list: List[Tensor]) -> N...
  function setup_for_distributed (line 391) | def setup_for_distributed(is_master):
  function is_dist_avail_and_initialized (line 406) | def is_dist_avail_and_initialized():
  function get_world_size (line 414) | def get_world_size():
  function get_rank (line 420) | def get_rank():
  function is_main_process (line 426) | def is_main_process():
  function save_on_master (line 430) | def save_on_master(*args, **kwargs):
  function init_distributed_mode (line 435) | def init_distributed_mode(args):
  function accuracy (line 461) | def accuracy(output, target, topk=(1,)):
  function interpolate (line 479) | def interpolate(input, size=None, scale_factor=None, mode="nearest", ali...

FILE: batchformer-v2/detr/util/plot_utils.py
  function plot_logs (line 13) | def plot_logs(logs, fields=('class_error', 'loss_bbox_unscaled', 'mAP'),...
  function plot_precision_recall (line 76) | def plot_precision_recall(files, naming_scheme='iter'):

FILE: czsl/data/dataset.py
  class ImageLoader (line 20) | class ImageLoader:
    method __init__ (line 21) | def __init__(self, root):
    method __call__ (line 24) | def __call__(self, img):
  function dataset_transform (line 29) | def dataset_transform(phase, norm_family = 'imagenet'):
  function filter_data (line 67) | def filter_data(all_data, pairs_gt, topk = 5):
  class CompositionDataset (line 94) | class CompositionDataset(Dataset):
    method __init__ (line 104) | def __init__(
    method parse_split (line 205) | def parse_split(self):
    method get_split_info (line 248) | def get_split_info(self):
    method get_dict_data (line 277) | def get_dict_data(self, data, pairs):
    method reset_dropout (line 289) | def reset_dropout(self):
    method sample_negative (line 310) | def sample_negative(self, attr, obj):
    method sample_affordance (line 327) | def sample_affordance(self, attr, obj):
    method sample_train_affordance (line 342) | def sample_train_affordance(self, attr, obj):
    method generate_features (line 357) | def generate_features(self, out_file, model):
    method __getitem__ (line 393) | def __getitem__(self, index):
    method __len__ (line 438) | def __len__(self):

FILE: czsl/models/common.py
  class MLP (line 10) | class MLP(nn.Module):
    method __init__ (line 20) | def __init__(self, inp_dim, out_dim, num_layers = 1, relu = True, bias...
    method forward (line 47) | def forward(self, x):
  class Reshape (line 50) | class Reshape(nn.Module):
    method __init__ (line 51) | def __init__(self, *args):
    method forward (line 55) | def forward(self, x):
  function calculate_margines (line 58) | def calculate_margines(domain_embedding, gt, margin_range = 5):
  function l2_all_batched (line 73) | def l2_all_batched(image_embedding, domain_embedding):
  function same_domain_triplet_loss (line 85) | def same_domain_triplet_loss(image_embedding, trip_images, gt, hard_k = ...
  function cross_domain_triplet_loss (line 123) | def cross_domain_triplet_loss(image_embedding, domain_embedding, gt, har...
  function same_domain_triplet_loss_old (line 167) | def same_domain_triplet_loss_old(image_embedding, positive_anchor, negat...
  function pairwise_distances (line 190) | def pairwise_distances(x, y=None):
  class Evaluator (line 212) | class Evaluator:
    method __init__ (line 214) | def __init__(self, dset, model):
    method generate_predictions (line 269) | def generate_predictions(self, scores, obj_truth, bias = 0.0, topk = 5...
    method score_clf_model (line 319) | def score_clf_model(self, scores, obj_truth, topk = 5):
    method score_manifold_model (line 339) | def score_manifold_model(self, scores, obj_truth, bias = 0.0, topk = 5):
    method score_fast_model (line 356) | def score_fast_model(self, scores, obj_truth, bias = 0.0, topk = 5):
    method evaluate_predictions (line 377) | def evaluate_predictions(self, predictions, attr_truth, obj_truth, pai...

FILE: czsl/models/compcos.py
  function compute_cosine_similarity (line 11) | def compute_cosine_similarity(names, weights, return_dict=True):
  class CompCos (line 23) | class CompCos(nn.Module):
    method __init__ (line 25) | def __init__(self, dset, args):
    method freeze_representations (line 130) | def freeze_representations(self):
    method compose (line 140) | def compose(self, attrs, objs):
    method compute_feasibility (line 148) | def compute_feasibility(self):
    method get_pair_scores_objs (line 171) | def get_pair_scores_objs(self, attr, obj, obj_embedding_sim):
    method get_pair_scores_attrs (line 180) | def get_pair_scores_attrs(self, attr, obj, attr_embedding_sim):
    method update_feasibility (line 189) | def update_feasibility(self,epoch):
    method val_forward (line 196) | def val_forward(self, x):
    method val_forward_with_threshold (line 210) | def val_forward_with_threshold(self, x, th=0.):
    method train_forward_open (line 228) | def train_forward_open(self, x):
    method train_forward_closed (line 249) | def train_forward_closed(self, x):
    method forward (line 263) | def forward(self, x):

FILE: czsl/models/gcn.py
  function normt_spm (line 12) | def normt_spm(mx, method='in'):
  function spm_to_tensor (line 30) | def spm_to_tensor(sparse_mx):
  class GraphConv (line 38) | class GraphConv(nn.Module):
    method __init__ (line 40) | def __init__(self, in_channels, out_channels, dropout=False, relu=True):
    method forward (line 56) | def forward(self, inputs, adj):
  class GCN (line 67) | class GCN(nn.Module):
    method __init__ (line 69) | def __init__(self, adj, in_channels, out_channels, hidden_layers):
    method forward (line 109) | def forward(self, x):
  class GraphConvolution (line 119) | class GraphConvolution(nn.Module):
    method __init__ (line 121) | def __init__(self, in_features, out_features, dropout=False, relu=True...
    method reset_parameters (line 143) | def reset_parameters(self):
    method forward (line 147) | def forward(self, input, adj , h0 , lamda, alpha, l):
  class GCNII (line 171) | class GCNII(nn.Module):
    method __init__ (line 172) | def __init__(self, adj, in_channels , out_channels, hidden_dim, hidden...
    method forward (line 195) | def forward(self, x):

FILE: czsl/models/graph_method.py
  class GraphFull (line 10) | class GraphFull(nn.Module):
    method __init__ (line 11) | def __init__(self, dset, args):
    method train_forward_normal (line 56) | def train_forward_normal(self, x):
    method val_forward_dotpr (line 79) | def val_forward_dotpr(self, x):
    method val_forward_distance_fast (line 99) | def val_forward_distance_fast(self, x):
    method forward (line 118) | def forward(self, x):

FILE: czsl/models/image_extractor.py
  class ResNet18_conv (line 7) | class ResNet18_conv(ResNet):
    method __init__ (line 8) | def __init__(self):
    method forward (line 11) | def forward(self, x):
  function get_image_extractor (line 26) | def get_image_extractor(arch = 'resnet18', pretrained = True, feature_di...

FILE: czsl/models/manifold_methods.py
  class ManifoldModel (line 11) | class ManifoldModel(nn.Module):
    method __init__ (line 13) | def __init__(self, dset, args):
    method train_forward_bce (line 46) | def train_forward_bce(self, x):
    method train_forward_triplet (line 65) | def train_forward_triplet(self, x):
    method val_forward_distance (line 84) | def val_forward_distance(self, x):
    method val_forward_distance_fast (line 99) | def val_forward_distance_fast(self, x):
    method val_forward_direct (line 118) | def val_forward_direct(self, x):
    method forward (line 132) | def forward(self, x):
  class RedWine (line 141) | class RedWine(ManifoldModel):
    method __init__ (line 143) | def __init__(self, dset, args):
    method compose (line 187) | def compose(self, attrs, objs):
  class LabelEmbedPlus (line 194) | class LabelEmbedPlus(ManifoldModel):
    method __init__ (line 195) | def __init__(self, dset, args):
    method compose (line 239) | def compose(self, attrs, objs):
  class AttributeOperator (line 245) | class AttributeOperator(ManifoldModel):
    method __init__ (line 246) | def __init__(self, dset, args):
    method apply_ops (line 274) | def apply_ops(self, ops, rep):
    method compose (line 279) | def compose(self, attrs, objs):
    method apply_inverse (line 285) | def apply_inverse(self, img_rep, attrs):
    method train_forward (line 296) | def train_forward(self, x):
    method forward (line 364) | def forward(self, x):

FILE: czsl/models/modular_methods.py
  class Flatten (line 21) | class Flatten(nn.Module):
    method forward (line 22) | def forward(self, input):
  class GatingSampler (line 26) | class GatingSampler(nn.Module):
    method __init__ (line 29) | def __init__(self, gater, stoch_sample=True, temperature=1.0):
    method disable_stochastic_sampling (line 38) | def disable_stochastic_sampling(self):
    method enable_stochastic_sampling (line 41) | def enable_stochastic_sampling(self):
    method forward (line 44) | def forward(self, tdesc=None, return_additional=False, gating_wt=None):
  class GatedModularNet (line 70) | class GatedModularNet(nn.Module):
    method __init__ (line 75) | def __init__(self,
    method forward (line 107) | def forward(self, x, sampled_g=None, t=None, return_feat=False):
  class CompositionalModel (line 218) | class CompositionalModel(nn.Module):
    method __init__ (line 219) | def __init__(self, dset, args):
    method train_forward_softmax (line 231) | def train_forward_softmax(self, x):
    method val_forward (line 276) | def val_forward(self, x):
    method forward (line 319) | def forward(self, x, with_grad=False):
  class GatedGeneralNN (line 334) | class GatedGeneralNN(CompositionalModel):
    method __init__ (line 337) | def __init__(self,
    method compose (line 440) | def compose(self, attrs, objs):
  class GeneralNormalizedNN (line 453) | class GeneralNormalizedNN(nn.Module):
    method __init__ (line 456) | def __init__(self, num_layers, num_modules_per_layer, in_dim, inter_dim):
  class GeneralGatingNN (line 478) | class GeneralGatingNN(nn.Module):
    method __init__ (line 479) | def __init__(
    method forward (line 545) | def forward(self, tdesc=None):
  function modularize_network (line 570) | def modularize_network(
  function modular_general (line 619) | def modular_general(

FILE: czsl/models/svm.py
  function train_svm (line 32) | def train_svm(Y_train, sample_weight=None):
  function generate_svms (line 45) | def generate_svms():
  function make_svm_tensor (line 91) | def make_svm_tensor():
  function evaluate_svms (line 116) | def evaluate_svms():
  function evaluate_tensorcompletion (line 158) | def evaluate_tensorcompletion():

FILE: czsl/models/symnet.py
  class Symnet (line 12) | class Symnet(nn.Module):
    method __init__ (line 13) | def __init__(self, dset, args):
    method CoN (line 43) | def CoN(self, img_embedding, attr_embedding):
    method DeCoN (line 51) | def DeCoN(self, img_embedding, attr_embedding):
    method distance_metric (line 60) | def distance_metric(self, a, b):
    method RMD_prob (line 63) | def RMD_prob(self, feat_plus, feat_minus, repeat_img_feat):
    method train_forward (line 73) | def train_forward(self, x):
    method val_forward (line 180) | def val_forward(self, x):
    method forward (line 208) | def forward(self, x):

FILE: czsl/models/visual_product.py
  class VisualProductNN (line 8) | class VisualProductNN(nn.Module):
    method __init__ (line 9) | def __init__(self, dset, args):
    method train_forward (line 15) | def train_forward(self, x):
    method val_forward (line 28) | def val_forward(self, x):
    method forward (line 41) | def forward(self, x):

FILE: czsl/models/word_embedding.py
  function load_word_embeddings (line 4) | def load_word_embeddings(emb_type, vocab):
  function load_fasttext_embeddings (line 40) | def load_fasttext_embeddings(vocab):
  function load_word2vec_embeddings (line 86) | def load_word2vec_embeddings(vocab):
  function load_glove_embeddings (line 130) | def load_glove_embeddings(vocab):

FILE: czsl/test.py
  function main (line 27) | def main():
  function test (line 138) | def test(image_extractor, model, testloader, evaluator,  args, threshold...

FILE: czsl/train.py
  function main (line 28) | def main():
  function train_normal (line 111) | def train_normal(epoch, image_extractor, model, trainloader, optimizer, ...
  function test (line 140) | def test(epoch, image_extractor, model, testloader, evaluator, writer, a...

FILE: czsl/utils/config_model.py
  class TransformerDecorator (line 14) | class TransformerDecorator(torch.nn.Module):
    method __init__ (line 15) | def __init__(self, model, model_name, add_bt=0, eval_bt=0):
    method is_open (line 26) | def is_open(self):
    method is_open (line 30) | def is_open(self, value):
    method update_feasibility (line 33) | def update_feasibility(self, value):
    method forward_feats (line 36) | def forward_feats(self, feature):
    method forward (line 48) | def forward(self, feature):
  function configure_model (line 55) | def configure_model(args, dataset):

FILE: czsl/utils/utils.py
  function chunks (line 11) | def chunks(l, n):
  function get_norm_values (line 16) | def get_norm_values(norm_family = 'imagenet'):
  function save_args (line 29) | def save_args(args, log_path, argfile):
  class UnNormalizer (line 45) | class UnNormalizer:
    method __init__ (line 54) | def __init__(self, norm_family = 'imagenet'):
    method __call__ (line 58) | def __call__(self, tensor):
  function load_args (line 61) | def load_args(filename, args):

FILE: domain_generalization/Transfer-Learning-Library/common/loss/__init__.py
  class KnowledgeDistillationLoss (line 5) | class KnowledgeDistillationLoss(nn.Module):
    method __init__ (line 24) | def __init__(self, T=1., reduction='batchmean'):
    method forward (line 29) | def forward(self, y_student, y_teacher):

FILE: domain_generalization/Transfer-Learning-Library/common/modules/classifier.py
  class Classifier (line 12) | class Classifier(nn.Module):
    method __init__ (line 47) | def __init__(self, backbone: nn.Module, num_classes: int, bottleneck: ...
    method features_dim (line 74) | def features_dim(self) -> int:
    method forward (line 78) | def forward(self, x: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor]:
    method get_parameters (line 88) | def get_parameters(self, base_lr=1.0) -> List[Dict]:
  class ImageClassifier (line 101) | class ImageClassifier(Classifier):

FILE: domain_generalization/Transfer-Learning-Library/common/modules/regressor.py
  class Regressor (line 12) | class Regressor(nn.Module):
    method __init__ (line 41) | def __init__(self, backbone: nn.Module, num_factors: int, bottleneck: ...
    method features_dim (line 71) | def features_dim(self) -> int:
    method forward (line 75) | def forward(self, x: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor]:
    method get_parameters (line 85) | def get_parameters(self, base_lr=1.0) -> List[Dict]:

FILE: domain_generalization/Transfer-Learning-Library/common/utils/analysis/__init__.py
  function collect_feature (line 7) | def collect_feature(data_loader: DataLoader, feature_extractor: nn.Module,

FILE: domain_generalization/Transfer-Learning-Library/common/utils/analysis/a_distance.py
  class ANet (line 15) | class ANet(nn.Module):
    method __init__ (line 16) | def __init__(self, in_feature):
    method forward (line 21) | def forward(self, x):
  function calculate (line 27) | def calculate(source_feature: torch.Tensor, target_feature: torch.Tensor,

FILE: domain_generalization/Transfer-Learning-Library/common/utils/analysis/tsne.py
  function visualize (line 15) | def visualize(source_feature: torch.Tensor, target_feature: torch.Tensor,

FILE: domain_generalization/Transfer-Learning-Library/common/utils/data.py
  function send_to_device (line 18) | def send_to_device(tensor, device):
  class ForeverDataIterator (line 40) | class ForeverDataIterator:
    method __init__ (line 43) | def __init__(self, data_loader: DataLoader, device=None):
    method __next__ (line 48) | def __next__(self):
    method __len__ (line 60) | def __len__(self):
  class RandomMultipleGallerySampler (line 64) | class RandomMultipleGallerySampler(Sampler):
    method __init__ (line 76) | def __init__(self, dataset, num_instances=4):
    method __len__ (line 97) | def __len__(self):
    method __iter__ (line 100) | def __iter__(self):
  class CombineDataset (line 141) | class CombineDataset(Dataset[T_co]):
    method __init__ (line 151) | def __init__(self, datasets: Iterable[Dataset]) -> None:
    method __len__ (line 157) | def __len__(self):
    method __getitem__ (line 160) | def __getitem__(self, idx):
  function concatenate (line 164) | def concatenate(tensors):

FILE: domain_generalization/Transfer-Learning-Library/common/utils/logger.py
  class TextLogger (line 9) | class TextLogger(object):
    method __init__ (line 16) | def __init__(self, filename, stream=sys.stdout):
    method write (line 20) | def write(self, message):
    method flush (line 25) | def flush(self):
    method close (line 29) | def close(self):
  class CompleteLogger (line 34) | class CompleteLogger:
    method __init__ (line 47) | def __init__(self, root, phase='train'):
    method set_epoch (line 69) | def set_epoch(self, epoch):
    method _get_phase_or_epoch (line 74) | def _get_phase_or_epoch(self):
    method get_image_path (line 80) | def get_image_path(self, filename: str):
    method get_checkpoint_path (line 86) | def get_checkpoint_path(self, name=None):
    method close (line 101) | def close(self):

FILE: domain_generalization/Transfer-Learning-Library/common/utils/meter.py
  class AverageMeter (line 8) | class AverageMeter(object):
    method __init__ (line 18) | def __init__(self, name: str, fmt: Optional[str] = ':f'):
    method reset (line 23) | def reset(self):
    method update (line 29) | def update(self, val, n=1):
    method __str__ (line 36) | def __str__(self):
  class AverageMeterDict (line 41) | class AverageMeterDict(object):
    method __init__ (line 42) | def __init__(self, names: List, fmt: Optional[str] = ':f'):
    method reset (line 47) | def reset(self):
    method update (line 51) | def update(self, accuracies, n=1):
    method average (line 55) | def average(self):
    method __getitem__ (line 60) | def __getitem__(self, item):
  class Meter (line 64) | class Meter(object):
    method __init__ (line 66) | def __init__(self, name: str, fmt: Optional[str] = ':f'):
    method reset (line 71) | def reset(self):
    method update (line 74) | def update(self, val):
    method __str__ (line 77) | def __str__(self):
  class ProgressMeter (line 82) | class ProgressMeter(object):
    method __init__ (line 83) | def __init__(self, num_batches, meters, prefix=""):
    method display (line 88) | def display(self, batch):
    method _get_batch_fmtstr (line 93) | def _get_batch_fmtstr(self, num_batches):

FILE: domain_generalization/Transfer-Learning-Library/common/utils/metric/__init__.py
  function binary_accuracy (line 6) | def binary_accuracy(output: torch.Tensor, target: torch.Tensor) -> float:
  function accuracy (line 16) | def accuracy(output, target, topk=(1,)):
  class ConfusionMatrix (line 43) | class ConfusionMatrix(object):
    method __init__ (line 44) | def __init__(self, num_classes):
    method update (line 48) | def update(self, target, output):
    method reset (line 68) | def reset(self):
    method compute (line 71) | def compute(self):
    method __str__ (line 87) | def __str__(self):
    method format (line 99) | def format(self, classes: list):

FILE: domain_generalization/Transfer-Learning-Library/common/utils/metric/keypoint_detection.py
  function get_max_preds (line 9) | def get_max_preds(batch_heatmaps):
  function calc_dists (line 40) | def calc_dists(preds, target, normalize):
  function dist_acc (line 55) | def dist_acc(dists, thr=0.5):
  function accuracy (line 65) | def accuracy(output, target, hm_type='gaussian', thr=0.5):

FILE: domain_generalization/Transfer-Learning-Library/common/utils/metric/reid.py
  function unique_sample (line 18) | def unique_sample(ids_dict, num):
  function cmc (line 27) | def cmc(dist_mat, query_ids, gallery_ids, query_cams, gallery_cams, topk...
  function mean_ap (line 79) | def mean_ap(dist_mat, query_ids, gallery_ids, query_cams, gallery_cams):
  function re_ranking (line 105) | def re_ranking(q_g_dist, q_q_dist, g_g_dist, k1=20, k2=6, lambda_value=0...
  function extract_reid_feature (line 178) | def extract_reid_feature(data_loader, model, device, normalize, print_fr...
  function pairwise_distance (line 214) | def pairwise_distance(feature_dict, query, gallery):
  function evaluate_all (line 233) | def evaluate_all(dist_mat, query, gallery, cmc_topk=(1, 5, 10), cmc_flag...
  function validate (line 259) | def validate(val_loader, model, query, gallery, device, criterion='cosin...
  function visualize_ranked_results (line 286) | def visualize_ranked_results(data_loader, model, query, gallery, device,...

FILE: domain_generalization/Transfer-Learning-Library/common/utils/scheduler.py
  class WarmupMultiStepLR (line 10) | class WarmupMultiStepLR(torch.optim.lr_scheduler._LRScheduler):
    method __init__ (line 27) | def __init__(
    method get_lr (line 55) | def get_lr(self):

FILE: domain_generalization/Transfer-Learning-Library/common/vision/datasets/_util.py
  function download (line 10) | def download(root: str, file_name: str, archive_name: str, url_link: str):
  function check_exits (line 37) | def check_exits(root: str, file_name: str):
  function read_list_from_file (line 44) | def read_list_from_file(file_name: str) -> List[str]:

FILE: domain_generalization/Transfer-Learning-Library/common/vision/datasets/aircrafts.py
  class Aircraft (line 11) | class Aircraft(ImageList):
    method __init__ (line 64) | def __init__(self, root: str, split: str, sample_rate: Optional[int]=1...

FILE: domain_generalization/Transfer-Learning-Library/common/vision/datasets/coco70.py
  class COCO70 (line 11) | class COCO70(ImageList):
    method __init__ (line 61) | def __init__(self, root: str, split: str, sample_rate: Optional[int] =...

FILE: domain_generalization/Transfer-Learning-Library/common/vision/datasets/cub200.py
  class CUB200 (line 11) | class CUB200(ImageList):
    method __init__ (line 57) | def __init__(self, root: str, split: str, sample_rate: Optional[int] =...

FILE: domain_generalization/Transfer-Learning-Library/common/vision/datasets/digits.py
  class MNIST (line 11) | class MNIST(ImageList):
    method __init__ (line 38) | def __init__(self, root, mode="L", split='train', download: Optional[b...
    method __getitem__ (line 51) | def __getitem__(self, index: int) -> Tuple[Any, int]:
    method get_classes (line 67) | def get_classes(self):
  class USPS (line 71) | class USPS(ImageList):
    method __init__ (line 101) | def __init__(self, root, mode="L", split='train', download: Optional[b...
    method __getitem__ (line 114) | def __getitem__(self, index: int) -> Tuple[Any, int]:
  class SVHN (line 130) | class SVHN(ImageList):
    method __init__ (line 162) | def __init__(self, root, mode="L", download: Optional[bool] = True, **...
    method __getitem__ (line 174) | def __getitem__(self, index: int) -> Tuple[Any, int]:
  class MNISTRGB (line 190) | class MNISTRGB(MNIST):
    method __init__ (line 191) | def __init__(self, root, **kwargs):
  class USPSRGB (line 195) | class USPSRGB(USPS):
    method __init__ (line 196) | def __init__(self, root, **kwargs):
  class SVHNRGB (line 200) | class SVHNRGB(SVHN):
    method __init__ (line 201) | def __init__(self, root, **kwargs):

FILE: domain_generalization/Transfer-Learning-Library/common/vision/datasets/domainnet.py
  class DomainNet (line 11) | class DomainNet(ImageList):
    method __init__ (line 95) | def __init__(self, root: str, task: str, split: Optional[str] = 'train...
    method domains (line 109) | def domains(cls):

FILE: domain_generalization/Transfer-Learning-Library/common/vision/datasets/dtd.py
  class DTD (line 10) | class DTD(ImageList):
    method __init__ (line 35) | def __init__(self, root, split, download=False, **kwargs):

FILE: domain_generalization/Transfer-Learning-Library/common/vision/datasets/eurosat.py
  class EuroSAT (line 10) | class EuroSAT(ImageList):
    method __init__ (line 30) | def __init__(self, root, split='train', download=False, **kwargs):

FILE: domain_generalization/Transfer-Learning-Library/common/vision/datasets/imagelist.py
  class ImageList (line 11) | class ImageList(datasets.VisionDataset):
    method __init__ (line 33) | def __init__(self, root: str, classes: List[str], data_list_file: str,
    method __getitem__ (line 43) | def __getitem__(self, index: int) -> Tuple[Any, int]:
    method __len__ (line 57) | def __len__(self) -> int:
    method parse_data_file (line 60) | def parse_data_file(self, file_name: str) -> List[Tuple[str, int]]:
    method num_classes (line 80) | def num_classes(self) -> int:
    method domains (line 85) | def domains(cls):

FILE: domain_generalization/Transfer-Learning-Library/common/vision/datasets/imagenet_r.py
  class ImageNetR (line 11) | class ImageNetR(ImageList):
    method __init__ (line 68) | def __init__(self, root: str, task: str, split: Optional[str] = 'all',...
    method domains (line 84) | def domains(cls):

FILE: domain_generalization/Transfer-Learning-Library/common/vision/datasets/imagenet_sketch.py
  class ImageNetSketch (line 12) | class ImageNetSketch(ImageList):
    method __init__ (line 53) | def __init__(self, root: str, task: str, split: Optional[str] = 'all',...
    method domains (line 69) | def domains(cls):

FILE: domain_generalization/Transfer-Learning-Library/common/vision/datasets/keypoint_detection/freihand.py
  function _assert_exist (line 18) | def _assert_exist(p):
  function json_load (line 23) | def json_load(p):
  function load_db_annotation (line 30) | def load_db_annotation(base_path, set_name=None):
  function projectPoints (line 56) | def projectPoints(xyz, K):
  function db_size (line 65) | def db_size(set_name):
  class sample_version (line 75) | class sample_version:
    method valid_options (line 84) | def valid_options(cls):
    method check_valid (line 89) | def check_valid(cls, version):
    method map_id (line 94) | def map_id(cls, id, version):
  class FreiHand (line 99) | class FreiHand(Hand21KeypointDataset):
    method __init__ (line 123) | def __init__(self, root, split='train', task='all', download=True, **k...
    method __getitem__ (line 150) | def __getitem__(self, index):
    method get_samples (line 201) | def get_samples(self, root, version='gs'):

FILE: domain_generalization/Transfer-Learning-Library/common/vision/datasets/keypoint_detection/hand_3d_studio.py
  class Hand3DStudio (line 19) | class Hand3DStudio(Hand21KeypointDataset):
    method __init__ (line 49) | def __init__(self, root, split='train', task='noobject', download=True...
    method __getitem__ (line 82) | def __getitem__(self, index):
  class Hand3DStudioAll (line 119) | class Hand3DStudioAll(Hand3DStudio):
    method __init__ (line 124) | def __init__(self,  root, task='all', **kwargs):

FILE: domain_generalization/Transfer-Learning-Library/common/vision/datasets/keypoint_detection/human36m.py
  class Human36M (line 17) | class Human36M(Body16KeypointDataset):
    method __init__ (line 50) | def __init__(self, root, split='train', task='all', download=True, **k...
    method __getitem__ (line 75) | def __getitem__(self, index):
    method preprocess (line 111) | def preprocess(self, part, root):

FILE: domain_generalization/Transfer-Learning-Library/common/vision/datasets/keypoint_detection/keypoint_dataset.py
  class KeypointDataset (line 12) | class KeypointDataset(Dataset, ABC):
    method __init__ (line 27) | def __init__(self, root, num_keypoints, samples, transforms=None, imag...
    method __len__ (line 39) | def __len__(self):
    method visualize (line 42) | def visualize(self, image, keypoints, filename):
    method group_accuracy (line 62) | def group_accuracy(self, accuracies):
  class Body16KeypointDataset (line 78) | class Body16KeypointDataset(KeypointDataset, ABC):
    method __init__ (line 97) | def __init__(self, root, samples, **kwargs):
  class Hand21KeypointDataset (line 119) | class Hand21KeypointDataset(KeypointDataset, ABC):
    method __init__ (line 135) | def __init__(self, root, samples, **kwargs):

FILE: domain_generalization/Transfer-Learning-Library/common/vision/datasets/keypoint_detection/lsp.py
  class LSP (line 19) | class LSP(Body16KeypointDataset):
    method __init__ (line 42) | def __init__(self, root, split='train', task='all', download=True, ima...
    method __getitem__ (line 69) | def __getitem__(self, index):

FILE: domain_generalization/Transfer-Learning-Library/common/vision/datasets/keypoint_detection/rendered_hand_pose.py
  class RenderedHandPose (line 15) | class RenderedHandPose(Hand21KeypointDataset):
    method __init__ (line 36) | def __init__(self, root, split='train', task='all', download=True, **k...
    method __getitem__ (line 54) | def __getitem__(self, index):
    method get_samples (line 106) | def get_samples(self, root, task, min_size=64):

FILE: domain_generalization/Transfer-Learning-Library/common/vision/datasets/keypoint_detection/surreal.py
  class SURREAL (line 17) | class SURREAL(Body16KeypointDataset):
    method __init__ (line 43) | def __init__(self, root, split='train', task='all', download=True, **k...
    method __getitem__ (line 82) | def __getitem__(self, index):
    method __len__ (line 120) | def __len__(self):

FILE: domain_generalization/Transfer-Learning-Library/common/vision/datasets/keypoint_detection/util.py
  function generate_target (line 9) | def generate_target(joints, joints_vis, heatmap_size, sigma, image_size):
  function keypoint2d_to_3d (line 71) | def keypoint2d_to_3d(keypoint2d: np.ndarray, intrinsic_matrix: np.ndarra...
  function keypoint3d_to_2d (line 78) | def keypoint3d_to_2d(keypoint3d: np.ndarray, intrinsic_matrix: np.ndarray):
  function scale_box (line 85) | def scale_box(box, image_width, image_height, scale):
  function get_bounding_box (line 114) | def get_bounding_box(keypoint2d: np.array):
  function visualize_heatmap (line 123) | def visualize_heatmap(image, heatmaps, filename):
  function area (line 135) | def area(left, upper, right, lower):
  function intersection (line 139) | def intersection(box_a, box_b):

FILE: domain_generalization/Transfer-Learning-Library/common/vision/datasets/office31.py
  class Office31 (line 11) | class Office31(ImageList):
    method __init__ (line 54) | def __init__(self, root: str, task: str, download: Optional[bool] = Tr...
    method domains (line 66) | def domains(cls):

FILE: domain_generalization/Transfer-Learning-Library/common/vision/datasets/officecaltech.py
  class OfficeCaltech (line 12) | class OfficeCaltech(DatasetFolder):
    method __init__ (line 50) | def __init__(self, root: str, task: str, download: Optional[bool] = Fa...
    method num_classes (line 69) | def num_classes(self):
    method domains (line 74) | def domains(cls):

FILE: domain_generalization/Transfer-Learning-Library/common/vision/datasets/officehome.py
  class OfficeHome (line 11) | class OfficeHome(ImageList):
    method __init__ (line 59) | def __init__(self, root: str, task: str, download: Optional[bool] = Fa...
    method domains (line 71) | def domains(cls):

FILE: domain_generalization/Transfer-Learning-Library/common/vision/datasets/openset/__init__.py
  function open_set (line 17) | def open_set(dataset_class: ClassVar, public_classes: Sequence[str],
  function default_open_set (line 67) | def default_open_set(dataset_class: ClassVar, source: bool) -> ClassVar:

FILE: domain_generalization/Transfer-Learning-Library/common/vision/datasets/oxfordflowers.py
  class OxfordFlowers102 (line 10) | class OxfordFlowers102(ImageList):
    method __init__ (line 48) | def __init__(self, root, split='train', download=False, **kwargs):

FILE: domain_generalization/Transfer-Learning-Library/common/vision/datasets/oxfordpet.py
  class OxfordIIITPet (line 11) | class OxfordIIITPet(ImageList):
    method __init__ (line 58) | def __init__(self, root: str, split: str, sample_rate: Optional[int] =...

FILE: domain_generalization/Transfer-Learning-Library/common/vision/datasets/pacs.py
  class PACS (line 7) | class PACS(ImageList):
    method __init__ (line 50) | def __init__(self, root: str, task: str, split='all', download: Option...
    method domains (line 66) | def domains(cls):

FILE: domain_generalization/Transfer-Learning-Library/common/vision/datasets/partial/__init__.py
  function partial (line 19) | def partial(dataset_class: ClassVar, partial_classes: Sequence[str]) -> ...
  function default_partial (line 59) | def default_partial(dataset_class: ClassVar) -> ClassVar:

FILE: domain_generalization/Transfer-Learning-Library/common/vision/datasets/partial/caltech_imagenet.py
  class CaltechImageNet (line 48) | class CaltechImageNet(ImageList):
    method __init__ (line 87) | def __init__(self, root: str, task: str, download: Optional[bool] = Tr...
  class CaltechImageNetUniversal (line 104) | class CaltechImageNetUniversal(ImageList):
    method __init__ (line 143) | def __init__(self, root: str, task: str, download: Optional[bool] = Tr...

FILE: domain_generalization/Transfer-Learning-Library/common/vision/datasets/partial/imagenet_caltech.py
  class ImageNetCaltech (line 391) | class ImageNetCaltech(ImageList):
    method __init__ (line 430) | def __init__(self, root: str, task: str, download: Optional[bool] = Tr...
  class ImageNetCaltechUniversal (line 447) | class ImageNetCaltechUniversal(ImageList):
    method __init__ (line 487) | def __init__(self, root: str, task: str, download: Optional[bool] = Tr...

FILE: domain_generalization/Transfer-Learning-Library/common/vision/datasets/patchcamelyon.py
  class PatchCamelyon (line 10) | class PatchCamelyon(ImageList):
    method __init__ (line 28) | def __init__(self, root, split, download=False,  **kwargs):

FILE: domain_generalization/Transfer-Learning-Library/common/vision/datasets/regression/dsprites.py
  class DSprites (line 11) | class DSprites(ImageRegression):
    method __init__ (line 53) | def __init__(self, root: str, task: str, split: Optional[str] = 'train',

FILE: domain_generalization/Transfer-Learning-Library/common/vision/datasets/regression/image_regression.py
  class ImageRegression (line 12) | class ImageRegression(datasets.VisionDataset):
    method __init__ (line 34) | def __init__(self, root: str, factors: Sequence[str], data_list_file: ...
    method __getitem__ (line 42) | def __getitem__(self, index: int) -> Tuple[Any, Tuple[float]]:
    method __len__ (line 58) | def __len__(self) -> int:
    method parse_data_file (line 61) | def parse_data_file(self, file_name: str) -> List[Tuple[str, Any]]:
    method num_factors (line 82) | def num_factors(self) -> int:

FILE: domain_generalization/Transfer-Learning-Library/common/vision/datasets/regression/mpi3d.py
  class MPI3D (line 11) | class MPI3D(ImageRegression):
    method __init__ (line 53) | def __init__(self, root: str, task: str, split: Optional[str] = 'train',

FILE: domain_generalization/Transfer-Learning-Library/common/vision/datasets/reid/basedataset.py
  class BaseDataset (line 10) | class BaseDataset(object):
    method get_imagedata_info (line 15) | def get_imagedata_info(self, data):
    method get_videodata_info (line 27) | def get_videodata_info(self, data, return_tracklet_stats=False):
    method print_dataset_statistics (line 42) | def print_dataset_statistics(self, train, query, galler):
    method check_before_run (line 45) | def check_before_run(self, required_files):
    method images_dir (line 58) | def images_dir(self):
  class BaseImageDataset (line 62) | class BaseImageDataset(BaseDataset):
    method print_dataset_statistics (line 67) | def print_dataset_statistics(self, train, query, gallery):
  class BaseVideoDataset (line 82) | class BaseVideoDataset(BaseDataset):
    method print_dataset_statistics (line 87) | def print_dataset_statistics(self, train, query, gallery):

FILE: domain_generalization/Transfer-Learning-Library/common/vision/datasets/reid/convert.py
  function convert_to_pytorch_dataset (line 10) | def convert_to_pytorch_dataset(dataset, root=None, transform=None, retur...

FILE: domain_generalization/Transfer-Learning-Library/common/vision/datasets/reid/dukemtmc.py
  class DukeMTMC (line 15) | class DukeMTMC(BaseImageDataset):
    method __init__ (line 32) | def __init__(self, root, verbose=True):
    method process_dir (line 60) | def process_dir(self, dir_path, relabel=False):
    method translate (line 81) | def translate(self, transform: Callable, target_root: str):
    method translate_dir (line 102) | def translate_dir(self, transform, origin_dir: str, target_dir: str):

FILE: domain_generalization/Transfer-Learning-Library/common/vision/datasets/reid/market1501.py
  class Market1501 (line 15) | class Market1501(BaseImageDataset):
    method __init__ (line 32) | def __init__(self, root, verbose=True):
    method process_dir (line 60) | def process_dir(self, dir_path, relabel=False):
    method translate (line 86) | def translate(self, transform: Callable, target_root: str):
    method translate_dir (line 107) | def translate_dir(self, transform, origin_dir: str, target_dir: str):

FILE: domain_generalization/Transfer-Learning-Library/common/vision/datasets/reid/msmt17.py
  class MSMT17 (line 13) | class MSMT17(BaseImageDataset):
    method __init__ (line 30) | def __init__(self, root, verbose=True):
    method process_dir (line 53) | def process_dir(self, dir_path):
    method translate (line 71) | def translate(self, transform: Callable, target_root: str):
    method translate_dir (line 92) | def translate_dir(self, transform, origin_dir: str, target_dir: str):

FILE: domain_generalization/Transfer-Learning-Library/common/vision/datasets/reid/personx.py
  class PersonX (line 16) | class PersonX(BaseImageDataset):
    method __init__ (line 33) | def __init__(self, root, verbose=True):
    method process_dir (line 61) | def process_dir(self, dir_path, relabel=False):
    method translate (line 84) | def translate(self, transform: Callable, target_root: str):
    method translate_dir (line 105) | def translate_dir(self, transform, origin_dir: str, target_dir: str):

FILE: domain_generalization/Transfer-Learning-Library/common/vision/datasets/reid/unreal.py
  class UnrealPerson (line 12) | class UnrealPerson(BaseImageDataset):
    method __init__ (line 42) | def __init__(self, root, verbose=True):
    method process_dir (line 66) | def process_dir(self, list_file):
    method translate (line 86) | def translate(self, transform: Callable, target_root: str):

FILE: domain_generalization/Transfer-Learning-Library/common/vision/datasets/resisc45.py
  class Resisc45 (line 10) | class Resisc45(ImageFolder):
    method __init__ (line 27) | def __init__(self, root, split='train', download=False, **kwargs):
    method num_classes (line 37) | def num_classes(self) -> int:

FILE: domain_generalization/Transfer-Learning-Library/common/vision/datasets/retinopathy.py
  class Retinopathy (line 9) | class Retinopathy(ImageList):
    method __init__ (line 27) | def __init__(self, root, split, download=False, **kwargs):

FILE: domain_generalization/Transfer-Learning-Library/common/vision/datasets/segmentation/cityscapes.py
  class Cityscapes (line 10) | class Cityscapes(SegmentationList):
    method __init__ (line 55) | def __init__(self, root, split='train', data_folder='leftImg8bit', lab...
    method parse_label_file (line 67) | def parse_label_file(self, label_list_file):
  class FoggyCityscapes (line 73) | class FoggyCityscapes(Cityscapes):
    method __init__ (line 99) | def __init__(self, root, split='train', data_folder='leftImg8bit_foggy...
    method parse_data_file (line 104) | def parse_data_file(self, file_name):

FILE: domain_generalization/Transfer-Learning-Library/common/vision/datasets/segmentation/gta5.py
  class GTA5 (line 11) | class GTA5(SegmentationList):
    method __init__ (line 33) | def __init__(self, root, split='train', data_folder='images', label_fo...

FILE: domain_generalization/Transfer-Learning-Library/common/vision/datasets/segmentation/segmentation_list.py
  class SegmentationList (line 14) | class SegmentationList(data.Dataset):
    method __init__ (line 42) | def __init__(self, root: str, classes: Sequence[str], data_list_file: ...
    method parse_data_file (line 59) | def parse_data_file(self, file_name):
    method parse_label_file (line 72) | def parse_label_file(self, file_name):
    method __len__ (line 85) | def __len__(self):
    method __getitem__ (line 88) | def __getitem__(self, index):
    method num_classes (line 107) | def num_classes(self) -> int:
    method decode_target (line 111) | def decode_target(self, target):
    method collect_image_paths (line 125) | def collect_image_paths(self):
    method _save_pil_image (line 130) | def _save_pil_image(image, path):
    method translate (line 134) | def translate(self, transform: Callable, target_root: str, color=False):
    method evaluate_classes (line 161) | def evaluate_classes(self):
    method ignore_classes (line 166) | def ignore_classes(self):

FILE: domain_generalization/Transfer-Learning-Library/common/vision/datasets/segmentation/synthia.py
  class Synthia (line 11) | class Synthia(SegmentationList):
    method __init__ (line 38) | def __init__(self, root, split='train', data_folder='RGB', label_folde...
    method evaluate_classes (line 48) | def evaluate_classes(self):

FILE: domain_generalization/Transfer-Learning-Library/common/vision/datasets/stanford_cars.py
  class StanfordCars (line 11) | class StanfordCars(ImageList):
    method __init__ (line 64) | def __init__(self, root: str, split: str, sample_rate: Optional[int] =...

FILE: domain_generalization/Transfer-Learning-Library/common/vision/datasets/stanford_dogs.py
  class StanfordDogs (line 11) | class StanfordDogs(ImageList):
    method __init__ (line 75) | def __init__(self, root: str, split: str, sample_rate: Optional[int] =...

FILE: domain_generalization/Transfer-Learning-Library/common/vision/datasets/visda2017.py
  class VisDA2017 (line 11) | class VisDA2017(ImageList):
    method __init__ (line 47) | def __init__(self, root: str, task: str, download: Optional[bool] = Fa...
    method domains (line 59) | def domains(cls):

FILE: domain_generalization/Transfer-Learning-Library/common/vision/models/digits.py
  class LeNet (line 8) | class LeNet(nn.Sequential):
    method __init__ (line 9) | def __init__(self, num_classes=10):
    method copy_head (line 26) | def copy_head(self):
  class DTN (line 30) | class DTN(nn.Sequential):
    method __init__ (line 31) | def __init__(self, num_classes=10):
    method copy_head (line 54) | def copy_head(self):
  function lenet (line 59) | def lenet(pretrained=False, **kwargs):
  function dtn (line 73) | def dtn(pretrained=False, **kwargs):

FILE: domain_generalization/Transfer-Learning-Library/common/vision/models/ibn.py
  class IBN (line 25) | class IBN(nn.Module):
    method __init__ (line 41) | def __init__(self, planes, ratio=0.5):
    method forward (line 47) | def forward(self, x):
  class BasicBlock_IBN (line 55) | class BasicBlock_IBN(nn.Module):
    method __init__ (line 58) | def __init__(self, inplanes, planes, ibn=None, stride=1, downsample=No...
    method forward (line 73) | def forward(self, x):
  class Bottleneck_IBN (line 94) | class Bottleneck_IBN(nn.Module):
    method __init__ (line 97) | def __init__(self, inplanes, planes, ibn=None, stride=1, downsample=No...
    method forward (line 114) | def forward(self, x):
  class ResNet_IBN (line 139) | class ResNet_IBN(nn.Module):
    method __init__ (line 144) | def __init__(self, block, layers, ibn_cfg=('a', 'a', 'a', None)):
    method _make_layer (line 169) | def _make_layer(self, block, planes, blocks, stride=1, ibn=None):
    method forward (line 189) | def forward(self, x):
    method out_features (line 204) | def out_features(self) -> int:
  function resnet18_ibn_a (line 209) | def resnet18_ibn_a(pretrained=False):
  function resnet34_ibn_a (line 223) | def resnet34_ibn_a(pretrained=False):
  function resnet50_ibn_a (line 237) | def resnet50_ibn_a(pretrained=False):
  function resnet101_ibn_a (line 251) | def resnet101_ibn_a(pretrained=False):
  function resnet18_ibn_b (line 265) | def resnet18_ibn_b(pretrained=False):
  function resnet34_ibn_b (line 279) | def resnet34_ibn_b(pretrained=False):
  function resnet50_ibn_b (line 293) | def resnet50_ibn_b(pretrained=False):
  function resnet101_ibn_b (line 307) | def resnet101_ibn_b(pretrained=False):

FILE: domain_generalization/Transfer-Learning-Library/common/vision/models/keypoint_detection/loss.py
  class JointsMSELoss (line 10) | class JointsMSELoss(nn.Module):
    method __init__ (line 33) | def __init__(self, reduction='mean'):
    method forward (line 38) | def forward(self, output, target, target_weight=None):
  class JointsKLLoss (line 51) | class JointsKLLoss(nn.Module):
    method __init__ (line 75) | def __init__(self, reduction='mean', epsilon=0.):
    method forward (line 81) | def forward(self, output, target, target_weight=None):

FILE: domain_generalization/Transfer-Learning-Library/common/vision/models/keypoint_detection/pose_resnet.py
  class Upsampling (line 10) | class Upsampling(nn.Sequential):
    method __init__ (line 14) | def __init__(self, in_channel=2048, hidden_dims=(256, 256, 256), kerne...
  class PoseResNet (line 58) | class PoseResNet(nn.Module):
    method __init__ (line 69) | def __init__(self, backbone, upsampling, feature_dim, num_keypoints, f...
    method forward (line 79) | def forward(self, x):
    method get_parameters (line 85) | def get_parameters(self, lr=1.):
  function _pose_resnet (line 93) | def _pose_resnet(arch, num_keypoints, block, layers, pretrained_backbone...
  function pose_resnet101 (line 100) | def pose_resnet101(num_keypoints, pretrained_backbone=True, deconv_with_...

FILE: domain_generalization/Transfer-Learning-Library/common/vision/models/reid/identifier.py
  class ReIdentifier (line 11) | class ReIdentifier(nn.Module):
    method __init__ (line 20) | def __init__(self, backbone: nn.Module, num_classes: int, bottleneck: ...
    method features_dim (line 54) | def features_dim(self) -> int:
    method forward (line 58) | def forward(self, x: torch.Tensor):
    method get_parameters (line 67) | def get_parameters(self, base_lr=1.0, rate=0.1) -> List[Dict]:

FILE: domain_generalization/Transfer-Learning-Library/common/vision/models/reid/loss.py
  function pairwise_euclidean_distance (line 11) | def pairwise_euclidean_distance(x, y):
  function hard_examples_mining (line 22) | def hard_examples_mining(dist_mat, identity_mat, return_idxes=False):
  class CrossEntropyLossWithLabelSmooth (line 52) | class CrossEntropyLossWithLabelSmooth(nn.Module):
    method __init__ (line 77) | def __init__(self, num_classes, epsilon=0.1):
    method forward (line 83) | def forward(self, y, labels):
  class TripletLoss (line 91) | class TripletLoss(nn.Module):
    method __init__ (line 101) | def __init__(self, margin, normalize_feature=False):
    method forward (line 107) | def forward(self, f, labels):
  class TripletLossXBM (line 122) | class TripletLossXBM(nn.Module):
    method __init__ (line 145) | def __init__(self, margin=0.3, normalize_feature=False):
    method forward (line 151) | def forward(self, f, labels, xbm_f, xbm_labels):
  class SoftTripletLoss (line 171) | class SoftTripletLoss(nn.Module):
    method __init__ (line 196) | def __init__(self, margin=None, normalize_feature=False):
    method forward (line 201) | def forward(self, features_1, features_2, labels):
  class CrossEntropyLoss (line 231) | class CrossEntropyLoss(nn.Module):
    method __init__ (line 248) | def __init__(self):
    method forward (line 252) | def forward(self, y, labels):

FILE: domain_generalization/Transfer-Learning-Library/common/vision/models/reid/resnet.py
  class ReidResNet (line 10) | class ReidResNet(ResNet):
    method __init__ (line 17) | def __init__(self, *args, **kwargs):
    method forward (line 22) | def forward(self, x):
  function _reid_resnet (line 36) | def _reid_resnet(arch, block, layers, pretrained, progress, **kwargs):
  function reid_resnet18 (line 48) | def reid_resnet18(pretrained=False, progress=True, **kwargs):
  function reid_resnet34 (line 59) | def reid_resnet34(pretrained=False, progress=True, **kwargs):
  function reid_resnet50 (line 70) | def reid_resnet50(pretrained=False, progress=True, **kwargs):
  function reid_resnet101 (line 81) | def reid_resnet101(pretrained=False, progress=True, **kwargs):

FILE: domain_generalization/Transfer-Learning-Library/common/vision/models/resnet.py
  class ResNet (line 18) | class ResNet(models.ResNet):
    method __init__ (line 21) | def __init__(self, *args, **kwargs):
    method forward (line 25) | def forward(self, x):
    method out_features (line 43) | def out_features(self) -> int:
    method copy_head (line 47) | def copy_head(self) -> nn.Module:
  function _resnet (line 52) | def _resnet(arch, block, layers, pretrained, progress, **kwargs):
  function resnet18 (line 64) | def resnet18(pretrained=False, progress=True, **kwargs):
  function resnet34 (line 76) | def resnet34(pretrained=False, progress=True, **kwargs):
  function resnet50 (line 88) | def resnet50(pretrained=False, progress=True, **kwargs):
  function resnet101 (line 100) | def resnet101(pretrained=False, progress=True, **kwargs):
  function resnet152 (line 112) | def resnet152(pretrained=False, progress=True, **kwargs):
  function resnext50_32x4d (line 124) | def resnext50_32x4d(pretrained=False, progress=True, **kwargs):
  function resnext101_32x8d (line 138) | def resnext101_32x8d(pretrained=False, progress=True, **kwargs):
  function wide_resnet50_2 (line 152) | def wide_resnet50_2(pretrained=False, progress=True, **kwargs):
  function wide_resnet101_2 (line 170) | def wide_resnet101_2(pretrained=False, progress=True, **kwargs):

FILE: domain_generalization/Transfer-Learning-Library/common/vision/models/segmentation/deeplabv2.py
  class Bottleneck (line 16) | class Bottleneck(nn.Module):
    method __init__ (line 19) | def __init__(self, inplanes, planes, stride=1, dilation=1, downsample=...
    method forward (line 43) | def forward(self, x):
  class ASPP_V2 (line 66) | class ASPP_V2(nn.Module):
    method __init__ (line 67) | def __init__(self, inplanes, dilation_series, padding_series, num_clas...
    method forward (line 77) | def forward(self, x):
  class ResNet (line 85) | class ResNet(nn.Module):
    method __init__ (line 86) | def __init__(self, block, layers):
    method _make_layer (line 109) | def _make_layer(self, block, planes, blocks, stride=1, dilation=1):
    method forward (line 125) | def forward(self, x):
  class Deeplab (line 137) | class Deeplab(nn.Module):
    method __init__ (line 138) | def __init__(self, backbone, classifier, num_classes):
    method forward (line 144) | def forward(self, x):
    method get_1x_lr_params_NOscale (line 149) | def get_1x_lr_params_NOscale(self):
    method get_10x_lr_params (line 164) | def get_10x_lr_params(self):
    method get_parameters (line 172) | def get_parameters(self, lr=1.):
  function deeplabv2_resnet101 (line 179) | def deeplabv2_resnet101(num_classes=19, pretrained_backbone=True):

FILE: domain_generalization/Transfer-Learning-Library/common/vision/transforms/__init__.py
  class ResizeImage (line 9) | class ResizeImage(object):
    method __init__ (line 18) | def __init__(self, size):
    method __call__ (line 24) | def __call__(self, img):
    method __repr__ (line 28) | def __repr__(self):
  class MultipleApply (line 32) | class MultipleApply:
    method __init__ (line 51) | def __init__(self, transforms):
    method __call__ (line 54) | def __call__(self, image):
    method __repr__ (line 57) | def __repr__(self):
  class Denormalize (line 66) | class Denormalize(Normalize):
    method __init__ (line 82) | def __init__(self, mean, std):
  class NormalizeAndTranspose (line 88) | class NormalizeAndTranspose:
    method __init__ (line 94) | def __init__(self, mean=(104.00698793, 116.66876762, 122.67891434)):
    method __call__ (line 97) | def __call__(self, image):
  class DeNormalizeAndTranspose (line 116) | class DeNormalizeAndTranspose:
    method __init__ (line 122) | def __init__(self, mean=(104.00698793, 116.66876762, 122.67891434)):
    method __call__ (line 125) | def __call__(self, image):
  class RandomErasing (line 134) | class RandomErasing(object):
    method __init__ (line 147) | def __init__(self, probability=0.5, sl=0.02, sh=0.4, r1=0.3, mean=(0.4...
    method __call__ (line 154) | def __call__(self, img):
    method __repr__ (line 181) | def __repr__(self):

FILE: domain_generalization/Transfer-Learning-Library/common/vision/transforms/keypoint_detection.py
  function wrapper (line 17) | def wrapper(transform: ClassVar):
  function resize (line 39) | def resize(image: Image.Image, size: int, interpolation=Image.BILINEAR,
  function crop (line 55) | def crop(image: Image.Image, top, left, height, width, keypoint2d: np.nd...
  function resized_crop (line 63) | def resized_crop(img, top, left, height, width, size, interpolation=Imag...
  function center_crop (line 87) | def center_crop(image, output_size, keypoint2d: np.ndarray):
  function hflip (line 105) | def hflip(image: Image.Image, keypoint2d: np.ndarray):
  function rotate (line 113) | def rotate(image: Image.Image, angle, keypoint2d: np.ndarray):
  function resize_pad (line 131) | def resize_pad(img, keypoint2d, size, interpolation=Image.BILINEAR):
  class Compose (line 158) | class Compose(object):
    method __init__ (line 165) | def __init__(self, transforms):
    method __call__ (line 168) | def __call__(self, image, **kwargs):
  class GaussianBlur (line 174) | class GaussianBlur(object):
    method __init__ (line 175) | def __init__(self, low=0, high=0.8):
    method __call__ (line 179) | def __call__(self, image: Image, **kwargs):
  class Resize (line 185) | class Resize(object):
    method __init__ (line 189) | def __init__(self, size, interpolation=Image.BILINEAR):
    method __call__ (line 194) | def __call__(self, image, keypoint2d: np.ndarray, intrinsic_matrix: np...
  class ResizePad (line 202) | class ResizePad(object):
    method __init__ (line 205) | def __init__(self, size, interpolation=Image.BILINEAR):
    method __call__ (line 209) | def __call__(self, img, keypoint2d, **kwargs):
  class CenterCrop (line 215) | class CenterCrop(object):
    method __init__ (line 219) | def __init__(self, size):
    method __call__ (line 225) | def __call__(self, image, keypoint2d, **kwargs):
  class RandomRotation (line 240) | class RandomRotation(object):
    method __init__ (line 249) | def __init__(self, degrees):
    method get_params (line 261) | def get_params(degrees):
    method __call__ (line 271) | def __call__(self, image, keypoint2d, **kwargs):
  class RandomResizedCrop (line 289) | class RandomResizedCrop(object):
    method __init__ (line 304) | def __init__(self, size, scale=(0.6, 1.3), interpolation=Image.BILINEAR):
    method get_params (line 313) | def get_params(img, scale):
    method __call__ (line 342) | def __call__(self, image, keypoint2d: np.ndarray, intrinsic_matrix: np...
  class RandomApply (line 358) | class RandomApply(T.RandomTransforms):
    method __init__ (line 366) | def __init__(self, transforms, p=0.5):
    method __call__ (line 370) | def __call__(self, image, **kwargs):

FILE: domain_generalization/Transfer-Learning-Library/common/vision/transforms/segmentation.py
  function wrapper (line 17) | def wrapper(transform: ClassVar):
  class Compose (line 42) | class Compose:
    method __init__ (line 54) | def __init__(self, transforms):
    method __call__ (line 58) | def __call__(self, image, target):
  class Resize (line 64) | class Resize(nn.Module):
    method __init__ (line 75) | def __init__(self, image_size, label_size=None):
    method forward (line 83) | def forward(self, image, label):
  class RandomCrop (line 98) | class RandomCrop(nn.Module):
    method __init__ (line 105) | def __init__(self, size):
    method forward (line 109) | def forward(self, image, label):
  class RandomHorizontalFlip (line 132) | class RandomHorizontalFlip(nn.Module):
    method __init__ (line 139) | def __init__(self, p=0.5):
    method forward (line 143) | def forward(self, image, label):
  class RandomResizedCrop (line 157) | class RandomResizedCrop(T.RandomResizedCrop):
    method __init__ (line 174) | def __init__(self, size, scale=(0.5, 1.0), ratio=(3. / 4., 4. / 3.), i...
    method get_params (line 178) | def get_params(
    method forward (line 222) | def forward(self, image, label):
  class RandomChoice (line 239) | class RandomChoice(T.RandomTransforms):
    method __call__ (line 242) | def __call__(self, image, label):
  class RandomApply (line 247) | class RandomApply(T.RandomTransforms):
    method __init__ (line 255) | def __init__(self, transforms, p=0.5):
    method __call__ (line 259) | def __call__(self, image, label):

FILE: domain_generalization/Transfer-Learning-Library/dalib/adaptation/adda.py
  class DomainAdversarialLoss (line 12) | class DomainAdversarialLoss(nn.Module):
    method __init__ (line 31) | def __init__(self):
    method forward (line 34) | def forward(self, domain_pred, domain_label='source'):
  class ImageClassifier (line 42) | class ImageClassifier(ClassifierBase):
    method __init__ (line 43) | def __init__(self, backbone: nn.Module, num_classes: int, bottleneck_d...
    method freeze_bn (line 53) | def freeze_bn(self):
    method get_parameters (line 58) | def get_parameters(self, base_lr=1.0, optimize_head=True) -> List[Dict]:

FILE: domain_generalization/Transfer-Learning-Library/dalib/adaptation/advent.py
  class Discriminator (line 11) | class Discriminator(nn.Sequential):
    method __init__ (line 27) | def __init__(self, num_classes, ndf=64):
  function prob_2_entropy (line 41) | def prob_2_entropy(prob):
  function bce_loss (line 48) | def bce_loss(y_pred, y_label):
  class DomainAdversarialEntropyLoss (line 55) | class DomainAdversarialEntropyLoss(nn.Module):
    method __init__ (line 82) | def __init__(self, discriminator: nn.Module):
    method forward (line 86) | def forward(self, logits, domain_label='source'):
    method train (line 98) | def train(self, mode=True):
    method eval (line 110) | def eval(self):

FILE: domain_generalization/Transfer-Learning-Library/dalib/adaptation/afn.py
  class AdaptiveFeatureNorm (line 14) | class AdaptiveFeatureNorm(nn.Module):
    method __init__ (line 49) | def __init__(self, delta):
    method forward (line 53) | def forward(self, f: torch.Tensor) -> torch.Tensor:
  class Block (line 61) | class Block(nn.Module):
    method __init__ (line 82) | def __init__(self, in_features: int, bottleneck_dim: Optional[int] = 1...
    method forward (line 90) | def forward(self, x: torch.Tensor) -> torch.Tensor:
  class ImageClassifier (line 100) | class ImageClassifier(ClassfierBase):
    method __init__ (line 112) | def __init__(self, backbone: nn.Module, num_classes: int, num_blocks: ...
    method get_parameters (line 135) | def get_parameters(self, base_lr=1.0) -> List[Dict]:

FILE: domain_generalization/Transfer-Learning-Library/dalib/adaptation/bsp.py
  class BatchSpectralPenalizationLoss (line 11) | class BatchSpectralPenalizationLoss(nn.Module):
    method __init__ (line 43) | def __init__(self):
    method forward (line 46) | def forward(self, f_s, f_t):
  class ImageClassifier (line 53) | class ImageClassifier(ClassifierBase):
    method __init__ (line 54) | def __init__(self, backbone: nn.Module, num_classes: int, bottleneck_d...

FILE: domain_generalization/Transfer-Learning-Library/dalib/adaptation/cdan.py
  class ConditionalDomainAdversarialLoss (line 20) | class ConditionalDomainAdversarialLoss(nn.Module):
    method __init__ (line 80) | def __init__(self, domain_discriminator: nn.Module, entropy_conditioni...
    method forward (line 100) | def forward(self, g_s: torch.Tensor, f_s: torch.Tensor, g_t: torch.Ten...
  class RandomizedMultiLinearMap (line 117) | class RandomizedMultiLinearMap(nn.Module):
    method __init__ (line 139) | def __init__(self, features_dim: int, num_classes: int, output_dim: Op...
    method forward (line 145) | def forward(self, f: torch.Tensor, g: torch.Tensor) -> torch.Tensor:
  class MultiLinearMap (line 152) | class MultiLinearMap(nn.Module):
    method __init__ (line 161) | def __init__(self):
    method forward (line 164) | def forward(self, f: torch.Tensor, g: torch.Tensor) -> torch.Tensor:
  class ImageClassifier (line 170) | class ImageClassifier(ClassifierBase):
    method __init__ (line 171) | def __init__(self, backbone: nn.Module, num_classes: int, bottleneck_d...

FILE: domain_generalization/Transfer-Learning-Library/dalib/adaptation/dan.py
  class MultipleKernelMaximumMeanDiscrepancy (line 15) | class MultipleKernelMaximumMeanDiscrepancy(nn.Module):
    method __init__ (line 72) | def __init__(self, kernels: Sequence[nn.Module], linear: Optional[bool...
    method forward (line 78) | def forward(self, z_s: torch.Tensor, z_t: torch.Tensor) -> torch.Tensor:
  function _update_index_matrix (line 92) | def _update_index_matrix(batch_size: int, index_matrix: Optional[torch.T...
  class ImageClassifier (line 122) | class ImageClassifier(ClassifierBase):
    method __init__ (line 123) | def __init__(self, backbone: nn.Module, num_classes: int, bottleneck_d...

FILE: domain_generalization/Transfer-Learning-Library/dalib/adaptation/dann.py
  class DomainAdversarialLoss (line 17) | class DomainAdversarialLoss(nn.Module):
    method __init__ (line 59) | def __init__(self, domain_discriminator: nn.Module, reduction: Optiona...
    method forward (line 68) | def forward(self, f_s: torch.Tensor, f_t: torch.Tensor,
  class ImageClassifier (line 84) | class ImageClassifier(ClassifierBase):
    method __init__ (line 85) | def __init__(self, backbone: nn.Module, num_classes: int, bottleneck_d...

FILE: domain_generalization/Transfer-Learning-Library/dalib/adaptation/fda.py
  function robust_entropy (line 9) | def robust_entropy(y, ita=1.5, num_classes=19, reduction='mean'):

FILE: domain_generalization/Transfer-Learning-Library/dalib/adaptation/idm/loss.py
  class DivLoss (line 10) | class DivLoss(nn.Module):
    method __init__ (line 13) | def __init__(self, ):
    method forward (line 16) | def forward(self, lam):
  class BridgeFeatLoss (line 23) | class BridgeFeatLoss(nn.Module):
    method __init__ (line 26) | def __init__(self):
    method forward (line 29) | def forward(self, f_s, f_t, f_mixed, lam):
  class BridgeProbLoss (line 43) | class BridgeProbLoss(nn.Module):
    method __init__ (line 46) | def __init__(self, num_classes, epsilon=0.1):
    method forward (line 52) | def forward(self, y, labels, lam, device_num=4):

FILE: domain_generalization/Transfer-Learning-Library/dalib/adaptation/idm/models/dsbn.py
  class DSBN2d (line 10) | class DSBN2d(nn.Module):
    method __init__ (line 14) | def __init__(self, planes):
    method forward (line 20) | def forward(self, x):
  class DSBN1d (line 33) | class DSBN1d(nn.Module):
    method __init__ (line 37) | def __init__(self, planes):
    method forward (line 43) | def forward(self, x):
  class DSBN2d_idm (line 56) | class DSBN2d_idm(nn.Module):
    method __init__ (line 61) | def __init__(self, planes):
    method forward (line 68) | def forward(self, x):
  class DSBN1d_idm (line 82) | class DSBN1d_idm(nn.Module):
    method __init__ (line 87) | def __init__(self, planes):
    method forward (line 94) | def forward(self, x):

FILE: domain_generalization/Transfer-Learning-Library/dalib/adaptation/idm/models/identifier.py
  class ReIdentifier (line 9) | class ReIdentifier(ReIdentifierBase):
    method __init__ (line 14) | def __init__(self, *args, **kwargs):
    method forward (line 17) | def forward(self, x, stage=0):

FILE: domain_generalization/Transfer-Learning-Library/dalib/adaptation/idm/models/idm.py
  class IDM (line 10) | class IDM(nn.Module):
    method __init__ (line 15) | def __init__(self, channel=64):
    method forward (line 25) | def forward(self, x):

FILE: domain_generalization/Transfer-Learning-Library/dalib/adaptation/idm/models/resnet.py
  class ReidResNet (line 17) | class ReidResNet(ResNetBase):
    method __init__ (line 23) | def __init__(self, *args, **kwargs):
    method forward (line 40) | def forward(self, x, stage=0):
  function _reid_resnet (line 65) | def _reid_resnet(arch, block, layers, pretrained, progress, **kwargs):
  function reid_resnet18 (line 77) | def reid_resnet18(pretrained=False, progress=True, **kwargs):
  function reid_resnet34 (line 88) | def reid_resnet34(pretrained=False, progress=True, **kwargs):
  function reid_resnet50 (line 99) | def reid_resnet50(pretrained=False, progress=True, **kwargs):
  function reid_resnet101 (line 110) | def reid_resnet101(pretrained=False, progress=True, **kwargs):

FILE: domain_generalization/Transfer-Learning-Library/dalib/adaptation/idm/utils.py
  function filter_layers (line 10) | def filter_layers(stage):
  function convert_dsbn_idm (line 19) | def convert_dsbn_idm(model, mixup_bn_names, idm=False):
  function convert_bn_idm (line 52) | def convert_bn_idm(model, use_target=True):

FILE: domain_generalization/Transfer-Learning-Library/dalib/adaptation/idm/xbm.py
  class XBM (line 9) | class XBM(object):
    method __init__ (line 12) | def __init__(self, memory_size, feature_size):
    method is_full (line 20) | def is_full(self):
    method get (line 23) | def get(self):
    method enqueue_dequeue (line 29) | def enqueue_dequeue(self, feats, targets):
    method clean_target_domain (line 40) | def clean_target_domain(self, source_classes, target_classes):

FILE: domain_generalization/Transfer-Learning-Library/dalib/adaptation/iwan.py
  class ImportanceWeightModule (line 12) | class ImportanceWeightModule(object):
    method __init__ (line 36) | def __init__(self, discriminator: nn.Module, partial_classes_index: Op...
    method get_importance_weight (line 40) | def get_importance_weight(self, feature):
    method get_partial_classes_weight (line 55) | def get_partial_classes_weight(self, weights: torch.Tensor, labels: to...
  class ImageClassifier (line 84) | class ImageClassifier(ClassifierBase):
    method __init__ (line 88) | def __init__(self, backbone: nn.Module, num_classes: int, bottleneck_d...

FILE: domain_generalization/Transfer-Learning-Library/dalib/adaptation/jan.py
  class JointMultipleKernelMaximumMeanDiscrepancy (line 19) | class JointMultipleKernelMaximumMeanDiscrepancy(nn.Module):
    method __init__ (line 69) | def __init__(self, kernels: Sequence[Sequence[nn.Module]], linear: Opt...
    method forward (line 79) | def forward(self, z_s: torch.Tensor, z_t: torch.Tensor) -> torch.Tensor:
  class Theta (line 96) | class Theta(nn.Module):
    method __init__ (line 101) | def __init__(self, dim: int):
    method forward (line 109) | def forward(self, features: torch.Tensor) -> torch.Tensor:
  class ImageClassifier (line 114) | class ImageClassifier(ClassifierBase):
    method __init__ (line 115) | def __init__(self, backbone: nn.Module, num_classes: int, bottleneck_d...

FILE: domain_generalization/Transfer-Learning-Library/dalib/adaptation/mcc.py
  class MinimumClassConfusionLoss (line 17) | class MinimumClassConfusionLoss(nn.Module):
    method __init__ (line 61) | def __init__(self, temperature: float):
    method forward (line 65) | def forward(self, logits: torch.Tensor) -> torch.Tensor:
  class ImageClassifier (line 77) | class ImageClassifier(ClassifierBase):
    method __init__ (line 78) | def __init__(self, backbone: nn.Module, num_classes: int, bottleneck_d...

FILE: domain_generalization/Transfer-Learning-Library/dalib/adaptation/mcd.py
  function classifier_discrepancy (line 10) | def classifier_discrepancy(predictions1: torch.Tensor, predictions2: tor...
  function entropy (line 28) | def entropy(predictions: torch.Tensor) -> torch.Tensor:
  class ImageClassifierHead (line 46) | class ImageClassifierHead(nn.Module):
    method __init__ (line 59) | def __init__(self, in_features: int, num_classes: int, bottleneck_dim:...
    method forward (line 81) | def forward(self, inputs: torch.Tensor) -> torch.Tensor:

FILE: domain_generalization/Transfer-Learning-Library/dalib/adaptation/mdd.py
  class MarginDisparityDiscrepancy (line 13) | class MarginDisparityDiscrepancy(nn.Module):
    method __init__ (line 60) | def __init__(self, source_disparity: Callable, target_disparity: Calla...
    method forward (line 68) | def forward(self, y_s: torch.Tensor, y_s_adv: torch.Tensor, y_t: torch...
  class ClassificationMarginDisparityDiscrepancy (line 88) | class ClassificationMarginDisparityDiscrepancy(MarginDisparityDiscrepancy):
    method __init__ (line 142) | def __init__(self, margin: Optional[float] = 4, **kwargs):
  class RegressionMarginDisparityDiscrepancy (line 155) | class RegressionMarginDisparityDiscrepancy(MarginDisparityDiscrepancy):
    method __init__ (line 209) | def __init__(self, margin: Optional[float] = 1, loss_function=F.l1_los...
  function shift_log (line 220) | def shift_log(x: torch.Tensor, offset: Optional[float] = 1e-6) -> torch....
  class GeneralModule (line 239) | class GeneralModule(nn.Module):
    method __init__ (line 240) | def __init__(self, backbone: nn.Module, num_classes: int, bottleneck: ...
    method forward (line 253) | def forward(self, x: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor]:
    method step (line 265) | def step(self):
    method get_parameters (line 271) | def get_parameters(self, base_lr=1.0) -> List[Dict]:
  class ImageClassifier (line 285) | class ImageClassifier(GeneralModule):
    method __init__ (line 321) | def __init__(self, backbone: nn.Module, num_classes: int,
  class ImageRegressor (line 365) | class ImageRegressor(GeneralModule):
    method __init__ (line 400) | def __init__(self, backbone: nn.Module, num_factors: int, bottleneck =...

FILE: domain_generalization/Transfer-Learning-Library/dalib/adaptation/osbp.py
  class UnknownClassBinaryCrossEntropy (line 14) | class UnknownClassBinaryCrossEntropy(nn.Module):
    method __init__ (line 38) | def __init__(self, t: Optional[float]=0.5):
    method forward (line 42) | def forward(self, y):
  class ImageClassifier (line 54) | class ImageClassifier(ClassifierBase):
    method __init__ (line 55) | def __init__(self, backbone: nn.Module, num_classes: int, bottleneck_d...
    method forward (line 71) | def forward(self, x: torch.Tensor, grad_reverse: Optional[bool] = False):

FILE: domain_generalization/Transfer-Learning-Library/dalib/adaptation/pada.py
  class AutomaticUpdateClassWeightModule (line 13) | class AutomaticUpdateClassWeightModule(object):
    method __init__ (line 41) | def __init__(self, update_steps: int, data_loader: DataLoader,
    method step (line 56) | def step(self):
    method get_class_weight_for_cross_entropy_loss (line 62) | def get_class_weight_for_cross_entropy_loss(self):
    method get_class_weight_for_adversarial_loss (line 70) | def get_class_weight_for_adversarial_loss(self, source_labels: torch.T...
    method get_partial_classes_weight (line 84) | def get_partial_classes_weight(self):
  class ClassWeightModule (line 98) | class ClassWeightModule(nn.Module):
    method __init__ (line 124) | def __init__(self, temperature: Optional[float] = 0.1):
    method forward (line 128) | def forward(self, outputs: torch.Tensor):
  function collect_classification_results (line 137) | def collect_classification_results(data_loader: DataLoader, classifier: ...

FILE: domain_generalization/Transfer-Learning-Library/dalib/adaptation/regda.py
  class FastPseudoLabelGenerator2d (line 15) | class FastPseudoLabelGenerator2d(nn.Module):
    method __init__ (line 16) | def __init__(self, sigma=2):
    method forward (line 20) | def forward(self, heatmap: torch.Tensor):
  class PseudoLabelGenerator2d (line 34) | class PseudoLabelGenerator2d(nn.Module):
    method __init__ (line 57) | def __init__(self, num_keypoints, height=64, width=64, sigma=2):
    method forward (line 93) | def forward(self, y):
  class RegressionDisparity (line 105) | class RegressionDisparity(nn.Module):
    method __init__ (line 145) | def __init__(self, pseudo_label_generator: PseudoLabelGenerator2d, cri...
    method forward (line 150) | def forward(self, y, y_adv, weight=None, mode='min'):
  class PoseResNet2d (line 161) | class PoseResNet2d(nn.Module):
    method __init__ (line 192) | def __init__(self, backbone, upsampling, feature_dim, num_keypoints,
    method _make_head (line 203) | def _make_head(num_layers, channel_dim, num_keypoints):
    method forward (line 227) | def forward(self, x):
    method get_parameters (line 239) | def get_parameters(self, lr=1.):
    method step (line 247) | def step(self):

FILE: domain_generalization/Transfer-Learning-Library/dalib/adaptation/rsd.py
  class RepresentationSubspaceDistance (line 9) | class RepresentationSubspaceDistance(nn.Module):
    method __init__ (line 22) | def __init__(self, trade_off=0.1):
    method forward (line 26) | def forward(self, f_s, f_t):

FILE: domain_generalization/Transfer-Learning-Library/dalib/adaptation/self_ensemble.py
  class ConsistencyLoss (line 15) | class ConsistencyLoss(nn.Module):
    method __init__ (line 41) | def __init__(self, distance_measure: Callable, reduction: Optional[str...
    method forward (line 46) | def forward(self, y: torch.Tensor, y_teacher: torch.Tensor, mask: torc...
  class L2ConsistencyLoss (line 55) | class L2ConsistencyLoss(ConsistencyLoss):
    method __init__ (line 65) | def __init__(self, reduction: Optional[str] = 'mean'):
  class ClassBalanceLoss (line 72) | class ClassBalanceLoss(nn.Module):
    method __init__ (line 97) | def __init__(self, num_classes):
    method forward (line 101) | def forward(self, y: torch.Tensor):
  class EmaTeacher (line 105) | class EmaTeacher(object):
    method __init__ (line 137) | def __init__(self, model, alpha):
    method set_alpha (line 143) | def set_alpha(self, alpha: float):
    method update (line 147) | def update(self):
    method __call__ (line 151) | def __call__(self, x: torch.Tensor):
    method train (line 154) | def train(self, mode: Optional[bool] = True):
    method eval (line 157) | def eval(self):
    method state_dict (line 160) | def state_dict(self):
    method load_state_dict (line 163) | def load_state_dict(self, state_dict):
    method module (line 167) | def module(self):
  class ImageClassifier (line 171) | class ImageClassifier(ClassifierBase):
    method __init__ (line 172) | def __init__(self, backbone: nn.Module, num_classes: int, bottleneck_d...

FILE: domain_generalization/Transfer-Learning-Library/dalib/modules/domain_discriminator.py
  class DomainDiscriminator (line 11) | class DomainDiscriminator(nn.Sequential):
    method __init__ (line 29) | def __init__(self, in_feature: int, hidden_size: int, batch_norm=True):
    method get_parameters (line 53) | def get_parameters(self) -> List[Dict]:

FILE: domain_generalization/Transfer-Learning-Library/dalib/modules/entropy.py
  function entropy (line 8) | def entropy(predictions: torch.Tensor, reduction='none') -> torch.Tensor:

FILE: domain_generalization/Transfer-Learning-Library/dalib/modules/gl.py
  class GradientFunction (line 12) | class GradientFunction(Function):
    method forward (line 15) | def forward(ctx: Any, input: torch.Tensor, coeff: Optional[float] = 1....
    method backward (line 21) | def backward(ctx: Any, grad_output: torch.Tensor) -> Tuple[torch.Tenso...
  class WarmStartGradientLayer (line 25) | class WarmStartGradientLayer(nn.Module):
    method __init__ (line 51) | def __init__(self, alpha: Optional[float] = 1.0, lo: Optional[float] =...
    method forward (line 61) | def forward(self, input: torch.Tensor) -> torch.Tensor:
    method step (line 71) | def step(self):

FILE: domain_generalization/Transfer-Learning-Library/dalib/modules/grl.py
  class GradientReverseFunction (line 12) | class GradientReverseFunction(Function):
    method forward (line 15) | def forward(ctx: Any, input: torch.Tensor, coeff: Optional[float] = 1....
    method backward (line 21) | def backward(ctx: Any, grad_output: torch.Tensor) -> Tuple[torch.Tenso...
  class GradientReverseLayer (line 25) | class GradientReverseLayer(nn.Module):
    method __init__ (line 26) | def __init__(self):
    method forward (line 29) | def forward(self, *input):
  class WarmStartGradientReverseLayer (line 33) | class WarmStartGradientReverseLayer(nn.Module):
    method __init__ (line 59) | def __init__(self, alpha: Optional[float] = 1.0, lo: Optional[float] =...
    method forward (line 69) | def forward(self, input: torch.Tensor) -> torch.Tensor:
    method step (line 79) | def step(self):

FILE: domain_generalization/Transfer-Learning-Library/dalib/modules/kernels.py
  class GaussianKernel (line 13) | class GaussianKernel(nn.Module):
    method __init__ (line 48) | def __init__(self, sigma: Optional[float] = None, track_running_stats:...
    method forward (line 56) | def forward(self, X: torch.Tensor) -> torch.Tensor:

FILE: domain_generalization/Transfer-Learning-Library/dalib/translation/cycada.py
  class SemanticConsistency (line 9) | class SemanticConsistency(nn.Module):
    method __init__ (line 49) | def __init__(self, ignore_index=(), reduction='mean'):
    method forward (line 54) | def forward(self, input: Tensor, target: Tensor) -> Tensor:

FILE: domain_generalization/Transfer-Learning-Library/dalib/translation/cyclegan/discriminator.py
  class NLayerDiscriminator (line 12) | class NLayerDiscriminator(nn.Module):
    method __init__ (line 22) | def __init__(self, input_nc, ndf=64, n_layers=3, norm_layer=nn.BatchNo...
    method forward (line 54) | def forward(self, input):
  class PixelDiscriminator (line 58) | class PixelDiscriminator(nn.Module):
    method __init__ (line 67) | def __init__(self, input_nc, ndf=64, norm_layer=nn.BatchNorm2d):
    method forward (line 84) | def forward(self, input):
  function patch (line 88) | def patch(ndf, input_nc=3, norm='batch', n_layers=3, init_type='normal',...
  function pixel (line 111) | def pixel(ndf, input_nc=3, norm='batch', init_type='normal', init_gain=0...

FILE: domain_generalization/Transfer-Learning-Library/dalib/translation/cyclegan/generator.py
  class ResnetBlock (line 12) | class ResnetBlock(nn.Module):
    method __init__ (line 15) | def __init__(self, dim, padding_type, norm_layer, use_dropout, use_bias):
    method build_conv_block (line 26) | def build_conv_block(self, dim, padding_type, norm_layer, use_dropout,...
    method forward (line 66) | def forward(self, x):
  class ResnetGenerator (line 72) | class ResnetGenerator(nn.Module):
    method __init__ (line 79) | def __init__(self, input_nc, output_nc, ngf=64, norm_layer=nn.BatchNor...
    method forward (line 129) | def forward(self, input):
  class UnetGenerator (line 134) | class UnetGenerator(nn.Module):
    method __init__ (line 137) | def __init__(self, input_nc, output_nc, num_downs, ngf=64, norm_layer=...
    method forward (line 161) | def forward(self, input):
  class UnetSkipConnectionBlock (line 166) | class UnetSkipConnectionBlock(nn.Module):
    method __init__ (line 172) | def __init__(self, outer_nc, inner_nc, input_nc=None,
    method forward (line 229) | def forward(self, x):
  function resnet_9 (line 236) | def resnet_9(ngf, input_nc=3, output_nc=3, norm='batch', use_dropout=False,
  function resnet_6 (line 257) | def resnet_6(ngf, input_nc=3, output_nc=3, norm='batch', use_dropout=False,
  function unet_256 (line 278) | def unet_256(ngf, input_nc=3, output_nc=3, norm='batch', use_dropout=False,
  function unet_128 (line 301) | def unet_128(ngf, input_nc=3, output_nc=3, norm='batch', use_dropout=False,
  function unet_32 (line 324) | def unet_32(ngf, input_nc=3, output_nc=3, norm='batch', use_dropout=False,

FILE: domain_generalization/Transfer-Learning-Library/dalib/translation/cyclegan/loss.py
  class LeastSquaresGenerativeAdversarialLoss (line 10) | class LeastSquaresGenerativeAdversarialLoss(nn.Module):
    method __init__ (line 28) | def __init__(self, reduction='mean'):
    method forward (line 32) | def forward(self, prediction, real=True):
  class VanillaGenerativeAdversarialLoss (line 40) | class VanillaGenerativeAdversarialLoss(nn.Module):
    method __init__ (line 58) | def __init__(self, reduction='mean'):
    method forward (line 62) | def forward(self, prediction, real=True):
  class WassersteinGenerativeAdversarialLoss (line 70) | class WassersteinGenerativeAdversarialLoss(nn.Module):
    method __init__ (line 88) | def __init__(self, reduction='mean'):
    method forward (line 92) | def forward(self, prediction, real=True):

FILE: domain_generalization/Transfer-Learning-Library/dalib/translation/cyclegan/transform.py
  class Translation (line 12) | class Translation(nn.Module):
    method __init__ (line 28) | def __init__(self, generator, device=torch.device("cpu"), mean=(0.5, 0...
    method forward (line 41) | def forward(self, image):

FILE: domain_generalization/Transfer-Learning-Library/dalib/translation/cyclegan/util.py
  class Identity (line 12) | class Identity(nn.Module):
    method forward (line 13) | def forward(self, x):
  function get_norm_layer (line 17) | def get_norm_layer(norm_type='instance'):
  function init_weights (line 37) | def init_weights(net, init_type='normal', init_gain=0.02):
  class ImagePool (line 72) | class ImagePool:
    method __init__ (line 83) | def __init__(self, pool_size):
    method query (line 89) | def query(self, images):
  function set_requires_grad (line 123) | def set_requires_grad(net, requires_grad=False):

FILE: domain_generalization/Transfer-Learning-Library/dalib/translation/fourier_transform.py
  function low_freq_mutate (line 14) | def low_freq_mutate(amp_src: np.ndarray, amp_trg: np.ndarray, beta: Opti...
  class FourierTransform (line 47) | class FourierTransform(nn.Module):
    method __init__ (line 116) | def __init__(self, image_list: Sequence[str], amplitude_dir: str,
    method build_amplitude (line 127) | def build_amplitude(image_list, amplitude_dir):
    method forward (line 137) | def forward(self, image):

FILE: domain_generalization/Transfer-Learning-Library/dalib/translation/spgan/loss.py
  class ContrastiveLoss (line 10) | class ContrastiveLoss(torch.nn.Module):
    method __init__ (line 33) | def __init__(self, margin=2.0):
    method forward (line 37) | def forward(self, output1, output2, label):

FILE: domain_generalization/Transfer-Learning-Library/dalib/translation/spgan/siamese.py
  class ConvBlock (line 10) | class ConvBlock(nn.Module):
    method __init__ (line 12) | def __init__(self, in_dim, out_dim):
    method forward (line 20) | def forward(self, x):
  class SiameseNetwork (line 24) | class SiameseNetwork(nn.Module):
    method __init__ (line 30) | def __init__(self, nsf=64):
    method forward (line 45) | def forward(self, x):

FILE: domain_generalization/Transfer-Learning-Library/dglib/generalization/coral.py
  class CorrelationAlignmentLoss (line 9) | class CorrelationAlignmentLoss(nn.Module):
    method __init__ (line 37) | def __init__(self):
    method forward (line 40) | def forward(self, f_s: torch.Tensor, f_t: torch.Tensor) -> torch.Tensor:

FILE: domain_generalization/Transfer-Learning-Library/dglib/generalization/groupdro.py
  class AutomaticUpdateDomainWeightModule (line 9) | class AutomaticUpdateDomainWeightModule(object):
    method __init__ (line 34) | def __init__(self, num_domains: int, eta: float, device):
    method get_domain_weight (line 38) | def get_domain_weight(self, sampled_domain_idxes):
    method update (line 52) | def update(self, sampled_domain_losses: torch.Tensor, sampled_domain_i...

FILE: domain_generalization/Transfer-Learning-Library/dglib/generalization/irm.py
  class InvariancePenaltyLoss (line 12) | class InvariancePenaltyLoss(nn.Module):
    method __init__ (line 28) | def __init__(self):
    method forward (line 32) | def forward(self, y: torch.Tensor, labels: torch.Tensor) -> torch.Tensor:

FILE: domain_generalization/Transfer-Learning-Library/dglib/generalization/mixstyle/models/mixstyle.py
  class MixStyle (line 11) | class MixStyle(nn.Module):
    method __init__ (line 34) | def __init__(self, p=0.5, alpha=0.1, eps=1e-6):
    method forward (line 41) | def forward(self, x):

FILE: domain_generalization/Transfer-Learning-Library/dglib/generalization/mixstyle/models/resnet.py
  function _resnet_with_mix_style (line 12) | def _resnet_with_mix_style(arch, block, layers, pretrained, progress, mi...
  function resnet18 (line 79) | def resnet18(pretrained=False, progress=True, **kwargs):
  function resnet34 (line 90) | def resnet34(pretrained=False, progress=True, **kwargs):
  function resnet50 (line 101) | def resnet50(pretrained=False, progress=True, **kwargs):
  function resnet101 (line 112) | def resnet101(pretrained=False, progress=True, **kwargs):

FILE: domain_generalization/Transfer-Learning-Library/dglib/generalization/mixstyle/sampler.py
  class RandomDomainMultiInstanceSampler (line 11) | class RandomDomainMultiInstanceSampler(Sampler):
    method __init__ (line 22) | def __init__(self, dataset, batch_size, n_domains_per_batch, num_insta...
    method __iter__ (line 42) | def __iter__(self):
    method sample_multi_instances (line 64) | def sample_multi_instances(self, sample_idxes):
    method __len__ (line 82) | def __len__(self):

FILE: domain_generalization/Transfer-Learning-Library/dglib/modules/classifier.py
  class ImageClassifier (line 11) | class ImageClassifier(ClassifierBase):
    method __init__ (line 23) | def __init__(self, backbone: nn.Module, num_classes: int, freeze_bn: O...
    method forward (line 30) | def forward(self, x: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor]:
    method train (line 41) | def train(self, mode=True):

FILE: domain_generalization/Transfer-Learning-Library/dglib/modules/sampler.py
  class DefaultSampler (line 12) | class DefaultSampler(Sampler):
    method __init__ (line 21) | def __init__(self, data_source: ConcatDataset, batch_size: int):
    method __iter__ (line 36) | def __iter__(self):
    method __len__ (line 55) | def __len__(self):
  class RandomDomainSampler (line 59) | class RandomDomainSampler(Sampler):
    method __init__ (line 69) | def __init__(self, data_source: ConcatDataset, batch_size: int, n_doma...
    method __iter__ (line 86) | def __iter__(self):
    method __len__ (line 112) | def __len__(self):

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_adaptation/image_classification/adda.py
  function main (line 42) | def main(args: argparse.Namespace):
  function train (line 152) | def train(train_source_iter: ForeverDataIterator, train_target_iter: For...

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_adaptation/image_classification/addagrl.py
  function main (line 39) | def main(args: argparse.Namespace):
  function train (line 179) | def train(train_source_iter: ForeverDataIterator, train_target_iter: For...

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_adaptation/image_classification/afn.py
  function main (line 35) | def main(args: argparse.Namespace):
  function train (line 135) | def train(train_source_iter: ForeverDataIterator, train_target_iter: For...

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_adaptation/image_classification/bsp.py
  function main (line 37) | def main(args: argparse.Namespace):
  function train (line 169) | def train(train_source_iter: ForeverDataIterator, train_target_iter: For...

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_adaptation/image_classification/cdan.py
  function main (line 36) | def main(args: argparse.Namespace):
  function train (line 150) | def train(train_source_iter: ForeverDataIterator, train_target_iter: For...

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_adaptation/image_classification/dan.py
  class TransformerDecorator (line 35) | class TransformerDecorator(torch.nn.Module):
    method __init__ (line 36) | def __init__(self, backbone=None, add_bt=3, dim=2048, eval_global=0):
    method forward_feats (line 43) | def forward_feats(self, feature):
    method forward (line 55) | def forward(self, feature):
  function main (line 60) | def main(args: argparse.Namespace):
  function train (line 170) | def train(train_source_iter: ForeverDataIterator, train_target_iter: For...

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_adaptation/image_classification/dann.py
  class TransformerDecorator (line 35) | class TransformerDecorator(torch.nn.Module):
    method __init__ (line 36) | def __init__(self, backbone=None, add_bt=3, dim=2048, eval_global=0):
    method forward_feats (line 43) | def forward_feats(self, feature):
    method forward (line 55) | def forward(self, feature):
  function main (line 60) | def main(args: argparse.Namespace):
  function train (line 170) | def train(train_source_iter: ForeverDataIterator, train_target_iter: For...

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_adaptation/image_classification/jan.py
  function main (line 36) | def main(args: argparse.Namespace):
  function train (line 152) | def train(train_source_iter: ForeverDataIterator, train_target_iter: For...

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_adaptation/image_classification/mcc.py
  class TransformerDecorator (line 34) | class TransformerDecorator(torch.nn.Module):
    method __init__ (line 35) | def __init__(self, backbone=None, add_bt=3, dim=2048, eval_global=0):
    method forward_feats (line 42) | def forward_feats(self, feature):
    method forward (line 54) | def forward(self, feature):
  function main (line 59) | def main(args: argparse.Namespace):
  function train (line 167) | def train(train_source_iter: ForeverDataIterator, train_target_iter: For...

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_adaptation/image_classification/mcd.py
  function main (line 36) | def main(args: argparse.Namespace):
  function train (line 150) | def train(train_source_iter: ForeverDataIterator, train_target_iter: For...
  function validate (line 247) | def validate(val_loader: DataLoader, G: nn.Module, F1: ImageClassifierHead,

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_adaptation/image_classification/mdd.py
  class TransformerDecorator (line 35) | class TransformerDecorator(torch.nn.Module):
    method __init__ (line 36) | def __init__(self, backbone=None, add_bt=3, dim=2048, eval_global=0):
    method forward_feats (line 43) | def forward_feats(self, feature):
    method forward (line 55) | def forward(self, feature):
  function main (line 60) | def main(args: argparse.Namespace):
  function train (line 167) | def train(train_source_iter: ForeverDataIterator, train_target_iter: For...

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_adaptation/image_classification/self_ensemble.py
  function main (line 37) | def main(args: argparse.Namespace):
  function train (line 175) | def train(train_source_iter: ForeverDataIterator, train_target_iter: For...

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_adaptation/image_classification/source_only.py
  class TransformerDecorator (line 34) | class TransformerDecorator(torch.nn.Module):
    method __init__ (line 35) | def __init__(self, backbone=None, add_bt=3, dim=2048, eval_global=0):
    method forward_feats (line 42) | def forward_feats(self, feature):
    method forward (line 54) | def forward(self, feature):
  function main (line 59) | def main(args: argparse.Namespace):

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_adaptation/image_classification/utils.py
  function get_model_names (line 24) | def get_model_names():
  function get_model (line 32) | def get_model(model_name, pretrain=True):
  function convert_from_wilds_dataset (line 48) | def convert_from_wilds_dataset(wild_dataset):
  function get_dataset_names (line 63) | def get_dataset_names():
  function get_dataset (line 70) | def get_dataset(dataset_name, root, source, target, train_source_transfo...
  function validate (line 109) | def validate(val_loader, model, args, device) -> float:
  function get_train_transform (line 156) | def get_train_transform(resizing='default', random_horizontal_flip=True,...
  function get_val_transform (line 195) | def get_val_transform(resizing='default', resize_size=224,
  function pretrain (line 218) | def pretrain(train_source_iter, model, optimizer, lr_scheduler, epoch, a...

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_adaptation/image_regression/dann.py
  function main (line 39) | def main(args: argparse.Namespace):
  function train (line 156) | def train(train_source_iter: ForeverDataIterator, train_target_iter: For...

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_adaptation/image_regression/dd.py
  function main (line 37) | def main(args: argparse.Namespace):
  function train (line 189) | def train(train_source_iter: ForeverDataIterator, train_target_iter: For...

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_adaptation/image_regression/rsd.py
  function main (line 38) | def main(args: argparse.Namespace):
  function train (line 154) | def train(train_source_iter: ForeverDataIterator, train_target_iter: For...

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_adaptation/image_regression/source_only.py
  function main (line 37) | def main(args: argparse.Namespace):
  function train (line 143) | def train(train_source_iter: ForeverDataIterator, train_target_iter: For...

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_adaptation/image_regression/utils.py
  function convert_model (line 16) | def convert_model(module):
  function validate (line 31) | def validate(val_loader, model, args, factors, device):

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_adaptation/keypoint_detection/regda.py
  function main (line 36) | def main(args: argparse.Namespace):
  function pretrain (line 227) | def pretrain(train_source_iter, model, criterion, optimizer,
  function train (line 277) | def train(train_source_iter, train_target_iter, model, criterion,regress...
  function validate (line 379) | def validate(val_loader, model, criterion, visualize, args: argparse.Nam...

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_adaptation/keypoint_detection/regda_fast.py
  function main (line 36) | def main(args: argparse.Namespace):
  function pretrain (line 227) | def pretrain(train_source_iter, model, criterion, optimizer,
  function train (line 277) | def train(train_source_iter, train_target_iter, model, criterion,regress...
  function validate (line 379) | def validate(val_loader, model, criterion, visualize, args: argparse.Nam...

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_adaptation/keypoint_detection/source_only.py
  function main (line 34) | def main(args: argparse.Namespace):
  function train (line 169) | def train(train_source_iter, train_target_iter, model, criterion,
  function validate (line 222) | def validate(val_loader, model, criterion, visualize, args: argparse.Nam...

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_adaptation/openset_domain_adaptation/dann.py
  function main (line 37) | def main(args: argparse.Namespace):
  function train (line 133) | def train(train_source_iter: ForeverDataIterator, train_target_iter: For...
  function validate (line 197) | def validate(val_loader: DataLoader, model: Classifier, args: argparse.N...

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_adaptation/openset_domain_adaptation/osbp.py
  function main (line 35) | def main(args: argparse.Namespace):
  function train (line 128) | def train(train_source_iter: ForeverDataIterator, train_target_iter: For...
  function validate (line 188) | def validate(val_loader: DataLoader, model: Classifier, args: argparse.N...

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_adaptation/openset_domain_adaptation/source_only.py
  function main (line 35) | def main(args: argparse.Namespace):
  function train (line 125) | def train(train_source_iter: ForeverDataIterator, model: Classifier, opt...
  function validate (line 174) | def validate(val_loader: DataLoader, model: Classifier, args: argparse.N...

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_adaptation/openset_domain_adaptation/utils.py
  function get_model_names (line 18) | def get_model_names():
  function get_model (line 26) | def get_model(model_name):
  function get_dataset_names (line 44) | def get_dataset_names():
  function get_dataset (line 51) | def get_dataset(dataset_name, root, source, target, train_source_transfo...
  function get_train_transform (line 71) | def get_train_transform(resizing='default', random_horizontal_flip=True,...
  function get_val_transform (line 132) | def get_val_transform(resizing='default'):

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_adaptation/partial_domain_adaptation/afn.py
  function main (line 36) | def main(args: argparse.Namespace):
  function train (line 134) | def train(train_source_iter: ForeverDataIterator, train_target_iter: For...

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_adaptation/partial_domain_adaptation/dann.py
  function main (line 37) | def main(args: argparse.Namespace):
  function train (line 142) | def train(train_source_iter: ForeverDataIterator, train_target_iter: For...

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_adaptation/partial_domain_adaptation/iwan.py
  function main (line 39) | def main(args: argparse.Namespace):
  function train (line 149) | def train(train_source_iter: ForeverDataIterator, train_target_iter: For...

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_adaptation/partial_domain_adaptation/pada.py
  function main (line 38) | def main(args: argparse.Namespace):
  function train (line 144) | def train(train_source_iter: ForeverDataIterator, train_target_iter: For...

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_adaptation/partial_domain_adaptation/source_only.py
  function main (line 35) | def main(args: argparse.Namespace):
  function train (line 130) | def train(train_source_iter: ForeverDataIterator, model: Classifier, opt...

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_adaptation/partial_domain_adaptation/utils.py
  function get_model_names (line 18) | def get_model_names():
  function get_model (line 26) | def get_model(model_name):
  function get_dataset_names (line 44) | def get_dataset_names():
  function get_dataset (line 51) | def get_dataset(dataset_name, root, source, target, train_source_transfo...
  function validate (line 70) | def validate(val_loader, model, args, device) -> float:
  function get_train_transform (line 117) | def get_train_transform(resizing='default', random_horizontal_flip=True,...
  function get_val_transform (line 173) | def get_val_transform(resizing='default'):

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_adaptation/re_identification/baseline.py
  function main (line 39) | def main(args: argparse.Namespace):
  function train (line 177) | def train(train_source_iter: ForeverDataIterator, train_target_iter: For...

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_adaptation/re_identification/baseline_cluster.py
  function main (line 40) | def main(args: argparse.Namespace):
  function run_kmeans (line 172) | def run_kmeans(cluster_loader: DataLoader, model: DataParallel, target_d...
  function run_dbscan (line 203) | def run_dbscan(cluster_loader: DataLoader, model: DataParallel, target_d...
  function train (line 247) | def train(train_target_iter: ForeverDataIterator, model, optimizer, crit...

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_adaptation/re_identification/idm.py
  function main (line 41) | def main(args: argparse.Namespace):
  function run_dbscan (line 201) | def run_dbscan(cluster_loader: DataLoader, model: DataParallel, target_d...
  function train (line 244) | def train(train_source_iter: ForeverDataIterator, train_target_iter: For...

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_adaptation/re_identification/mmt.py
  function main (line 41) | def main(args: argparse.Namespace):
  function create_model (line 183) | def create_model(args: argparse.Namespace, pretrained_model_path: str):
  function run_kmeans (line 199) | def run_kmeans(cluster_loader: DataLoader, model_1: DataParallel, model_...
  function run_dbscan (line 241) | def run_dbscan(cluster_loader: DataLoader, model_1: DataParallel, model_...
  function train (line 301) | def train(train_target_iter: ForeverDataIterator, model_1: DataParallel,...

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_adaptation/re_identification/spgan.py
  function main (line 36) | def main(args):
  function train (line 192) | def train(train_source_iter: ForeverDataIterator, train_target_iter: For...

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_adaptation/re_identification/utils.py
  function copy_state_dict (line 20) | def copy_state_dict(model, state_dict, strip=None):
  function get_model_names (line 46) | def get_model_names():
  function get_model (line 54) | def get_model(model_name):
  function get_train_transform (line 70) | def get_train_transform(height, width, resizing='default', random_horizo...
  function get_val_transform (line 104) | def get_val_transform(height, width):
  function visualize_tsne (line 112) | def visualize_tsne(source_loader, target_loader, model, filename, device...
  function k_reciprocal_neigh (line 130) | def k_reciprocal_neigh(initial_rank, i, k1):
  function compute_rerank_dist (line 140) | def compute_rerank_dist(target_features, k1=30, k2=6):

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_adaptation/semantic_segmentation/advent.py
  function main (line 36) | def main(args: argparse.Namespace):
  function train (line 184) | def train(train_source_iter: ForeverDataIterator, train_target_iter: For...
  function validate (line 276) | def validate(val_loader: DataLoader, model, interp, criterion, visualize...

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_adaptation/semantic_segmentation/cycada.py
  function main (line 36) | def main(args):
  function train (line 198) | def train(train_source_iter, train_target_iter, netG_S2T, netG_T2S, netD...

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_adaptation/semantic_segmentation/cycle_gan.py
  function main (line 34) | def main(args):
  function train (line 168) | def train(train_source_iter, train_target_iter, netG_S2T, netG_T2S, netD...

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_adaptation/semantic_segmentation/fda.py
  function main (line 38) | def main(args: argparse.Namespace):
  function train (line 182) | def train(train_source_iter: ForeverDataIterator, train_target_iter: For...
  function validate (line 263) | def validate(val_loader: DataLoader, model, interp, criterion, visualize...

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_adaptation/semantic_segmentation/source_only.py
  function main (line 34) | def main(args: argparse.Namespace):
  function train (line 161) | def train(train_source_iter: ForeverDataIterator, model, interp, criteri...
  function validate (line 217) | def validate(val_loader: DataLoader, model, interp, criterion, visualize...

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_generalization/image_classification/baseline.py
  class TransformerDecorator (line 34) | class TransformerDecorator(torch.nn.Module):
    method __init__ (line 35) | def __init__(self, backbone=None, add_bt=3, dim=2048, eval_global=0):
    method forward_feats (line 42) | def forward_feats(self, feature):
    method forward (line 54) | def forward(self, feature):
  function main (line 59) | def main(args: argparse.Namespace):
  function train (line 172) | def train(train_iter: ForeverDataIterator, model: Classifier, optimizer,

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_generalization/image_classification/coral.py
  class TransformerDecorator (line 36) | class TransformerDecorator(torch.nn.Module):
    method __init__ (line 37) | def __init__(self, backbone=None, add_bt=3, dim=2048, eval_global=0):
    method forward_feats (line 44) | def forward_feats(self, feature):
    method forward (line 56) | def forward(self, feature):
  function main (line 61) | def main(args: argparse.Namespace):
  function train (line 179) | def train(train_iter: ForeverDataIterator, model: Classifier, optimizer,...

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_generalization/image_classification/groupdro.py
  function main (line 37) | def main(args: argparse.Namespace):
  function train (line 148) | def train(train_iter: ForeverDataIterator, model: Classifier, optimizer,...

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_generalization/image_classification/irm.py
  class TransformerDecorator (line 36) | class TransformerDecorator(torch.nn.Module):
    method __init__ (line 37) | def __init__(self, backbone=None, add_bt=3, dim=2048, eval_global=0):
    method forward (line 45) | def forward(self, feature):
  function main (line 58) | def main(args: argparse.Namespace):
  function train (line 184) | def train(train_iter: ForeverDataIterator, model: Classifier, optimizer,...

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_generalization/image_classification/mixstyle.py
  class TransformerDecorator (line 36) | class TransformerDecorator(torch.nn.Module):
    method __init__ (line 37) | def __init__(self, backbone=None, add_bt=3, dim=2048, eval_global=0):
    method forward (line 44) | def forward(self, feature):
  function main (line 57) | def main(args: argparse.Namespace):
  function train (line 172) | def train(train_iter: ForeverDataIterator, model: Classifier, optimizer,

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_generalization/image_classification/mldg.py
  function main (line 37) | def main(args: argparse.Namespace):
  function random_split (line 146) | def random_split(x_list, labels_list, n_domains_per_batch, n_support_dom...
  function train (line 158) | def train(train_iter: ForeverDataIterator, model: Classifier, optimizer,...

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_generalization/image_classification/utils.py
  function get_model_names (line 25) | def get_model_names():
  function get_model (line 33) | def get_model(model_name):
  function get_dataset_names (line 49) | def get_dataset_names():
  class ConcatDatasetWithDomainLabel (line 56) | class ConcatDatasetWithDomainLabel(ConcatDataset):
    method __init__ (line 59) | def __init__(self, *args, **kwargs):
    method __getitem__ (line 70) | def __getitem__(self, index):
  function convert_from_wilds_dataset (line 76) | def convert_from_wilds_dataset(dataset_name, wild_dataset):
  function get_dataset (line 111) | def get_dataset(dataset_name, root, task_list, split='train', download=T...
  function split_dataset (line 171) | def split_dataset(dataset, n, seed=0):
  function validate (line 185) | def validate(val_loader, model, args, device) -> float:
  function get_train_transform (line 224) | def get_train_transform(resizing='default', random_horizontal_flip=True,...
  function get_val_transform (line 286) | def get_val_transform(resizing='default'):
  function collect_feature (line 311) | def collect_feature(data_loader, feature_extractor: nn.Module, device: t...

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_generalization/image_classification/vrex.py
  class TransformerDecorator (line 35) | class TransformerDecorator(torch.nn.Module):
    method __init__ (line 36) | def __init__(self, backbone=None, add_bt=3, dim=2048, eval_global=0):
    method forward (line 44) | def forward(self, feature):
  function main (line 57) | def main(args: argparse.Namespace):
  function train (line 179) | def train(train_iter: ForeverDataIterator, model: Classifier, optimizer,...

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_generalization/re_identification/baseline.py
  function main (line 39) | def main(args: argparse.Namespace):
  function train (line 173) | def train(train_iter: ForeverDataIterator, model, criterion_ce: CrossEnt...

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_generalization/re_identification/mixstyle.py
  function main (line 41) | def main(args: argparse.Namespace):
  function train (line 176) | def train(train_iter: ForeverDataIterator, model, criterion_ce: CrossEnt...

FILE: domain_generalization/Transfer-Learning-Library/examples/domain_generalization/re_identification/utils.py
  function get_model_names (line 17) | def get_model_names():
  function get_model (line 25) | def get_model(model_name):
  function get_train_transform (line 41) | def get_train_transform(height, width, resizing='default', random_horizo...
  function get_val_transform (line 73) | def get_val_transform(height, width):
  function visualize_tsne (line 81) | def visualize_tsne(source_loader, target_loader, model, filename, device...

FILE: domain_generalization/Transfer-Learning-Library/examples/task_adaptation/image_classification/baseline.py
  function main (line 32) | def main(args: argparse.Namespace):
  function train (line 101) | def train(train_iter: ForeverDataIterator, model: Classifier, optimizer:...

FILE: domain_generalization/Transfer-Learning-Library/examples/task_adaptation/image_classification/bi_tuning.py
  function main (line 32) | def main(args: argparse.Namespace):
  function train (line 114) | def train(train_iter: ForeverDataIterator, bituning: BiTuning, optimizer...

FILE: domain_generalization/Transfer-Learning-Library/examples/task_adaptation/image_classification/bss.py
  function main (line 33) | def main(args: argparse.Namespace):
  function train (line 102) | def train(train_iter: ForeverDataIterator, model: Classifier, bss_module...

FILE: domain_generalization/Transfer-Learning-Library/examples/task_adaptation/image_classification/co_tuning.py
  function get_dataset (line 35) | def get_dataset(dataset_name, root, train_transform, val_transform, samp...
  function main (line 56) | def main(args: argparse.Namespace):
  function train (line 131) | def train(train_iter: ForeverDataIterator, model: Classifier, optimizer:...

FILE: domain_generalization/Transfer-Learning-Library/examples/task_adaptation/image_classification/delta.py
  function main (line 35) | def main(args: argparse.Namespace):
  function calculate_channel_attention (line 141) | def calculate_channel_attention(dataset, return_layers, num_classes, args):
  function train (line 231) | def train(train_iter: ForeverDataIterator, model: Classifier, backbone_r...

FILE: domain_generalization/Transfer-Learning-Library/examples/task_adaptation/image_classification/lwf.py
  function main (line 34) | def main(args: argparse.Namespace):
  function train (line 109) | def train(train_iter: ForeverDataIterator, model: Classifier, kd, optimi...

FILE: domain_generalization/Transfer-Learning-Library/examples/task_adaptation/image_classification/stochnorm.py
  function main (line 33) | def main(args: argparse.Namespace):
  function train (line 103) | def train(train_iter: ForeverDataIterator, model: Classifier, optimizer:...

FILE: domain_generalization/Transfer-Learning-Library/examples/task_adaptation/image_classification/utils.py
  function get_model_names (line 25) | def get_model_names():
  function get_model (line 33) | def get_model(model_name, pretrained_checkpoint=None):
  function get_dataset (line 55) | def get_dataset(dataset_name, root, train_transform, val_transform, samp...
  function validate (line 80) | def validate(val_loader, model, args, device, visualize=None) -> float:
  function get_train_transform (line 121) | def get_train_transform(resizing='default', random_horizontal_flip=True,...
  function get_val_transform (line 168) | def get_val_transform(resizing='default'):
  function get_optimizer (line 197) | def get_optimizer(optimizer_name, params, lr, wd, momentum):
  function visualize (line 217) | def visualize(image, filename):

FILE: domain_generalization/Transfer-Learning-Library/talib/finetune/bi_tuning.py
  class Classifier (line 11) | class Classifier(ClassifierBase):
    method __init__ (line 43) | def __init__(self, backbone: nn.Module, num_classes: int, projection_d...
    method forward (line 52) | def forward(self, x: torch.Tensor):
    method get_parameters (line 66) | def get_parameters(self, base_lr=1.0):
  class BiTuning (line 80) | class BiTuning(nn.Module):
    method __init__ (line 112) | def __init__(self, encoder_q: Classifier, encoder_k: Classifier, num_c...
    method _momentum_update_key_encoder (line 137) | def _momentum_update_key_encoder(self):
    method _dequeue_and_enqueue (line 145) | def _dequeue_and_enqueue(self, h, z, label):
    method forward (line 157) | def forward(self, im_q, im_k, labels):

FILE: domain_generalization/Transfer-Learning-Library/talib/finetune/bss.py
  class BatchSpectralShrinkage (line 11) | class BatchSpectralShrinkage(nn.Module):
    method __init__ (line 40) | def __init__(self, k=1):
    method forward (line 44) | def forward(self, feature):

FILE: domain_generalization/Transfer-Learning-Library/talib/finetune/co_tuning.py
  class CoTuningLoss (line 17) | class CoTuningLoss(nn.Module):
    method __init__ (line 32) | def __init__(self):
    method forward (line 35) | def forward(self, input: torch.Tensor, target: torch.Tensor) -> torch....
  class Relationship (line 41) | class Relationship(object):
    method __init__ (line 51) | def __init__(self, data_loader, classifier, device, cache=None):
    method __getitem__ (line 64) | def __getitem__(self, category):
    method collect_labels (line 67) | def collect_labels(self):
    method get_category_relationship (line 91) | def get_category_relationship(self, source_probabilities, target_labels):
  class Classifier (line 111) | class Classifier(ClassifierBase):
    method __init__ (line 136) | def __init__(self, backbone: nn.Module, num_classes: int,  head_source...
    method get_parameters (line 139) | def get_parameters(self, base_lr=1.0) -> List[Dict]:

FILE: domain_generalization/Transfer-Learning-Library/talib/finetune/delta.py
  class L2Regularization (line 12) | class L2Regularization(nn.Module):
    method __init__ (line 24) | def __init__(self, model: nn.Module):
    method forward (line 28) | def forward(self):
  class SPRegularization (line 35) | class SPRegularization(nn.Module):
    method __init__ (line 55) | def __init__(self, source_model: nn.Module, target_model: nn.Module):
    method forward (line 62) | def forward(self):
  class BehavioralRegularization (line 69) | class BehavioralRegularization(nn.Module):
    method __init__ (line 92) | def __init__(self):
    method forward (line 95) | def forward(self, layer_outputs_source, layer_outputs_target):
  class AttentionBehavioralRegularization (line 102) | class AttentionBehavioralRegularization(nn.Module):
    method __init__ (line 129) | def __init__(self, channel_attention):
    method forward (line 133) | def forward(self, layer_outputs_source, layer_outputs_target):
  function get_attribute (line 147) | def get_attribute(obj, attr, *args):
  class IntermediateLayerGetter (line 153) | class IntermediateLayerGetter:
    method __init__ (line 167) | def __init__(self, model, return_layers, keep_output=True):
    method __call__ (line 172) | def __call__(self, *args, **kwargs):

FILE: domain_generalization/Transfer-Learning-Library/talib/finetune/lwf.py
  function collect_pretrain_labels (line 11) | def collect_pretrain_labels(data_loader, classifier, device):
  class Classifier (line 23) | class Classifier(nn.Module):
    method __init__ (line 48) | def __init__(self, backbone: nn.Module, num_classes: int,  head_source,
    method features_dim (line 77) | def features_dim(self) -> int:
    method forward (line 81) | def forward(self, x: torch.Tensor):
    method get_parameters (line 92) | def get_parameters(self, base_lr=1.0) -> List[Dict]:

FILE: domain_generalization/Transfer-Learning-Library/talib/finetune/stochnorm.py
  class _StochNorm (line 15) | class _StochNorm(nn.Module):
    method __init__ (line 17) | def __init__(self, num_features, eps=1e-5, momentum=0.1, affine=True, ...
    method reset_parameters (line 40) | def reset_parameters(self):
    method _check_input_dim (line 48) | def _check_input_dim(self, input):
    method forward (line 51) | def forward(self, input):
  class StochNorm1d (line 87) | class StochNorm1d(_StochNorm):
    method _check_input_dim (line 136) | def _check_input_dim(self, input):
  class StochNorm2d (line 142) | class StochNorm2d(_StochNorm):
    method _check_input_dim (line 192) | def _check_input_dim(self, input):
  class StochNorm3d (line 198) | class StochNorm3d(_StochNorm):
    method _check_input_dim (line 248) | def _check_input_dim(self, input):
  function convert_model (line 254) | def convert_model(module, p):

FILE: domain_generalization/baseline.py
  class TransformerDecorator (line 34) | class TransformerDecorator(torch.nn.Module):
    method __init__ (line 35) | def __init__(self, backbone=None, add_bt=3, dim=2048, eval_global=0):
    method forward_feats (line 42) | def forward_feats(self, feature):
    method forward (line 54) | def forward(self, feature):
  function main (line 59) | def main(args: argparse.Namespace):
  function train (line 172) | def train(train_iter: ForeverDataIterator, model: Classifier, optimizer,

FILE: domain_generalization/coral.py
  class TransformerDecorator (line 36) | class TransformerDecorator(torch.nn.Module):
    method __init__ (line 37) | def __init__(self, backbone=None, add_bt=3, dim=2048, eval_global=0):
    method forward_feats (line 44) | def forward_feats(self, feature):
    method forward (line 56) | def forward(self, feature):
  function main (line 61) | def main(args: argparse.Namespace):
  function train (line 179) | def train(train_iter: ForeverDataIterator, model: Classifier, optimizer,...

FILE: domain_generalization/irm.py
  class TransformerDecorator (line 36) | class TransformerDecorator(torch.nn.Module):
    method __init__ (line 37) | def __init__(self, backbone=None, add_bt=3, dim=2048, eval_global=0):
    method forward (line 45) | def forward(self, feature):
  function main (line 58) | def main(args: argparse.Namespace):
  function train (line 184) | def train(train_iter: ForeverDataIterator, model: Classifier, optimizer,...

FILE: domain_generalization/mixstyle.py
  class TransformerDecorator (line 36) | class TransformerDecorator(torch.nn.Module):
    method __init__ (line 37) | def __init__(self, backbone=None, add_bt=3, dim=2048, eval_global=0):
    method forward (line 44) | def forward(self, feature):
  function main (line 57) | def main(args: argparse.Namespace):
  function train (line 172) | def train(train_iter: ForeverDataIterator, model: Classifier, optimizer,

FILE: domain_generalization/swad/domainbed/algorithms/__init__.py
  function get_algorithm_class (line 4) | def get_algorithm_class(algorithm_name):

FILE: domain_generalization/swad/domainbed/algorithms/algorithms.py
  function to_minibatch (line 28) | def to_minibatch(x, y):
  class Algorithm (line 33) | class Algorithm(torch.nn.Module):
    method __init__ (line 43) | def __init__(self, input_shape, num_classes, num_domains, hparams):
    method update (line 50) | def update(self, x, y, **kwargs):
    method predict (line 57) | def predict(self, x):
    method forward (line 60) | def forward(self, x):
    method new_optimizer (line 63) | def new_optimizer(self, parameters):
    method clone (line 72) | def clone(self):
  class ERM (line 80) | class ERM(Algorithm):
    method __init__ (line 85) | def __init__(self, input_shape, num_classes, num_domains, hparams):
    method update (line 97) | def update(self, x, y, **kwargs):
    method predict (line 111) | def predict(self, x):
  class Mixstyle (line 115) | class Mixstyle(Algorithm):
    method __init__ (line 118) | def __init__(self, input_shape, num_classes, num_domains, hparams):
    method update (line 131) | def update(self, x, y, **kwargs):
    method predict (line 145) | def predict(self, x):
  class Mixstyle2 (line 149) | class Mixstyle2(Algorithm):
    method __init__ (line 152) | def __init__(self, input_shape, num_classes, num_domains, hparams):
    method pair_batches (line 165) | def pair_batches(self, xs, ys):
    method update (line 179) | def update(self, x, y, **kwargs):
    method predict (line 202) | def predict(self, x):
  class ARM (line 206) | class ARM(ERM):
    method __init__ (line 209) | def __init__(self, input_shape, num_classes, num_domains, hparams):
    method predict (line 216) | def predict(self, x):
  class SAM (line 231) | class SAM(ERM):
    method norm (line 235) | def norm(tensor_list: List[torch.tensor], p=2):
    method update (line 239) | def update(self, x, y, **kwargs):
  class AbstractDANN (line 269) | class AbstractDANN(Algorithm):
    method __init__ (line 272) | def __init__(self, input_shape, num_classes, num_domains, hparams, con...
    method update (line 303) | def update(self, x, y, **kwargs):
    method predict (line 357) | def predict(self, x):
  class DANN (line 361) | class DANN(AbstractDANN):
    method __init__ (line 364) | def __init__(self, input_shape, num_classes, num_domains, hparams):
  class CDANN (line 375) | class CDANN(AbstractDANN):
    method __init__ (line 378) | def __init__(self, input_shape, num_classes, num_domains, hparams):
  class IRM (line 389) | class IRM(ERM):
    method __init__ (line 392) | def __init__(self, input_shape, num_classes, num_domains, hparams):
    method _irm_penalty (line 397) | def _irm_penalty(logits, y):
    method update (line 406) | def update(self, x, y, **kwargs):
  class VREx (line 446) | class VREx(ERM):
    method __init__ (line 449) | def __init__(self, input_shape, num_classes, num_domains, hparams):
    method update (line 453) | def update(self, x, y, **kwargs):
  class Mixup (line 494) | class Mixup(ERM):
    method __init__ (line 501) | def __init__(self, input_shape, num_classes, num_domains, hparams):
    method update (line 504) | def update(self, x, y, **kwargs):
  class OrgMixup (line 526) | class OrgMixup(ERM):
    method update (line 531) | def update(self, x, y, **kwargs):
  class CutMix (line 554) | class CutMix(ERM):
    method rand_bbox (line 556) | def rand_bbox(size, lam):
    method update (line 574) | def update(self, x, y, **kwargs):
  class GroupDRO (line 607) | class GroupDRO(ERM):
    method __init__ (line 613) | def __init__(self, input_shape, num_classes, num_domains, hparams):
    method update (line 617) | def update(self, x, y, **kwargs):
  class MLDG (line 642) | class MLDG(ERM):
    method __init__ (line 650) | def __init__(self, input_shape, num_classes, num_domains, hparams):
    method update (line 653) | def update(self, x, y, **kwargs):
  class AbstractMMD (line 763) | class AbstractMMD(ERM):
    method __init__ (line 769) | def __init__(self, input_shape, num_classes, num_domains, hparams, gau...
    method my_cdist (line 776) | def my_cdist(self, x1, x2):
    method gaussian_kernel (line 784) | def gaussian_kernel(self, x, y, gamma=(0.001, 0.01, 0.1, 1, 10, 100, 1...
    method mmd (line 793) | def mmd(self, x, y):
    method update (line 812) | def update(self, x, y, **kwargs):
  class MMD (line 841) | class MMD(AbstractMMD):
    method __init__ (line 846) | def __init__(self, input_shape, num_classes, num_domains, hparams):
  class CORAL (line 850) | class CORAL(AbstractMMD):
    method __init__ (line 855) | def __init__(self, input_shape, num_classes, num_domains, hparams):
  class MTL (line 859) | class MTL(Algorithm):
    method __init__ (line 866) | def __init__(self, input_shape, num_classes, num_domains, hparams):
    method update (line 881) | def update(self, x, y, **kwargs):
    method update_embeddings_ (line 893) | def update_embeddings_(self, features, env=None):
    method predict (line 903) | def predict(self, x, env=None):
  class SagNet (line 909) | class SagNet(Algorithm):
    method __init__ (line 915) | def __init__(self, input_shape, num_classes, num_domains, hparams):
    method forward_c (line 961) | def forward_c(self, x):
    method forward_s (line 965) | def forward_s(self, x):
    method randomize (line 969) | def randomize(self, x, what="style", eps=1e-5):
    method update (line 992) | def update(self, x, y, **kwargs):
    method predict (line 1023) | def predict(self, x):
  class RSC (line 1027) | class RSC(ERM):
    method __init__ (line 1028) | def __init__(self, input_shape, num_classes, num_domains, hparams):
    method update (line 1034) | def update(self, x, y, **kwargs):

FILE: domain_generalization/swad/domainbed/datasets/__init__.py
  function set_transfroms (line 9) | def set_transfroms(dset, data_type, hparams, algorithm_class=None):
  function get_dataset (line 41) | def get_dataset(test_envs, args, hparams, algorithm_class=None):
  class _SplitDataset (line 84) | class _SplitDataset(torch.utils.data.Dataset):
    method __init__ (line 87) | def __init__(self, underlying_dataset, keys):
    method __getitem__ (line 95) | def __getitem__(self, key):
    method __len__ (line 107) | def __len__(self):
  function split_dataset (line 111) | def split_dataset(dataset, n, seed=0):

FILE: domain_generalization/swad/domainbed/datasets/datasets.py
  function get_dataset_class (line 29) | def get_dataset_class(dataset_name):
  function num_environments (line 36) | def num_environments(dataset_name):
  class MultipleDomainDataset (line 40) | class MultipleDomainDataset:
    method __getitem__ (line 47) | def __getitem__(self, index):
    method __len__ (line 53) | def __len__(self):
  class Debug (line 60) | class Debug(MultipleDomainDataset):
    method __init__ (line 61) | def __init__(self, root):
  class Debug28 (line 75) | class Debug28(Debug):
  class Debug224 (line 80) | class Debug224(Debug):
  class MultipleEnvironmentMNIST (line 85) | class MultipleEnvironmentMNIST(MultipleDomainDataset):
    method __init__ (line 86) | def __init__(self, root, environments, dataset_transform, input_shape,...
  class ColoredMNIST (line 121) | class ColoredMNIST(MultipleEnvironmentMNIST):
    method __init__ (line 124) | def __init__(self, root):
    method color_dataset (line 133) | def color_dataset(self, images, labels, environment):
    method torch_bernoulli_ (line 152) | def torch_bernoulli_(self, p, size):
    method torch_xor_ (line 155) | def torch_xor_(self, a, b):
  class RotatedMNIST (line 159) | class RotatedMNIST(MultipleEnvironmentMNIST):
    method __init__ (line 162) | def __init__(self, root):
    method rotate_dataset (line 171) | def rotate_dataset(self, images, labels, angle):
  class MultipleEnvironmentImageFolder (line 189) | class MultipleEnvironmentImageFolder(MultipleDomainDataset):
    method __init__ (line 190) | def __init__(self, root):
  class VLCS (line 207) | class VLCS(MultipleEnvironmentImageFolder):
    method __init__ (line 211) | def __init__(self, root):
  class PACS (line 216) | class PACS(MultipleEnvironmentImageFolder):
    method __init__ (line 220) | def __init__(self, root):
  class DomainNet (line 225) | class DomainNet(MultipleEnvironmentImageFolder):
    method __init__ (line 230) | def __init__(self, root):
  class OfficeHome (line 235) | class OfficeHome(MultipleEnvironmentImageFolder):
    method __init__ (line 239) | def __init__(self, root):
  class TerraIncognita (line 244) | class TerraIncognita(MultipleEnvironmentImageFolder):
    method __init__ (line 248) | def __init__(self, root):

FILE: domain_generalization/swad/domainbed/evaluator.py
  function accuracy_from_loader (line 13) | def accuracy_from_loader(algorithm, loader, weights, debug=False):
  function accuracy (line 54) | def accuracy(algorithm, loader_kwargs, weights, **kwargs):
  class Evaluator (line 64) | class Evaluator:
    method __init__ (line 65) | def __init__(
    method set_target_env (line 81) | def set_target_env(self, target_env):
    method evaluate (line 85) | def evaluate(self, algorithm, ret_losses=False):

FILE: domain_generalization/swad/domainbed/hparams_registry.py
  function _hparams (line 6) | def _hparams(algorithm, dataset, random_state):
  function default_hparams (line 101) | def default_hparams(algorithm, dataset):
  function random_hparams (line 106) | def random_hparams(algorithm, dataset, seed):

FILE: domain_generalization/swad/domainbed/lib/fast_data_loader.py
  class _InfiniteSampler (line 6) | class _InfiniteSampler(torch.utils.data.Sampler):
    method __init__ (line 9) | def __init__(self, sampler):
    method __iter__ (line 12) | def __iter__(self):
  class InfiniteDataLoader (line 18) | class InfiniteDataLoader:
    method __init__ (line 19) | def __init__(self, dataset, weights, batch_size, num_workers):
    method __iter__ (line 41) | def __iter__(self):
    method __len__ (line 45) | def __len__(self):
  class FastDataLoader (line 49) | class FastDataLoader:
    method __init__ (line 55) | def __init__(self, dataset, batch_size, num_workers, shuffle=False):
    method __iter__ (line 79) | def __iter__(self):
    method __len__ (line 83) | def __len__(self):

FILE: domain_generalization/swad/domainbed/lib/logger.py
  function levelize (line 6) | def levelize(levelname):
  class ColorFormatter (line 14) | class ColorFormatter(logging.Formatter):
    method format (line 23) | def format(self, record):
  class Logger (line 29) | class Logger(logging.Logger):
    method get (line 33) | def get(cls, file_path=None, level="INFO", colorize=True, track_code=F...
    method nofmt (line 77) | def nofmt(self, msg, *args, level="INFO", **kwargs):
    method remove_formats (line 83) | def remove_formats(self):
    method set_formats (line 92) | def set_formats(self, formatters):
    method set_file_handler (line 97) | def set_file_handler(self, file_path):

FILE: domain_generalization/swad/domainbed/lib/misc.py
  function make_weights_for_balanced_classes (line 19) | def make_weights_for_balanced_classes(dataset):
  function seed_hash (line 40) | def seed_hash(*args):
  function to_row (line 48) | def to_row(row, colwidth=10, latex=False):
  function random_pairs_of_minibatches (line 65) | def random_pairs_of_minibatches(minibatches):
  function index_conditional_iterate (line 89) | def index_conditional_iterate(skip_condition, iterable, index):
  class SplitIterator (line 100) | class SplitIterator:
    method __init__ (line 101) | def __init__(self, test_envs):
    method train (line 104) | def train(self, iterable, index=False):
    method test (line 107) | def test(self, iterable, index=False):
  class AverageMeter (line 111) | class AverageMeter:
    method __init__ (line 114) | def __init__(self):
    method reset (line 117) | def reset(self):
    method update (line 124) | def update(self, val, n=1):
    method __repr__ (line 131) | def __repr__(self):
  class AverageMeters (line 135) | class AverageMeters:
    method __init__ (line 136) | def __init__(self, *keys):
    method resets (line 141) | def resets(self):
    method updates (line 145) | def updates(self, dic, n=1):
    method __repr__ (line 149) | def __repr__(self):
    method get_averages (line 152) | def get_averages(self):
  function timestamp (line 157) | def timestamp(fmt="%y%m%d_%H-%M-%S"):
  function makedirs (line 161) | def makedirs(path):
  function rm (line 170) | def rm(path):
  function cp (line 178) | def cp(src, dst):
  function get_lr (line 182) | def get_lr(optimizer):
  function hash_bn (line 190) | def hash_bn(module):
  function merge_dictlist (line 204) | def merge_dictlist(dictlist):

FILE: domain_generalization/swad/domainbed/lib/query.py
  function make_selector_fn (line 13) | def make_selector_fn(selector):
  function hashable (line 46) | def hashable(obj):
  class Q (line 54) | class Q(object):
    method __init__ (line 55) | def __init__(self, list_):
    method __len__ (line 59) | def __len__(self):
    method __getitem__ (line 62) | def __getitem__(self, key):
    method __eq__ (line 65) | def __eq__(self, other):
    method __str__ (line 71) | def __str__(self):
    method __repr__ (line 74) | def __repr__(self):
    method _append (line 77) | def _append(self, item):
    method group (line 81) | def group(self, selector):
    method group_map (line 97) | def group_map(self, selector, fn):
    method map (line 104) | def map(self, fn):
    method select (line 114) | def select(self, selector):
    method min (line 118) | def min(self):
    method max (line 121) | def max(self):
    method sum (line 124) | def sum(self):
    method len (line 127) | def len(self):
    method mean (line 130) | def mean(self):
    method std (line 135) | def std(self):
    method mean_std (line 140) | def mean_std(self):
    method argmax (line 143) | def argmax(self, selector):
    method filter (line 147) | def filter(self, fn):
    method filter_equals (line 150) | def filter_equals(self, selector, value):
    method filter_not_none (line 155) | def filter_not_none(self):
    method filter_not_nan (line 158) | def filter_not_nan(self):
    method flatten (line 161) | def flatten(self):
    method unique (line 164) | def unique(self):
    method sorted (line 174) | def sorted(self, key=None, reverse=False):

FILE: domain_generalization/swad/domainbed/lib/swa_utils.py
  class AveragedModel (line 9) | class AveragedModel(Module):
    method __init__ (line 10) | def __init__(self, model, device=None, avg_fn=None, rm_optimizer=False):
    method forward (line 36) | def forward(self, *args, **kwargs):
    method predict (line 40) | def predict(self, *args, **kwargs):
    method network (line 44) | def network(self):
    method update_parameters (line 47) | def update_parameters(self, model, step=None, start_step=None, end_ste...
    method clone (line 82) | def clone(self):
  function cvt_dbiterator_to_loader (line 88) | def cvt_dbiterator_to_loader(dbiterator, n_iter):
  function update_bn (line 99) | def update_bn(iterator, model, n_steps, device="cuda"):

FILE: domain_generalization/swad/domainbed/lib/wide_resnet.py
  function conv3x3 (line 17) | def conv3x3(in_planes, out_planes, stride=1):
  function conv_init (line 21) | def conv_init(m):
  class wide_basic (line 31) | class wide_basic(nn.Module):
    method __init__ (line 32) | def __init__(self, in_planes, planes, dropout_rate, stride=1):
    method forward (line 46) | def forward(self, x):
  class Wide_ResNet (line 54) | class Wide_ResNet(nn.Module):
    method __init__ (line 57) | def __init__(self, input_shape, depth, widen_factor, dropout_rate):
    method _wide_layer (line 76) | def _wide_layer(self, block, planes, num_blocks, dropout_rate, stride):
    method forward (line 86) | def forward(self, x):

FILE: domain_generalization/swad/domainbed/lib/writers.py
  class Writer (line 1) | class Writer:
    method add_scalars (line 2) | def add_scalars(self, tag_scalar_dic, global_step):
    method add_scalars_with_prefix (line 5) | def add_scalars_with_prefix(self, tag_scalar_dic, global_step, prefix):
  class TBWriter (line 10) | class TBWriter(Writer):
    method __init__ (line 11) | def __init__(self, dir_path):
    method add_scalars (line 16) | def add_scalars(self, tag_scalar_dic, global_step):
  function get_writer (line 21) | def get_writer(dir_path):

FILE: domain_generalization/swad/domainbed/lr_scheduler/lr_scheduler.py
  function get_scheduler (line 4) | def get_scheduler(name, optimizer, lr, total_steps, final_div_factor=1e4):

FILE: domain_generalization/swad/domainbed/models/mixstyle.py
  class MixStyle (line 9) | class MixStyle(nn.Module):
    method __init__ (line 15) | def __init__(self, p=0.5, alpha=0.3, eps=1e-6):
    method __repr__ (line 32) | def __repr__(self):
    method forward (line 35) | def forward(self, x):
  class MixStyle2 (line 61) | class MixStyle2(nn.Module):
    method __init__ (line 68) | def __init__(self, p=0.5, alpha=0.3, eps=1e-6):
    method __repr__ (line 85) | def __repr__(self):
    method forward (line 88) | def forward(self, x):

FILE: domain_generalization/swad/domainbed/models/resnet_mixstyle.py
  function conv3x3 (line 19) | def conv3x3(in_planes, out_planes, stride=1):
  class BasicBlock (line 24) | class BasicBlock(nn.Module):
    method __init__ (line 27) | def __init__(self, inplanes, planes, stride=1, downsample=None):
    method forward (line 37) | def forward(self, x):
  class Bottleneck (line 56) | class Bottleneck(nn.Module):
    method __init__ (line 59) | def __init__(self, inplanes, planes, stride=1, downsample=None):
    method forward (line 71) | def forward(self, x):
  class ResNet (line 94) | class ResNet(nn.Module):
    method __init__ (line 95) | def __init__(
    method _make_layer (line 125) | def _make_layer(self, block, planes, blocks, stride=1):
    method _init_params (line 147) | def _init_params(self):
    method compute_style (line 164) | def compute_style(self, x):
    method featuremaps (line 169) | def featuremaps(self, x):
    method forward (line 193) | def forward(self, x):
  function init_pretrained_weights (line 199) | def init_pretrained_weights(model, model_url):
  function resnet18_mixstyle_L234_p0d5_a0d1 (line 204) | def resnet18_mixstyle_L234_p0d5_a0d1(pretrained=True, **kwargs):
  function resnet50_mixstyle_L234_p0d5_a0d1 (line 219) | def resnet50_mixstyle_L234_p0d5_a0d1(pretrained=True, **kwargs):

FILE: domain_generalization/swad/domainbed/models/resnet_mixstyle2.py
  function conv3x3 (line 20) | def conv3x3(in_planes, out_planes, stride=1):
  class BasicBlock (line 25) | class BasicBlock(nn.Module):
    method __init__ (line 28) | def __init__(self, inplanes, planes, stride=1, downsample=None):
    method forward (line 38) | def forward(self, x):
  class Bottleneck (line 57) | class Bottleneck(nn.Module):
    method __init__ (line 60) | def __init__(self, inplanes, planes, stride=1, downsample=None):
    method forward (line 72) | def forward(self, x):
  class ResNet (line 95) | class ResNet(nn.Module):
    method __init__ (line 96) | def __init__(
    method _make_layer (line 126) | def _make_layer(self, block, planes, blocks, stride=1):
    method _init_params (line 148) | def _init_params(self):
    method compute_style (line 165) | def compute_style(self, x):
    method featuremaps (line 170) | def featuremaps(self, x):
    method forward (line 194) | def forward(self, x):
  function init_pretrained_weights (line 200) | def init_pretrained_weights(model, model_url):
  function resnet18_mixstyle2_L234_p0d5_a0d1 (line 216) | def resnet18_mixstyle2_L234_p0d5_a0d1(pretrained=True, **kwargs):
  function resnet50_mixstyle2_L234_p0d5_a0d1 (line 231) | def resnet50_mixstyle2_L234_p0d5_a0d1(pretrained=True, **kwargs):

FILE: domain_generalization/swad/domainbed/networks.py
  class Identity (line 11) | class Identity(nn.Module):
    method __init__ (line 14) | def __init__(self):
    method forward (line 17) | def forward(self, x):
  class SqueezeLastTwo (line 21) | class SqueezeLastTwo(nn.Module):
    method __init__ (line 27) | def __init__(self):
    method forward (line 30) | def forward(self, x):
  class MLP (line 34) | class MLP(nn.Module):
    method __init__ (line 37) | def __init__(self, n_inputs, n_outputs, hparams):
    method forward (line 50) | def forward(self, x):
  class ResNet (line 62) | class ResNet(torch.nn.Module):
    method __init__ (line 65) | def __init__(self, input_shape, hparams, network=None):
    method forward (line 98) | def forward(self, x):
    method train (line 102) | def train(self, mode=True):
    method freeze_bn (line 109) | def freeze_bn(self):
  class MNIST_CNN (line 118) | class MNIST_CNN(nn.Module):
    method __init__ (line 128) | def __init__(self, input_shape):
    method forward (line 143) | def forward(self, x):
  class ContextNet (line 165) | class ContextNet(nn.Module):
    method __init__ (line 166) | def __init__(self, input_shape):
    method forward (line 181) | def forward(self, x):
  function Featurizer (line 185) | def Featurizer(input_shape, hparams):

FILE: domain_generalization/swad/domainbed/optimizers.py
  function get_optimizer (line 4) | def get_optimizer(name, params, **kwargs):

FILE: domain_generalization/swad/domainbed/scripts/download.py
  function stage_path (line 18) | def stage_path(data_dir, name):
  function download_and_extract (line 27) | def download_and_extract(url, dst, remove=True):
  function download_vlcs (line 95) | def download_vlcs(data_dir):
  function download_mnist (line 108) | def download_mnist(data_dir):
  function download_pacs (line 117) | def download_pacs(data_dir):
  function download_office_home (line 132) | def download_office_home(data_dir):
  function download_domain_net (line 147) | def download_domain_net(data_dir):
  function download_terra_incognita (line 174) | def download_terra_incognita(data_dir):

FILE: domain_generalization/swad/domainbed/swad.py
  class SWADBase (line 7) | class SWADBase:
    method update_and_evaluate (line 8) | def update_and_evaluate(self, segment_swa, val_acc, val_loss, prt_fn):
    method get_final_model (line 11) | def get_final_model(self):
  class IIDMax (line 15) | class IIDMax(SWADBase):
    method __init__ (line 18) | def __init__(self, evaluator, **kwargs):
    method update_and_evaluate (line 25) | def update_and_evaluate(self, segment_swa, val_acc, val_loss, prt_fn):
    method get_final_model (line 44) | def get_final_model(self):
  class LossValley (line 48) | class LossValley(SWADBase):
    method __init__ (line 53) | def __init__(self, evaluator, n_converge, n_tolerance, tolerance_ratio...
    method get_smooth_loss (line 75) | def get_smooth_loss(self, idx):
    method is_converged (line 80) | def is_converged(self):
    method update_and_evaluate (line 83) | def update_and_evaluate(self, segment_swa, val_acc, val_loss, prt_fn):
    method get_final_model (line 146) | def get_final_model(self):

FILE: domain_generalization/swad/domainbed/trainer.py
  function json_handler (line 27) | def json_handler(v):
  class TransformerDecorator (line 33) | class TransformerDecorator(torch.nn.Module):
    method __init__ (line 34) | def __init__(self, classifier, add_bt = 0, eval_batch=0):
    method forward (line 46) | def forward(self, x):
  function train (line 57) | def train(test_envs, args, hparams, n_steps, checkpoint_freq, logger, wr...

FILE: domain_generalization/swad/train_all.py
  function main (line 22) | def main():

FILE: long-tailed_recognition/BalancedSoftmax/data/ClassAwareSampler.py
  class RandomCycleIter (line 24) | class RandomCycleIter:
    method __init__ (line 26) | def __init__ (self, data, test_mode=False):
    method __iter__ (line 32) | def __iter__ (self):
    method __next__ (line 35) | def __next__ (self):
  function class_aware_sample_generator (line 45) | def class_aware_sample_generator (cls_iter, data_iter_list, n, num_sampl...
  class ClassAwareSampler (line 65) | class ClassAwareSampler (Sampler):
    method __init__ (line 67) | def __init__(self, data_source, num_samples_cls=1, is_infinite=False):
    method __iter__ (line 79) | def __iter__ (self):
    method __len__ (line 83) | def __len__ (self):
  function get_sampler (line 86) | def get_sampler():

FILE: long-tailed_recognition/BalancedSoftmax/data/ClassPrioritySampler.py
  class RandomCycleIter (line 14) | class RandomCycleIter:
    method __init__ (line 16) | def __init__ (self, data, test_mode=False):
    method __iter__ (line 22) | def __iter__ (self):
    method __next__ (line 25) | def __next__ (self):
  class PriorityTree (line 36) | class PriorityTree(object):
    method __init__ (line 37) | def __init__(self, capacity, init_weights, fixed_weights=None, fixed_s...
    method initialize (line 54) | def initialize(self, init_weights):
    method reset_adaptive_weights (line 68) | def reset_adaptive_weights(self, adaptive_weights):
    method reset_fixed_weights (line 71) | def reset_fixed_weights(self, fixed_weights, rescale=False):
    method update_whole (line 90) | def update_whole(self, total_weights):
    method get_adaptive_weights (line 107) | def get_adaptive_weights(self):
    method get_total_weights (line 114) | def get_total_weights(self):
    method get_raw_total_weights (line 122) | def get_raw_total_weights(self):
    method size (line 131) | def size(self):
    method capacity (line 135) | def capacity(self):
    method __len__ (line 138) | def __len__(se
Copy disabled (too large) Download .json
Condensed preview — 770 files, each showing path, character count, and a content snippet. Download the .json file for the full structured content (20,554K chars).
[
  {
    "path": "README.md",
    "chars": 12953,
    "preview": "# BatchFormer: Learning to Explore Sample Relationships for Robust Representation Learning\n\n## Introduction\n\nThis is the"
  },
  {
    "path": "batchformer-v2/deformable-detr/LICENSE",
    "chars": 11963,
    "preview": "Copyright (c) 2020 SenseTime. All Rights Reserved.\n\n                                 Apache License\n                    "
  },
  {
    "path": "batchformer-v2/deformable-detr/README.md",
    "chars": 2667,
    "preview": "# BatchFormerV2: Exploring Sample Relationships for Dense Representation Learning\n\nThis repository is based on Deformabl"
  },
  {
    "path": "batchformer-v2/deformable-detr/benchmark.py",
    "chars": 2445,
    "preview": "# ------------------------------------------------------------------------\n# Deformable DETR\n# Copyright (c) 2020 SenseT"
  },
  {
    "path": "batchformer-v2/deformable-detr/configs/r101_deformable_detr.sh",
    "chars": 220,
    "preview": "#!/usr/bin/env bash\n\nsource /usr/local/anaconda/4.2.0/etc/profile.d/conda.sh\nconda activate pyt\n\nset -x\n\nEXP_DIR=exps/r1"
  },
  {
    "path": "batchformer-v2/deformable-detr/configs/r50_deformable_detr.sh",
    "chars": 143,
    "preview": "#!/usr/bin/env bash\n\nset -x\n\nEXP_DIR=exps/r50_deformable_detr\nPY_ARGS=${@:1}\n\npython -u main.py \\\n    --output_dir ${EXP"
  },
  {
    "path": "batchformer-v2/deformable-detr/configs/r50_deformable_detr_plus_iterative_bbox_refinement.sh",
    "chars": 198,
    "preview": "#!/usr/bin/env bash\n\nset -x\n\nEXP_DIR=exps/r50_deformable_detr_plus_iterative_bbox_refinement\nPY_ARGS=${@:1}\n\npython -u m"
  },
  {
    "path": "batchformer-v2/deformable-detr/configs/r50_deformable_detr_plus_iterative_bbox_refinement_plus_plus_two_stage.sh",
    "chars": 236,
    "preview": "#!/usr/bin/env bash\n\nset -x\n\nEXP_DIR=exps/r50_deformable_detr_plus_iterative_bbox_refinement_plus_plus_two_stage\nPY_ARGS"
  },
  {
    "path": "batchformer-v2/deformable-detr/configs/r50_deformable_detr_single_scale.sh",
    "chars": 185,
    "preview": "#!/usr/bin/env bash\n\nset -x\n\nEXP_DIR=exps/r50_deformable_detr_single_scale\nPY_ARGS=${@:1}\n\npython -u main.py \\\n    --num"
  },
  {
    "path": "batchformer-v2/deformable-detr/configs/r50_deformable_detr_single_scale_dc5.sh",
    "chars": 206,
    "preview": "#!/usr/bin/env bash\n\nset -x\n\nEXP_DIR=exps/r50_deformable_detr_single_scale_dc5\nPY_ARGS=${@:1}\n\npython -u main.py \\\n    -"
  },
  {
    "path": "batchformer-v2/deformable-detr/datasets/__init__.py",
    "chars": 1341,
    "preview": "# ------------------------------------------------------------------------\n# Deformable DETR\n# Copyright (c) 2020 SenseT"
  },
  {
    "path": "batchformer-v2/deformable-detr/datasets/coco.py",
    "chars": 6044,
    "preview": "# ------------------------------------------------------------------------\n# Deformable DETR\n# Copyright (c) 2020 SenseT"
  },
  {
    "path": "batchformer-v2/deformable-detr/datasets/coco_eval.py",
    "chars": 9171,
    "preview": "# ------------------------------------------------------------------------\n# Deformable DETR\n# Copyright (c) 2020 SenseT"
  },
  {
    "path": "batchformer-v2/deformable-detr/datasets/coco_panoptic.py",
    "chars": 4159,
    "preview": "# ------------------------------------------------------------------------\n# Deformable DETR\n# Copyright (c) 2020 SenseT"
  },
  {
    "path": "batchformer-v2/deformable-detr/datasets/data_prefetcher.py",
    "chars": 3085,
    "preview": "# ------------------------------------------------------------------------\n# Deformable DETR\n# Copyright (c) 2020 SenseT"
  },
  {
    "path": "batchformer-v2/deformable-detr/datasets/panoptic_eval.py",
    "chars": 1929,
    "preview": "# ------------------------------------------------------------------------\n# Deformable DETR\n# Copyright (c) 2020 SenseT"
  },
  {
    "path": "batchformer-v2/deformable-detr/datasets/samplers.py",
    "chars": 5608,
    "preview": "# ------------------------------------------------------------------------\n# Deformable DETR\n# Copyright (c) 2020 SenseT"
  },
  {
    "path": "batchformer-v2/deformable-detr/datasets/torchvision_datasets/__init__.py",
    "chars": 329,
    "preview": "# ------------------------------------------------------------------------\n# Deformable DETR\n# Copyright (c) 2020 SenseT"
  },
  {
    "path": "batchformer-v2/deformable-detr/datasets/torchvision_datasets/coco.py",
    "chars": 3285,
    "preview": "# ------------------------------------------------------------------------\n# Deformable DETR\n# Copyright (c) 2020 SenseT"
  },
  {
    "path": "batchformer-v2/deformable-detr/datasets/transforms.py",
    "chars": 8955,
    "preview": "# ------------------------------------------------------------------------\n# Deformable DETR\n# Copyright (c) 2020 SenseT"
  },
  {
    "path": "batchformer-v2/deformable-detr/docs/changelog.md",
    "chars": 383,
    "preview": "## Changelog\n\n**[2020.12.07]** Fix a bug of sampling offset normalization (see [this issue](https://github.com/fundament"
  },
  {
    "path": "batchformer-v2/deformable-detr/engine.py",
    "chars": 7695,
    "preview": "# ------------------------------------------------------------------------\n# Deformable DETR\n# Copyright (c) 2020 SenseT"
  },
  {
    "path": "batchformer-v2/deformable-detr/main.py",
    "chars": 15929,
    "preview": "# ------------------------------------------------------------------------\n# Deformable DETR\n# Copyright (c) 2020 SenseT"
  },
  {
    "path": "batchformer-v2/deformable-detr/models/__init__.py",
    "chars": 591,
    "preview": "# ------------------------------------------------------------------------\n# Deformable DETR\n# Copyright (c) 2020 SenseT"
  },
  {
    "path": "batchformer-v2/deformable-detr/models/backbone.py",
    "chars": 5297,
    "preview": "# ------------------------------------------------------------------------\n# Deformable DETR\n# Copyright (c) 2020 SenseT"
  },
  {
    "path": "batchformer-v2/deformable-detr/models/deformable_detr.py",
    "chars": 23338,
    "preview": "# ------------------------------------------------------------------------\n# Deformable DETR\n# Copyright (c) 2020 SenseT"
  },
  {
    "path": "batchformer-v2/deformable-detr/models/deformable_transformer.py",
    "chars": 19808,
    "preview": "\nimport copy\nfrom typing import Optional, List\nimport math\n\nimport torch\nimport torch.nn.functional as F\nfrom torch impo"
  },
  {
    "path": "batchformer-v2/deformable-detr/models/matcher.py",
    "chars": 4964,
    "preview": "# ------------------------------------------------------------------------\n# Deformable DETR\n# Copyright (c) 2020 SenseT"
  },
  {
    "path": "batchformer-v2/deformable-detr/models/ops/functions/__init__.py",
    "chars": 598,
    "preview": "# ------------------------------------------------------------------------------------------------\n# Deformable DETR\n# C"
  },
  {
    "path": "batchformer-v2/deformable-detr/models/ops/functions/ms_deform_attn_func.py",
    "chars": 3298,
    "preview": "# ------------------------------------------------------------------------------------------------\n# Deformable DETR\n# C"
  },
  {
    "path": "batchformer-v2/deformable-detr/models/ops/make.sh",
    "chars": 593,
    "preview": "#!/usr/bin/env bash\n# ------------------------------------------------------------------------------------------------\n#"
  },
  {
    "path": "batchformer-v2/deformable-detr/models/ops/modules/__init__.py",
    "chars": 584,
    "preview": "# ------------------------------------------------------------------------------------------------\n# Deformable DETR\n# C"
  },
  {
    "path": "batchformer-v2/deformable-detr/models/ops/modules/ms_deform_attn.py",
    "chars": 6270,
    "preview": "# ------------------------------------------------------------------------------------------------\n# Deformable DETR\n# C"
  },
  {
    "path": "batchformer-v2/deformable-detr/models/ops/setup.py",
    "chars": 2559,
    "preview": "# ------------------------------------------------------------------------------------------------\n# Deformable DETR\n# C"
  },
  {
    "path": "batchformer-v2/deformable-detr/models/ops/src/cpu/ms_deform_attn_cpu.cpp",
    "chars": 1256,
    "preview": "/*!\n**************************************************************************************************\n* Deformable DETR"
  },
  {
    "path": "batchformer-v2/deformable-detr/models/ops/src/cpu/ms_deform_attn_cpu.h",
    "chars": 1139,
    "preview": "/*!\n**************************************************************************************************\n* Deformable DETR"
  },
  {
    "path": "batchformer-v2/deformable-detr/models/ops/src/cuda/ms_deform_attn_cuda.cu",
    "chars": 7316,
    "preview": "/*!\n**************************************************************************************************\n* Deformable DETR"
  },
  {
    "path": "batchformer-v2/deformable-detr/models/ops/src/cuda/ms_deform_attn_cuda.h",
    "chars": 1140,
    "preview": "/*!\n**************************************************************************************************\n* Deformable DETR"
  },
  {
    "path": "batchformer-v2/deformable-detr/models/ops/src/cuda/ms_deform_im2col_cuda.cuh",
    "chars": 54694,
    "preview": "/*!\n**************************************************************************\n* Deformable DETR\n* Copyright (c) 2020 Se"
  },
  {
    "path": "batchformer-v2/deformable-detr/models/ops/src/ms_deform_attn.h",
    "chars": 1838,
    "preview": "/*!\n**************************************************************************************************\n* Deformable DETR"
  },
  {
    "path": "batchformer-v2/deformable-detr/models/ops/src/vision.cpp",
    "chars": 799,
    "preview": "/*!\n**************************************************************************************************\n* Deformable DETR"
  },
  {
    "path": "batchformer-v2/deformable-detr/models/ops/test.py",
    "chars": 4087,
    "preview": "# ------------------------------------------------------------------------------------------------\n# Deformable DETR\n# C"
  },
  {
    "path": "batchformer-v2/deformable-detr/models/position_encoding.py",
    "chars": 3788,
    "preview": "# ------------------------------------------------------------------------\n# Deformable DETR\n# Copyright (c) 2020 SenseT"
  },
  {
    "path": "batchformer-v2/deformable-detr/models/segmentation.py",
    "chars": 15925,
    "preview": "# ------------------------------------------------------------------------\n# Deformable DETR\n# Copyright (c) 2020 SenseT"
  },
  {
    "path": "batchformer-v2/deformable-detr/requirements.txt",
    "chars": 30,
    "preview": "pycocotools\ntqdm\ncython\nscipy\n"
  },
  {
    "path": "batchformer-v2/deformable-detr/tools/launch.py",
    "chars": 9306,
    "preview": "# ----------------------------------------------------------------------------------------------------------------------"
  },
  {
    "path": "batchformer-v2/deformable-detr/tools/run_dist_launch.sh",
    "chars": 812,
    "preview": "#!/usr/bin/env bash\n# ------------------------------------------------------------------------\n# Deformable DETR\n# Copyr"
  },
  {
    "path": "batchformer-v2/deformable-detr/tools/run_dist_slurm.sh",
    "chars": 1157,
    "preview": "#!/usr/bin/env bash\n# --------------------------------------------------------------------------------------------------"
  },
  {
    "path": "batchformer-v2/deformable-detr/util/__init__.py",
    "chars": 506,
    "preview": "# ------------------------------------------------------------------------\n# Deformable DETR\n# Copyright (c) 2020 SenseT"
  },
  {
    "path": "batchformer-v2/deformable-detr/util/box_ops.py",
    "chars": 2997,
    "preview": "# ------------------------------------------------------------------------\n# Deformable DETR\n# Copyright (c) 2020 SenseT"
  },
  {
    "path": "batchformer-v2/deformable-detr/util/misc.py",
    "chars": 17603,
    "preview": "# ------------------------------------------------------------------------\n# Deformable DETR\n# Copyright (c) 2020 SenseT"
  },
  {
    "path": "batchformer-v2/deformable-detr/util/plot_utils.py",
    "chars": 4664,
    "preview": "# ------------------------------------------------------------------------\n# Deformable DETR\n# Copyright (c) 2020 SenseT"
  },
  {
    "path": "batchformer-v2/deformable-detr/util/visualizer.py",
    "chars": 1045,
    "preview": "\nimport argparse\n\nimport cv2\nimport numpy as np\nimport re\n\nfrom detectron2 import model_zoo\nfrom detectron2.config impor"
  },
  {
    "path": "batchformer-v2/deit_share/.circleci/config.yml",
    "chars": 605,
    "preview": "version: 2.1\n\njobs:\n  python_lint:\n    docker:\n      - image: circleci/python:3.7\n    steps:\n      - checkout\n      - ru"
  },
  {
    "path": "batchformer-v2/deit_share/.github/CODE_OF_CONDUCT.md",
    "chars": 244,
    "preview": "# Code of Conduct\n\nFacebook has adopted a Code of Conduct that we expect project participants to adhere to.\nPlease read "
  },
  {
    "path": "batchformer-v2/deit_share/.github/CONTRIBUTING.md",
    "chars": 1609,
    "preview": "# Contributing to DeiT\nWe want to make contributing to this project as easy and transparent as\npossible.\n\n## Our Develop"
  },
  {
    "path": "batchformer-v2/deit_share/.gitignore",
    "chars": 83,
    "preview": "*.swp\n**/__pycache__/**\nimnet_resnet50_scratch/timm_temp/\n.dumbo.json\ncheckpoints/\n"
  },
  {
    "path": "batchformer-v2/deit_share/.idea/.gitignore",
    "chars": 176,
    "preview": "# Default ignored files\n/shelf/\n/workspace.xml\n# Datasource local storage ignored files\n/dataSources/\n/dataSources.local"
  },
  {
    "path": "batchformer-v2/deit_share/.idea/deit_share.iml",
    "chars": 441,
    "preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<module type=\"PYTHON_MODULE\" version=\"4\">\n  <component name=\"NewModuleRootManager"
  },
  {
    "path": "batchformer-v2/deit_share/.idea/inspectionProfiles/profiles_settings.xml",
    "chars": 174,
    "preview": "<component name=\"InspectionProjectProfileManager\">\n  <settings>\n    <option name=\"USE_PROJECT_PROFILE\" value=\"false\" />\n"
  },
  {
    "path": "batchformer-v2/deit_share/.idea/misc.xml",
    "chars": 185,
    "preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<project version=\"4\">\n  <component name=\"ProjectRootManager\" version=\"2\" project-"
  },
  {
    "path": "batchformer-v2/deit_share/.idea/modules.xml",
    "chars": 272,
    "preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<project version=\"4\">\n  <component name=\"ProjectModuleManager\">\n    <modules>\n   "
  },
  {
    "path": "batchformer-v2/deit_share/.idea/vcs.xml",
    "chars": 238,
    "preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<project version=\"4\">\n  <component name=\"VcsDirectoryMappings\">\n    <mapping dire"
  },
  {
    "path": "batchformer-v2/deit_share/LICENSE",
    "chars": 11354,
    "preview": "                                 Apache License\n                           Version 2.0, January 2004\n                   "
  },
  {
    "path": "batchformer-v2/deit_share/README.md",
    "chars": 203,
    "preview": "#BatchFormerV2\n\nThe hyperparameters\n\n--add_global 2 --insert_idx 8 --bt_lr 0.5 # for larger model, maybe, it requires to"
  },
  {
    "path": "batchformer-v2/deit_share/README_cait.md",
    "chars": 2853,
    "preview": "\n# CaiT: Going deeper with Image Transformers\n\nThis repository contains PyTorch evaluation code, training code and pretr"
  },
  {
    "path": "batchformer-v2/deit_share/README_resmlp.md",
    "chars": 3679,
    "preview": "\n# ResMLP: Feedforward networks for image classification with data-efficient training\n\nThis repository contains PyTorch "
  },
  {
    "path": "batchformer-v2/deit_share/bt.py",
    "chars": 11872,
    "preview": "import torch\nfrom timm.models.vision_transformer import Attention, Block\n\n\nclass BlockBF(torch.nn.Module):\n\n    def __in"
  },
  {
    "path": "batchformer-v2/deit_share/cait_models.py",
    "chars": 17956,
    "preview": "# Copyright (c) 2015-present, Facebook, Inc.\n# All rights reserved.\n\nimport torch\nimport torch.nn as nn\nfrom functools i"
  },
  {
    "path": "batchformer-v2/deit_share/datasets.py",
    "chars": 4146,
    "preview": "# Copyright (c) 2015-present, Facebook, Inc.\n# All rights reserved.\nimport os\nimport json\n\nfrom torchvision import datas"
  },
  {
    "path": "batchformer-v2/deit_share/engine.py",
    "chars": 7977,
    "preview": "# Copyright (c) 2015-present, Facebook, Inc.\n# All rights reserved.\n\"\"\"\nTrain and eval functions used in main.py\n\"\"\"\nimp"
  },
  {
    "path": "batchformer-v2/deit_share/gpu.pbs",
    "chars": 160,
    "preview": "#!/bin/bash\n#PBS -P ZHIHOU\n#PBS -l select=4:ngpus=1:ncpus=6:mem=24GB\n#PBS -l walltime=72:00:00\n#PBS -q alloc-dt\nsource a"
  },
  {
    "path": "batchformer-v2/deit_share/hubconf.py",
    "chars": 138,
    "preview": "# Copyright (c) 2015-present, Facebook, Inc.\n# All rights reserved.\nfrom models import *\n\ndependencies = [\"torch\", \"torc"
  },
  {
    "path": "batchformer-v2/deit_share/losses.py",
    "chars": 4760,
    "preview": "# Copyright (c) 2015-present, Facebook, Inc.\n# All rights reserved.\n\"\"\"\nImplements the knowledge distillation loss\n\"\"\"\ni"
  },
  {
    "path": "batchformer-v2/deit_share/main.py",
    "chars": 31618,
    "preview": "# Copyright (c) 2015-present, Facebook, Inc.\n# All rights reserved.\nimport argparse\nimport datetime\nimport numpy as np\ni"
  },
  {
    "path": "batchformer-v2/deit_share/models.py",
    "chars": 8716,
    "preview": "# Copyright (c) 2015-present, Facebook, Inc.\n# All rights reserved.\nimport os\n\nimport torch\nimport torch.nn as nn\nfrom f"
  },
  {
    "path": "batchformer-v2/deit_share/optimizer.py",
    "chars": 6957,
    "preview": "import torch\nfrom timm.optim import optimizer_kwargs\nfrom timm.optim.optim_factory import add_weight_decay\nfrom torch im"
  },
  {
    "path": "batchformer-v2/deit_share/requirements.txt",
    "chars": 44,
    "preview": "torch==1.7.0\ntorchvision==0.8.1\ntimm==0.3.2\n"
  },
  {
    "path": "batchformer-v2/deit_share/resmlp_models.py",
    "chars": 6573,
    "preview": "# Copyright (c) 2015-present, Facebook, Inc.\n# All rights reserved.\nimport torch\nimport torch.nn as nn\nfrom functools im"
  },
  {
    "path": "batchformer-v2/deit_share/run_with_submitit.py",
    "chars": 4075,
    "preview": "# Copyright (c) 2015-present, Facebook, Inc.\n# All rights reserved.\n\"\"\"\nA script to run multinode training with submitit"
  },
  {
    "path": "batchformer-v2/deit_share/samplers.py",
    "chars": 2292,
    "preview": "# Copyright (c) 2015-present, Facebook, Inc.\n# All rights reserved.\nimport torch\nimport torch.distributed as dist\nimport"
  },
  {
    "path": "batchformer-v2/deit_share/temp.txt",
    "chars": 2000,
    "preview": "n01443537\nn01629819\nn01641577\nn01644900\nn01698640\nn01742172\nn01768244\nn01770393\nn01774384\nn01774750\nn01784675\nn01855672\n"
  },
  {
    "path": "batchformer-v2/deit_share/tiny_img.py",
    "chars": 388,
    "preview": "import os\nimport sys\nos.makedirs('/ImageNetTiny')\nos.makedirs('/ImageNetTiny/train')\nos.makedirs('/ImageNetTiny/val')\n\nw"
  },
  {
    "path": "batchformer-v2/deit_share/tox.ini",
    "chars": 65,
    "preview": "[flake8]\nmax-line-length = 120\nignore = F401,E402,F403,W503,W504\n"
  },
  {
    "path": "batchformer-v2/deit_share/utils.py",
    "chars": 7067,
    "preview": "# Copyright (c) 2015-present, Facebook, Inc.\n# All rights reserved.\n\"\"\"\nMisc functions, including distributed helpers.\n\n"
  },
  {
    "path": "batchformer-v2/detr/.circleci/config.yml",
    "chars": 703,
    "preview": "version: 2.1\n\njobs:\n  python_lint:\n    docker:\n      - image: circleci/python:3.7\n    steps:\n      - checkout\n      - ru"
  },
  {
    "path": "batchformer-v2/detr/.github/CODE_OF_CONDUCT.md",
    "chars": 244,
    "preview": "# Code of Conduct\n\nFacebook has adopted a Code of Conduct that we expect project participants to adhere to.\nPlease read "
  },
  {
    "path": "batchformer-v2/detr/.github/CONTRIBUTING.md",
    "chars": 1611,
    "preview": "# Contributing to DETR\nWe want to make contributing to this project as easy and transparent as\npossible.\n\n## Our Develop"
  },
  {
    "path": "batchformer-v2/detr/.github/ISSUE_TEMPLATE/bugs.md",
    "chars": 719,
    "preview": "---\nname: \"🐛 Bugs\"\nabout: Report bugs in DETR\ntitle: Please read & provide the following\n\n---\n\n## Instructions To Reprod"
  },
  {
    "path": "batchformer-v2/detr/.github/ISSUE_TEMPLATE/questions-help-support.md",
    "chars": 787,
    "preview": "---\nname: \"How to do something❓\"\nabout: How to do something using DETR?\n\n---\n\n## ❓ How to do something using DETR\n\nDescr"
  },
  {
    "path": "batchformer-v2/detr/.github/ISSUE_TEMPLATE/unexpected-problems-bugs.md",
    "chars": 1145,
    "preview": "---\nname: \"Unexpected behaviors\"\nabout: Run into unexpected behaviors when using DETR\ntitle: Please read & provide the f"
  },
  {
    "path": "batchformer-v2/detr/.gitignore",
    "chars": 189,
    "preview": ".nfs*\n*.ipynb\n*.pyc\n.dumbo.json\n.DS_Store\n.*.swp\n*.pth\n**/__pycache__/**\n.ipynb_checkpoints/\ndatasets/data/\nexperiment-*"
  },
  {
    "path": "batchformer-v2/detr/Dockerfile",
    "chars": 328,
    "preview": "FROM pytorch/pytorch:1.5-cuda10.1-cudnn7-runtime\n\nENV DEBIAN_FRONTEND=noninteractive\n\nRUN apt-get update -qq && \\\n    ap"
  },
  {
    "path": "batchformer-v2/detr/LICENSE",
    "chars": 11354,
    "preview": "                                 Apache License\n                           Version 2.0, January 2004\n                   "
  },
  {
    "path": "batchformer-v2/detr/README.md",
    "chars": 1002,
    "preview": "This is the repository based on DETR. This repository includes the implementation of batchformer based on DETR. The corr"
  },
  {
    "path": "batchformer-v2/detr/configs/base.sh",
    "chars": 230,
    "preview": "#!/usr/bin/env bash\n\nsource /usr/local/anaconda/4.2.0/etc/profile.d/conda.sh\nconda activate pyt\n\nset -x\n\npython main.py "
  },
  {
    "path": "batchformer-v2/detr/configs/panoptic.sh",
    "chars": 481,
    "preview": "#!/usr/bin/env bash\n\nsource /usr/local/anaconda/4.2.0/etc/profile.d/conda.sh\nconda activate pyt\n\nset -x\n\n#python main.py"
  },
  {
    "path": "batchformer-v2/detr/configs/panoptic_1.sh",
    "chars": 380,
    "preview": "#!/usr/bin/env bash\n\nsource /usr/local/anaconda/4.2.0/etc/profile.d/conda.sh\nconda activate pyt\n\nset -x\n\n\npython main.py"
  },
  {
    "path": "batchformer-v2/detr/configs/panoptic_2.sh",
    "chars": 406,
    "preview": "#!/usr/bin/env bash\n\nsource /usr/local/anaconda/4.2.0/etc/profile.d/conda.sh\nconda activate pyt\n\nset -x\n\n\npython main.py"
  },
  {
    "path": "batchformer-v2/detr/configs/swin.sh",
    "chars": 248,
    "preview": "#!/usr/bin/env bash\n\nsource /usr/local/anaconda/4.2.0/etc/profile.d/conda.sh\nconda activate pyt\n\nset -x\n\npython main.py "
  },
  {
    "path": "batchformer-v2/detr/d2/README.md",
    "chars": 2228,
    "preview": "Detectron2 wrapper for DETR\n=======\n\nWe provide a Detectron2 wrapper for DETR, thus providing a way to better integrate "
  },
  {
    "path": "batchformer-v2/detr/d2/configs/detr_256_6_6_torchvision.yaml",
    "chars": 1012,
    "preview": "MODEL:\n  META_ARCHITECTURE: \"Detr\"\n  WEIGHTS: \"detectron2://ImageNetPretrained/torchvision/R-50.pkl\"\n  PIXEL_MEAN: [123."
  },
  {
    "path": "batchformer-v2/detr/d2/configs/detr_segm_256_6_6_torchvision.yaml",
    "chars": 1033,
    "preview": "MODEL:\n  META_ARCHITECTURE: \"Detr\"\n#  WEIGHTS: \"detectron2://ImageNetPretrained/torchvision/R-50.pkl\"\n  PIXEL_MEAN: [123"
  },
  {
    "path": "batchformer-v2/detr/d2/converter.py",
    "chars": 2590,
    "preview": "# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved\n\"\"\"\nHelper script to convert models trained with "
  },
  {
    "path": "batchformer-v2/detr/d2/detr/__init__.py",
    "chars": 176,
    "preview": "# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved\nfrom .config import add_detr_config\nfrom .detr im"
  },
  {
    "path": "batchformer-v2/detr/d2/detr/config.py",
    "chars": 888,
    "preview": "# -*- coding: utf-8 -*-\n# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved\nfrom detectron2.config im"
  },
  {
    "path": "batchformer-v2/detr/d2/detr/dataset_mapper.py",
    "chars": 4570,
    "preview": "# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved\nimport copy\nimport logging\n\nimport numpy as np\nim"
  },
  {
    "path": "batchformer-v2/detr/d2/detr/detr.py",
    "chars": 11143,
    "preview": "# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved\nimport logging\nimport math\nfrom typing import Lis"
  },
  {
    "path": "batchformer-v2/detr/d2/train_net.py",
    "chars": 4999,
    "preview": "# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved\n\"\"\"\nDETR Training Script.\n\nThis script is a simpl"
  },
  {
    "path": "batchformer-v2/detr/datasets/__init__.py",
    "chars": 1111,
    "preview": "# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved\nimport torch.utils.data\nimport torchvision\n\nfrom "
  },
  {
    "path": "batchformer-v2/detr/datasets/coco.py",
    "chars": 6310,
    "preview": "# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved\n\"\"\"\nCOCO dataset which returns image_id for evalu"
  },
  {
    "path": "batchformer-v2/detr/datasets/coco_eval.py",
    "chars": 8735,
    "preview": "# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved\n\"\"\"\nCOCO evaluator that works in distributed mode"
  },
  {
    "path": "batchformer-v2/detr/datasets/coco_panoptic.py",
    "chars": 3723,
    "preview": "# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved\nimport json\nfrom pathlib import Path\n\nimport nump"
  },
  {
    "path": "batchformer-v2/detr/datasets/panoptic_eval.py",
    "chars": 1493,
    "preview": "# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved\nimport json\nimport os\n\nimport util.misc as utils\n"
  },
  {
    "path": "batchformer-v2/detr/datasets/transforms.py",
    "chars": 8524,
    "preview": "# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved\n\"\"\"\nTransforms and data augmentation for both ima"
  },
  {
    "path": "batchformer-v2/detr/detr.pbs",
    "chars": 592,
    "preview": "#!/bin/bash\n#PBS -P ZHIHOU\n#PBS -l select=8:ngpus=1:ncpus=6:mem=24GB\n#PBS -l walltime=48:00:00\n##PBS -q alloc-dt\nsource "
  },
  {
    "path": "batchformer-v2/detr/engine.py",
    "chars": 6721,
    "preview": "# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved\n\"\"\"\nTrain and eval functions used in main.py\n\"\"\"\n"
  },
  {
    "path": "batchformer-v2/detr/hubconf.py",
    "chars": 6265,
    "preview": "# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved\nimport torch\n\nfrom models.backbone import Backbon"
  },
  {
    "path": "batchformer-v2/detr/main.py",
    "chars": 14227,
    "preview": "# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved\nimport argparse\nimport datetime\nimport json\nimpor"
  },
  {
    "path": "batchformer-v2/detr/models/__init__.py",
    "chars": 143,
    "preview": "# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved\nfrom .detr import build\n\n\ndef build_model(args):\n"
  },
  {
    "path": "batchformer-v2/detr/models/backbone.py",
    "chars": 6519,
    "preview": "# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved\n\"\"\"\nBackbone modules.\n\"\"\"\nfrom collections import"
  },
  {
    "path": "batchformer-v2/detr/models/detr.py",
    "chars": 18048,
    "preview": "# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved\n\"\"\"\nDETR model and criterion classes.\n\"\"\"\nimport "
  },
  {
    "path": "batchformer-v2/detr/models/matcher.py",
    "chars": 4250,
    "preview": "# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved\n\"\"\"\nModules to compute the matching cost and solv"
  },
  {
    "path": "batchformer-v2/detr/models/position_encoding.py",
    "chars": 3336,
    "preview": "# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved\n\"\"\"\nVarious positional encodings for the transfor"
  },
  {
    "path": "batchformer-v2/detr/models/segmentation.py",
    "chars": 16013,
    "preview": "# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved\n\"\"\"\nThis file provides the definition of the conv"
  },
  {
    "path": "batchformer-v2/detr/models/transformer.py",
    "chars": 16826,
    "preview": "# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved\n\"\"\"\nDETR Transformer class.\n\nCopy-paste from torc"
  },
  {
    "path": "batchformer-v2/detr/requirements.txt",
    "chars": 224,
    "preview": "cython\ngit+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI&egg=pycocotools\nsubmitit\ntorch>=1.5.0\ntorch"
  },
  {
    "path": "batchformer-v2/detr/run.py",
    "chars": 6836,
    "preview": "#!/usr/local/anaconda/4.2.0/bin/python\n\n##################################\n'''\nCode is based on hpc_check_py36_withquota"
  },
  {
    "path": "batchformer-v2/detr/run_with_submitit.py",
    "chars": 3476,
    "preview": "# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved\n\"\"\"\nA script to run multinode training with submi"
  },
  {
    "path": "batchformer-v2/detr/test_all.py",
    "chars": 8804,
    "preview": "# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved\nimport io\nimport unittest\n\nimport torch\nfrom torc"
  },
  {
    "path": "batchformer-v2/detr/tools/launch.py",
    "chars": 9505,
    "preview": "# ----------------------------------------------------------------------------------------------------------------------"
  },
  {
    "path": "batchformer-v2/detr/tools/run_dist_launch.sh",
    "chars": 1046,
    "preview": "#!/usr/bin/env bash\n# ------------------------------------------------------------------------\n# Deformable DETR\n# Copyr"
  },
  {
    "path": "batchformer-v2/detr/tools/run_dist_slurm.sh",
    "chars": 1157,
    "preview": "#!/usr/bin/env bash\n# --------------------------------------------------------------------------------------------------"
  },
  {
    "path": "batchformer-v2/detr/tox.ini",
    "chars": 65,
    "preview": "[flake8]\nmax-line-length = 120\nignore = F401,E402,F403,W503,W504\n"
  },
  {
    "path": "batchformer-v2/detr/util/__init__.py",
    "chars": 71,
    "preview": "# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved\n"
  },
  {
    "path": "batchformer-v2/detr/util/box_ops.py",
    "chars": 2561,
    "preview": "# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved\n\"\"\"\nUtilities for bounding box manipulation and G"
  },
  {
    "path": "batchformer-v2/detr/util/misc.py",
    "chars": 16899,
    "preview": "# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved\n\"\"\"\nMisc functions, including distributed helpers"
  },
  {
    "path": "batchformer-v2/detr/util/plot_utils.py",
    "chars": 4514,
    "preview": "\"\"\"\nPlotting utilities to visualize training logs.\n\"\"\"\nimport torch\nimport pandas as pd\nimport numpy as np\nimport seabor"
  },
  {
    "path": "czsl/LICENSE",
    "chars": 35149,
    "preview": "                    GNU GENERAL PUBLIC LICENSE\n                       Version 3, 29 June 2007\n\n Copyright (C) 2007 Free "
  },
  {
    "path": "czsl/README.md",
    "chars": 1889,
    "preview": "\n# BatchFormer for Compositional Zero-Shot Learning\n\n\n## Setup \n\n1. Clone the repo and \n\n```\ncd czsl\n```\n\n2. We recommen"
  },
  {
    "path": "czsl/configs/baselines/cgqa/aopp.yml",
    "chars": 708,
    "preview": "---\nexperiment:\n  name: aopp/cgqa/\ndataset:\n  data_dir: cgqa\n  dataset: cgqa\n  splitname: compositional-split-natural\nmo"
  },
  {
    "path": "czsl/configs/baselines/cgqa/le+.yml",
    "chars": 681,
    "preview": "---\nexperiment:\n  name: labelembed/cgqa/\ndataset:\n  data_dir: cgqa\n  dataset: cgqa\n  splitname: compositional-split-natu"
  },
  {
    "path": "czsl/configs/baselines/cgqa/symnet.yml",
    "chars": 672,
    "preview": "---\nexperiment:\n  name: symnet/cgqa/\ndataset:\n  data_dir: cgqa\n  dataset: cgqa\n  splitname: compositional-split-natural\n"
  },
  {
    "path": "czsl/configs/baselines/cgqa/tmn.yml",
    "chars": 531,
    "preview": "---\nexperiment:\n  name: tmn/cgqa/\ndataset:\n  data_dir: cgqa\n  dataset: cgqa\n  splitname: compositional-split-natural\nmod"
  },
  {
    "path": "czsl/configs/baselines/mit/aopp.yml",
    "chars": 727,
    "preview": "---\nexperiment:\n  name: aopp/mitstates/\ndataset:\n  data_dir: mit-states\n  dataset: mitstates\n  splitname: compositional-"
  },
  {
    "path": "czsl/configs/baselines/mit/le+.yml",
    "chars": 651,
    "preview": "---\nexperiment:\n  name: labelembed/mitstates/\ndataset:\n  data_dir: mit-states\n  dataset: mitstates\n  splitname: composit"
  },
  {
    "path": "czsl/configs/baselines/mit/symnet.yml",
    "chars": 709,
    "preview": "---\nexperiment:\n  name: symnet/mit-states/\ndataset:\n  data_dir: mit-states\n  dataset: mitstates\n  splitname: composition"
  },
  {
    "path": "czsl/configs/baselines/mit/tmn.yml",
    "chars": 549,
    "preview": "---\nexperiment:\n  name: tmn/mitstates/\ndataset:\n  data_dir: mit-states\n  dataset: mitstates\n  splitname: compositional-s"
  },
  {
    "path": "czsl/configs/baselines/utzppos/aopp.yml",
    "chars": 721,
    "preview": "---\nexperiment:\n  name: aopp/utzappos/\ndataset:\n  data_dir: ut-zap50k\n  dataset: utzappos\n  splitname: compositional-spl"
  },
  {
    "path": "czsl/configs/baselines/utzppos/le+.yml",
    "chars": 648,
    "preview": "---\nexperiment:\n  name: labelembed/utzappos/\ndataset:\n  data_dir: ut-zap50k\n  dataset: utzappos\n  splitname: composition"
  },
  {
    "path": "czsl/configs/baselines/utzppos/symnet.yml",
    "chars": 688,
    "preview": "---\nexperiment:\n  name: symnet/utzappos/\ndataset:\n  data_dir: ut-zap50k\n  dataset: utzappos\n  splitname: compositional-s"
  },
  {
    "path": "czsl/configs/baselines/utzppos/tmn.yml",
    "chars": 616,
    "preview": "---\nexperiment:\n  name: tmn/utzappos/\ndataset:\n  data_dir: ut-zap50k\n  dataset: utzappos\n  splitname: compositional-spli"
  },
  {
    "path": "czsl/configs/cge/cgqa.yml",
    "chars": 732,
    "preview": "experiment:\n  name: graphembed/cgqa\ndataset:\n  data_dir: cgqa\n  dataset: cgqa\n  splitname: compositional-split-natural\nm"
  },
  {
    "path": "czsl/configs/cge/mit.yml",
    "chars": 643,
    "preview": "---\nexperiment:\n  name: graphembed/mitstates/base\ndataset:\n  data_dir: mit-states\n  dataset: mitstates\n  splitname: comp"
  },
  {
    "path": "czsl/configs/cge/utzappos.yml",
    "chars": 917,
    "preview": "---\nexperiment:\n  name: graphembed/utzappos/base\ndataset:\n  data_dir: ut-zap50k\n  dataset: utzappos\n  splitname: composi"
  },
  {
    "path": "czsl/configs/compcos/cgqa/compcos.yml",
    "chars": 661,
    "preview": "---\nexperiment:\n  name: compcos/cgqa\ndataset:\n  data_dir: cgqa\n  dataset: cgqa\n  splitname: compositional-split-natural\n"
  },
  {
    "path": "czsl/configs/compcos/cgqa/compcos_cw.yml",
    "chars": 645,
    "preview": "---\nexperiment:\n  name: compcos_cw/cgqa/\ndataset:\n  data_dir: cgqa\n  dataset: cgqa\n  splitname: compositional-split-natu"
  },
  {
    "path": "czsl/configs/compcos/mit/compcos.yml",
    "chars": 674,
    "preview": "---\nexperiment:\n  name: compcos/mitstates\ndataset:\n  data_dir: mit-states\n  dataset: mitstates\n  splitname: compositiona"
  },
  {
    "path": "czsl/configs/compcos/mit/compcos_cw.yml",
    "chars": 657,
    "preview": "---\nexperiment:\n  name: compcos_cw/mitstates\ndataset:\n  data_dir: mit-states\n  dataset: mitstates\n  splitname: compositi"
  },
  {
    "path": "czsl/configs/compcos/utzppos/compcos.yml",
    "chars": 668,
    "preview": "---\nexperiment:\n  name: compcos/utzappos\ndataset:\n  data_dir: ut-zap50k\n  dataset: utzappos\n  splitname: compositional-s"
  },
  {
    "path": "czsl/configs/compcos/utzppos/compcos_cw.yml",
    "chars": 648,
    "preview": "---\nexperiment:\n  name: compcos/utzappos\ndataset:\n  data_dir: ut-zap50k\n  dataset: utzappos\n  splitname: compositional-s"
  },
  {
    "path": "czsl/data/__init__.py",
    "chars": 0,
    "preview": ""
  },
  {
    "path": "czsl/data/dataset.py",
    "chars": 15653,
    "preview": "#external libs\nimport numpy as np\nfrom tqdm import tqdm\nfrom PIL import Image\nimport os\nimport random\nfrom os.path impor"
  },
  {
    "path": "czsl/environment.yml",
    "chars": 2092,
    "preview": "name: czsl\nchannels:\n  - pytorch\n  - defaults\ndependencies:\n  - _libgcc_mutex=0.1=main\n  - blas=1.0=mkl\n  - ca-certifica"
  },
  {
    "path": "czsl/flags.py",
    "chars": 7097,
    "preview": "import argparse\n\nDATA_FOLDER = \"/project/ZHIHOUDATA/CZSL\"\nparser = argparse.ArgumentParser(formatter_class=argparse.Argu"
  },
  {
    "path": "czsl/models/__init__.py",
    "chars": 0,
    "preview": ""
  },
  {
    "path": "czsl/models/common.py",
    "chars": 20689,
    "preview": "import torch\nimport torch.nn as nn\nimport torch.nn.functional as F\nimport numpy as np\nimport copy\nfrom scipy.stats impor"
  },
  {
    "path": "czsl/models/compcos.py",
    "chars": 10248,
    "preview": "import torch\nimport torch.nn as nn\nimport torch.nn.functional as F\nfrom .word_embedding import load_word_embeddings\nfrom"
  },
  {
    "path": "czsl/models/gcn.py",
    "chars": 5869,
    "preview": "import numpy as np\nimport scipy.sparse as sp\n\nimport math\nimport torch\nimport torch.nn as nn\nimport torch.nn.functional "
  },
  {
    "path": "czsl/models/graph_method.py",
    "chars": 4246,
    "preview": "import torch\nimport torch.nn as nn\nimport torch.nn.functional as F\nimport numpy as np\nfrom .common import MLP, cross_dom"
  },
  {
    "path": "czsl/models/image_extractor.py",
    "chars": 2428,
    "preview": "import torch\nimport torch.nn as nn\nimport torch.nn.functional as F\nfrom torchvision import models\nfrom torchvision.model"
  },
  {
    "path": "czsl/models/manifold_methods.py",
    "chars": 15340,
    "preview": "import torch\nimport torch.nn as nn\nimport torch.nn.functional as F\nimport numpy as np\nfrom .word_embedding import load_w"
  },
  {
    "path": "czsl/models/modular_methods.py",
    "chars": 23151,
    "preview": "# Copyright (c) Facebook, Inc. and its affiliates.\n# All rights reserved.\n#\n# This source code is licensed under the lic"
  },
  {
    "path": "czsl/models/svm.py",
    "chars": 9922,
    "preview": "import numpy as np\nimport tqdm\nfrom data import dataset as dset\nimport os\nfrom utils import utils\nimport torch\nfrom torc"
  },
  {
    "path": "czsl/models/symnet.py",
    "chars": 9135,
    "preview": "import torch\nimport torch.nn as nn\nimport torch.nn.functional as F\nimport numpy as np\nfrom .word_embedding import load_w"
  },
  {
    "path": "czsl/models/visual_product.py",
    "chars": 1457,
    "preview": "import torch\nimport torch.nn as nn\nimport torch.nn.functional as F\nimport torchvision.models as models\nimport numpy as n"
  },
  {
    "path": "czsl/models/word_embedding.py",
    "chars": 6636,
    "preview": "import torch\nimport numpy as np\nfrom flags import DATA_FOLDER\ndef load_word_embeddings(emb_type, vocab):\n    if emb_type"
  },
  {
    "path": "czsl/notebooks/analysis.ipynb",
    "chars": 8984,
    "preview": "{\n \"cells\": [\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": null,\n   \"metadata\": {},\n   \"outputs\": [],\n   \"source\": "
  },
  {
    "path": "czsl/test.py",
    "chars": 6186,
    "preview": "#  Torch imports\nimport torch\nfrom torch.utils.tensorboard import SummaryWriter\nimport torch.backends.cudnn as cudnn\nimp"
  },
  {
    "path": "czsl/train.py",
    "chars": 7277,
    "preview": "#  Torch imports\nimport torch\nimport torch.nn as nn\nimport torch.nn.functional as F\nfrom torch.utils.tensorboard import "
  },
  {
    "path": "czsl/utils/__init__.py",
    "chars": 0,
    "preview": ""
  },
  {
    "path": "czsl/utils/config_model.py",
    "chars": 4811,
    "preview": "import torch\nimport torch.optim as optim\n\nfrom models.image_extractor import get_image_extractor\nfrom models.visual_prod"
  },
  {
    "path": "czsl/utils/download_data.sh",
    "chars": 2585,
    "preview": "# Copyright (c) Facebook, Inc. and its affiliates.\n# All rights reserved.\n#\n# This source code is licensed under the lic"
  },
  {
    "path": "czsl/utils/download_embeddings.py",
    "chars": 88,
    "preview": "import fasttext.util\nfasttext.util.download_model('en', if_exists='ignore')  # English\n\n"
  },
  {
    "path": "czsl/utils/reorganize_utzap.py",
    "chars": 844,
    "preview": "# Copyright (c) Facebook, Inc. and its affiliates.\n# All rights reserved.\n#\n# This source code is licensed under the lic"
  },
  {
    "path": "czsl/utils/utils.py",
    "chars": 1943,
    "preview": "import os\nfrom os.path import join as ospj\nimport torch\nimport random\nimport copy\nimport shutil\nimport sys\nimport yaml\n\n"
  },
  {
    "path": "domain_generalization/README.md",
    "chars": 1828,
    "preview": "# BatchFormer for Domain Generalization\n\n## Installation\nCode is based on Transfer-Learning-Library (https://github.com/"
  },
  {
    "path": "domain_generalization/Transfer-Learning-Library/.github/ISSUE_TEMPLATE/bug_report.md",
    "chars": 834,
    "preview": "---\nname: Bug report\nabout: Create a report to help us improve\ntitle: ''\nlabels: ''\nassignees: ''\n\n---\n\n**Describe the b"
  },
  {
    "path": "domain_generalization/Transfer-Learning-Library/.github/ISSUE_TEMPLATE/custom.md",
    "chars": 126,
    "preview": "---\nname: Custom issue template\nabout: Describe this issue template's purpose here.\ntitle: ''\nlabels: ''\nassignees: ''\n\n"
  },
  {
    "path": "domain_generalization/Transfer-Learning-Library/.github/ISSUE_TEMPLATE/feature_request.md",
    "chars": 595,
    "preview": "---\nname: Feature request\nabout: Suggest an idea for this project\ntitle: ''\nlabels: ''\nassignees: ''\n\n---\n\n**Is your fea"
  },
  {
    "path": "domain_generalization/Transfer-Learning-Library/.gitignore",
    "chars": 1859,
    "preview": "# Byte-compiled / optimized / DLL files\n__pycache__/\n*.py[cod]\n*$py.class\n\n# C extensions\n*.so\n\n# Distribution / packagi"
  },
  {
    "path": "domain_generalization/Transfer-Learning-Library/CONTRIBUTING.md",
    "chars": 518,
    "preview": "## Contributing to Transfer-Learning-Library\n\nAll kinds of contributions are welcome, including but not limited to the f"
  },
  {
    "path": "domain_generalization/Transfer-Learning-Library/LICENSE",
    "chars": 1073,
    "preview": "Copyright (c) 2018 The Python Packaging Authority\n\nPermission is hereby granted, free of charge, to any person obtaining"
  },
  {
    "path": "domain_generalization/Transfer-Learning-Library/README.md",
    "chars": 8910,
    "preview": "<img src=\"https://github.com/thuml/Transfer-Learning-Library/blob/master/TransLearn.png\"/>\n\n## Introduction\n*Transfer-Le"
  },
  {
    "path": "domain_generalization/Transfer-Learning-Library/common/__init__.py",
    "chars": 41,
    "preview": "__all__ = ['modules', 'utils', 'vision']\n"
  },
  {
    "path": "domain_generalization/Transfer-Learning-Library/common/loss/__init__.py",
    "chars": 1134,
    "preview": "import torch.nn as nn\nimport torch.nn.functional as F\n\n\nclass KnowledgeDistillationLoss(nn.Module):\n    \"\"\"Knowledge Dis"
  },
  {
    "path": "domain_generalization/Transfer-Learning-Library/common/modules/__init__.py",
    "chars": 89,
    "preview": "from .classifier import *\nfrom .regressor import *\n\n__all__ = ['classifier', 'regressor']"
  },
  {
    "path": "domain_generalization/Transfer-Learning-Library/common/modules/classifier.py",
    "chars": 3871,
    "preview": "\"\"\"\n@author: Junguang Jiang\n@contact: JiangJunguang1123@outlook.com\n\"\"\"\nfrom typing import Tuple, Optional, List, Dict\ni"
  },
  {
    "path": "domain_generalization/Transfer-Learning-Library/common/modules/regressor.py",
    "chars": 3521,
    "preview": "\"\"\"\n@author: Junguang Jiang\n@contact: JiangJunguang1123@outlook.com\n\"\"\"\nfrom typing import Tuple, Optional, List, Dict\ni"
  },
  {
    "path": "domain_generalization/Transfer-Learning-Library/common/utils/__init__.py",
    "chars": 154,
    "preview": "from .logger import CompleteLogger\nfrom .meter import *\nfrom .data import ForeverDataIterator\n\n__all__ = ['metric', 'ana"
  }
]

// ... and 570 more files (download for full content)

About this extraction

This page contains the full source code of the zhihou7/BatchFormer GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 770 files (96.6 MB), approximately 5.0M tokens, and a symbol index with 2960 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!