├── bands ├── __init__.py ├── raft │ ├── __init__.py │ ├── utils │ │ └── __init__.py │ └── LICENSE ├── common │ ├── __init__.py │ └── geom.py ├── gmflow │ ├── __init__.py │ └── position.py ├── mmdet │ ├── requirements │ │ ├── mminstall.txt │ │ ├── readthedocs.txt │ │ ├── albu.txt │ │ ├── optional.txt │ │ ├── build.txt │ │ ├── runtime.txt │ │ ├── docs.txt │ │ └── tests.txt │ ├── requirements.txt │ ├── models │ │ ├── roi_heads │ │ │ ├── shared_heads │ │ │ │ └── __init__.py │ │ │ ├── roi_extractors │ │ │ │ └── __init__.py │ │ │ ├── bbox_heads │ │ │ │ └── __init__.py │ │ │ ├── mask_heads │ │ │ │ ├── __init__.py │ │ │ │ ├── scnet_mask_head.py │ │ │ │ ├── scnet_semantic_head.py │ │ │ │ ├── htc_mask_head.py │ │ │ │ └── feature_relay_head.py │ │ │ ├── double_roi_head.py │ │ │ └── __init__.py │ │ ├── seg_heads │ │ │ ├── __init__.py │ │ │ └── panoptic_fusion_heads │ │ │ │ ├── __init__.py │ │ │ │ └── base_panoptic_fusion_head.py │ │ ├── detectors │ │ │ ├── deformable_detr.py │ │ │ ├── scnet.py │ │ │ ├── htc.py │ │ │ ├── gfl.py │ │ │ ├── atss.py │ │ │ ├── fcos.py │ │ │ ├── fsaf.py │ │ │ ├── paa.py │ │ │ ├── ddod.py │ │ │ ├── fovea.py │ │ │ ├── retinanet.py │ │ │ ├── vfnet.py │ │ │ ├── yolof.py │ │ │ ├── autoassign.py │ │ │ ├── nasfcos.py │ │ │ ├── tood.py │ │ │ ├── reppoints_detector.py │ │ │ ├── mask_rcnn.py │ │ │ ├── faster_rcnn.py │ │ │ ├── queryinst.py │ │ │ ├── mask_scoring_rcnn.py │ │ │ ├── mask2former.py │ │ │ ├── solo.py │ │ │ ├── solov2.py │ │ │ ├── point_rend.py │ │ │ ├── grid_rcnn.py │ │ │ ├── panoptic_fpn.py │ │ │ ├── yolo.py │ │ │ ├── cascade_rcnn.py │ │ │ ├── fast_rcnn.py │ │ │ └── __init__.py │ │ ├── plugins │ │ │ └── __init__.py │ │ ├── necks │ │ │ └── __init__.py │ │ ├── __init__.py │ │ ├── backbones │ │ │ └── __init__.py │ │ ├── utils │ │ │ ├── make_divisible.py │ │ │ ├── builder.py │ │ │ ├── __init__.py │ │ │ └── brick_wrappers.py │ │ ├── builder.py │ │ └── losses │ │ │ ├── __init__.py │ │ │ └── mse_loss.py │ ├── core │ │ ├── data_structures │ │ │ └── __init__.py │ │ ├── bbox │ │ │ ├── iou_calculators │ │ │ │ ├── __init__.py │ │ │ │ └── builder.py │ │ │ ├── match_costs │ │ │ │ ├── builder.py │ │ │ │ └── __init__.py │ │ │ ├── assigners │ │ │ │ ├── base_assigner.py │ │ │ │ ├── __init__.py │ │ │ │ └── ascend_assign_result.py │ │ │ ├── coder │ │ │ │ ├── base_bbox_coder.py │ │ │ │ ├── pseudo_bbox_coder.py │ │ │ │ └── __init__.py │ │ │ ├── builder.py │ │ │ ├── samplers │ │ │ │ ├── combined_sampler.py │ │ │ │ ├── __init__.py │ │ │ │ ├── pseudo_sampler.py │ │ │ │ ├── mask_pseudo_sampler.py │ │ │ │ └── mask_sampling_result.py │ │ │ ├── demodata.py │ │ │ └── __init__.py │ │ ├── evaluation │ │ │ ├── panoptic_utils.py │ │ │ └── __init__.py │ │ ├── optimizers │ │ │ ├── __init__.py │ │ │ └── builder.py │ │ ├── visualization │ │ │ ├── __init__.py │ │ │ └── palette.py │ │ ├── mask │ │ │ └── __init__.py │ │ ├── post_processing │ │ │ └── __init__.py │ │ ├── __init__.py │ │ ├── hook │ │ │ ├── set_epoch_info_hook.py │ │ │ ├── checkloss_hook.py │ │ │ ├── __init__.py │ │ │ ├── sync_norm_hook.py │ │ │ ├── memory_profiler_hook.py │ │ │ └── yolox_mode_switch_hook.py │ │ ├── export │ │ │ └── __init__.py │ │ ├── anchor │ │ │ ├── builder.py │ │ │ └── __init__.py │ │ └── utils │ │ │ └── __init__.py │ ├── datasets │ │ ├── api_wrappers │ │ │ ├── __init__.py │ │ │ └── coco_api.py │ │ ├── pipelines │ │ │ ├── formating.py │ │ │ ├── compose.py │ │ │ └── __init__.py │ │ ├── samplers │ │ │ ├── __init__.py │ │ │ └── distributed_sampler.py │ │ ├── deepfashion.py │ │ ├── __init__.py │ │ └── wider_face.py │ ├── utils │ │ ├── collect_env.py │ │ ├── __init__.py │ │ ├── util_random.py │ │ ├── profiling.py │ │ ├── rfnext.py │ │ ├── split_batch.py │ │ └── logger.py │ ├── version.py │ ├── apis │ │ └── __init__.py │ ├── setup.cfg │ └── __init__.py ├── d_anything │ └── torchhub │ │ └── facebookresearch_dinov2_main │ │ ├── requirements-dev.txt │ │ ├── setup.cfg │ │ ├── dinov2 │ │ ├── configs │ │ │ ├── train │ │ │ │ ├── vitl16_short.yaml │ │ │ │ ├── vitg14.yaml │ │ │ │ └── vitl14.yaml │ │ │ ├── eval │ │ │ │ ├── vitb14_pretrain.yaml │ │ │ │ ├── vitl14_pretrain.yaml │ │ │ │ ├── vits14_pretrain.yaml │ │ │ │ └── vitg14_pretrain.yaml │ │ │ └── __init__.py │ │ ├── eval │ │ │ ├── __init__.py │ │ │ └── setup.py │ │ ├── run │ │ │ ├── __init__.py │ │ │ ├── eval │ │ │ │ ├── knn.py │ │ │ │ ├── linear.py │ │ │ │ └── log_regression.py │ │ │ └── train │ │ │ │ └── train.py │ │ ├── utils │ │ │ ├── __init__.py │ │ │ └── dtype.py │ │ ├── __init__.py │ │ ├── data │ │ │ ├── datasets │ │ │ │ ├── __init__.py │ │ │ │ ├── decoders.py │ │ │ │ └── extended.py │ │ │ ├── __init__.py │ │ │ ├── adapters.py │ │ │ └── collate.py │ │ ├── train │ │ │ └── __init__.py │ │ ├── loss │ │ │ ├── __init__.py │ │ │ └── koleo_loss.py │ │ ├── layers │ │ │ ├── __init__.py │ │ │ ├── layer_scale.py │ │ │ ├── drop_path.py │ │ │ ├── mlp.py │ │ │ ├── swiglu_ffn.py │ │ │ └── dino_head.py │ │ └── models │ │ │ └── __init__.py │ │ ├── requirements.txt │ │ ├── scripts │ │ └── lint.sh │ │ ├── conda.yaml │ │ ├── pyproject.toml │ │ ├── CONTRIBUTING.md │ │ └── utils.py ├── patchfusion │ ├── zoedepth │ │ ├── models │ │ │ ├── zoedepth │ │ │ │ ├── config_zoedepth_kitti.json │ │ │ │ ├── __init__.py │ │ │ │ ├── config_zoedepth.json │ │ │ │ ├── config_zoedepth_fine.json │ │ │ │ └── color_channel │ │ │ │ │ └── config_zoedepth_rgb.json │ │ │ ├── base_models │ │ │ │ ├── LICENSE │ │ │ │ └── __init__.py │ │ │ ├── __init__.py │ │ │ └── zoedepth_custom │ │ │ │ └── __init__.py │ │ ├── LICENSE │ │ ├── data │ │ │ └── __init__.py │ │ ├── utils │ │ │ ├── __init__.py │ │ │ └── arg_utils.py │ │ └── trainers │ │ │ └── builder.py │ └── LICENSE └── marigold │ ├── __init__.py │ └── util │ └── seed_all.py ├── models └── README.md ├── data └── README.md ├── .gitignore ├── _base_ ├── schedules │ └── schedule_1x.py ├── default_runtime.py └── datasets │ └── coco_instance.py ├── environment.yml └── download_models.sh /bands/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /bands/raft/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /bands/common/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /bands/gmflow/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /bands/raft/utils/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /bands/mmdet/requirements/mminstall.txt: -------------------------------------------------------------------------------- 1 | mmcv-full>=1.3.17 2 | -------------------------------------------------------------------------------- /models/README.md: -------------------------------------------------------------------------------- 1 | This folder will contain the pretrained models -------------------------------------------------------------------------------- /data/README.md: -------------------------------------------------------------------------------- 1 | This folder will contain the data, like images and videos -------------------------------------------------------------------------------- /bands/mmdet/requirements/readthedocs.txt: -------------------------------------------------------------------------------- 1 | mmcv 2 | scipy 3 | torch 4 | torchvision 5 | -------------------------------------------------------------------------------- /bands/mmdet/requirements/albu.txt: -------------------------------------------------------------------------------- 1 | albumentations>=0.3.2 --no-binary qudida,albumentations 2 | -------------------------------------------------------------------------------- /bands/mmdet/requirements/optional.txt: -------------------------------------------------------------------------------- 1 | cityscapesscripts 2 | imagecorruptions 3 | scikit-learn 4 | -------------------------------------------------------------------------------- /bands/mmdet/requirements/build.txt: -------------------------------------------------------------------------------- 1 | # These must be installed before building mmdetection 2 | cython 3 | numpy 4 | -------------------------------------------------------------------------------- /bands/mmdet/requirements/runtime.txt: -------------------------------------------------------------------------------- 1 | matplotlib 2 | numpy 3 | pycocotools 4 | scipy 5 | six 6 | terminaltables 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | *.egg-info 3 | *.png 4 | *.jpg 5 | *.jpeg 6 | *.mp4 7 | 8 | __pycache__/ 9 | models/* 10 | data/* -------------------------------------------------------------------------------- /bands/d_anything/torchhub/facebookresearch_dinov2_main/requirements-dev.txt: -------------------------------------------------------------------------------- 1 | black==22.6.0 2 | flake8==5.0.4 3 | pylint==2.15.0 4 | -------------------------------------------------------------------------------- /bands/mmdet/requirements.txt: -------------------------------------------------------------------------------- 1 | -r requirements/build.txt 2 | -r requirements/optional.txt 3 | -r requirements/runtime.txt 4 | -r requirements/tests.txt 5 | -------------------------------------------------------------------------------- /bands/mmdet/models/roi_heads/shared_heads/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from .res_layer import ResLayer 3 | 4 | __all__ = ['ResLayer'] 5 | -------------------------------------------------------------------------------- /bands/d_anything/torchhub/facebookresearch_dinov2_main/setup.cfg: -------------------------------------------------------------------------------- 1 | [flake8] 2 | max-line-length = 120 3 | ignore = E203,E501,W503 4 | per-file-ignores = 5 | __init__.py:F401 6 | exclude = 7 | venv 8 | -------------------------------------------------------------------------------- /bands/mmdet/models/seg_heads/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from .panoptic_fpn_head import PanopticFPNHead # noqa: F401,F403 3 | from .panoptic_fusion_heads import * # noqa: F401,F403 4 | -------------------------------------------------------------------------------- /bands/mmdet/core/data_structures/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from .general_data import GeneralData 3 | from .instance_data import InstanceData 4 | 5 | __all__ = ['GeneralData', 'InstanceData'] 6 | -------------------------------------------------------------------------------- /bands/d_anything/torchhub/facebookresearch_dinov2_main/dinov2/configs/train/vitl16_short.yaml: -------------------------------------------------------------------------------- 1 | # this corresponds to the default config 2 | train: 3 | dataset_path: ImageNet:split=TRAIN 4 | batch_size_per_gpu: 64 5 | student: 6 | block_chunks: 4 7 | -------------------------------------------------------------------------------- /bands/d_anything/torchhub/facebookresearch_dinov2_main/dinov2/configs/eval/vitb14_pretrain.yaml: -------------------------------------------------------------------------------- 1 | student: 2 | arch: vit_base 3 | patch_size: 14 4 | crops: 5 | global_crops_size: 518 # this is to set up the position embeddings properly 6 | local_crops_size: 98 -------------------------------------------------------------------------------- /bands/d_anything/torchhub/facebookresearch_dinov2_main/dinov2/configs/eval/vitl14_pretrain.yaml: -------------------------------------------------------------------------------- 1 | student: 2 | arch: vit_large 3 | patch_size: 14 4 | crops: 5 | global_crops_size: 518 # this is to set up the position embeddings properly 6 | local_crops_size: 98 -------------------------------------------------------------------------------- /bands/d_anything/torchhub/facebookresearch_dinov2_main/dinov2/configs/eval/vits14_pretrain.yaml: -------------------------------------------------------------------------------- 1 | student: 2 | arch: vit_small 3 | patch_size: 14 4 | crops: 5 | global_crops_size: 518 # this is to set up the position embeddings properly 6 | local_crops_size: 98 -------------------------------------------------------------------------------- /bands/mmdet/requirements/docs.txt: -------------------------------------------------------------------------------- 1 | docutils==0.16.0 2 | markdown>=3.4.0 3 | myst-parser 4 | -e git+https://github.com/open-mmlab/pytorch_sphinx_theme.git#egg=pytorch_sphinx_theme 5 | sphinx==5.3.0 6 | sphinx-copybutton 7 | sphinx_markdown_tables>=0.0.17 8 | sphinx_rtd_theme 9 | -------------------------------------------------------------------------------- /bands/mmdet/core/bbox/iou_calculators/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from .builder import build_iou_calculator 3 | from .iou2d_calculator import BboxOverlaps2D, bbox_overlaps 4 | 5 | __all__ = ['build_iou_calculator', 'BboxOverlaps2D', 'bbox_overlaps'] 6 | -------------------------------------------------------------------------------- /bands/d_anything/torchhub/facebookresearch_dinov2_main/dinov2/configs/eval/vitg14_pretrain.yaml: -------------------------------------------------------------------------------- 1 | student: 2 | arch: vit_giant2 3 | patch_size: 14 4 | ffn_layer: swiglufused 5 | crops: 6 | global_crops_size: 518 # this is to set up the position embeddings properly 7 | local_crops_size: 98 -------------------------------------------------------------------------------- /bands/d_anything/torchhub/facebookresearch_dinov2_main/dinov2/eval/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | -------------------------------------------------------------------------------- /bands/d_anything/torchhub/facebookresearch_dinov2_main/dinov2/run/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | -------------------------------------------------------------------------------- /bands/d_anything/torchhub/facebookresearch_dinov2_main/dinov2/utils/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | -------------------------------------------------------------------------------- /bands/d_anything/torchhub/facebookresearch_dinov2_main/dinov2/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | __version__ = "0.0.1" 8 | -------------------------------------------------------------------------------- /bands/mmdet/datasets/api_wrappers/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from .coco_api import COCO, COCOeval 3 | from .panoptic_evaluation import pq_compute_multi_core, pq_compute_single_core 4 | 5 | __all__ = [ 6 | 'COCO', 'COCOeval', 'pq_compute_multi_core', 'pq_compute_single_core' 7 | ] 8 | -------------------------------------------------------------------------------- /bands/d_anything/torchhub/facebookresearch_dinov2_main/requirements.txt: -------------------------------------------------------------------------------- 1 | --extra-index-url https://download.pytorch.org/whl/cu117 2 | torch==2.0.0 3 | torchvision==0.15.0 4 | omegaconf 5 | torchmetrics==0.10.3 6 | fvcore 7 | iopath 8 | xformers==0.0.18 9 | submitit 10 | --extra-index-url https://pypi.nvidia.com 11 | cuml-cu11 12 | -------------------------------------------------------------------------------- /bands/mmdet/core/evaluation/panoptic_utils.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | # A custom value to distinguish instance ID and category ID; need to 3 | # be greater than the number of categories. 4 | # For a pixel in the panoptic result map: 5 | # pan_id = ins_id * INSTANCE_OFFSET + cat_id 6 | INSTANCE_OFFSET = 1000 7 | -------------------------------------------------------------------------------- /bands/mmdet/models/detectors/deformable_detr.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from ..builder import DETECTORS 3 | from .detr import DETR 4 | 5 | 6 | @DETECTORS.register_module() 7 | class DeformableDETR(DETR): 8 | 9 | def __init__(self, *args, **kwargs): 10 | super(DETR, self).__init__(*args, **kwargs) 11 | -------------------------------------------------------------------------------- /bands/mmdet/core/bbox/match_costs/builder.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from mmcv.utils import Registry, build_from_cfg 3 | 4 | MATCH_COST = Registry('Match Cost') 5 | 6 | 7 | def build_match_cost(cfg, default_args=None): 8 | """Builder of IoU calculator.""" 9 | return build_from_cfg(cfg, MATCH_COST, default_args) 10 | -------------------------------------------------------------------------------- /bands/mmdet/models/roi_heads/roi_extractors/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from .base_roi_extractor import BaseRoIExtractor 3 | from .generic_roi_extractor import GenericRoIExtractor 4 | from .single_level_roi_extractor import SingleRoIExtractor 5 | 6 | __all__ = ['BaseRoIExtractor', 'SingleRoIExtractor', 'GenericRoIExtractor'] 7 | -------------------------------------------------------------------------------- /bands/mmdet/models/seg_heads/panoptic_fusion_heads/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from .base_panoptic_fusion_head import \ 3 | BasePanopticFusionHead # noqa: F401,F403 4 | from .heuristic_fusion_head import HeuristicFusionHead # noqa: F401,F403 5 | from .maskformer_fusion_head import MaskFormerFusionHead # noqa: F401,F403 6 | -------------------------------------------------------------------------------- /bands/mmdet/datasets/pipelines/formating.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | # flake8: noqa 3 | import warnings 4 | 5 | from .formatting import * 6 | 7 | warnings.warn('DeprecationWarning: mmdet.datasets.pipelines.formating will be ' 8 | 'deprecated, please replace it with ' 9 | 'mmdet.datasets.pipelines.formatting.') 10 | -------------------------------------------------------------------------------- /bands/mmdet/core/bbox/iou_calculators/builder.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from mmcv.utils import Registry, build_from_cfg 3 | 4 | IOU_CALCULATORS = Registry('IoU calculator') 5 | 6 | 7 | def build_iou_calculator(cfg, default_args=None): 8 | """Builder of IoU calculator.""" 9 | return build_from_cfg(cfg, IOU_CALCULATORS, default_args) 10 | -------------------------------------------------------------------------------- /bands/mmdet/core/optimizers/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from .builder import OPTIMIZER_BUILDERS, build_optimizer 3 | from .layer_decay_optimizer_constructor import \ 4 | LearningRateDecayOptimizerConstructor 5 | 6 | __all__ = [ 7 | 'LearningRateDecayOptimizerConstructor', 'OPTIMIZER_BUILDERS', 8 | 'build_optimizer' 9 | ] 10 | -------------------------------------------------------------------------------- /bands/d_anything/torchhub/facebookresearch_dinov2_main/dinov2/data/datasets/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | from .image_net import ImageNet 8 | from .image_net_22k import ImageNet22k 9 | -------------------------------------------------------------------------------- /bands/d_anything/torchhub/facebookresearch_dinov2_main/dinov2/train/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | from .train import get_args_parser, main 8 | from .ssl_meta_arch import SSLMetaArch 9 | -------------------------------------------------------------------------------- /bands/mmdet/requirements/tests.txt: -------------------------------------------------------------------------------- 1 | asynctest 2 | codecov 3 | flake8 4 | interrogate 5 | isort==4.3.21 6 | # Note: used for kwarray.group_items, this may be ported to mmcv in the future. 7 | kwarray 8 | -e git+https://github.com/open-mmlab/mmtracking#egg=mmtrack 9 | onnx==1.13.0 10 | onnxruntime>=1.8.0 11 | protobuf<=3.20.1 12 | pytest 13 | ubelt 14 | xdoctest>=0.10.0 15 | yapf 16 | -------------------------------------------------------------------------------- /_base_/schedules/schedule_1x.py: -------------------------------------------------------------------------------- 1 | # optimizer 2 | optimizer = dict(type='SGD', lr=0.02, momentum=0.9, weight_decay=0.0001) 3 | optimizer_config = dict(grad_clip=None) 4 | # learning policy 5 | lr_config = dict( 6 | policy='step', 7 | warmup='linear', 8 | warmup_iters=500, 9 | warmup_ratio=0.001, 10 | step=[8, 11]) 11 | runner = dict(type='EpochBasedRunner', max_epochs=12) 12 | -------------------------------------------------------------------------------- /bands/mmdet/core/visualization/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from .image import (color_val_matplotlib, imshow_det_bboxes, 3 | imshow_gt_det_bboxes) 4 | from .palette import get_palette, palette_val 5 | 6 | __all__ = [ 7 | 'imshow_det_bboxes', 'imshow_gt_det_bboxes', 'color_val_matplotlib', 8 | 'palette_val', 'get_palette' 9 | ] 10 | -------------------------------------------------------------------------------- /bands/mmdet/models/plugins/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from .dropblock import DropBlock 3 | from .msdeformattn_pixel_decoder import MSDeformAttnPixelDecoder 4 | from .pixel_decoder import PixelDecoder, TransformerEncoderPixelDecoder 5 | 6 | __all__ = [ 7 | 'DropBlock', 'PixelDecoder', 'TransformerEncoderPixelDecoder', 8 | 'MSDeformAttnPixelDecoder' 9 | ] 10 | -------------------------------------------------------------------------------- /bands/mmdet/models/detectors/scnet.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from ..builder import DETECTORS 3 | from .cascade_rcnn import CascadeRCNN 4 | 5 | 6 | @DETECTORS.register_module() 7 | class SCNet(CascadeRCNN): 8 | """Implementation of `SCNet `_""" 9 | 10 | def __init__(self, **kwargs): 11 | super(SCNet, self).__init__(**kwargs) 12 | -------------------------------------------------------------------------------- /bands/d_anything/torchhub/facebookresearch_dinov2_main/dinov2/loss/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | from .dino_clstoken_loss import DINOLoss 8 | from .ibot_patch_loss import iBOTPatchLoss 9 | from .koleo_loss import KoLeoLoss 10 | -------------------------------------------------------------------------------- /bands/mmdet/core/bbox/match_costs/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from .builder import build_match_cost 3 | from .match_cost import (BBoxL1Cost, ClassificationCost, CrossEntropyLossCost, 4 | DiceCost, FocalLossCost, IoUCost) 5 | 6 | __all__ = [ 7 | 'build_match_cost', 'ClassificationCost', 'BBoxL1Cost', 'IoUCost', 8 | 'FocalLossCost', 'DiceCost', 'CrossEntropyLossCost' 9 | ] 10 | -------------------------------------------------------------------------------- /bands/mmdet/core/mask/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from .mask_target import mask_target 3 | from .structures import BaseInstanceMasks, BitmapMasks, PolygonMasks 4 | from .utils import encode_mask_results, mask2bbox, split_combined_polys 5 | 6 | __all__ = [ 7 | 'split_combined_polys', 'mask_target', 'BaseInstanceMasks', 'BitmapMasks', 8 | 'PolygonMasks', 'encode_mask_results', 'mask2bbox' 9 | ] 10 | -------------------------------------------------------------------------------- /bands/mmdet/core/bbox/assigners/base_assigner.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from abc import ABCMeta, abstractmethod 3 | 4 | 5 | class BaseAssigner(metaclass=ABCMeta): 6 | """Base assigner that assigns boxes to ground truth boxes.""" 7 | 8 | @abstractmethod 9 | def assign(self, bboxes, gt_bboxes, gt_bboxes_ignore=None, gt_labels=None): 10 | """Assign boxes to either a ground truth boxes or a negative boxes.""" 11 | -------------------------------------------------------------------------------- /bands/mmdet/core/post_processing/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from .bbox_nms import fast_nms, multiclass_nms 3 | from .matrix_nms import mask_matrix_nms 4 | from .merge_augs import (merge_aug_bboxes, merge_aug_masks, 5 | merge_aug_proposals, merge_aug_scores) 6 | 7 | __all__ = [ 8 | 'multiclass_nms', 'merge_aug_proposals', 'merge_aug_bboxes', 9 | 'merge_aug_scores', 'merge_aug_masks', 'mask_matrix_nms', 'fast_nms' 10 | ] 11 | -------------------------------------------------------------------------------- /bands/d_anything/torchhub/facebookresearch_dinov2_main/scripts/lint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ -n "$1" ]; then 4 | echo "linting \"$1\"" 5 | fi 6 | 7 | echo "running black" 8 | if [ -n "$1" ]; then 9 | black "$1" 10 | else 11 | black dinov2 12 | fi 13 | 14 | echo "running flake8" 15 | if [ -n "$1" ]; then 16 | flake8 "$1" 17 | else 18 | flake8 19 | fi 20 | 21 | echo "running pylint" 22 | if [ -n "$1" ]; then 23 | pylint "$1" 24 | else 25 | pylint dinov2 26 | fi 27 | 28 | exit 0 29 | -------------------------------------------------------------------------------- /bands/mmdet/core/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from .anchor import * # noqa: F401, F403 3 | from .bbox import * # noqa: F401, F403 4 | from .data_structures import * # noqa: F401, F403 5 | from .evaluation import * # noqa: F401, F403 6 | from .hook import * # noqa: F401, F403 7 | from .mask import * # noqa: F401, F403 8 | from .optimizers import * # noqa: F401, F403 9 | from .post_processing import * # noqa: F401, F403 10 | from .utils import * # noqa: F401, F403 11 | -------------------------------------------------------------------------------- /bands/mmdet/datasets/samplers/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from .class_aware_sampler import ClassAwareSampler 3 | from .distributed_sampler import DistributedSampler 4 | from .group_sampler import DistributedGroupSampler, GroupSampler 5 | from .infinite_sampler import InfiniteBatchSampler, InfiniteGroupBatchSampler 6 | 7 | __all__ = [ 8 | 'DistributedSampler', 'DistributedGroupSampler', 'GroupSampler', 9 | 'InfiniteGroupBatchSampler', 'InfiniteBatchSampler', 'ClassAwareSampler' 10 | ] 11 | -------------------------------------------------------------------------------- /bands/d_anything/torchhub/facebookresearch_dinov2_main/dinov2/layers/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | from .dino_head import DINOHead 8 | from .mlp import Mlp 9 | from .patch_embed import PatchEmbed 10 | from .swiglu_ffn import SwiGLUFFN, SwiGLUFFNFused 11 | from .block import NestedTensorBlock 12 | from .attention import MemEffAttention 13 | -------------------------------------------------------------------------------- /bands/mmdet/core/hook/set_epoch_info_hook.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from mmcv.parallel import is_module_wrapper 3 | from mmcv.runner import HOOKS, Hook 4 | 5 | 6 | @HOOKS.register_module() 7 | class SetEpochInfoHook(Hook): 8 | """Set runner's epoch information to the model.""" 9 | 10 | def before_train_epoch(self, runner): 11 | epoch = runner.epoch 12 | model = runner.model 13 | if is_module_wrapper(model): 14 | model = model.module 15 | model.set_epoch(epoch) 16 | -------------------------------------------------------------------------------- /bands/d_anything/torchhub/facebookresearch_dinov2_main/dinov2/data/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | from .adapters import DatasetWithEnumeratedTargets 8 | from .loaders import make_data_loader, make_dataset, SamplerType 9 | from .collate import collate_data_and_cast 10 | from .masking import MaskingGenerator 11 | from .augmentations import DataAugmentationDINO 12 | -------------------------------------------------------------------------------- /bands/mmdet/utils/collect_env.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from mmcv.utils import collect_env as collect_base_env 3 | from mmcv.utils import get_git_hash 4 | 5 | import mmdet 6 | 7 | 8 | def collect_env(): 9 | """Collect the information of the running environments.""" 10 | env_info = collect_base_env() 11 | env_info['MMDetection'] = mmdet.__version__ + '+' + get_git_hash()[:7] 12 | return env_info 13 | 14 | 15 | if __name__ == '__main__': 16 | for name, val in collect_env().items(): 17 | print(f'{name}: {val}') 18 | -------------------------------------------------------------------------------- /bands/mmdet/core/export/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from .onnx_helper import (add_dummy_nms_for_onnx, dynamic_clip_for_onnx, 3 | get_k_for_topk) 4 | from .pytorch2onnx import (build_model_from_cfg, 5 | generate_inputs_and_wrap_model, 6 | preprocess_example_input) 7 | 8 | __all__ = [ 9 | 'build_model_from_cfg', 'generate_inputs_and_wrap_model', 10 | 'preprocess_example_input', 'get_k_for_topk', 'add_dummy_nms_for_onnx', 11 | 'dynamic_clip_for_onnx' 12 | ] 13 | -------------------------------------------------------------------------------- /bands/d_anything/torchhub/facebookresearch_dinov2_main/conda.yaml: -------------------------------------------------------------------------------- 1 | name: dinov2 2 | channels: 3 | - defaults 4 | - pytorch 5 | - nvidia 6 | - xformers 7 | - conda-forge 8 | dependencies: 9 | - python=3.9 10 | - pytorch::pytorch=2.0.0 11 | - pytorch::pytorch-cuda=11.7.0 12 | - pytorch::torchvision=0.15.0 13 | - omegaconf 14 | - torchmetrics=0.10.3 15 | - fvcore 16 | - iopath 17 | - xformers::xformers=0.0.18 18 | - pip 19 | - pip: 20 | - git+https://github.com/facebookincubator/submitit 21 | - --extra-index-url https://pypi.nvidia.com 22 | - cuml-cu11 23 | -------------------------------------------------------------------------------- /bands/mmdet/models/detectors/htc.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from ..builder import DETECTORS 3 | from .cascade_rcnn import CascadeRCNN 4 | 5 | 6 | @DETECTORS.register_module() 7 | class HybridTaskCascade(CascadeRCNN): 8 | """Implementation of `HTC `_""" 9 | 10 | def __init__(self, **kwargs): 11 | super(HybridTaskCascade, self).__init__(**kwargs) 12 | 13 | @property 14 | def with_semantic(self): 15 | """bool: whether the detector has a semantic head""" 16 | return self.roi_head.with_semantic 17 | -------------------------------------------------------------------------------- /bands/d_anything/torchhub/facebookresearch_dinov2_main/pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.black] 2 | line-length = 120 3 | 4 | [tool.pylint.master] 5 | persistent = false 6 | score = false 7 | 8 | [tool.pylint.messages_control] 9 | disable = "all" 10 | enable = [ 11 | "miscellaneous", 12 | "similarities", 13 | ] 14 | 15 | [tool.pylint.similarities] 16 | ignore-comments = true 17 | ignore-docstrings = true 18 | ignore-imports = true 19 | min-similarity-lines = 8 20 | 21 | [tool.pylint.reports] 22 | reports = false 23 | 24 | [tool.pylint.miscellaneous] 25 | notes = [ 26 | "FIXME", 27 | "XXX", 28 | "TODO", 29 | ] 30 | -------------------------------------------------------------------------------- /bands/mmdet/core/bbox/coder/base_bbox_coder.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from abc import ABCMeta, abstractmethod 3 | 4 | 5 | class BaseBBoxCoder(metaclass=ABCMeta): 6 | """Base bounding box coder.""" 7 | 8 | def __init__(self, **kwargs): 9 | pass 10 | 11 | @abstractmethod 12 | def encode(self, bboxes, gt_bboxes): 13 | """Encode deltas between bboxes and ground truth boxes.""" 14 | 15 | @abstractmethod 16 | def decode(self, bboxes, bboxes_pred): 17 | """Decode the predicted bboxes according to prediction and base 18 | boxes.""" 19 | -------------------------------------------------------------------------------- /bands/mmdet/models/roi_heads/bbox_heads/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from .bbox_head import BBoxHead 3 | from .convfc_bbox_head import (ConvFCBBoxHead, Shared2FCBBoxHead, 4 | Shared4Conv1FCBBoxHead) 5 | from .dii_head import DIIHead 6 | from .double_bbox_head import DoubleConvFCBBoxHead 7 | from .sabl_head import SABLHead 8 | from .scnet_bbox_head import SCNetBBoxHead 9 | 10 | __all__ = [ 11 | 'BBoxHead', 'ConvFCBBoxHead', 'Shared2FCBBoxHead', 12 | 'Shared4Conv1FCBBoxHead', 'DoubleConvFCBBoxHead', 'SABLHead', 'DIIHead', 13 | 'SCNetBBoxHead' 14 | ] 15 | -------------------------------------------------------------------------------- /bands/mmdet/version.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | 3 | __version__ = '2.28.2' 4 | short_version = __version__ 5 | 6 | 7 | def parse_version_info(version_str): 8 | version_info = [] 9 | for x in version_str.split('.'): 10 | if x.isdigit(): 11 | version_info.append(int(x)) 12 | elif x.find('rc') != -1: 13 | patch_version = x.split('rc') 14 | version_info.append(int(patch_version[0])) 15 | version_info.append(f'rc{patch_version[1]}') 16 | return tuple(version_info) 17 | 18 | 19 | version_info = parse_version_info(__version__) 20 | -------------------------------------------------------------------------------- /bands/mmdet/apis/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from .inference import (async_inference_detector, inference_detector, 3 | init_detector, show_result_pyplot) 4 | from .test import multi_gpu_test, single_gpu_test 5 | from .train import (get_root_logger, init_random_seed, set_random_seed, 6 | train_detector) 7 | 8 | __all__ = [ 9 | 'get_root_logger', 'set_random_seed', 'train_detector', 'init_detector', 10 | 'async_inference_detector', 'inference_detector', 'show_result_pyplot', 11 | 'multi_gpu_test', 'single_gpu_test', 'init_random_seed' 12 | ] 13 | -------------------------------------------------------------------------------- /bands/mmdet/models/detectors/gfl.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from ..builder import DETECTORS 3 | from .single_stage import SingleStageDetector 4 | 5 | 6 | @DETECTORS.register_module() 7 | class GFL(SingleStageDetector): 8 | 9 | def __init__(self, 10 | backbone, 11 | neck, 12 | bbox_head, 13 | train_cfg=None, 14 | test_cfg=None, 15 | pretrained=None, 16 | init_cfg=None): 17 | super(GFL, self).__init__(backbone, neck, bbox_head, train_cfg, 18 | test_cfg, pretrained, init_cfg) 19 | -------------------------------------------------------------------------------- /bands/mmdet/core/anchor/builder.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | import warnings 3 | 4 | from mmcv.utils import Registry, build_from_cfg 5 | 6 | PRIOR_GENERATORS = Registry('Generator for anchors and points') 7 | 8 | ANCHOR_GENERATORS = PRIOR_GENERATORS 9 | 10 | 11 | def build_prior_generator(cfg, default_args=None): 12 | return build_from_cfg(cfg, PRIOR_GENERATORS, default_args) 13 | 14 | 15 | def build_anchor_generator(cfg, default_args=None): 16 | warnings.warn( 17 | '``build_anchor_generator`` would be deprecated soon, please use ' 18 | '``build_prior_generator`` ') 19 | return build_prior_generator(cfg, default_args=default_args) 20 | -------------------------------------------------------------------------------- /bands/mmdet/core/bbox/coder/pseudo_bbox_coder.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from ..builder import BBOX_CODERS 3 | from .base_bbox_coder import BaseBBoxCoder 4 | 5 | 6 | @BBOX_CODERS.register_module() 7 | class PseudoBBoxCoder(BaseBBoxCoder): 8 | """Pseudo bounding box coder.""" 9 | 10 | def __init__(self, **kwargs): 11 | super(BaseBBoxCoder, self).__init__(**kwargs) 12 | 13 | def encode(self, bboxes, gt_bboxes): 14 | """torch.Tensor: return the given ``bboxes``""" 15 | return gt_bboxes 16 | 17 | def decode(self, bboxes, pred_bboxes): 18 | """torch.Tensor: return the given ``pred_bboxes``""" 19 | return pred_bboxes 20 | -------------------------------------------------------------------------------- /bands/patchfusion/zoedepth/models/zoedepth/config_zoedepth_kitti.json: -------------------------------------------------------------------------------- 1 | { 2 | "model": { 3 | "bin_centers_type": "normed", 4 | "img_size": [384, 768] 5 | }, 6 | 7 | "train": { 8 | }, 9 | 10 | "infer":{ 11 | "train_midas": false, 12 | "use_pretrained_midas": false, 13 | "pretrained_resource" : "url::https://github.com/isl-org/ZoeDepth/releases/download/v1.0/ZoeD_M12_K.pt", 14 | "force_keep_ar": true 15 | }, 16 | 17 | "eval":{ 18 | "train_midas": false, 19 | "use_pretrained_midas": false, 20 | "pretrained_resource" : "url::https://github.com/isl-org/ZoeDepth/releases/download/v1.0/ZoeD_M12_K.pt" 21 | } 22 | } -------------------------------------------------------------------------------- /bands/mmdet/core/utils/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from .dist_utils import (DistOptimizerHook, all_reduce_dict, allreduce_grads, 3 | reduce_mean, sync_random_seed) 4 | from .misc import (center_of_mass, filter_scores_and_topk, flip_tensor, 5 | generate_coordinate, mask2ndarray, multi_apply, 6 | select_single_mlvl, unmap) 7 | 8 | __all__ = [ 9 | 'allreduce_grads', 'DistOptimizerHook', 'reduce_mean', 'multi_apply', 10 | 'unmap', 'mask2ndarray', 'flip_tensor', 'all_reduce_dict', 11 | 'center_of_mass', 'generate_coordinate', 'select_single_mlvl', 12 | 'filter_scores_and_topk', 'sync_random_seed' 13 | ] 14 | -------------------------------------------------------------------------------- /bands/d_anything/torchhub/facebookresearch_dinov2_main/dinov2/configs/train/vitg14.yaml: -------------------------------------------------------------------------------- 1 | dino: 2 | head_n_prototypes: 131072 3 | head_bottleneck_dim: 384 4 | ibot: 5 | separate_head: true 6 | head_n_prototypes: 131072 7 | train: 8 | batch_size_per_gpu: 12 9 | dataset_path: ImageNet22k 10 | centering: sinkhorn_knopp 11 | student: 12 | arch: vit_giant2 13 | patch_size: 14 14 | drop_path_rate: 0.4 15 | ffn_layer: swiglufused 16 | block_chunks: 4 17 | teacher: 18 | momentum_teacher: 0.994 19 | optim: 20 | epochs: 500 21 | weight_decay_end: 0.2 22 | base_lr: 2.0e-04 # learning rate for a batch size of 1024 23 | warmup_epochs: 80 24 | layerwise_decay: 1.0 25 | crops: 26 | local_crops_size: 98 -------------------------------------------------------------------------------- /bands/d_anything/torchhub/facebookresearch_dinov2_main/dinov2/configs/train/vitl14.yaml: -------------------------------------------------------------------------------- 1 | dino: 2 | head_n_prototypes: 131072 3 | head_bottleneck_dim: 384 4 | ibot: 5 | separate_head: true 6 | head_n_prototypes: 131072 7 | train: 8 | batch_size_per_gpu: 32 9 | dataset_path: ImageNet22k 10 | centering: sinkhorn_knopp 11 | student: 12 | arch: vit_large 13 | patch_size: 14 14 | drop_path_rate: 0.4 15 | ffn_layer: swiglufused 16 | block_chunks: 4 17 | teacher: 18 | momentum_teacher: 0.994 19 | optim: 20 | epochs: 500 21 | weight_decay_end: 0.2 22 | base_lr: 2.0e-04 # learning rate for a batch size of 1024 23 | warmup_epochs: 80 24 | layerwise_decay: 1.0 25 | crops: 26 | local_crops_size: 98 -------------------------------------------------------------------------------- /bands/mmdet/datasets/deepfashion.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from .builder import DATASETS 3 | from .coco import CocoDataset 4 | 5 | 6 | @DATASETS.register_module() 7 | class DeepFashionDataset(CocoDataset): 8 | 9 | CLASSES = ('top', 'skirt', 'leggings', 'dress', 'outer', 'pants', 'bag', 10 | 'neckwear', 'headwear', 'eyeglass', 'belt', 'footwear', 'hair', 11 | 'skin', 'face') 12 | 13 | PALETTE = [(0, 192, 64), (0, 64, 96), (128, 192, 192), (0, 64, 64), 14 | (0, 192, 224), (0, 192, 192), (128, 192, 64), (0, 192, 96), 15 | (128, 32, 192), (0, 0, 224), (0, 0, 64), (0, 160, 192), 16 | (128, 0, 96), (128, 0, 192), (0, 32, 192)] 17 | -------------------------------------------------------------------------------- /bands/mmdet/core/bbox/builder.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from mmcv.utils import Registry, build_from_cfg 3 | 4 | BBOX_ASSIGNERS = Registry('bbox_assigner') 5 | BBOX_SAMPLERS = Registry('bbox_sampler') 6 | BBOX_CODERS = Registry('bbox_coder') 7 | 8 | 9 | def build_assigner(cfg, **default_args): 10 | """Builder of box assigner.""" 11 | return build_from_cfg(cfg, BBOX_ASSIGNERS, default_args) 12 | 13 | 14 | def build_sampler(cfg, **default_args): 15 | """Builder of box sampler.""" 16 | return build_from_cfg(cfg, BBOX_SAMPLERS, default_args) 17 | 18 | 19 | def build_bbox_coder(cfg, **default_args): 20 | """Builder of box coder.""" 21 | return build_from_cfg(cfg, BBOX_CODERS, default_args) 22 | -------------------------------------------------------------------------------- /bands/mmdet/models/detectors/atss.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from ..builder import DETECTORS 3 | from .single_stage import SingleStageDetector 4 | 5 | 6 | @DETECTORS.register_module() 7 | class ATSS(SingleStageDetector): 8 | """Implementation of `ATSS `_.""" 9 | 10 | def __init__(self, 11 | backbone, 12 | neck, 13 | bbox_head, 14 | train_cfg=None, 15 | test_cfg=None, 16 | pretrained=None, 17 | init_cfg=None): 18 | super(ATSS, self).__init__(backbone, neck, bbox_head, train_cfg, 19 | test_cfg, pretrained, init_cfg) 20 | -------------------------------------------------------------------------------- /bands/mmdet/models/detectors/fcos.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from ..builder import DETECTORS 3 | from .single_stage import SingleStageDetector 4 | 5 | 6 | @DETECTORS.register_module() 7 | class FCOS(SingleStageDetector): 8 | """Implementation of `FCOS `_""" 9 | 10 | def __init__(self, 11 | backbone, 12 | neck, 13 | bbox_head, 14 | train_cfg=None, 15 | test_cfg=None, 16 | pretrained=None, 17 | init_cfg=None): 18 | super(FCOS, self).__init__(backbone, neck, bbox_head, train_cfg, 19 | test_cfg, pretrained, init_cfg) 20 | -------------------------------------------------------------------------------- /bands/mmdet/models/detectors/fsaf.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from ..builder import DETECTORS 3 | from .single_stage import SingleStageDetector 4 | 5 | 6 | @DETECTORS.register_module() 7 | class FSAF(SingleStageDetector): 8 | """Implementation of `FSAF `_""" 9 | 10 | def __init__(self, 11 | backbone, 12 | neck, 13 | bbox_head, 14 | train_cfg=None, 15 | test_cfg=None, 16 | pretrained=None, 17 | init_cfg=None): 18 | super(FSAF, self).__init__(backbone, neck, bbox_head, train_cfg, 19 | test_cfg, pretrained, init_cfg) 20 | -------------------------------------------------------------------------------- /bands/mmdet/models/detectors/paa.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from ..builder import DETECTORS 3 | from .single_stage import SingleStageDetector 4 | 5 | 6 | @DETECTORS.register_module() 7 | class PAA(SingleStageDetector): 8 | """Implementation of `PAA `_.""" 9 | 10 | def __init__(self, 11 | backbone, 12 | neck, 13 | bbox_head, 14 | train_cfg=None, 15 | test_cfg=None, 16 | pretrained=None, 17 | init_cfg=None): 18 | super(PAA, self).__init__(backbone, neck, bbox_head, train_cfg, 19 | test_cfg, pretrained, init_cfg) 20 | -------------------------------------------------------------------------------- /bands/mmdet/core/bbox/coder/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from .base_bbox_coder import BaseBBoxCoder 3 | from .bucketing_bbox_coder import BucketingBBoxCoder 4 | from .delta_xywh_bbox_coder import DeltaXYWHBBoxCoder 5 | from .distance_point_bbox_coder import DistancePointBBoxCoder 6 | from .legacy_delta_xywh_bbox_coder import LegacyDeltaXYWHBBoxCoder 7 | from .pseudo_bbox_coder import PseudoBBoxCoder 8 | from .tblr_bbox_coder import TBLRBBoxCoder 9 | from .yolo_bbox_coder import YOLOBBoxCoder 10 | 11 | __all__ = [ 12 | 'BaseBBoxCoder', 'PseudoBBoxCoder', 'DeltaXYWHBBoxCoder', 13 | 'LegacyDeltaXYWHBBoxCoder', 'TBLRBBoxCoder', 'YOLOBBoxCoder', 14 | 'BucketingBBoxCoder', 'DistancePointBBoxCoder' 15 | ] 16 | -------------------------------------------------------------------------------- /bands/mmdet/models/detectors/ddod.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from ..builder import DETECTORS 3 | from .single_stage import SingleStageDetector 4 | 5 | 6 | @DETECTORS.register_module() 7 | class DDOD(SingleStageDetector): 8 | """Implementation of `DDOD `_.""" 9 | 10 | def __init__(self, 11 | backbone, 12 | neck, 13 | bbox_head, 14 | train_cfg=None, 15 | test_cfg=None, 16 | pretrained=None, 17 | init_cfg=None): 18 | super(DDOD, self).__init__(backbone, neck, bbox_head, train_cfg, 19 | test_cfg, pretrained, init_cfg) 20 | -------------------------------------------------------------------------------- /bands/mmdet/models/detectors/fovea.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from ..builder import DETECTORS 3 | from .single_stage import SingleStageDetector 4 | 5 | 6 | @DETECTORS.register_module() 7 | class FOVEA(SingleStageDetector): 8 | """Implementation of `FoveaBox `_""" 9 | 10 | def __init__(self, 11 | backbone, 12 | neck, 13 | bbox_head, 14 | train_cfg=None, 15 | test_cfg=None, 16 | pretrained=None, 17 | init_cfg=None): 18 | super(FOVEA, self).__init__(backbone, neck, bbox_head, train_cfg, 19 | test_cfg, pretrained, init_cfg) 20 | -------------------------------------------------------------------------------- /bands/mmdet/models/detectors/retinanet.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from ..builder import DETECTORS 3 | from .single_stage import SingleStageDetector 4 | 5 | 6 | @DETECTORS.register_module() 7 | class RetinaNet(SingleStageDetector): 8 | """Implementation of `RetinaNet `_""" 9 | 10 | def __init__(self, 11 | backbone, 12 | neck, 13 | bbox_head, 14 | train_cfg=None, 15 | test_cfg=None, 16 | pretrained=None, 17 | init_cfg=None): 18 | super(RetinaNet, self).__init__(backbone, neck, bbox_head, train_cfg, 19 | test_cfg, pretrained, init_cfg) 20 | -------------------------------------------------------------------------------- /bands/mmdet/models/detectors/vfnet.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from ..builder import DETECTORS 3 | from .single_stage import SingleStageDetector 4 | 5 | 6 | @DETECTORS.register_module() 7 | class VFNet(SingleStageDetector): 8 | """Implementation of `VarifocalNet 9 | (VFNet).`_""" 10 | 11 | def __init__(self, 12 | backbone, 13 | neck, 14 | bbox_head, 15 | train_cfg=None, 16 | test_cfg=None, 17 | pretrained=None, 18 | init_cfg=None): 19 | super(VFNet, self).__init__(backbone, neck, bbox_head, train_cfg, 20 | test_cfg, pretrained, init_cfg) 21 | -------------------------------------------------------------------------------- /bands/mmdet/models/detectors/yolof.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from ..builder import DETECTORS 3 | from .single_stage import SingleStageDetector 4 | 5 | 6 | @DETECTORS.register_module() 7 | class YOLOF(SingleStageDetector): 8 | r"""Implementation of `You Only Look One-level Feature 9 | `_""" 10 | 11 | def __init__(self, 12 | backbone, 13 | neck, 14 | bbox_head, 15 | train_cfg=None, 16 | test_cfg=None, 17 | pretrained=None, 18 | init_cfg=None): 19 | super(YOLOF, self).__init__(backbone, neck, bbox_head, train_cfg, 20 | test_cfg, pretrained, init_cfg) 21 | -------------------------------------------------------------------------------- /bands/mmdet/models/detectors/autoassign.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from ..builder import DETECTORS 3 | from .single_stage import SingleStageDetector 4 | 5 | 6 | @DETECTORS.register_module() 7 | class AutoAssign(SingleStageDetector): 8 | """Implementation of `AutoAssign: Differentiable Label Assignment for Dense 9 | Object Detection `_.""" 10 | 11 | def __init__(self, 12 | backbone, 13 | neck, 14 | bbox_head, 15 | train_cfg=None, 16 | test_cfg=None, 17 | pretrained=None): 18 | super(AutoAssign, self).__init__(backbone, neck, bbox_head, train_cfg, 19 | test_cfg, pretrained) 20 | -------------------------------------------------------------------------------- /bands/mmdet/core/anchor/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from .anchor_generator import (AnchorGenerator, LegacyAnchorGenerator, 3 | YOLOAnchorGenerator) 4 | from .builder import (ANCHOR_GENERATORS, PRIOR_GENERATORS, 5 | build_anchor_generator, build_prior_generator) 6 | from .point_generator import MlvlPointGenerator, PointGenerator 7 | from .utils import anchor_inside_flags, calc_region, images_to_levels 8 | 9 | __all__ = [ 10 | 'AnchorGenerator', 'LegacyAnchorGenerator', 'anchor_inside_flags', 11 | 'PointGenerator', 'images_to_levels', 'calc_region', 12 | 'build_anchor_generator', 'ANCHOR_GENERATORS', 'YOLOAnchorGenerator', 13 | 'build_prior_generator', 'PRIOR_GENERATORS', 'MlvlPointGenerator' 14 | ] 15 | -------------------------------------------------------------------------------- /bands/mmdet/core/hook/checkloss_hook.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | import torch 3 | from mmcv.runner.hooks import HOOKS, Hook 4 | 5 | 6 | @HOOKS.register_module() 7 | class CheckInvalidLossHook(Hook): 8 | """Check invalid loss hook. 9 | 10 | This hook will regularly check whether the loss is valid 11 | during training. 12 | 13 | Args: 14 | interval (int): Checking interval (every k iterations). 15 | Default: 50. 16 | """ 17 | 18 | def __init__(self, interval=50): 19 | self.interval = interval 20 | 21 | def after_train_iter(self, runner): 22 | if self.every_n_iters(runner, self.interval): 23 | assert torch.isfinite(runner.outputs['loss']), \ 24 | runner.logger.info('loss become infinite or NaN!') 25 | -------------------------------------------------------------------------------- /bands/mmdet/models/detectors/nasfcos.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from ..builder import DETECTORS 3 | from .single_stage import SingleStageDetector 4 | 5 | 6 | @DETECTORS.register_module() 7 | class NASFCOS(SingleStageDetector): 8 | """NAS-FCOS: Fast Neural Architecture Search for Object Detection. 9 | 10 | https://arxiv.org/abs/1906.0442 11 | """ 12 | 13 | def __init__(self, 14 | backbone, 15 | neck, 16 | bbox_head, 17 | train_cfg=None, 18 | test_cfg=None, 19 | pretrained=None, 20 | init_cfg=None): 21 | super(NASFCOS, self).__init__(backbone, neck, bbox_head, train_cfg, 22 | test_cfg, pretrained, init_cfg) 23 | -------------------------------------------------------------------------------- /bands/mmdet/core/hook/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from .checkloss_hook import CheckInvalidLossHook 3 | from .ema import ExpMomentumEMAHook, LinearMomentumEMAHook 4 | from .memory_profiler_hook import MemoryProfilerHook 5 | from .set_epoch_info_hook import SetEpochInfoHook 6 | from .sync_norm_hook import SyncNormHook 7 | from .sync_random_size_hook import SyncRandomSizeHook 8 | from .wandblogger_hook import MMDetWandbHook 9 | from .yolox_lrupdater_hook import YOLOXLrUpdaterHook 10 | from .yolox_mode_switch_hook import YOLOXModeSwitchHook 11 | 12 | __all__ = [ 13 | 'SyncRandomSizeHook', 'YOLOXModeSwitchHook', 'SyncNormHook', 14 | 'ExpMomentumEMAHook', 'LinearMomentumEMAHook', 'YOLOXLrUpdaterHook', 15 | 'CheckInvalidLossHook', 'SetEpochInfoHook', 'MemoryProfilerHook', 16 | 'MMDetWandbHook' 17 | ] 18 | -------------------------------------------------------------------------------- /bands/d_anything/torchhub/facebookresearch_dinov2_main/dinov2/configs/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | import pathlib 8 | 9 | from omegaconf import OmegaConf 10 | 11 | 12 | def load_config(config_name: str): 13 | config_filename = config_name + ".yaml" 14 | return OmegaConf.load(pathlib.Path(__file__).parent.resolve() / config_filename) 15 | 16 | 17 | dinov2_default_config = load_config("ssl_default_config") 18 | 19 | 20 | def load_and_merge_config(config_name: str): 21 | default_config = OmegaConf.create(dinov2_default_config) 22 | loaded_config = load_config(config_name) 23 | return OmegaConf.merge(default_config, loaded_config) 24 | -------------------------------------------------------------------------------- /bands/mmdet/models/necks/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from .bfp import BFP 3 | from .channel_mapper import ChannelMapper 4 | from .ct_resnet_neck import CTResNetNeck 5 | from .dilated_encoder import DilatedEncoder 6 | from .dyhead import DyHead 7 | from .fpg import FPG 8 | from .fpn import FPN 9 | from .fpn_carafe import FPN_CARAFE 10 | from .hrfpn import HRFPN 11 | from .nas_fpn import NASFPN 12 | from .nasfcos_fpn import NASFCOS_FPN 13 | from .pafpn import PAFPN 14 | from .rfp import RFP 15 | from .ssd_neck import SSDNeck 16 | from .yolo_neck import YOLOV3Neck 17 | from .yolox_pafpn import YOLOXPAFPN 18 | 19 | __all__ = [ 20 | 'FPN', 'BFP', 'ChannelMapper', 'HRFPN', 'NASFPN', 'FPN_CARAFE', 'PAFPN', 21 | 'NASFCOS_FPN', 'RFP', 'YOLOV3Neck', 'FPG', 'DilatedEncoder', 22 | 'CTResNetNeck', 'SSDNeck', 'YOLOXPAFPN', 'DyHead' 23 | ] 24 | -------------------------------------------------------------------------------- /bands/mmdet/core/bbox/samplers/combined_sampler.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from ..builder import BBOX_SAMPLERS, build_sampler 3 | from .base_sampler import BaseSampler 4 | 5 | 6 | @BBOX_SAMPLERS.register_module() 7 | class CombinedSampler(BaseSampler): 8 | """A sampler that combines positive sampler and negative sampler.""" 9 | 10 | def __init__(self, pos_sampler, neg_sampler, **kwargs): 11 | super(CombinedSampler, self).__init__(**kwargs) 12 | self.pos_sampler = build_sampler(pos_sampler, **kwargs) 13 | self.neg_sampler = build_sampler(neg_sampler, **kwargs) 14 | 15 | def _sample_pos(self, **kwargs): 16 | """Sample positive samples.""" 17 | raise NotImplementedError 18 | 19 | def _sample_neg(self, **kwargs): 20 | """Sample negative samples.""" 21 | raise NotImplementedError 22 | -------------------------------------------------------------------------------- /bands/mmdet/models/detectors/tood.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from ..builder import DETECTORS 3 | from .single_stage import SingleStageDetector 4 | 5 | 6 | @DETECTORS.register_module() 7 | class TOOD(SingleStageDetector): 8 | r"""Implementation of `TOOD: Task-aligned One-stage Object Detection. 9 | `_.""" 10 | 11 | def __init__(self, 12 | backbone, 13 | neck, 14 | bbox_head, 15 | train_cfg=None, 16 | test_cfg=None, 17 | pretrained=None, 18 | init_cfg=None): 19 | super(TOOD, self).__init__(backbone, neck, bbox_head, train_cfg, 20 | test_cfg, pretrained, init_cfg) 21 | 22 | def set_epoch(self, epoch): 23 | self.bbox_head.epoch = epoch 24 | -------------------------------------------------------------------------------- /_base_/default_runtime.py: -------------------------------------------------------------------------------- 1 | checkpoint_config = dict(interval=1) 2 | # yapf:disable 3 | log_config = dict( 4 | interval=50, 5 | hooks=[ 6 | dict(type='TextLoggerHook'), 7 | # dict(type='TensorboardLoggerHook') 8 | ]) 9 | # yapf:enable 10 | custom_hooks = [dict(type='NumClassCheckHook')] 11 | 12 | dist_params = dict(backend='nccl') 13 | log_level = 'INFO' 14 | load_from = None 15 | resume_from = None 16 | workflow = [('train', 1)] 17 | 18 | # disable opencv multithreading to avoid system being overloaded 19 | opencv_num_threads = 0 20 | # set multi-process start method as `fork` to speed up the training 21 | mp_start_method = 'fork' 22 | 23 | # Default setting for scaling LR automatically 24 | # - `enable` means enable scaling LR automatically 25 | # or not by default. 26 | # - `base_batch_size` = (8 GPUs) x (2 samples per GPU). 27 | auto_scale_lr = dict(enable=False, base_batch_size=16) -------------------------------------------------------------------------------- /bands/mmdet/models/detectors/reppoints_detector.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from ..builder import DETECTORS 3 | from .single_stage import SingleStageDetector 4 | 5 | 6 | @DETECTORS.register_module() 7 | class RepPointsDetector(SingleStageDetector): 8 | """RepPoints: Point Set Representation for Object Detection. 9 | 10 | This detector is the implementation of: 11 | - RepPoints detector (https://arxiv.org/pdf/1904.11490) 12 | """ 13 | 14 | def __init__(self, 15 | backbone, 16 | neck, 17 | bbox_head, 18 | train_cfg=None, 19 | test_cfg=None, 20 | pretrained=None, 21 | init_cfg=None): 22 | super(RepPointsDetector, 23 | self).__init__(backbone, neck, bbox_head, train_cfg, test_cfg, 24 | pretrained, init_cfg) 25 | -------------------------------------------------------------------------------- /bands/mmdet/setup.cfg: -------------------------------------------------------------------------------- 1 | [isort] 2 | line_length = 79 3 | multi_line_output = 0 4 | extra_standard_library = setuptools 5 | known_first_party = mmdet 6 | known_third_party = PIL,asynctest,cityscapesscripts,cv2,gather_models,matplotlib,mmcv,numpy,onnx,onnxruntime,pycocotools,pytest,pytorch_sphinx_theme,requests,scipy,seaborn,six,terminaltables,torch,ts,yaml 7 | no_lines_before = STDLIB,LOCALFOLDER 8 | default_section = THIRDPARTY 9 | 10 | [yapf] 11 | BASED_ON_STYLE = pep8 12 | BLANK_LINE_BEFORE_NESTED_CLASS_OR_DEF = true 13 | SPLIT_BEFORE_EXPRESSION_AFTER_OPENING_PAREN = true 14 | 15 | # ignore-words-list needs to be lowercase format. For example, if we want to 16 | # ignore word "BA", then we need to append "ba" to ignore-words-list rather 17 | # than "BA" 18 | [codespell] 19 | skip = *.ipynb 20 | quiet-level = 3 21 | ignore-words-list = patten,nd,ty,mot,hist,formating,winn,gool,datas,wan,confids,TOOD,tood,ba,warmup,nam,dota,DOTA 22 | -------------------------------------------------------------------------------- /bands/mmdet/core/bbox/samplers/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from .base_sampler import BaseSampler 3 | from .combined_sampler import CombinedSampler 4 | from .instance_balanced_pos_sampler import InstanceBalancedPosSampler 5 | from .iou_balanced_neg_sampler import IoUBalancedNegSampler 6 | from .mask_pseudo_sampler import MaskPseudoSampler 7 | from .mask_sampling_result import MaskSamplingResult 8 | from .ohem_sampler import OHEMSampler 9 | from .pseudo_sampler import PseudoSampler 10 | from .random_sampler import RandomSampler 11 | from .sampling_result import SamplingResult 12 | from .score_hlr_sampler import ScoreHLRSampler 13 | 14 | __all__ = [ 15 | 'BaseSampler', 'PseudoSampler', 'RandomSampler', 16 | 'InstanceBalancedPosSampler', 'IoUBalancedNegSampler', 'CombinedSampler', 17 | 'OHEMSampler', 'SamplingResult', 'ScoreHLRSampler', 'MaskPseudoSampler', 18 | 'MaskSamplingResult' 19 | ] 20 | -------------------------------------------------------------------------------- /bands/mmdet/models/roi_heads/mask_heads/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from .coarse_mask_head import CoarseMaskHead 3 | from .dynamic_mask_head import DynamicMaskHead 4 | from .fcn_mask_head import FCNMaskHead 5 | from .feature_relay_head import FeatureRelayHead 6 | from .fused_semantic_head import FusedSemanticHead 7 | from .global_context_head import GlobalContextHead 8 | from .grid_head import GridHead 9 | from .htc_mask_head import HTCMaskHead 10 | from .mask_point_head import MaskPointHead 11 | from .maskiou_head import MaskIoUHead 12 | from .scnet_mask_head import SCNetMaskHead 13 | from .scnet_semantic_head import SCNetSemanticHead 14 | 15 | __all__ = [ 16 | 'FCNMaskHead', 'HTCMaskHead', 'FusedSemanticHead', 'GridHead', 17 | 'MaskIoUHead', 'CoarseMaskHead', 'MaskPointHead', 'SCNetMaskHead', 18 | 'SCNetSemanticHead', 'GlobalContextHead', 'FeatureRelayHead', 19 | 'DynamicMaskHead' 20 | ] 21 | -------------------------------------------------------------------------------- /bands/mmdet/models/detectors/mask_rcnn.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from ..builder import DETECTORS 3 | from .two_stage import TwoStageDetector 4 | 5 | 6 | @DETECTORS.register_module() 7 | class MaskRCNN(TwoStageDetector): 8 | """Implementation of `Mask R-CNN `_""" 9 | 10 | def __init__(self, 11 | backbone, 12 | rpn_head, 13 | roi_head, 14 | train_cfg, 15 | test_cfg, 16 | neck=None, 17 | pretrained=None, 18 | init_cfg=None): 19 | super(MaskRCNN, self).__init__( 20 | backbone=backbone, 21 | neck=neck, 22 | rpn_head=rpn_head, 23 | roi_head=roi_head, 24 | train_cfg=train_cfg, 25 | test_cfg=test_cfg, 26 | pretrained=pretrained, 27 | init_cfg=init_cfg) 28 | -------------------------------------------------------------------------------- /bands/mmdet/models/detectors/faster_rcnn.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from ..builder import DETECTORS 3 | from .two_stage import TwoStageDetector 4 | 5 | 6 | @DETECTORS.register_module() 7 | class FasterRCNN(TwoStageDetector): 8 | """Implementation of `Faster R-CNN `_""" 9 | 10 | def __init__(self, 11 | backbone, 12 | rpn_head, 13 | roi_head, 14 | train_cfg, 15 | test_cfg, 16 | neck=None, 17 | pretrained=None, 18 | init_cfg=None): 19 | super(FasterRCNN, self).__init__( 20 | backbone=backbone, 21 | neck=neck, 22 | rpn_head=rpn_head, 23 | roi_head=roi_head, 24 | train_cfg=train_cfg, 25 | test_cfg=test_cfg, 26 | pretrained=pretrained, 27 | init_cfg=init_cfg) 28 | -------------------------------------------------------------------------------- /bands/mmdet/models/detectors/queryinst.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from ..builder import DETECTORS 3 | from .sparse_rcnn import SparseRCNN 4 | 5 | 6 | @DETECTORS.register_module() 7 | class QueryInst(SparseRCNN): 8 | r"""Implementation of 9 | `Instances as Queries `_""" 10 | 11 | def __init__(self, 12 | backbone, 13 | rpn_head, 14 | roi_head, 15 | train_cfg, 16 | test_cfg, 17 | neck=None, 18 | pretrained=None, 19 | init_cfg=None): 20 | super(QueryInst, self).__init__( 21 | backbone=backbone, 22 | neck=neck, 23 | rpn_head=rpn_head, 24 | roi_head=roi_head, 25 | train_cfg=train_cfg, 26 | test_cfg=test_cfg, 27 | pretrained=pretrained, 28 | init_cfg=init_cfg) 29 | -------------------------------------------------------------------------------- /bands/d_anything/torchhub/facebookresearch_dinov2_main/dinov2/data/datasets/decoders.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | from io import BytesIO 8 | from typing import Any 9 | 10 | from PIL import Image 11 | 12 | 13 | class Decoder: 14 | def decode(self) -> Any: 15 | raise NotImplementedError 16 | 17 | 18 | class ImageDataDecoder(Decoder): 19 | def __init__(self, image_data: bytes) -> None: 20 | self._image_data = image_data 21 | 22 | def decode(self) -> Image: 23 | f = BytesIO(self._image_data) 24 | return Image.open(f).convert(mode="RGB") 25 | 26 | 27 | class TargetDecoder(Decoder): 28 | def __init__(self, target: Any): 29 | self._target = target 30 | 31 | def decode(self) -> Any: 32 | return self._target 33 | -------------------------------------------------------------------------------- /bands/mmdet/models/detectors/mask_scoring_rcnn.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from ..builder import DETECTORS 3 | from .two_stage import TwoStageDetector 4 | 5 | 6 | @DETECTORS.register_module() 7 | class MaskScoringRCNN(TwoStageDetector): 8 | """Mask Scoring RCNN. 9 | 10 | https://arxiv.org/abs/1903.00241 11 | """ 12 | 13 | def __init__(self, 14 | backbone, 15 | rpn_head, 16 | roi_head, 17 | train_cfg, 18 | test_cfg, 19 | neck=None, 20 | pretrained=None, 21 | init_cfg=None): 22 | super(MaskScoringRCNN, self).__init__( 23 | backbone=backbone, 24 | neck=neck, 25 | rpn_head=rpn_head, 26 | roi_head=roi_head, 27 | train_cfg=train_cfg, 28 | test_cfg=test_cfg, 29 | pretrained=pretrained, 30 | init_cfg=init_cfg) 31 | -------------------------------------------------------------------------------- /environment.yml: -------------------------------------------------------------------------------- 1 | 2 | name: prisma 3 | channels: 4 | - pytorch 5 | - conda-forge 6 | - defaults 7 | dependencies: 8 | - cudatoolkit=11.3.1=h2bc3f7f_2 9 | - h5py=3.7.0 10 | - hdf5=1.12.2 11 | - matplotlib=3.6.2 12 | - matplotlib-base=3.6.2 13 | - numpy=1.24.1 14 | - pip=22.3.1 15 | - python=3.9.16 16 | - pytorch=1.10.0=py3.9_cuda11.3_cudnn8.2.0_0 17 | - pytorch-mutex=1.0=cuda 18 | - scipy=1.10.0 19 | - torchaudio=0.10.0=py39_cu113 20 | - torchvision=0.11.1=py39_cu113 21 | - json5=0.9.14 22 | - pip: 23 | - accelerate==0.25.0 24 | - av==11.0.0 25 | - cython==0.29.33 26 | - decord==0.6.0 27 | - diffusers==0.24.0 28 | - pymediainfo==6.1.0 29 | - kornia==0.7.0 30 | - opencv-contrib-python==4.8.1.78 31 | - opencv-python==4.8.1.78 32 | - pyyaml==6.0.1 33 | - rerun-sdk==0.11.0 34 | - snowy==0.0.9 35 | - timm==0.6.12 36 | - tqdm==4.64.1 37 | - terminaltables==3.1.10 38 | - transformers==4.36.2 39 | -------------------------------------------------------------------------------- /bands/mmdet/models/detectors/mask2former.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from ..builder import DETECTORS 3 | from .maskformer import MaskFormer 4 | 5 | 6 | @DETECTORS.register_module() 7 | class Mask2Former(MaskFormer): 8 | r"""Implementation of `Masked-attention Mask 9 | Transformer for Universal Image Segmentation 10 | `_.""" 11 | 12 | def __init__(self, 13 | backbone, 14 | neck=None, 15 | panoptic_head=None, 16 | panoptic_fusion_head=None, 17 | train_cfg=None, 18 | test_cfg=None, 19 | init_cfg=None): 20 | super().__init__( 21 | backbone, 22 | neck=neck, 23 | panoptic_head=panoptic_head, 24 | panoptic_fusion_head=panoptic_fusion_head, 25 | train_cfg=train_cfg, 26 | test_cfg=test_cfg, 27 | init_cfg=init_cfg) 28 | -------------------------------------------------------------------------------- /bands/mmdet/models/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from .backbones import * # noqa: F401,F403 3 | from .builder import (BACKBONES, DETECTORS, HEADS, LOSSES, NECKS, 4 | ROI_EXTRACTORS, SHARED_HEADS, build_backbone, 5 | build_detector, build_head, build_loss, build_neck, 6 | build_roi_extractor, build_shared_head) 7 | from .dense_heads import * # noqa: F401,F403 8 | from .detectors import * # noqa: F401,F403 9 | from .losses import * # noqa: F401,F403 10 | from .necks import * # noqa: F401,F403 11 | from .plugins import * # noqa: F401,F403 12 | from .roi_heads import * # noqa: F401,F403 13 | from .seg_heads import * # noqa: F401,F403 14 | 15 | __all__ = [ 16 | 'BACKBONES', 'NECKS', 'ROI_EXTRACTORS', 'SHARED_HEADS', 'HEADS', 'LOSSES', 17 | 'DETECTORS', 'build_backbone', 'build_neck', 'build_roi_extractor', 18 | 'build_shared_head', 'build_head', 'build_loss', 'build_detector' 19 | ] 20 | -------------------------------------------------------------------------------- /bands/d_anything/torchhub/facebookresearch_dinov2_main/dinov2/layers/layer_scale.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | # Modified from: https://github.com/huggingface/pytorch-image-models/blob/main/timm/models/vision_transformer.py#L103-L110 8 | 9 | from typing import Union 10 | 11 | import torch 12 | from torch import Tensor 13 | from torch import nn 14 | 15 | 16 | class LayerScale(nn.Module): 17 | def __init__( 18 | self, 19 | dim: int, 20 | init_values: Union[float, Tensor] = 1e-5, 21 | inplace: bool = False, 22 | ) -> None: 23 | super().__init__() 24 | self.inplace = inplace 25 | self.gamma = nn.Parameter(init_values * torch.ones(dim)) 26 | 27 | def forward(self, x: Tensor) -> Tensor: 28 | return x.mul_(self.gamma) if self.inplace else x * self.gamma 29 | -------------------------------------------------------------------------------- /bands/mmdet/models/detectors/solo.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from ..builder import DETECTORS 3 | from .single_stage_instance_seg import SingleStageInstanceSegmentor 4 | 5 | 6 | @DETECTORS.register_module() 7 | class SOLO(SingleStageInstanceSegmentor): 8 | """`SOLO: Segmenting Objects by Locations 9 | `_ 10 | 11 | """ 12 | 13 | def __init__(self, 14 | backbone, 15 | neck=None, 16 | bbox_head=None, 17 | mask_head=None, 18 | train_cfg=None, 19 | test_cfg=None, 20 | init_cfg=None, 21 | pretrained=None): 22 | super().__init__( 23 | backbone=backbone, 24 | neck=neck, 25 | bbox_head=bbox_head, 26 | mask_head=mask_head, 27 | train_cfg=train_cfg, 28 | test_cfg=test_cfg, 29 | init_cfg=init_cfg, 30 | pretrained=pretrained) 31 | -------------------------------------------------------------------------------- /bands/mmdet/models/detectors/solov2.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from ..builder import DETECTORS 3 | from .single_stage_instance_seg import SingleStageInstanceSegmentor 4 | 5 | 6 | @DETECTORS.register_module() 7 | class SOLOv2(SingleStageInstanceSegmentor): 8 | """`SOLOv2: Dynamic and Fast Instance Segmentation 9 | `_ 10 | 11 | """ 12 | 13 | def __init__(self, 14 | backbone, 15 | neck=None, 16 | bbox_head=None, 17 | mask_head=None, 18 | train_cfg=None, 19 | test_cfg=None, 20 | init_cfg=None, 21 | pretrained=None): 22 | super().__init__( 23 | backbone=backbone, 24 | neck=neck, 25 | bbox_head=bbox_head, 26 | mask_head=mask_head, 27 | train_cfg=train_cfg, 28 | test_cfg=test_cfg, 29 | init_cfg=init_cfg, 30 | pretrained=pretrained) 31 | -------------------------------------------------------------------------------- /bands/mmdet/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | import mmcv 3 | 4 | from .version import __version__, short_version 5 | 6 | 7 | def digit_version(version_str): 8 | digit_version = [] 9 | for x in version_str.split('.'): 10 | if x.isdigit(): 11 | digit_version.append(int(x)) 12 | elif x.find('rc') != -1: 13 | patch_version = x.split('rc') 14 | digit_version.append(int(patch_version[0]) - 1) 15 | digit_version.append(int(patch_version[1])) 16 | return digit_version 17 | 18 | 19 | mmcv_minimum_version = '1.3.17' 20 | mmcv_maximum_version = '1.8.0' 21 | mmcv_version = digit_version(mmcv.__version__) 22 | 23 | 24 | assert (mmcv_version >= digit_version(mmcv_minimum_version) 25 | and mmcv_version <= digit_version(mmcv_maximum_version)), \ 26 | f'MMCV=={mmcv.__version__} is used but incompatible. ' \ 27 | f'Please install mmcv>={mmcv_minimum_version}, <={mmcv_maximum_version}.' 28 | 29 | __all__ = ['__version__', 'short_version'] 30 | -------------------------------------------------------------------------------- /bands/mmdet/models/detectors/point_rend.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from ..builder import DETECTORS 3 | from .two_stage import TwoStageDetector 4 | 5 | 6 | @DETECTORS.register_module() 7 | class PointRend(TwoStageDetector): 8 | """PointRend: Image Segmentation as Rendering 9 | 10 | This detector is the implementation of 11 | `PointRend `_. 12 | 13 | """ 14 | 15 | def __init__(self, 16 | backbone, 17 | rpn_head, 18 | roi_head, 19 | train_cfg, 20 | test_cfg, 21 | neck=None, 22 | pretrained=None, 23 | init_cfg=None): 24 | super(PointRend, self).__init__( 25 | backbone=backbone, 26 | neck=neck, 27 | rpn_head=rpn_head, 28 | roi_head=roi_head, 29 | train_cfg=train_cfg, 30 | test_cfg=test_cfg, 31 | pretrained=pretrained, 32 | init_cfg=init_cfg) 33 | -------------------------------------------------------------------------------- /bands/d_anything/torchhub/facebookresearch_dinov2_main/dinov2/data/adapters.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | from typing import Any, Tuple 8 | 9 | from torch.utils.data import Dataset 10 | 11 | 12 | class DatasetWithEnumeratedTargets(Dataset): 13 | def __init__(self, dataset): 14 | self._dataset = dataset 15 | 16 | def get_image_data(self, index: int) -> bytes: 17 | return self._dataset.get_image_data(index) 18 | 19 | def get_target(self, index: int) -> Tuple[Any, int]: 20 | target = self._dataset.get_target(index) 21 | return (index, target) 22 | 23 | def __getitem__(self, index: int) -> Tuple[Any, Tuple[Any, int]]: 24 | image, target = self._dataset[index] 25 | target = index if target is None else target 26 | return image, (index, target) 27 | 28 | def __len__(self) -> int: 29 | return len(self._dataset) 30 | -------------------------------------------------------------------------------- /bands/mmdet/models/detectors/grid_rcnn.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from ..builder import DETECTORS 3 | from .two_stage import TwoStageDetector 4 | 5 | 6 | @DETECTORS.register_module() 7 | class GridRCNN(TwoStageDetector): 8 | """Grid R-CNN. 9 | 10 | This detector is the implementation of: 11 | - Grid R-CNN (https://arxiv.org/abs/1811.12030) 12 | - Grid R-CNN Plus: Faster and Better (https://arxiv.org/abs/1906.05688) 13 | """ 14 | 15 | def __init__(self, 16 | backbone, 17 | rpn_head, 18 | roi_head, 19 | train_cfg, 20 | test_cfg, 21 | neck=None, 22 | pretrained=None, 23 | init_cfg=None): 24 | super(GridRCNN, self).__init__( 25 | backbone=backbone, 26 | neck=neck, 27 | rpn_head=rpn_head, 28 | roi_head=roi_head, 29 | train_cfg=train_cfg, 30 | test_cfg=test_cfg, 31 | pretrained=pretrained, 32 | init_cfg=init_cfg) 33 | -------------------------------------------------------------------------------- /bands/mmdet/models/backbones/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from .csp_darknet import CSPDarknet 3 | from .darknet import Darknet 4 | from .detectors_resnet import DetectoRS_ResNet 5 | from .detectors_resnext import DetectoRS_ResNeXt 6 | from .efficientnet import EfficientNet 7 | from .hourglass import HourglassNet 8 | from .hrnet import HRNet 9 | from .mobilenet_v2 import MobileNetV2 10 | from .pvt import PyramidVisionTransformer, PyramidVisionTransformerV2 11 | from .regnet import RegNet 12 | from .res2net import Res2Net 13 | from .resnest import ResNeSt 14 | from .resnet import ResNet, ResNetV1d 15 | from .resnext import ResNeXt 16 | from .ssd_vgg import SSDVGG 17 | from .swin import SwinTransformer 18 | from .trident_resnet import TridentResNet 19 | 20 | __all__ = [ 21 | 'RegNet', 'ResNet', 'ResNetV1d', 'ResNeXt', 'SSDVGG', 'HRNet', 22 | 'MobileNetV2', 'Res2Net', 'HourglassNet', 'DetectoRS_ResNet', 23 | 'DetectoRS_ResNeXt', 'Darknet', 'ResNeSt', 'TridentResNet', 'CSPDarknet', 24 | 'SwinTransformer', 'PyramidVisionTransformer', 25 | 'PyramidVisionTransformerV2', 'EfficientNet' 26 | ] 27 | -------------------------------------------------------------------------------- /bands/mmdet/models/roi_heads/mask_heads/scnet_mask_head.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from mmdet.models.builder import HEADS 3 | from mmdet.models.utils import ResLayer, SimplifiedBasicBlock 4 | from .fcn_mask_head import FCNMaskHead 5 | 6 | 7 | @HEADS.register_module() 8 | class SCNetMaskHead(FCNMaskHead): 9 | """Mask head for `SCNet `_. 10 | 11 | Args: 12 | conv_to_res (bool, optional): if True, change the conv layers to 13 | ``SimplifiedBasicBlock``. 14 | """ 15 | 16 | def __init__(self, conv_to_res=True, **kwargs): 17 | super(SCNetMaskHead, self).__init__(**kwargs) 18 | self.conv_to_res = conv_to_res 19 | if conv_to_res: 20 | assert self.conv_kernel_size == 3 21 | self.num_res_blocks = self.num_convs // 2 22 | self.convs = ResLayer( 23 | SimplifiedBasicBlock, 24 | self.in_channels, 25 | self.conv_out_channels, 26 | self.num_res_blocks, 27 | conv_cfg=self.conv_cfg, 28 | norm_cfg=self.norm_cfg) 29 | -------------------------------------------------------------------------------- /bands/mmdet/utils/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from .ascend_util import (batch_images_to_levels, 3 | get_max_num_gt_division_factor, masked_fill) 4 | from .collect_env import collect_env 5 | from .compat_config import compat_cfg 6 | from .logger import get_caller_name, get_root_logger, log_img_scale 7 | from .memory import AvoidCUDAOOM, AvoidOOM 8 | from .misc import find_latest_checkpoint, update_data_root 9 | from .replace_cfg_vals import replace_cfg_vals 10 | from .rfnext import rfnext_init_model 11 | from .setup_env import setup_multi_processes 12 | from .split_batch import split_batch 13 | from .util_distribution import build_ddp, build_dp, get_device 14 | 15 | __all__ = [ 16 | 'get_root_logger', 'collect_env', 'find_latest_checkpoint', 17 | 'update_data_root', 'setup_multi_processes', 'get_caller_name', 18 | 'log_img_scale', 'compat_cfg', 'split_batch', 'build_ddp', 'build_dp', 19 | 'get_device', 'replace_cfg_vals', 'AvoidOOM', 'AvoidCUDAOOM', 20 | 'get_max_num_gt_division_factor', 'masked_fill', 'batch_images_to_levels', 21 | 'rfnext_init_model' 22 | ] 23 | -------------------------------------------------------------------------------- /bands/patchfusion/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Zhenyu Li 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /bands/mmdet/models/roi_heads/mask_heads/scnet_semantic_head.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from mmdet.models.builder import HEADS 3 | from mmdet.models.utils import ResLayer, SimplifiedBasicBlock 4 | from .fused_semantic_head import FusedSemanticHead 5 | 6 | 7 | @HEADS.register_module() 8 | class SCNetSemanticHead(FusedSemanticHead): 9 | """Mask head for `SCNet `_. 10 | 11 | Args: 12 | conv_to_res (bool, optional): if True, change the conv layers to 13 | ``SimplifiedBasicBlock``. 14 | """ 15 | 16 | def __init__(self, conv_to_res=True, **kwargs): 17 | super(SCNetSemanticHead, self).__init__(**kwargs) 18 | self.conv_to_res = conv_to_res 19 | if self.conv_to_res: 20 | num_res_blocks = self.num_convs // 2 21 | self.convs = ResLayer( 22 | SimplifiedBasicBlock, 23 | self.in_channels, 24 | self.conv_out_channels, 25 | num_res_blocks, 26 | conv_cfg=self.conv_cfg, 27 | norm_cfg=self.norm_cfg) 28 | self.num_convs = num_res_blocks 29 | -------------------------------------------------------------------------------- /bands/marigold/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023 Bingxin Ke, ETH Zurich. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # -------------------------------------------------------------------------- 15 | # If you find this code useful, we kindly ask you to cite our paper in your work. 16 | # Please find bibtex at: https://github.com/prs-eth/Marigold#-citation 17 | # More information about the method can be found at https://marigoldmonodepth.github.io 18 | # -------------------------------------------------------------------------- 19 | 20 | 21 | from .marigold_pipeline import MarigoldPipeline, MarigoldDepthOutput 22 | -------------------------------------------------------------------------------- /bands/mmdet/utils/util_random.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | """Helpers for random number generators.""" 3 | import numpy as np 4 | 5 | 6 | def ensure_rng(rng=None): 7 | """Coerces input into a random number generator. 8 | 9 | If the input is None, then a global random state is returned. 10 | 11 | If the input is a numeric value, then that is used as a seed to construct a 12 | random state. Otherwise the input is returned as-is. 13 | 14 | Adapted from [1]_. 15 | 16 | Args: 17 | rng (int | numpy.random.RandomState | None): 18 | if None, then defaults to the global rng. Otherwise this can be an 19 | integer or a RandomState class 20 | Returns: 21 | (numpy.random.RandomState) : rng - 22 | a numpy random number generator 23 | 24 | References: 25 | .. [1] https://gitlab.kitware.com/computer-vision/kwarray/blob/master/kwarray/util_random.py#L270 # noqa: E501 26 | """ 27 | 28 | if rng is None: 29 | rng = np.random.mtrand._rand 30 | elif isinstance(rng, int): 31 | rng = np.random.RandomState(rng) 32 | else: 33 | rng = rng 34 | return rng 35 | -------------------------------------------------------------------------------- /bands/patchfusion/zoedepth/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Intelligent Systems Lab Org 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /bands/mmdet/core/evaluation/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from .class_names import (cityscapes_classes, coco_classes, dataset_aliases, 3 | get_classes, imagenet_det_classes, 4 | imagenet_vid_classes, objects365v1_classes, 5 | objects365v2_classes, oid_challenge_classes, 6 | oid_v6_classes, voc_classes) 7 | from .eval_hooks import DistEvalHook, EvalHook 8 | from .mean_ap import average_precision, eval_map, print_map_summary 9 | from .panoptic_utils import INSTANCE_OFFSET 10 | from .recall import (eval_recalls, plot_iou_recall, plot_num_recall, 11 | print_recall_summary) 12 | 13 | __all__ = [ 14 | 'voc_classes', 'imagenet_det_classes', 'imagenet_vid_classes', 15 | 'coco_classes', 'cityscapes_classes', 'dataset_aliases', 'get_classes', 16 | 'DistEvalHook', 'EvalHook', 'average_precision', 'eval_map', 17 | 'print_map_summary', 'eval_recalls', 'print_recall_summary', 18 | 'plot_num_recall', 'plot_iou_recall', 'oid_v6_classes', 19 | 'oid_challenge_classes', 'objects365v1_classes', 'objects365v2_classes', 20 | 'INSTANCE_OFFSET' 21 | ] 22 | -------------------------------------------------------------------------------- /bands/patchfusion/zoedepth/models/base_models/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Intel ISL (Intel Intelligent Systems Lab) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /bands/mmdet/models/detectors/panoptic_fpn.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from ..builder import DETECTORS 3 | from .panoptic_two_stage_segmentor import TwoStagePanopticSegmentor 4 | 5 | 6 | @DETECTORS.register_module() 7 | class PanopticFPN(TwoStagePanopticSegmentor): 8 | r"""Implementation of `Panoptic feature pyramid 9 | networks `_""" 10 | 11 | def __init__( 12 | self, 13 | backbone, 14 | neck=None, 15 | rpn_head=None, 16 | roi_head=None, 17 | train_cfg=None, 18 | test_cfg=None, 19 | pretrained=None, 20 | init_cfg=None, 21 | # for panoptic segmentation 22 | semantic_head=None, 23 | panoptic_fusion_head=None): 24 | super(PanopticFPN, self).__init__( 25 | backbone=backbone, 26 | neck=neck, 27 | rpn_head=rpn_head, 28 | roi_head=roi_head, 29 | train_cfg=train_cfg, 30 | test_cfg=test_cfg, 31 | pretrained=pretrained, 32 | init_cfg=init_cfg, 33 | semantic_head=semantic_head, 34 | panoptic_fusion_head=panoptic_fusion_head) 35 | -------------------------------------------------------------------------------- /download_models.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # RAFTs 4 | # wget https://www.dropbox.com/s/4j4z58wuv8o0mfz/models.zip 5 | wget https://www.dropbox.com/scl/fi/zh3220fwav2l8i2zbvreo/models.zip?rlkey=dg8bynghzm1xaeqkmnvlv1q3n&dl=0 -O models.zip 6 | unzip models.zip 7 | rm models.zip 8 | 9 | cd models 10 | 11 | # MMDetect 12 | wget https://download.openmmlab.com/mmdetection/v2.0/solov2/solov2_r101_fpn_3x_coco/solov2_r101_fpn_3x_coco_20220511_095119-c559a076.pth 13 | wget https://raw.githubusercontent.com/open-mmlab/mmdetection/master/configs/solov2/solov2_r101_fpn_3x_coco.py 14 | wget https://raw.githubusercontent.com/open-mmlab/mmdetection/master/configs/solov2/solov2_r50_fpn_3x_coco.py 15 | wget https://raw.githubusercontent.com/open-mmlab/mmdetection/master/configs/solov2/solov2_r50_fpn_1x_coco.py 16 | 17 | # DepthAnything 18 | 19 | wget https://huggingface.co/spaces/LiheYoung/Depth-Anything/resolve/main/checkpoints_metric_depth/depth_anything_metric_depth_indoor.pt?download=true 20 | wget https://huggingface.co/spaces/LiheYoung/Depth-Anything/resolve/main/checkpoints_metric_depth/depth_anything_metric_depth_outdoor.pt?download=true 21 | wget https://huggingface.co/spaces/LiheYoung/Depth-Anything/resolve/main/checkpoints/depth_anything_vitl14.pth?download=true 22 | 23 | cd .. -------------------------------------------------------------------------------- /bands/patchfusion/zoedepth/data/__init__.py: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | # Copyright (c) 2022 Intelligent Systems Lab Org 4 | 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | # File author: Shariq Farooq Bhat 24 | 25 | -------------------------------------------------------------------------------- /bands/patchfusion/zoedepth/models/__init__.py: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | # Copyright (c) 2022 Intelligent Systems Lab Org 4 | 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | # File author: Shariq Farooq Bhat 24 | 25 | -------------------------------------------------------------------------------- /bands/patchfusion/zoedepth/utils/__init__.py: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | # Copyright (c) 2022 Intelligent Systems Lab Org 4 | 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | # File author: Shariq Farooq Bhat 24 | 25 | -------------------------------------------------------------------------------- /bands/patchfusion/zoedepth/models/base_models/__init__.py: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | # Copyright (c) 2022 Intelligent Systems Lab Org 4 | 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | # File author: Shariq Farooq Bhat 24 | 25 | -------------------------------------------------------------------------------- /bands/mmdet/core/bbox/assigners/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from .approx_max_iou_assigner import ApproxMaxIoUAssigner 3 | from .ascend_assign_result import AscendAssignResult 4 | from .ascend_max_iou_assigner import AscendMaxIoUAssigner 5 | from .assign_result import AssignResult 6 | from .atss_assigner import ATSSAssigner 7 | from .base_assigner import BaseAssigner 8 | from .center_region_assigner import CenterRegionAssigner 9 | from .grid_assigner import GridAssigner 10 | from .hungarian_assigner import HungarianAssigner 11 | from .mask_hungarian_assigner import MaskHungarianAssigner 12 | from .max_iou_assigner import MaxIoUAssigner 13 | from .point_assigner import PointAssigner 14 | from .region_assigner import RegionAssigner 15 | from .sim_ota_assigner import SimOTAAssigner 16 | from .task_aligned_assigner import TaskAlignedAssigner 17 | from .uniform_assigner import UniformAssigner 18 | 19 | __all__ = [ 20 | 'BaseAssigner', 'MaxIoUAssigner', 'ApproxMaxIoUAssigner', 'AssignResult', 21 | 'PointAssigner', 'ATSSAssigner', 'CenterRegionAssigner', 'GridAssigner', 22 | 'HungarianAssigner', 'RegionAssigner', 'UniformAssigner', 'SimOTAAssigner', 23 | 'TaskAlignedAssigner', 'MaskHungarianAssigner', 'AscendAssignResult', 24 | 'AscendMaxIoUAssigner' 25 | ] 26 | -------------------------------------------------------------------------------- /bands/d_anything/torchhub/facebookresearch_dinov2_main/dinov2/utils/dtype.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | 8 | from typing import Dict, Union 9 | 10 | import numpy as np 11 | import torch 12 | 13 | 14 | TypeSpec = Union[str, np.dtype, torch.dtype] 15 | 16 | 17 | _NUMPY_TO_TORCH_DTYPE: Dict[np.dtype, torch.dtype] = { 18 | np.dtype("bool"): torch.bool, 19 | np.dtype("uint8"): torch.uint8, 20 | np.dtype("int8"): torch.int8, 21 | np.dtype("int16"): torch.int16, 22 | np.dtype("int32"): torch.int32, 23 | np.dtype("int64"): torch.int64, 24 | np.dtype("float16"): torch.float16, 25 | np.dtype("float32"): torch.float32, 26 | np.dtype("float64"): torch.float64, 27 | np.dtype("complex64"): torch.complex64, 28 | np.dtype("complex128"): torch.complex128, 29 | } 30 | 31 | 32 | def as_torch_dtype(dtype: TypeSpec) -> torch.dtype: 33 | if isinstance(dtype, torch.dtype): 34 | return dtype 35 | if isinstance(dtype, str): 36 | dtype = np.dtype(dtype) 37 | assert isinstance(dtype, np.dtype), f"Expected an instance of nunpy dtype, got {type(dtype)}" 38 | return _NUMPY_TO_TORCH_DTYPE[dtype] 39 | -------------------------------------------------------------------------------- /bands/d_anything/torchhub/facebookresearch_dinov2_main/dinov2/layers/drop_path.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | # References: 8 | # https://github.com/facebookresearch/dino/blob/master/vision_transformer.py 9 | # https://github.com/rwightman/pytorch-image-models/tree/master/timm/layers/drop.py 10 | 11 | 12 | from torch import nn 13 | 14 | 15 | def drop_path(x, drop_prob: float = 0.0, training: bool = False): 16 | if drop_prob == 0.0 or not training: 17 | return x 18 | keep_prob = 1 - drop_prob 19 | shape = (x.shape[0],) + (1,) * (x.ndim - 1) # work with diff dim tensors, not just 2D ConvNets 20 | random_tensor = x.new_empty(shape).bernoulli_(keep_prob) 21 | if keep_prob > 0.0: 22 | random_tensor.div_(keep_prob) 23 | output = x * random_tensor 24 | return output 25 | 26 | 27 | class DropPath(nn.Module): 28 | """Drop paths (Stochastic Depth) per sample (when applied in main path of residual blocks).""" 29 | 30 | def __init__(self, drop_prob=None): 31 | super(DropPath, self).__init__() 32 | self.drop_prob = drop_prob 33 | 34 | def forward(self, x): 35 | return drop_path(x, self.drop_prob, self.training) 36 | -------------------------------------------------------------------------------- /bands/mmdet/core/optimizers/builder.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | import copy 3 | 4 | from mmcv.runner.optimizer import OPTIMIZER_BUILDERS as MMCV_OPTIMIZER_BUILDERS 5 | from mmcv.utils import Registry, build_from_cfg 6 | 7 | OPTIMIZER_BUILDERS = Registry( 8 | 'optimizer builder', parent=MMCV_OPTIMIZER_BUILDERS) 9 | 10 | 11 | def build_optimizer_constructor(cfg): 12 | constructor_type = cfg.get('type') 13 | if constructor_type in OPTIMIZER_BUILDERS: 14 | return build_from_cfg(cfg, OPTIMIZER_BUILDERS) 15 | elif constructor_type in MMCV_OPTIMIZER_BUILDERS: 16 | return build_from_cfg(cfg, MMCV_OPTIMIZER_BUILDERS) 17 | else: 18 | raise KeyError(f'{constructor_type} is not registered ' 19 | 'in the optimizer builder registry.') 20 | 21 | 22 | def build_optimizer(model, cfg): 23 | optimizer_cfg = copy.deepcopy(cfg) 24 | constructor_type = optimizer_cfg.pop('constructor', 25 | 'DefaultOptimizerConstructor') 26 | paramwise_cfg = optimizer_cfg.pop('paramwise_cfg', None) 27 | optim_constructor = build_optimizer_constructor( 28 | dict( 29 | type=constructor_type, 30 | optimizer_cfg=optimizer_cfg, 31 | paramwise_cfg=paramwise_cfg)) 32 | optimizer = optim_constructor(model) 33 | return optimizer 34 | -------------------------------------------------------------------------------- /bands/mmdet/core/bbox/demodata.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | import numpy as np 3 | import torch 4 | 5 | from mmdet.utils.util_random import ensure_rng 6 | 7 | 8 | def random_boxes(num=1, scale=1, rng=None): 9 | """Simple version of ``kwimage.Boxes.random`` 10 | 11 | Returns: 12 | Tensor: shape (n, 4) in x1, y1, x2, y2 format. 13 | 14 | References: 15 | https://gitlab.kitware.com/computer-vision/kwimage/blob/master/kwimage/structs/boxes.py#L1390 16 | 17 | Example: 18 | >>> num = 3 19 | >>> scale = 512 20 | >>> rng = 0 21 | >>> boxes = random_boxes(num, scale, rng) 22 | >>> print(boxes) 23 | tensor([[280.9925, 278.9802, 308.6148, 366.1769], 24 | [216.9113, 330.6978, 224.0446, 456.5878], 25 | [405.3632, 196.3221, 493.3953, 270.7942]]) 26 | """ 27 | rng = ensure_rng(rng) 28 | 29 | tlbr = rng.rand(num, 4).astype(np.float32) 30 | 31 | tl_x = np.minimum(tlbr[:, 0], tlbr[:, 2]) 32 | tl_y = np.minimum(tlbr[:, 1], tlbr[:, 3]) 33 | br_x = np.maximum(tlbr[:, 0], tlbr[:, 2]) 34 | br_y = np.maximum(tlbr[:, 1], tlbr[:, 3]) 35 | 36 | tlbr[:, 0] = tl_x * scale 37 | tlbr[:, 1] = tl_y * scale 38 | tlbr[:, 2] = br_x * scale 39 | tlbr[:, 3] = br_y * scale 40 | 41 | boxes = torch.from_numpy(tlbr) 42 | return boxes 43 | -------------------------------------------------------------------------------- /bands/marigold/util/seed_all.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023 Bingxin Ke, ETH Zurich. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # -------------------------------------------------------------------------- 15 | # If you find this code useful, we kindly ask you to cite our paper in your work. 16 | # Please find bibtex at: https://github.com/prs-eth/Marigold#-citation 17 | # More information about the method can be found at https://marigoldmonodepth.github.io 18 | # -------------------------------------------------------------------------- 19 | 20 | 21 | import numpy as np 22 | import random 23 | import torch 24 | 25 | 26 | def seed_all(seed: int = 0): 27 | """ 28 | Set random seeds of all components. 29 | """ 30 | random.seed(seed) 31 | np.random.seed(seed) 32 | torch.manual_seed(seed) 33 | torch.cuda.manual_seed_all(seed) 34 | -------------------------------------------------------------------------------- /bands/mmdet/models/utils/make_divisible.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | def make_divisible(value, divisor, min_value=None, min_ratio=0.9): 3 | """Make divisible function. 4 | 5 | This function rounds the channel number to the nearest value that can be 6 | divisible by the divisor. It is taken from the original tf repo. It ensures 7 | that all layers have a channel number that is divisible by divisor. It can 8 | be seen here: https://github.com/tensorflow/models/blob/master/research/slim/nets/mobilenet/mobilenet.py # noqa 9 | 10 | Args: 11 | value (int): The original channel number. 12 | divisor (int): The divisor to fully divide the channel number. 13 | min_value (int): The minimum value of the output channel. 14 | Default: None, means that the minimum value equal to the divisor. 15 | min_ratio (float): The minimum ratio of the rounded channel number to 16 | the original channel number. Default: 0.9. 17 | 18 | Returns: 19 | int: The modified output channel number. 20 | """ 21 | 22 | if min_value is None: 23 | min_value = divisor 24 | new_value = max(min_value, int(value + divisor / 2) // divisor * divisor) 25 | # Make sure that round down does not go down by more than (1-min_ratio). 26 | if new_value < min_ratio * value: 27 | new_value += divisor 28 | return new_value 29 | -------------------------------------------------------------------------------- /bands/d_anything/torchhub/facebookresearch_dinov2_main/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to DINOv2 2 | We want to make contributing to this project as easy and transparent as 3 | possible. 4 | 5 | ## Pull Requests 6 | We actively welcome your pull requests. 7 | 8 | 1. Fork the repo and create your branch from `main`. 9 | 2. If you've added code that should be tested, add tests. 10 | 3. If you've changed APIs, update the documentation. 11 | 4. Ensure the test suite passes. 12 | 5. Make sure your code lints. 13 | 6. If you haven't already, complete the Contributor License Agreement ("CLA"). 14 | 15 | ## Contributor License Agreement ("CLA") 16 | In order to accept your pull request, we need you to submit a CLA. You only need 17 | to do this once to work on any of Meta's open source projects. 18 | 19 | Complete your CLA here: 20 | 21 | ## Issues 22 | We use GitHub issues to track public bugs. Please ensure your description is 23 | clear and has sufficient instructions to be able to reproduce the issue. 24 | 25 | Meta has a [bounty program](https://www.facebook.com/whitehat/) for the safe 26 | disclosure of security bugs. In those cases, please go through the process 27 | outlined on that page and do not file a public issue. 28 | 29 | ## License 30 | By contributing to DINOv2, you agree that your contributions will be licensed 31 | under the LICENSE file in the root directory of this source tree. 32 | -------------------------------------------------------------------------------- /bands/mmdet/models/roi_heads/double_roi_head.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from ..builder import HEADS 3 | from .standard_roi_head import StandardRoIHead 4 | 5 | 6 | @HEADS.register_module() 7 | class DoubleHeadRoIHead(StandardRoIHead): 8 | """RoI head for Double Head RCNN. 9 | 10 | https://arxiv.org/abs/1904.06493 11 | """ 12 | 13 | def __init__(self, reg_roi_scale_factor, **kwargs): 14 | super(DoubleHeadRoIHead, self).__init__(**kwargs) 15 | self.reg_roi_scale_factor = reg_roi_scale_factor 16 | 17 | def _bbox_forward(self, x, rois): 18 | """Box head forward function used in both training and testing time.""" 19 | bbox_cls_feats = self.bbox_roi_extractor( 20 | x[:self.bbox_roi_extractor.num_inputs], rois) 21 | bbox_reg_feats = self.bbox_roi_extractor( 22 | x[:self.bbox_roi_extractor.num_inputs], 23 | rois, 24 | roi_scale_factor=self.reg_roi_scale_factor) 25 | if self.with_shared_head: 26 | bbox_cls_feats = self.shared_head(bbox_cls_feats) 27 | bbox_reg_feats = self.shared_head(bbox_reg_feats) 28 | cls_score, bbox_pred = self.bbox_head(bbox_cls_feats, bbox_reg_feats) 29 | 30 | bbox_results = dict( 31 | cls_score=cls_score, 32 | bbox_pred=bbox_pred, 33 | bbox_feats=bbox_cls_feats) 34 | return bbox_results 35 | -------------------------------------------------------------------------------- /bands/patchfusion/zoedepth/models/zoedepth/__init__.py: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | # Copyright (c) 2022 Intelligent Systems Lab Org 4 | 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | # File author: Shariq Farooq Bhat 24 | 25 | from .zoedepth_v1 import ZoeDepth 26 | 27 | all_versions = { 28 | "v1": ZoeDepth, 29 | } 30 | 31 | get_version = lambda v : all_versions[v] -------------------------------------------------------------------------------- /bands/d_anything/torchhub/facebookresearch_dinov2_main/dinov2/data/datasets/extended.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | from typing import Any, Tuple 8 | 9 | from torchvision.datasets import VisionDataset 10 | 11 | from .decoders import TargetDecoder, ImageDataDecoder 12 | 13 | 14 | class ExtendedVisionDataset(VisionDataset): 15 | def __init__(self, *args, **kwargs) -> None: 16 | super().__init__(*args, **kwargs) # type: ignore 17 | 18 | def get_image_data(self, index: int) -> bytes: 19 | raise NotImplementedError 20 | 21 | def get_target(self, index: int) -> Any: 22 | raise NotImplementedError 23 | 24 | def __getitem__(self, index: int) -> Tuple[Any, Any]: 25 | try: 26 | image_data = self.get_image_data(index) 27 | image = ImageDataDecoder(image_data).decode() 28 | except Exception as e: 29 | raise RuntimeError(f"can not read image for sample {index}") from e 30 | target = self.get_target(index) 31 | target = TargetDecoder(target).decode() 32 | 33 | if self.transforms is not None: 34 | image, target = self.transforms(image, target) 35 | 36 | return image, target 37 | 38 | def __len__(self) -> int: 39 | raise NotImplementedError 40 | -------------------------------------------------------------------------------- /bands/d_anything/torchhub/facebookresearch_dinov2_main/utils.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # 3 | # This source code is licensed under the Apache License, Version 2.0 4 | # found in the LICENSE file in the root directory of this source tree. 5 | 6 | import itertools 7 | import math 8 | 9 | import torch 10 | import torch.nn as nn 11 | import torch.nn.functional as F 12 | 13 | 14 | _DINOV2_BASE_URL = "https://dl.fbaipublicfiles.com/dinov2" 15 | 16 | 17 | def _make_dinov2_model_name(arch_name: str, patch_size: int, num_register_tokens: int = 0) -> str: 18 | compact_arch_name = arch_name.replace("_", "")[:4] 19 | registers_suffix = f"_reg{num_register_tokens}" if num_register_tokens else "" 20 | return f"dinov2_{compact_arch_name}{patch_size}{registers_suffix}" 21 | 22 | 23 | class CenterPadding(nn.Module): 24 | def __init__(self, multiple): 25 | super().__init__() 26 | self.multiple = multiple 27 | 28 | def _get_pad(self, size): 29 | new_size = math.ceil(size / self.multiple) * self.multiple 30 | pad_size = new_size - size 31 | pad_size_left = pad_size // 2 32 | pad_size_right = pad_size - pad_size_left 33 | return pad_size_left, pad_size_right 34 | 35 | @torch.inference_mode() 36 | def forward(self, x): 37 | pads = list(itertools.chain.from_iterable(self._get_pad(m) for m in x.shape[:1:-1])) 38 | output = F.pad(x, pads) 39 | return output 40 | -------------------------------------------------------------------------------- /bands/mmdet/models/roi_heads/mask_heads/htc_mask_head.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from mmcv.cnn import ConvModule 3 | 4 | from mmdet.models.builder import HEADS 5 | from .fcn_mask_head import FCNMaskHead 6 | 7 | 8 | @HEADS.register_module() 9 | class HTCMaskHead(FCNMaskHead): 10 | 11 | def __init__(self, with_conv_res=True, *args, **kwargs): 12 | super(HTCMaskHead, self).__init__(*args, **kwargs) 13 | self.with_conv_res = with_conv_res 14 | if self.with_conv_res: 15 | self.conv_res = ConvModule( 16 | self.conv_out_channels, 17 | self.conv_out_channels, 18 | 1, 19 | conv_cfg=self.conv_cfg, 20 | norm_cfg=self.norm_cfg) 21 | 22 | def forward(self, x, res_feat=None, return_logits=True, return_feat=True): 23 | if res_feat is not None: 24 | assert self.with_conv_res 25 | res_feat = self.conv_res(res_feat) 26 | x = x + res_feat 27 | for conv in self.convs: 28 | x = conv(x) 29 | res_feat = x 30 | outs = [] 31 | if return_logits: 32 | x = self.upsample(x) 33 | if self.upsample_method == 'deconv': 34 | x = self.relu(x) 35 | mask_pred = self.conv_logits(x) 36 | outs.append(mask_pred) 37 | if return_feat: 38 | outs.append(res_feat) 39 | return outs if len(outs) > 1 else outs[0] 40 | -------------------------------------------------------------------------------- /bands/d_anything/torchhub/facebookresearch_dinov2_main/dinov2/layers/mlp.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | # References: 8 | # https://github.com/facebookresearch/dino/blob/master/vision_transformer.py 9 | # https://github.com/rwightman/pytorch-image-models/tree/master/timm/layers/mlp.py 10 | 11 | 12 | from typing import Callable, Optional 13 | 14 | from torch import Tensor, nn 15 | 16 | 17 | class Mlp(nn.Module): 18 | def __init__( 19 | self, 20 | in_features: int, 21 | hidden_features: Optional[int] = None, 22 | out_features: Optional[int] = None, 23 | act_layer: Callable[..., nn.Module] = nn.GELU, 24 | drop: float = 0.0, 25 | bias: bool = True, 26 | ) -> None: 27 | super().__init__() 28 | out_features = out_features or in_features 29 | hidden_features = hidden_features or in_features 30 | self.fc1 = nn.Linear(in_features, hidden_features, bias=bias) 31 | self.act = act_layer() 32 | self.fc2 = nn.Linear(hidden_features, out_features, bias=bias) 33 | self.drop = nn.Dropout(drop) 34 | 35 | def forward(self, x: Tensor) -> Tensor: 36 | x = self.fc1(x) 37 | x = self.act(x) 38 | x = self.drop(x) 39 | x = self.fc2(x) 40 | x = self.drop(x) 41 | return x 42 | -------------------------------------------------------------------------------- /bands/mmdet/utils/profiling.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | import contextlib 3 | import sys 4 | import time 5 | 6 | import torch 7 | 8 | if sys.version_info >= (3, 7): 9 | 10 | @contextlib.contextmanager 11 | def profile_time(trace_name, 12 | name, 13 | enabled=True, 14 | stream=None, 15 | end_stream=None): 16 | """Print time spent by CPU and GPU. 17 | 18 | Useful as a temporary context manager to find sweet spots of code 19 | suitable for async implementation. 20 | """ 21 | if (not enabled) or not torch.cuda.is_available(): 22 | yield 23 | return 24 | stream = stream if stream else torch.cuda.current_stream() 25 | end_stream = end_stream if end_stream else stream 26 | start = torch.cuda.Event(enable_timing=True) 27 | end = torch.cuda.Event(enable_timing=True) 28 | stream.record_event(start) 29 | try: 30 | cpu_start = time.monotonic() 31 | yield 32 | finally: 33 | cpu_end = time.monotonic() 34 | end_stream.record_event(end) 35 | end.synchronize() 36 | cpu_time = (cpu_end - cpu_start) * 1000 37 | gpu_time = start.elapsed_time(end) 38 | msg = f'{trace_name} {name} cpu_time {cpu_time:.2f} ms ' 39 | msg += f'gpu_time {gpu_time:.2f} ms stream {stream}' 40 | print(msg, end_stream) 41 | -------------------------------------------------------------------------------- /bands/patchfusion/zoedepth/models/zoedepth_custom/__init__.py: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | # Copyright (c) 2022 Intelligent Systems Lab Org 4 | 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | # File author: Zhenyu Li 24 | 25 | from .zoedepth_custom import ZoeDepthCustom 26 | from .patchfusion import PatchFusion 27 | 28 | all_versions = { 29 | "custom": ZoeDepthCustom, 30 | "patchfusion": PatchFusion 31 | } 32 | 33 | get_version = lambda v : all_versions[v] -------------------------------------------------------------------------------- /bands/common/geom.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | from plyfile import PlyData, PlyElement 4 | 5 | def create_point_cloud(depth, u0, v0, fx=1000.0, fy=1000.0): 6 | depth_blured = cv2.medianBlur(depth, 5) 7 | 8 | H, W = depth_blured.shape 9 | x_row = np.arange(0, W) 10 | x = np.tile(x_row, (H, 1)) 11 | x = x.astype(np.float32) 12 | u = x - u0 13 | 14 | y_col = np.arange(0, H) 15 | y = np.tile(y_col, (W, 1)).T 16 | y = y.astype(np.float32) 17 | v = y - v0 18 | 19 | x = u / fx 20 | y = v / fy 21 | z = np.ones_like(x) 22 | pcl = np.stack([x, -y, -z], axis=2) 23 | 24 | return depth_blured[:, :, None] * pcl 25 | 26 | 27 | def save_point_cloud(pcl, rgb, filename, binary=True): 28 | assert pcl.shape[0] == rgb.shape[0] 29 | 30 | points_3d = np.hstack((pcl, rgb)) 31 | python_types = (float, float, float, int, int, int) 32 | npy_types = [('x', 'f4'), ('y', 'f4'), ('z', 'f4'), 33 | ('red', 'u1'), ('green', 'u1'), ('blue', 'u1')] 34 | 35 | # Format into Numpy structured array 36 | vertices = [] 37 | for row_idx in range(points_3d.shape[0]): 38 | cur_point = points_3d[row_idx] 39 | vertices.append( 40 | tuple( 41 | dtype(point) 42 | for dtype, point in zip(python_types, cur_point))) 43 | vertices_array = np.array(vertices, dtype=npy_types) 44 | el = PlyElement.describe(vertices_array, 'vertex') 45 | 46 | # write 47 | PlyData([el], text=(not binary)).write(filename) 48 | -------------------------------------------------------------------------------- /bands/d_anything/torchhub/facebookresearch_dinov2_main/dinov2/models/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | import logging 8 | 9 | from . import vision_transformer as vits 10 | 11 | 12 | logger = logging.getLogger("dinov2") 13 | 14 | 15 | def build_model(args, only_teacher=False, img_size=224): 16 | args.arch = args.arch.removesuffix("_memeff") 17 | if "vit" in args.arch: 18 | vit_kwargs = dict( 19 | img_size=img_size, 20 | patch_size=args.patch_size, 21 | init_values=args.layerscale, 22 | ffn_layer=args.ffn_layer, 23 | block_chunks=args.block_chunks, 24 | qkv_bias=args.qkv_bias, 25 | proj_bias=args.proj_bias, 26 | ffn_bias=args.ffn_bias, 27 | ) 28 | teacher = vits.__dict__[args.arch](**vit_kwargs) 29 | if only_teacher: 30 | return teacher, teacher.embed_dim 31 | student = vits.__dict__[args.arch]( 32 | **vit_kwargs, 33 | drop_path_rate=args.drop_path_rate, 34 | drop_path_uniform=args.drop_path_uniform, 35 | ) 36 | embed_dim = student.embed_dim 37 | return student, teacher, embed_dim 38 | 39 | 40 | def build_model_from_cfg(cfg, only_teacher=False): 41 | return build_model(cfg.student, only_teacher=only_teacher, img_size=cfg.crops.global_crops_size) 42 | -------------------------------------------------------------------------------- /bands/mmdet/core/bbox/assigners/ascend_assign_result.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from mmdet.utils import util_mixins 3 | 4 | 5 | class AscendAssignResult(util_mixins.NiceRepr): 6 | """Stores ascend assignments between predicted and truth boxes. 7 | 8 | Arguments: 9 | batch_num_gts (list[int]): the number of truth boxes considered. 10 | batch_pos_mask (IntTensor): Positive samples mask in all images. 11 | batch_neg_mask (IntTensor): Negative samples mask in all images. 12 | batch_max_overlaps (FloatTensor): The max overlaps of all bboxes 13 | and ground truth boxes. 14 | batch_anchor_gt_indes(None | LongTensor): The assigned truth 15 | box index of all anchors. 16 | batch_anchor_gt_labels(None | LongTensor): The gt labels 17 | of all anchors 18 | """ 19 | 20 | def __init__(self, 21 | batch_num_gts, 22 | batch_pos_mask, 23 | batch_neg_mask, 24 | batch_max_overlaps, 25 | batch_anchor_gt_indes=None, 26 | batch_anchor_gt_labels=None): 27 | self.batch_num_gts = batch_num_gts 28 | self.batch_pos_mask = batch_pos_mask 29 | self.batch_neg_mask = batch_neg_mask 30 | self.batch_max_overlaps = batch_max_overlaps 31 | self.batch_anchor_gt_indes = batch_anchor_gt_indes 32 | self.batch_anchor_gt_labels = batch_anchor_gt_labels 33 | # Interface for possible user-defined properties 34 | self._extra_properties = {} 35 | -------------------------------------------------------------------------------- /bands/mmdet/models/detectors/yolo.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | # Copyright (c) 2019 Western Digital Corporation or its affiliates. 3 | import torch 4 | 5 | from ..builder import DETECTORS 6 | from .single_stage import SingleStageDetector 7 | 8 | 9 | @DETECTORS.register_module() 10 | class YOLOV3(SingleStageDetector): 11 | 12 | def __init__(self, 13 | backbone, 14 | neck, 15 | bbox_head, 16 | train_cfg=None, 17 | test_cfg=None, 18 | pretrained=None, 19 | init_cfg=None): 20 | super(YOLOV3, self).__init__(backbone, neck, bbox_head, train_cfg, 21 | test_cfg, pretrained, init_cfg) 22 | 23 | def onnx_export(self, img, img_metas): 24 | """Test function for exporting to ONNX, without test time augmentation. 25 | 26 | Args: 27 | img (torch.Tensor): input images. 28 | img_metas (list[dict]): List of image information. 29 | 30 | Returns: 31 | tuple[Tensor, Tensor]: dets of shape [N, num_det, 5] 32 | and class labels of shape [N, num_det]. 33 | """ 34 | x = self.extract_feat(img) 35 | outs = self.bbox_head.forward(x) 36 | # get shape as tensor 37 | img_shape = torch._shape_as_tensor(img)[2:] 38 | img_metas[0]['img_shape_for_onnx'] = img_shape 39 | 40 | det_bboxes, det_labels = self.bbox_head.onnx_export(*outs, img_metas) 41 | 42 | return det_bboxes, det_labels 43 | -------------------------------------------------------------------------------- /bands/raft/LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2020, princeton-vl 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | * Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | * Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /bands/mmdet/core/bbox/samplers/pseudo_sampler.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | import torch 3 | 4 | from ..builder import BBOX_SAMPLERS 5 | from .base_sampler import BaseSampler 6 | from .sampling_result import SamplingResult 7 | 8 | 9 | @BBOX_SAMPLERS.register_module() 10 | class PseudoSampler(BaseSampler): 11 | """A pseudo sampler that does not do sampling actually.""" 12 | 13 | def __init__(self, **kwargs): 14 | pass 15 | 16 | def _sample_pos(self, **kwargs): 17 | """Sample positive samples.""" 18 | raise NotImplementedError 19 | 20 | def _sample_neg(self, **kwargs): 21 | """Sample negative samples.""" 22 | raise NotImplementedError 23 | 24 | def sample(self, assign_result, bboxes, gt_bboxes, *args, **kwargs): 25 | """Directly returns the positive and negative indices of samples. 26 | 27 | Args: 28 | assign_result (:obj:`AssignResult`): Assigned results 29 | bboxes (torch.Tensor): Bounding boxes 30 | gt_bboxes (torch.Tensor): Ground truth boxes 31 | 32 | Returns: 33 | :obj:`SamplingResult`: sampler results 34 | """ 35 | pos_inds = torch.nonzero( 36 | assign_result.gt_inds > 0, as_tuple=False).squeeze(-1).unique() 37 | neg_inds = torch.nonzero( 38 | assign_result.gt_inds == 0, as_tuple=False).squeeze(-1).unique() 39 | gt_flags = bboxes.new_zeros(bboxes.shape[0], dtype=torch.uint8) 40 | sampling_result = SamplingResult(pos_inds, neg_inds, bboxes, gt_bboxes, 41 | assign_result, gt_flags) 42 | return sampling_result 43 | -------------------------------------------------------------------------------- /bands/mmdet/utils/rfnext.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | try: 3 | from mmcv.cnn import RFSearchHook 4 | except ImportError: 5 | RFSearchHook = None 6 | 7 | 8 | def rfnext_init_model(detector, cfg): 9 | """Rcecptive field search via dilation rates. 10 | 11 | Please refer to `RF-Next: Efficient Receptive Field 12 | Search for Convolutional Neural Networks 13 | `_ for more details. 14 | 15 | Args: 16 | detector (nn.Module): The detector before initializing RF-Next. 17 | cfg (mmcv.Config): The config for RF-Next. 18 | If the RFSearchHook is defined in the cfg.custom_hooks, 19 | the detector will be initialized for RF-Next. 20 | """ 21 | 22 | if cfg.get('custom_hooks', None) is None: 23 | return 24 | custom_hook_types = [hook['type'] for hook in cfg.custom_hooks] 25 | if 'RFSearchHook' not in custom_hook_types: 26 | return 27 | 28 | index = custom_hook_types.index('RFSearchHook') 29 | rfsearch_cfg = cfg.custom_hooks[index] 30 | assert rfsearch_cfg['type'] == 'RFSearchHook' 31 | 32 | assert RFSearchHook is not None, 'Please install mmcv > 1.7.0' 33 | 34 | # initlize a RFSearchHook 35 | rfsearch_warp = RFSearchHook( 36 | mode=rfsearch_cfg.get('mode', 'search'), 37 | config=rfsearch_cfg.get('config', None), 38 | rfstructure_file=rfsearch_cfg.get('rfstructure_file', None), 39 | by_epoch=rfsearch_cfg.get('by_epoch', True), 40 | verbose=rfsearch_cfg.get('verbose', True), 41 | ) 42 | rfsearch_warp.init_model(detector) 43 | rfsearch_cfg['rfstructure_file'] = None 44 | -------------------------------------------------------------------------------- /bands/mmdet/models/builder.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | import warnings 3 | 4 | from mmcv.cnn import MODELS as MMCV_MODELS 5 | from mmcv.utils import Registry 6 | 7 | MODELS = Registry('models', parent=MMCV_MODELS) 8 | 9 | BACKBONES = MODELS 10 | NECKS = MODELS 11 | ROI_EXTRACTORS = MODELS 12 | SHARED_HEADS = MODELS 13 | HEADS = MODELS 14 | LOSSES = MODELS 15 | DETECTORS = MODELS 16 | 17 | 18 | def build_backbone(cfg): 19 | """Build backbone.""" 20 | return BACKBONES.build(cfg) 21 | 22 | 23 | def build_neck(cfg): 24 | """Build neck.""" 25 | return NECKS.build(cfg) 26 | 27 | 28 | def build_roi_extractor(cfg): 29 | """Build roi extractor.""" 30 | return ROI_EXTRACTORS.build(cfg) 31 | 32 | 33 | def build_shared_head(cfg): 34 | """Build shared head.""" 35 | return SHARED_HEADS.build(cfg) 36 | 37 | 38 | def build_head(cfg): 39 | """Build head.""" 40 | return HEADS.build(cfg) 41 | 42 | 43 | def build_loss(cfg): 44 | """Build loss.""" 45 | return LOSSES.build(cfg) 46 | 47 | 48 | def build_detector(cfg, train_cfg=None, test_cfg=None): 49 | """Build detector.""" 50 | if train_cfg is not None or test_cfg is not None: 51 | warnings.warn( 52 | 'train_cfg and test_cfg is deprecated, ' 53 | 'please specify them in model', UserWarning) 54 | assert cfg.get('train_cfg') is None or train_cfg is None, \ 55 | 'train_cfg specified in both outer field and model field ' 56 | assert cfg.get('test_cfg') is None or test_cfg is None, \ 57 | 'test_cfg specified in both outer field and model field ' 58 | return DETECTORS.build( 59 | cfg, default_args=dict(train_cfg=train_cfg, test_cfg=test_cfg)) 60 | -------------------------------------------------------------------------------- /bands/mmdet/datasets/api_wrappers/coco_api.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | # This file add snake case alias for coco api 3 | 4 | import warnings 5 | 6 | import pycocotools 7 | from pycocotools.coco import COCO as _COCO 8 | from pycocotools.cocoeval import COCOeval as _COCOeval 9 | 10 | 11 | class COCO(_COCO): 12 | """This class is almost the same as official pycocotools package. 13 | 14 | It implements some snake case function aliases. So that the COCO class has 15 | the same interface as LVIS class. 16 | """ 17 | 18 | def __init__(self, annotation_file=None): 19 | if getattr(pycocotools, '__version__', '0') >= '12.0.2': 20 | warnings.warn( 21 | 'mmpycocotools is deprecated. Please install official pycocotools by "pip install pycocotools"', # noqa: E501 22 | UserWarning) 23 | super().__init__(annotation_file=annotation_file) 24 | self.img_ann_map = self.imgToAnns 25 | self.cat_img_map = self.catToImgs 26 | 27 | def get_ann_ids(self, img_ids=[], cat_ids=[], area_rng=[], iscrowd=None): 28 | return self.getAnnIds(img_ids, cat_ids, area_rng, iscrowd) 29 | 30 | def get_cat_ids(self, cat_names=[], sup_names=[], cat_ids=[]): 31 | return self.getCatIds(cat_names, sup_names, cat_ids) 32 | 33 | def get_img_ids(self, img_ids=[], cat_ids=[]): 34 | return self.getImgIds(img_ids, cat_ids) 35 | 36 | def load_anns(self, ids): 37 | return self.loadAnns(ids) 38 | 39 | def load_cats(self, ids): 40 | return self.loadCats(ids) 41 | 42 | def load_imgs(self, ids): 43 | return self.loadImgs(ids) 44 | 45 | 46 | # just for the ease of import 47 | COCOeval = _COCOeval 48 | -------------------------------------------------------------------------------- /bands/mmdet/models/utils/builder.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | import torch.nn as nn 3 | from mmcv.utils import Registry, build_from_cfg 4 | 5 | TRANSFORMER = Registry('Transformer') 6 | LINEAR_LAYERS = Registry('linear layers') 7 | 8 | 9 | def build_transformer(cfg, default_args=None): 10 | """Builder for Transformer.""" 11 | return build_from_cfg(cfg, TRANSFORMER, default_args) 12 | 13 | 14 | LINEAR_LAYERS.register_module('Linear', module=nn.Linear) 15 | 16 | 17 | def build_linear_layer(cfg, *args, **kwargs): 18 | """Build linear layer. 19 | Args: 20 | cfg (None or dict): The linear layer config, which should contain: 21 | - type (str): Layer type. 22 | - layer args: Args needed to instantiate an linear layer. 23 | args (argument list): Arguments passed to the `__init__` 24 | method of the corresponding linear layer. 25 | kwargs (keyword arguments): Keyword arguments passed to the `__init__` 26 | method of the corresponding linear layer. 27 | Returns: 28 | nn.Module: Created linear layer. 29 | """ 30 | if cfg is None: 31 | cfg_ = dict(type='Linear') 32 | else: 33 | if not isinstance(cfg, dict): 34 | raise TypeError('cfg must be a dict') 35 | if 'type' not in cfg: 36 | raise KeyError('the cfg dict must contain the key "type"') 37 | cfg_ = cfg.copy() 38 | 39 | layer_type = cfg_.pop('type') 40 | if layer_type not in LINEAR_LAYERS: 41 | raise KeyError(f'Unrecognized linear type {layer_type}') 42 | else: 43 | linear_layer = LINEAR_LAYERS.get(layer_type) 44 | 45 | layer = linear_layer(*args, **kwargs, **cfg_) 46 | 47 | return layer 48 | -------------------------------------------------------------------------------- /bands/mmdet/models/seg_heads/panoptic_fusion_heads/base_panoptic_fusion_head.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from abc import ABCMeta, abstractmethod 3 | 4 | from mmcv.runner import BaseModule 5 | 6 | from ...builder import build_loss 7 | 8 | 9 | class BasePanopticFusionHead(BaseModule, metaclass=ABCMeta): 10 | """Base class for panoptic heads.""" 11 | 12 | def __init__(self, 13 | num_things_classes=80, 14 | num_stuff_classes=53, 15 | test_cfg=None, 16 | loss_panoptic=None, 17 | init_cfg=None, 18 | **kwargs): 19 | super(BasePanopticFusionHead, self).__init__(init_cfg) 20 | self.num_things_classes = num_things_classes 21 | self.num_stuff_classes = num_stuff_classes 22 | self.num_classes = num_things_classes + num_stuff_classes 23 | self.test_cfg = test_cfg 24 | 25 | if loss_panoptic: 26 | self.loss_panoptic = build_loss(loss_panoptic) 27 | else: 28 | self.loss_panoptic = None 29 | 30 | @property 31 | def with_loss(self): 32 | """bool: whether the panoptic head contains loss function.""" 33 | return self.loss_panoptic is not None 34 | 35 | @abstractmethod 36 | def forward_train(self, gt_masks=None, gt_semantic_seg=None, **kwargs): 37 | """Forward function during training.""" 38 | 39 | @abstractmethod 40 | def simple_test(self, 41 | img_metas, 42 | det_labels, 43 | mask_preds, 44 | seg_preds, 45 | det_bboxes, 46 | cfg=None, 47 | **kwargs): 48 | """Test without augmentation.""" 49 | -------------------------------------------------------------------------------- /bands/mmdet/datasets/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from .builder import DATASETS, PIPELINES, build_dataloader, build_dataset 3 | from .cityscapes import CityscapesDataset 4 | from .coco import CocoDataset 5 | from .coco_occluded import OccludedSeparatedCocoDataset 6 | from .coco_panoptic import CocoPanopticDataset 7 | from .custom import CustomDataset 8 | from .dataset_wrappers import (ClassBalancedDataset, ConcatDataset, 9 | MultiImageMixDataset, RepeatDataset) 10 | from .deepfashion import DeepFashionDataset 11 | from .lvis import LVISDataset, LVISV1Dataset, LVISV05Dataset 12 | from .objects365 import Objects365V1Dataset, Objects365V2Dataset 13 | from .openimages import OpenImagesChallengeDataset, OpenImagesDataset 14 | from .samplers import DistributedGroupSampler, DistributedSampler, GroupSampler 15 | from .utils import (NumClassCheckHook, get_loading_pipeline, 16 | replace_ImageToTensor) 17 | from .voc import VOCDataset 18 | from .wider_face import WIDERFaceDataset 19 | from .xml_style import XMLDataset 20 | 21 | __all__ = [ 22 | 'CustomDataset', 'XMLDataset', 'CocoDataset', 'DeepFashionDataset', 23 | 'VOCDataset', 'CityscapesDataset', 'LVISDataset', 'LVISV05Dataset', 24 | 'LVISV1Dataset', 'GroupSampler', 'DistributedGroupSampler', 25 | 'DistributedSampler', 'build_dataloader', 'ConcatDataset', 'RepeatDataset', 26 | 'ClassBalancedDataset', 'WIDERFaceDataset', 'DATASETS', 'PIPELINES', 27 | 'build_dataset', 'replace_ImageToTensor', 'get_loading_pipeline', 28 | 'NumClassCheckHook', 'CocoPanopticDataset', 'MultiImageMixDataset', 29 | 'OpenImagesDataset', 'OpenImagesChallengeDataset', 'Objects365V1Dataset', 30 | 'Objects365V2Dataset', 'OccludedSeparatedCocoDataset' 31 | ] 32 | -------------------------------------------------------------------------------- /bands/mmdet/core/bbox/samplers/mask_pseudo_sampler.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | """copy from 3 | https://github.com/ZwwWayne/K-Net/blob/main/knet/det/mask_pseudo_sampler.py.""" 4 | 5 | import torch 6 | 7 | from mmdet.core.bbox.builder import BBOX_SAMPLERS 8 | from .base_sampler import BaseSampler 9 | from .mask_sampling_result import MaskSamplingResult 10 | 11 | 12 | @BBOX_SAMPLERS.register_module() 13 | class MaskPseudoSampler(BaseSampler): 14 | """A pseudo sampler that does not do sampling actually.""" 15 | 16 | def __init__(self, **kwargs): 17 | pass 18 | 19 | def _sample_pos(self, **kwargs): 20 | """Sample positive samples.""" 21 | raise NotImplementedError 22 | 23 | def _sample_neg(self, **kwargs): 24 | """Sample negative samples.""" 25 | raise NotImplementedError 26 | 27 | def sample(self, assign_result, masks, gt_masks, **kwargs): 28 | """Directly returns the positive and negative indices of samples. 29 | 30 | Args: 31 | assign_result (:obj:`AssignResult`): Assigned results 32 | masks (torch.Tensor): Bounding boxes 33 | gt_masks (torch.Tensor): Ground truth boxes 34 | Returns: 35 | :obj:`SamplingResult`: sampler results 36 | """ 37 | pos_inds = torch.nonzero( 38 | assign_result.gt_inds > 0, as_tuple=False).squeeze(-1).unique() 39 | neg_inds = torch.nonzero( 40 | assign_result.gt_inds == 0, as_tuple=False).squeeze(-1).unique() 41 | gt_flags = masks.new_zeros(masks.shape[0], dtype=torch.uint8) 42 | sampling_result = MaskSamplingResult(pos_inds, neg_inds, masks, 43 | gt_masks, assign_result, gt_flags) 44 | return sampling_result 45 | -------------------------------------------------------------------------------- /bands/mmdet/core/bbox/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from .assigners import (AssignResult, BaseAssigner, CenterRegionAssigner, 3 | MaxIoUAssigner, RegionAssigner) 4 | from .builder import build_assigner, build_bbox_coder, build_sampler 5 | from .coder import (BaseBBoxCoder, DeltaXYWHBBoxCoder, DistancePointBBoxCoder, 6 | PseudoBBoxCoder, TBLRBBoxCoder) 7 | from .iou_calculators import BboxOverlaps2D, bbox_overlaps 8 | from .samplers import (BaseSampler, CombinedSampler, 9 | InstanceBalancedPosSampler, IoUBalancedNegSampler, 10 | OHEMSampler, PseudoSampler, RandomSampler, 11 | SamplingResult, ScoreHLRSampler) 12 | from .transforms import (bbox2distance, bbox2result, bbox2roi, 13 | bbox_cxcywh_to_xyxy, bbox_flip, bbox_mapping, 14 | bbox_mapping_back, bbox_rescale, bbox_xyxy_to_cxcywh, 15 | distance2bbox, find_inside_bboxes, roi2bbox) 16 | 17 | __all__ = [ 18 | 'bbox_overlaps', 'BboxOverlaps2D', 'BaseAssigner', 'MaxIoUAssigner', 19 | 'AssignResult', 'BaseSampler', 'PseudoSampler', 'RandomSampler', 20 | 'InstanceBalancedPosSampler', 'IoUBalancedNegSampler', 'CombinedSampler', 21 | 'OHEMSampler', 'SamplingResult', 'ScoreHLRSampler', 'build_assigner', 22 | 'build_sampler', 'bbox_flip', 'bbox_mapping', 'bbox_mapping_back', 23 | 'bbox2roi', 'roi2bbox', 'bbox2result', 'distance2bbox', 'bbox2distance', 24 | 'build_bbox_coder', 'BaseBBoxCoder', 'PseudoBBoxCoder', 25 | 'DeltaXYWHBBoxCoder', 'TBLRBBoxCoder', 'DistancePointBBoxCoder', 26 | 'CenterRegionAssigner', 'bbox_rescale', 'bbox_cxcywh_to_xyxy', 27 | 'bbox_xyxy_to_cxcywh', 'RegionAssigner', 'find_inside_bboxes' 28 | ] 29 | -------------------------------------------------------------------------------- /bands/mmdet/datasets/wider_face.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | import os.path as osp 3 | import xml.etree.ElementTree as ET 4 | 5 | import mmcv 6 | 7 | from .builder import DATASETS 8 | from .xml_style import XMLDataset 9 | 10 | 11 | @DATASETS.register_module() 12 | class WIDERFaceDataset(XMLDataset): 13 | """Reader for the WIDER Face dataset in PASCAL VOC format. 14 | 15 | Conversion scripts can be found in 16 | https://github.com/sovrasov/wider-face-pascal-voc-annotations 17 | """ 18 | CLASSES = ('face', ) 19 | 20 | PALETTE = [(0, 255, 0)] 21 | 22 | def __init__(self, **kwargs): 23 | super(WIDERFaceDataset, self).__init__(**kwargs) 24 | 25 | def load_annotations(self, ann_file): 26 | """Load annotation from WIDERFace XML style annotation file. 27 | 28 | Args: 29 | ann_file (str): Path of XML file. 30 | 31 | Returns: 32 | list[dict]: Annotation info from XML file. 33 | """ 34 | 35 | data_infos = [] 36 | img_ids = mmcv.list_from_file(ann_file) 37 | for img_id in img_ids: 38 | filename = f'{img_id}.jpg' 39 | xml_path = osp.join(self.img_prefix, 'Annotations', 40 | f'{img_id}.xml') 41 | tree = ET.parse(xml_path) 42 | root = tree.getroot() 43 | size = root.find('size') 44 | width = int(size.find('width').text) 45 | height = int(size.find('height').text) 46 | folder = root.find('folder').text 47 | data_infos.append( 48 | dict( 49 | id=img_id, 50 | filename=osp.join(folder, filename), 51 | width=width, 52 | height=height)) 53 | 54 | return data_infos 55 | -------------------------------------------------------------------------------- /bands/mmdet/models/losses/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from .accuracy import Accuracy, accuracy 3 | from .ae_loss import AssociativeEmbeddingLoss 4 | from .balanced_l1_loss import BalancedL1Loss, balanced_l1_loss 5 | from .cross_entropy_loss import (CrossEntropyLoss, binary_cross_entropy, 6 | cross_entropy, mask_cross_entropy) 7 | from .dice_loss import DiceLoss 8 | from .focal_loss import FocalLoss, sigmoid_focal_loss 9 | from .gaussian_focal_loss import GaussianFocalLoss 10 | from .gfocal_loss import DistributionFocalLoss, QualityFocalLoss 11 | from .ghm_loss import GHMC, GHMR 12 | from .iou_loss import (BoundedIoULoss, CIoULoss, DIoULoss, GIoULoss, IoULoss, 13 | bounded_iou_loss, iou_loss) 14 | from .kd_loss import KnowledgeDistillationKLDivLoss 15 | from .mse_loss import MSELoss, mse_loss 16 | from .pisa_loss import carl_loss, isr_p 17 | from .seesaw_loss import SeesawLoss 18 | from .smooth_l1_loss import L1Loss, SmoothL1Loss, l1_loss, smooth_l1_loss 19 | from .utils import reduce_loss, weight_reduce_loss, weighted_loss 20 | from .varifocal_loss import VarifocalLoss 21 | 22 | __all__ = [ 23 | 'accuracy', 'Accuracy', 'cross_entropy', 'binary_cross_entropy', 24 | 'mask_cross_entropy', 'CrossEntropyLoss', 'sigmoid_focal_loss', 25 | 'FocalLoss', 'smooth_l1_loss', 'SmoothL1Loss', 'balanced_l1_loss', 26 | 'BalancedL1Loss', 'mse_loss', 'MSELoss', 'iou_loss', 'bounded_iou_loss', 27 | 'IoULoss', 'BoundedIoULoss', 'GIoULoss', 'DIoULoss', 'CIoULoss', 'GHMC', 28 | 'GHMR', 'reduce_loss', 'weight_reduce_loss', 'weighted_loss', 'L1Loss', 29 | 'l1_loss', 'isr_p', 'carl_loss', 'AssociativeEmbeddingLoss', 30 | 'GaussianFocalLoss', 'QualityFocalLoss', 'DistributionFocalLoss', 31 | 'VarifocalLoss', 'KnowledgeDistillationKLDivLoss', 'SeesawLoss', 'DiceLoss' 32 | ] 33 | -------------------------------------------------------------------------------- /bands/d_anything/torchhub/facebookresearch_dinov2_main/dinov2/loss/koleo_loss.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | import logging 8 | 9 | import torch 10 | import torch.nn as nn 11 | import torch.nn.functional as F 12 | 13 | # import torch.distributed as dist 14 | 15 | 16 | logger = logging.getLogger("dinov2") 17 | 18 | 19 | class KoLeoLoss(nn.Module): 20 | """Kozachenko-Leonenko entropic loss regularizer from Sablayrolles et al. - 2018 - Spreading vectors for similarity search""" 21 | 22 | def __init__(self): 23 | super().__init__() 24 | self.pdist = nn.PairwiseDistance(2, eps=1e-8) 25 | 26 | def pairwise_NNs_inner(self, x): 27 | """ 28 | Pairwise nearest neighbors for L2-normalized vectors. 29 | Uses Torch rather than Faiss to remain on GPU. 30 | """ 31 | # parwise dot products (= inverse distance) 32 | dots = torch.mm(x, x.t()) 33 | n = x.shape[0] 34 | dots.view(-1)[:: (n + 1)].fill_(-1) # Trick to fill diagonal with -1 35 | # max inner prod -> min distance 36 | _, I = torch.max(dots, dim=1) # noqa: E741 37 | return I 38 | 39 | def forward(self, student_output, eps=1e-8): 40 | """ 41 | Args: 42 | student_output (BxD): backbone output of student 43 | """ 44 | with torch.cuda.amp.autocast(enabled=False): 45 | student_output = F.normalize(student_output, eps=eps, p=2, dim=-1) 46 | I = self.pairwise_NNs_inner(student_output) # noqa: E741 47 | distances = self.pdist(student_output, student_output[I]) # BxD, BxD -> B 48 | loss = -torch.log(distances + eps).mean() 49 | return loss 50 | -------------------------------------------------------------------------------- /bands/mmdet/datasets/pipelines/compose.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | import collections 3 | 4 | from mmcv.utils import build_from_cfg 5 | 6 | from ..builder import PIPELINES 7 | 8 | 9 | @PIPELINES.register_module() 10 | class Compose: 11 | """Compose multiple transforms sequentially. 12 | 13 | Args: 14 | transforms (Sequence[dict | callable]): Sequence of transform object or 15 | config dict to be composed. 16 | """ 17 | 18 | def __init__(self, transforms): 19 | assert isinstance(transforms, collections.abc.Sequence) 20 | self.transforms = [] 21 | for transform in transforms: 22 | if isinstance(transform, dict): 23 | transform = build_from_cfg(transform, PIPELINES) 24 | self.transforms.append(transform) 25 | elif callable(transform): 26 | self.transforms.append(transform) 27 | else: 28 | raise TypeError('transform must be callable or a dict') 29 | 30 | def __call__(self, data): 31 | """Call function to apply transforms sequentially. 32 | 33 | Args: 34 | data (dict): A result dict contains the data to transform. 35 | 36 | Returns: 37 | dict: Transformed data. 38 | """ 39 | 40 | for t in self.transforms: 41 | data = t(data) 42 | if data is None: 43 | return None 44 | return data 45 | 46 | def __repr__(self): 47 | format_string = self.__class__.__name__ + '(' 48 | for t in self.transforms: 49 | str_ = t.__repr__() 50 | if 'Compose(' in str_: 51 | str_ = str_.replace('\n', '\n ') 52 | format_string += '\n' 53 | format_string += f' {str_}' 54 | format_string += '\n)' 55 | return format_string 56 | -------------------------------------------------------------------------------- /bands/mmdet/models/detectors/cascade_rcnn.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from ..builder import DETECTORS 3 | from .two_stage import TwoStageDetector 4 | 5 | 6 | @DETECTORS.register_module() 7 | class CascadeRCNN(TwoStageDetector): 8 | r"""Implementation of `Cascade R-CNN: Delving into High Quality Object 9 | Detection `_""" 10 | 11 | def __init__(self, 12 | backbone, 13 | neck=None, 14 | rpn_head=None, 15 | roi_head=None, 16 | train_cfg=None, 17 | test_cfg=None, 18 | pretrained=None, 19 | init_cfg=None): 20 | super(CascadeRCNN, self).__init__( 21 | backbone=backbone, 22 | neck=neck, 23 | rpn_head=rpn_head, 24 | roi_head=roi_head, 25 | train_cfg=train_cfg, 26 | test_cfg=test_cfg, 27 | pretrained=pretrained, 28 | init_cfg=init_cfg) 29 | 30 | def show_result(self, data, result, **kwargs): 31 | """Show prediction results of the detector. 32 | 33 | Args: 34 | data (str or np.ndarray): Image filename or loaded image. 35 | result (Tensor or tuple): The results to draw over `img` 36 | bbox_result or (bbox_result, segm_result). 37 | 38 | Returns: 39 | np.ndarray: The image with bboxes drawn on it. 40 | """ 41 | if self.with_mask: 42 | ms_bbox_result, ms_segm_result = result 43 | if isinstance(ms_bbox_result, dict): 44 | result = (ms_bbox_result['ensemble'], 45 | ms_segm_result['ensemble']) 46 | else: 47 | if isinstance(result, dict): 48 | result = result['ensemble'] 49 | return super(CascadeRCNN, self).show_result(data, result, **kwargs) 50 | -------------------------------------------------------------------------------- /bands/mmdet/datasets/pipelines/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from .auto_augment import (AutoAugment, BrightnessTransform, ColorTransform, 3 | ContrastTransform, EqualizeTransform, Rotate, Shear, 4 | Translate) 5 | from .compose import Compose 6 | from .formatting import (Collect, DefaultFormatBundle, ImageToTensor, 7 | ToDataContainer, ToTensor, Transpose, to_tensor) 8 | from .instaboost import InstaBoost 9 | from .loading import (FilterAnnotations, LoadAnnotations, LoadImageFromFile, 10 | LoadImageFromWebcam, LoadMultiChannelImageFromFiles, 11 | LoadPanopticAnnotations, LoadProposals) 12 | from .test_time_aug import MultiScaleFlipAug 13 | from .transforms import (Albu, CopyPaste, CutOut, Expand, MinIoURandomCrop, 14 | MixUp, Mosaic, Normalize, Pad, PhotoMetricDistortion, 15 | RandomAffine, RandomCenterCropPad, RandomCrop, 16 | RandomFlip, RandomShift, Resize, SegRescale, 17 | YOLOXHSVRandomAug) 18 | 19 | __all__ = [ 20 | 'Compose', 'to_tensor', 'ToTensor', 'ImageToTensor', 'ToDataContainer', 21 | 'Transpose', 'Collect', 'DefaultFormatBundle', 'LoadAnnotations', 22 | 'LoadImageFromFile', 'LoadImageFromWebcam', 'LoadPanopticAnnotations', 23 | 'LoadMultiChannelImageFromFiles', 'LoadProposals', 'FilterAnnotations', 24 | 'MultiScaleFlipAug', 'Resize', 'RandomFlip', 'Pad', 'RandomCrop', 25 | 'Normalize', 'SegRescale', 'MinIoURandomCrop', 'Expand', 26 | 'PhotoMetricDistortion', 'Albu', 'InstaBoost', 'RandomCenterCropPad', 27 | 'AutoAugment', 'CutOut', 'Shear', 'Rotate', 'ColorTransform', 28 | 'EqualizeTransform', 'BrightnessTransform', 'ContrastTransform', 29 | 'Translate', 'RandomShift', 'Mosaic', 'MixUp', 'RandomAffine', 30 | 'YOLOXHSVRandomAug', 'CopyPaste' 31 | ] 32 | -------------------------------------------------------------------------------- /_base_/datasets/coco_instance.py: -------------------------------------------------------------------------------- 1 | # dataset settings 2 | dataset_type = 'CocoDataset' 3 | data_root = 'data/coco/' 4 | img_norm_cfg = dict( 5 | mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True) 6 | train_pipeline = [ 7 | dict(type='LoadImageFromFile'), 8 | dict(type='LoadAnnotations', with_bbox=True, with_mask=True), 9 | dict(type='Resize', img_scale=(1333, 800), keep_ratio=True), 10 | dict(type='RandomFlip', flip_ratio=0.5), 11 | dict(type='Normalize', **img_norm_cfg), 12 | dict(type='Pad', size_divisor=32), 13 | dict(type='DefaultFormatBundle'), 14 | dict(type='Collect', keys=['img', 'gt_bboxes', 'gt_labels', 'gt_masks']), 15 | ] 16 | test_pipeline = [ 17 | dict(type='LoadImageFromFile'), 18 | dict( 19 | type='MultiScaleFlipAug', 20 | img_scale=(1333, 800), 21 | flip=False, 22 | transforms=[ 23 | dict(type='Resize', keep_ratio=True), 24 | dict(type='RandomFlip'), 25 | dict(type='Normalize', **img_norm_cfg), 26 | dict(type='Pad', size_divisor=32), 27 | dict(type='ImageToTensor', keys=['img']), 28 | dict(type='Collect', keys=['img']), 29 | ]) 30 | ] 31 | data = dict( 32 | samples_per_gpu=2, 33 | workers_per_gpu=2, 34 | train=dict( 35 | type=dataset_type, 36 | ann_file=data_root + 'annotations/instances_train2017.json', 37 | img_prefix=data_root + 'train2017/', 38 | pipeline=train_pipeline), 39 | val=dict( 40 | type=dataset_type, 41 | ann_file=data_root + 'annotations/instances_val2017.json', 42 | img_prefix=data_root + 'val2017/', 43 | pipeline=test_pipeline), 44 | test=dict( 45 | type=dataset_type, 46 | ann_file=data_root + 'annotations/instances_val2017.json', 47 | img_prefix=data_root + 'val2017/', 48 | pipeline=test_pipeline)) 49 | evaluation = dict(metric=['bbox', 'segm']) 50 | -------------------------------------------------------------------------------- /bands/mmdet/models/utils/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from .brick_wrappers import AdaptiveAvgPool2d, adaptive_avg_pool2d 3 | from .builder import build_linear_layer, build_transformer 4 | from .ckpt_convert import pvt_convert 5 | from .conv_upsample import ConvUpsample 6 | from .csp_layer import CSPLayer 7 | from .gaussian_target import gaussian_radius, gen_gaussian_target 8 | from .inverted_residual import InvertedResidual 9 | from .make_divisible import make_divisible 10 | from .misc import interpolate_as, sigmoid_geometric_mean 11 | from .normed_predictor import NormedConv2d, NormedLinear 12 | from .panoptic_gt_processing import preprocess_panoptic_gt 13 | from .point_sample import (get_uncertain_point_coords_with_randomness, 14 | get_uncertainty) 15 | from .positional_encoding import (LearnedPositionalEncoding, 16 | SinePositionalEncoding) 17 | from .res_layer import ResLayer, SimplifiedBasicBlock 18 | from .se_layer import DyReLU, SELayer 19 | from .transformer import (DetrTransformerDecoder, DetrTransformerDecoderLayer, 20 | DynamicConv, PatchEmbed, Transformer, nchw_to_nlc, 21 | nlc_to_nchw) 22 | 23 | __all__ = [ 24 | 'ResLayer', 'gaussian_radius', 'gen_gaussian_target', 25 | 'DetrTransformerDecoderLayer', 'DetrTransformerDecoder', 'Transformer', 26 | 'build_transformer', 'build_linear_layer', 'SinePositionalEncoding', 27 | 'LearnedPositionalEncoding', 'DynamicConv', 'SimplifiedBasicBlock', 28 | 'NormedLinear', 'NormedConv2d', 'make_divisible', 'InvertedResidual', 29 | 'SELayer', 'interpolate_as', 'ConvUpsample', 'CSPLayer', 30 | 'adaptive_avg_pool2d', 'AdaptiveAvgPool2d', 'PatchEmbed', 'nchw_to_nlc', 31 | 'nlc_to_nchw', 'pvt_convert', 'sigmoid_geometric_mean', 32 | 'preprocess_panoptic_gt', 'DyReLU', 33 | 'get_uncertain_point_coords_with_randomness', 'get_uncertainty' 34 | ] 35 | -------------------------------------------------------------------------------- /bands/mmdet/utils/split_batch.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | import torch 3 | 4 | 5 | def split_batch(img, img_metas, kwargs): 6 | """Split data_batch by tags. 7 | 8 | Code is modified from 9 | # noqa: E501 10 | 11 | Args: 12 | img (Tensor): of shape (N, C, H, W) encoding input images. 13 | Typically these should be mean centered and std scaled. 14 | img_metas (list[dict]): List of image info dict where each dict 15 | has: 'img_shape', 'scale_factor', 'flip', and may also contain 16 | 'filename', 'ori_shape', 'pad_shape', and 'img_norm_cfg'. 17 | For details on the values of these keys, see 18 | :class:`mmdet.datasets.pipelines.Collect`. 19 | kwargs (dict): Specific to concrete implementation. 20 | 21 | Returns: 22 | data_groups (dict): a dict that data_batch splited by tags, 23 | such as 'sup', 'unsup_teacher', and 'unsup_student'. 24 | """ 25 | 26 | # only stack img in the batch 27 | def fuse_list(obj_list, obj): 28 | return torch.stack(obj_list) if isinstance(obj, 29 | torch.Tensor) else obj_list 30 | 31 | # select data with tag from data_batch 32 | def select_group(data_batch, current_tag): 33 | group_flag = [tag == current_tag for tag in data_batch['tag']] 34 | return { 35 | k: fuse_list([vv for vv, gf in zip(v, group_flag) if gf], v) 36 | for k, v in data_batch.items() 37 | } 38 | 39 | kwargs.update({'img': img, 'img_metas': img_metas}) 40 | kwargs.update({'tag': [meta['tag'] for meta in img_metas]}) 41 | tags = list(set(kwargs['tag'])) 42 | data_groups = {tag: select_group(kwargs, tag) for tag in tags} 43 | for tag, group in data_groups.items(): 44 | group.pop('tag') 45 | return data_groups 46 | -------------------------------------------------------------------------------- /bands/d_anything/torchhub/facebookresearch_dinov2_main/dinov2/run/eval/knn.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | import logging 8 | import os 9 | import sys 10 | 11 | from dinov2.eval.knn import get_args_parser as get_knn_args_parser 12 | from dinov2.logging import setup_logging 13 | from dinov2.run.submit import get_args_parser, submit_jobs 14 | 15 | 16 | logger = logging.getLogger("dinov2") 17 | 18 | 19 | class Evaluator: 20 | def __init__(self, args): 21 | self.args = args 22 | 23 | def __call__(self): 24 | from dinov2.eval.knn import main as knn_main 25 | 26 | self._setup_args() 27 | knn_main(self.args) 28 | 29 | def checkpoint(self): 30 | import submitit 31 | 32 | logger.info(f"Requeuing {self.args}") 33 | empty = type(self)(self.args) 34 | return submitit.helpers.DelayedSubmission(empty) 35 | 36 | def _setup_args(self): 37 | import submitit 38 | 39 | job_env = submitit.JobEnvironment() 40 | self.args.output_dir = self.args.output_dir.replace("%j", str(job_env.job_id)) 41 | logger.info(f"Process group: {job_env.num_tasks} tasks, rank: {job_env.global_rank}") 42 | logger.info(f"Args: {self.args}") 43 | 44 | 45 | def main(): 46 | description = "Submitit launcher for DINOv2 k-NN evaluation" 47 | knn_args_parser = get_knn_args_parser(add_help=False) 48 | parents = [knn_args_parser] 49 | args_parser = get_args_parser(description=description, parents=parents) 50 | args = args_parser.parse_args() 51 | 52 | setup_logging() 53 | 54 | assert os.path.exists(args.config_file), "Configuration file does not exist!" 55 | submit_jobs(Evaluator, args, name="dinov2:knn") 56 | return 0 57 | 58 | 59 | if __name__ == "__main__": 60 | sys.exit(main()) 61 | -------------------------------------------------------------------------------- /bands/d_anything/torchhub/facebookresearch_dinov2_main/dinov2/run/train/train.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | import logging 8 | import os 9 | import sys 10 | 11 | from dinov2.logging import setup_logging 12 | from dinov2.train import get_args_parser as get_train_args_parser 13 | from dinov2.run.submit import get_args_parser, submit_jobs 14 | 15 | 16 | logger = logging.getLogger("dinov2") 17 | 18 | 19 | class Trainer(object): 20 | def __init__(self, args): 21 | self.args = args 22 | 23 | def __call__(self): 24 | from dinov2.train import main as train_main 25 | 26 | self._setup_args() 27 | train_main(self.args) 28 | 29 | def checkpoint(self): 30 | import submitit 31 | 32 | logger.info(f"Requeuing {self.args}") 33 | empty = type(self)(self.args) 34 | return submitit.helpers.DelayedSubmission(empty) 35 | 36 | def _setup_args(self): 37 | import submitit 38 | 39 | job_env = submitit.JobEnvironment() 40 | self.args.output_dir = self.args.output_dir.replace("%j", str(job_env.job_id)) 41 | logger.info(f"Process group: {job_env.num_tasks} tasks, rank: {job_env.global_rank}") 42 | logger.info(f"Args: {self.args}") 43 | 44 | 45 | def main(): 46 | description = "Submitit launcher for DINOv2 training" 47 | train_args_parser = get_train_args_parser(add_help=False) 48 | parents = [train_args_parser] 49 | args_parser = get_args_parser(description=description, parents=parents) 50 | args = args_parser.parse_args() 51 | 52 | setup_logging() 53 | 54 | assert os.path.exists(args.config_file), "Configuration file does not exist!" 55 | submit_jobs(Trainer, args, name="dinov2:train") 56 | return 0 57 | 58 | 59 | if __name__ == "__main__": 60 | sys.exit(main()) 61 | -------------------------------------------------------------------------------- /bands/d_anything/torchhub/facebookresearch_dinov2_main/dinov2/run/eval/linear.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | import logging 8 | import os 9 | import sys 10 | 11 | from dinov2.eval.linear import get_args_parser as get_linear_args_parser 12 | from dinov2.logging import setup_logging 13 | from dinov2.run.submit import get_args_parser, submit_jobs 14 | 15 | 16 | logger = logging.getLogger("dinov2") 17 | 18 | 19 | class Evaluator: 20 | def __init__(self, args): 21 | self.args = args 22 | 23 | def __call__(self): 24 | from dinov2.eval.linear import main as linear_main 25 | 26 | self._setup_args() 27 | linear_main(self.args) 28 | 29 | def checkpoint(self): 30 | import submitit 31 | 32 | logger.info(f"Requeuing {self.args}") 33 | empty = type(self)(self.args) 34 | return submitit.helpers.DelayedSubmission(empty) 35 | 36 | def _setup_args(self): 37 | import submitit 38 | 39 | job_env = submitit.JobEnvironment() 40 | self.args.output_dir = self.args.output_dir.replace("%j", str(job_env.job_id)) 41 | logger.info(f"Process group: {job_env.num_tasks} tasks, rank: {job_env.global_rank}") 42 | logger.info(f"Args: {self.args}") 43 | 44 | 45 | def main(): 46 | description = "Submitit launcher for DINOv2 linear evaluation" 47 | linear_args_parser = get_linear_args_parser(add_help=False) 48 | parents = [linear_args_parser] 49 | args_parser = get_args_parser(description=description, parents=parents) 50 | args = args_parser.parse_args() 51 | 52 | setup_logging() 53 | 54 | assert os.path.exists(args.config_file), "Configuration file does not exist!" 55 | submit_jobs(Evaluator, args, name="dinov2:linear") 56 | return 0 57 | 58 | 59 | if __name__ == "__main__": 60 | sys.exit(main()) 61 | -------------------------------------------------------------------------------- /bands/patchfusion/zoedepth/models/zoedepth/config_zoedepth.json: -------------------------------------------------------------------------------- 1 | { 2 | "model": { 3 | "name": "ZoeDepth", 4 | "version_name": "v1", 5 | "n_bins": 64, 6 | "bin_embedding_dim": 128, 7 | "bin_centers_type": "softplus", 8 | "n_attractors":[16, 8, 4, 1], 9 | "attractor_alpha": 1000, 10 | "attractor_gamma": 2, 11 | "attractor_kind" : "mean", 12 | "attractor_type" : "inv", 13 | "midas_model_type" : "DPT_BEiT_L_384", 14 | "min_temp": 0.0212, 15 | "max_temp": 50.0, 16 | "output_distribution": "logbinomial", 17 | "memory_efficient": true, 18 | "inverse_midas": false, 19 | "img_size": [392, 518] 20 | }, 21 | 22 | "train": { 23 | "train_midas": true, 24 | "use_pretrained_midas": true, 25 | "trainer": "zoedepth", 26 | "epochs": 5, 27 | "bs": 16, 28 | "optim_kwargs": {"lr": 0.000161, "wd": 0.01}, 29 | "sched_kwargs": {"div_factor": 1, "final_div_factor": 10000, "pct_start": 0.7, "three_phase":false, "cycle_momentum": true}, 30 | "same_lr": false, 31 | "w_si": 1, 32 | "w_domain": 0.2, 33 | "w_reg": 0, 34 | "w_grad": 0, 35 | "avoid_boundary": false, 36 | "random_crop": false, 37 | "input_width": 640, 38 | "input_height": 480, 39 | "midas_lr_factor": 50, 40 | "encoder_lr_factor":50, 41 | "pos_enc_lr_factor":50, 42 | "freeze_midas_bn": true 43 | 44 | }, 45 | 46 | "infer":{ 47 | "train_midas": false, 48 | "use_pretrained_midas": false, 49 | "pretrained_resource" : "url::https://github.com/isl-org/ZoeDepth/releases/download/v1.0/ZoeD_M12_N.pt", 50 | "force_keep_ar": true 51 | }, 52 | 53 | "eval":{ 54 | "train_midas": false, 55 | "use_pretrained_midas": false, 56 | "pretrained_resource" : "url::https://github.com/isl-org/ZoeDepth/releases/download/v1.0/ZoeD_M12_N.pt" 57 | } 58 | } -------------------------------------------------------------------------------- /bands/mmdet/core/hook/sync_norm_hook.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from collections import OrderedDict 3 | 4 | from mmcv.runner import get_dist_info 5 | from mmcv.runner.hooks import HOOKS, Hook 6 | from torch import nn 7 | 8 | from ..utils.dist_utils import all_reduce_dict 9 | 10 | 11 | def get_norm_states(module): 12 | async_norm_states = OrderedDict() 13 | for name, child in module.named_modules(): 14 | if isinstance(child, nn.modules.batchnorm._NormBase): 15 | for k, v in child.state_dict().items(): 16 | async_norm_states['.'.join([name, k])] = v 17 | return async_norm_states 18 | 19 | 20 | @HOOKS.register_module() 21 | class SyncNormHook(Hook): 22 | """Synchronize Norm states after training epoch, currently used in YOLOX. 23 | 24 | Args: 25 | num_last_epochs (int): The number of latter epochs in the end of the 26 | training to switch to synchronizing norm interval. Default: 15. 27 | interval (int): Synchronizing norm interval. Default: 1. 28 | """ 29 | 30 | def __init__(self, num_last_epochs=15, interval=1): 31 | self.interval = interval 32 | self.num_last_epochs = num_last_epochs 33 | 34 | def before_train_epoch(self, runner): 35 | epoch = runner.epoch 36 | if (epoch + 1) == runner.max_epochs - self.num_last_epochs: 37 | # Synchronize norm every epoch. 38 | self.interval = 1 39 | 40 | def after_train_epoch(self, runner): 41 | """Synchronizing norm.""" 42 | epoch = runner.epoch 43 | module = runner.model 44 | if (epoch + 1) % self.interval == 0: 45 | _, world_size = get_dist_info() 46 | if world_size == 1: 47 | return 48 | norm_states = get_norm_states(module) 49 | if len(norm_states) == 0: 50 | return 51 | norm_states = all_reduce_dict(norm_states, op='mean') 52 | module.load_state_dict(norm_states, strict=False) 53 | -------------------------------------------------------------------------------- /bands/patchfusion/zoedepth/utils/arg_utils.py: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | # Copyright (c) 2022 Intelligent Systems Lab Org 4 | 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | # File author: Shariq Farooq Bhat 24 | 25 | def infer_type(x): # hacky way to infer type from string args 26 | if not isinstance(x, str): 27 | return x 28 | 29 | try: 30 | x = int(x) 31 | return x 32 | except ValueError: 33 | pass 34 | 35 | try: 36 | x = float(x) 37 | return x 38 | except ValueError: 39 | pass 40 | 41 | return x 42 | 43 | 44 | def parse_unknown(unknown_args): 45 | clean = [] 46 | for a in unknown_args: 47 | if "=" in a: 48 | k, v = a.split("=") 49 | clean.extend([k, v]) 50 | else: 51 | clean.append(a) 52 | 53 | keys = clean[::2] 54 | values = clean[1::2] 55 | return {k.replace("--", ""): infer_type(v) for k, v in zip(keys, values)} 56 | -------------------------------------------------------------------------------- /bands/d_anything/torchhub/facebookresearch_dinov2_main/dinov2/run/eval/log_regression.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | import logging 8 | import os 9 | import sys 10 | 11 | from dinov2.eval.log_regression import get_args_parser as get_log_regression_args_parser 12 | from dinov2.logging import setup_logging 13 | from dinov2.run.submit import get_args_parser, submit_jobs 14 | 15 | 16 | logger = logging.getLogger("dinov2") 17 | 18 | 19 | class Evaluator: 20 | def __init__(self, args): 21 | self.args = args 22 | 23 | def __call__(self): 24 | from dinov2.eval.log_regression import main as log_regression_main 25 | 26 | self._setup_args() 27 | log_regression_main(self.args) 28 | 29 | def checkpoint(self): 30 | import submitit 31 | 32 | logger.info(f"Requeuing {self.args}") 33 | empty = type(self)(self.args) 34 | return submitit.helpers.DelayedSubmission(empty) 35 | 36 | def _setup_args(self): 37 | import submitit 38 | 39 | job_env = submitit.JobEnvironment() 40 | self.args.output_dir = self.args.output_dir.replace("%j", str(job_env.job_id)) 41 | logger.info(f"Process group: {job_env.num_tasks} tasks, rank: {job_env.global_rank}") 42 | logger.info(f"Args: {self.args}") 43 | 44 | 45 | def main(): 46 | description = "Submitit launcher for DINOv2 logistic evaluation" 47 | log_regression_args_parser = get_log_regression_args_parser(add_help=False) 48 | parents = [log_regression_args_parser] 49 | args_parser = get_args_parser(description=description, parents=parents) 50 | args = args_parser.parse_args() 51 | 52 | setup_logging() 53 | 54 | assert os.path.exists(args.config_file), "Configuration file does not exist!" 55 | submit_jobs(Evaluator, args, name="dinov2:logreg") 56 | return 0 57 | 58 | 59 | if __name__ == "__main__": 60 | sys.exit(main()) 61 | -------------------------------------------------------------------------------- /bands/mmdet/models/utils/brick_wrappers.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | import torch 3 | import torch.nn as nn 4 | import torch.nn.functional as F 5 | from mmcv.cnn.bricks.wrappers import NewEmptyTensorOp, obsolete_torch_version 6 | 7 | if torch.__version__ == 'parrots': 8 | TORCH_VERSION = torch.__version__ 9 | else: 10 | # torch.__version__ could be 1.3.1+cu92, we only need the first two 11 | # for comparison 12 | TORCH_VERSION = tuple(int(x) for x in torch.__version__.split('.')[:2]) 13 | 14 | 15 | def adaptive_avg_pool2d(input, output_size): 16 | """Handle empty batch dimension to adaptive_avg_pool2d. 17 | 18 | Args: 19 | input (tensor): 4D tensor. 20 | output_size (int, tuple[int,int]): the target output size. 21 | """ 22 | if input.numel() == 0 and obsolete_torch_version(TORCH_VERSION, (1, 9)): 23 | if isinstance(output_size, int): 24 | output_size = [output_size, output_size] 25 | output_size = [*input.shape[:2], *output_size] 26 | empty = NewEmptyTensorOp.apply(input, output_size) 27 | return empty 28 | else: 29 | return F.adaptive_avg_pool2d(input, output_size) 30 | 31 | 32 | class AdaptiveAvgPool2d(nn.AdaptiveAvgPool2d): 33 | """Handle empty batch dimension to AdaptiveAvgPool2d.""" 34 | 35 | def forward(self, x): 36 | # PyTorch 1.9 does not support empty tensor inference yet 37 | if x.numel() == 0 and obsolete_torch_version(TORCH_VERSION, (1, 9)): 38 | output_size = self.output_size 39 | if isinstance(output_size, int): 40 | output_size = [output_size, output_size] 41 | else: 42 | output_size = [ 43 | v if v is not None else d 44 | for v, d in zip(output_size, 45 | x.size()[-2:]) 46 | ] 47 | output_size = [*x.shape[:2], *output_size] 48 | empty = NewEmptyTensorOp.apply(x, output_size) 49 | return empty 50 | 51 | return super().forward(x) 52 | -------------------------------------------------------------------------------- /bands/mmdet/models/roi_heads/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from .base_roi_head import BaseRoIHead 3 | from .bbox_heads import (BBoxHead, ConvFCBBoxHead, DIIHead, 4 | DoubleConvFCBBoxHead, SABLHead, SCNetBBoxHead, 5 | Shared2FCBBoxHead, Shared4Conv1FCBBoxHead) 6 | from .cascade_roi_head import CascadeRoIHead 7 | from .double_roi_head import DoubleHeadRoIHead 8 | from .dynamic_roi_head import DynamicRoIHead 9 | from .grid_roi_head import GridRoIHead 10 | from .htc_roi_head import HybridTaskCascadeRoIHead 11 | from .mask_heads import (CoarseMaskHead, FCNMaskHead, FeatureRelayHead, 12 | FusedSemanticHead, GlobalContextHead, GridHead, 13 | HTCMaskHead, MaskIoUHead, MaskPointHead, 14 | SCNetMaskHead, SCNetSemanticHead) 15 | from .mask_scoring_roi_head import MaskScoringRoIHead 16 | from .pisa_roi_head import PISARoIHead 17 | from .point_rend_roi_head import PointRendRoIHead 18 | from .roi_extractors import (BaseRoIExtractor, GenericRoIExtractor, 19 | SingleRoIExtractor) 20 | from .scnet_roi_head import SCNetRoIHead 21 | from .shared_heads import ResLayer 22 | from .sparse_roi_head import SparseRoIHead 23 | from .standard_roi_head import StandardRoIHead 24 | from .trident_roi_head import TridentRoIHead 25 | 26 | __all__ = [ 27 | 'BaseRoIHead', 'CascadeRoIHead', 'DoubleHeadRoIHead', 'MaskScoringRoIHead', 28 | 'HybridTaskCascadeRoIHead', 'GridRoIHead', 'ResLayer', 'BBoxHead', 29 | 'ConvFCBBoxHead', 'DIIHead', 'SABLHead', 'Shared2FCBBoxHead', 30 | 'StandardRoIHead', 'Shared4Conv1FCBBoxHead', 'DoubleConvFCBBoxHead', 31 | 'FCNMaskHead', 'HTCMaskHead', 'FusedSemanticHead', 'GridHead', 32 | 'MaskIoUHead', 'BaseRoIExtractor', 'GenericRoIExtractor', 33 | 'SingleRoIExtractor', 'PISARoIHead', 'PointRendRoIHead', 'MaskPointHead', 34 | 'CoarseMaskHead', 'DynamicRoIHead', 'SparseRoIHead', 'TridentRoIHead', 35 | 'SCNetRoIHead', 'SCNetMaskHead', 'SCNetSemanticHead', 'SCNetBBoxHead', 36 | 'FeatureRelayHead', 'GlobalContextHead' 37 | ] 38 | -------------------------------------------------------------------------------- /bands/mmdet/models/losses/mse_loss.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | import torch.nn as nn 3 | import torch.nn.functional as F 4 | 5 | from ..builder import LOSSES 6 | from .utils import weighted_loss 7 | 8 | 9 | @weighted_loss 10 | def mse_loss(pred, target): 11 | """Wrapper of mse loss.""" 12 | return F.mse_loss(pred, target, reduction='none') 13 | 14 | 15 | @LOSSES.register_module() 16 | class MSELoss(nn.Module): 17 | """MSELoss. 18 | 19 | Args: 20 | reduction (str, optional): The method that reduces the loss to a 21 | scalar. Options are "none", "mean" and "sum". 22 | loss_weight (float, optional): The weight of the loss. Defaults to 1.0 23 | """ 24 | 25 | def __init__(self, reduction='mean', loss_weight=1.0): 26 | super().__init__() 27 | self.reduction = reduction 28 | self.loss_weight = loss_weight 29 | 30 | def forward(self, 31 | pred, 32 | target, 33 | weight=None, 34 | avg_factor=None, 35 | reduction_override=None): 36 | """Forward function of loss. 37 | 38 | Args: 39 | pred (torch.Tensor): The prediction. 40 | target (torch.Tensor): The learning target of the prediction. 41 | weight (torch.Tensor, optional): Weight of the loss for each 42 | prediction. Defaults to None. 43 | avg_factor (int, optional): Average factor that is used to average 44 | the loss. Defaults to None. 45 | reduction_override (str, optional): The reduction method used to 46 | override the original reduction method of the loss. 47 | Defaults to None. 48 | 49 | Returns: 50 | torch.Tensor: The calculated loss 51 | """ 52 | assert reduction_override in (None, 'none', 'mean', 'sum') 53 | reduction = ( 54 | reduction_override if reduction_override else self.reduction) 55 | loss = self.loss_weight * mse_loss( 56 | pred, target, weight, reduction=reduction, avg_factor=avg_factor) 57 | return loss 58 | -------------------------------------------------------------------------------- /bands/d_anything/torchhub/facebookresearch_dinov2_main/dinov2/layers/swiglu_ffn.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | from typing import Callable, Optional 8 | 9 | from torch import Tensor, nn 10 | import torch.nn.functional as F 11 | 12 | 13 | class SwiGLUFFN(nn.Module): 14 | def __init__( 15 | self, 16 | in_features: int, 17 | hidden_features: Optional[int] = None, 18 | out_features: Optional[int] = None, 19 | act_layer: Callable[..., nn.Module] = None, 20 | drop: float = 0.0, 21 | bias: bool = True, 22 | ) -> None: 23 | super().__init__() 24 | out_features = out_features or in_features 25 | hidden_features = hidden_features or in_features 26 | self.w12 = nn.Linear(in_features, 2 * hidden_features, bias=bias) 27 | self.w3 = nn.Linear(hidden_features, out_features, bias=bias) 28 | 29 | def forward(self, x: Tensor) -> Tensor: 30 | x12 = self.w12(x) 31 | x1, x2 = x12.chunk(2, dim=-1) 32 | hidden = F.silu(x1) * x2 33 | return self.w3(hidden) 34 | 35 | 36 | try: 37 | from xformers.ops import SwiGLU 38 | 39 | XFORMERS_AVAILABLE = True 40 | except ImportError: 41 | SwiGLU = SwiGLUFFN 42 | XFORMERS_AVAILABLE = False 43 | 44 | 45 | class SwiGLUFFNFused(SwiGLU): 46 | def __init__( 47 | self, 48 | in_features: int, 49 | hidden_features: Optional[int] = None, 50 | out_features: Optional[int] = None, 51 | act_layer: Callable[..., nn.Module] = None, 52 | drop: float = 0.0, 53 | bias: bool = True, 54 | ) -> None: 55 | out_features = out_features or in_features 56 | hidden_features = hidden_features or in_features 57 | hidden_features = (int(hidden_features * 2 / 3) + 7) // 8 * 8 58 | super().__init__( 59 | in_features=in_features, 60 | hidden_features=hidden_features, 61 | out_features=out_features, 62 | bias=bias, 63 | ) 64 | -------------------------------------------------------------------------------- /bands/mmdet/models/roi_heads/mask_heads/feature_relay_head.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | import torch.nn as nn 3 | from mmcv.runner import BaseModule, auto_fp16 4 | 5 | from mmdet.models.builder import HEADS 6 | 7 | 8 | @HEADS.register_module() 9 | class FeatureRelayHead(BaseModule): 10 | """Feature Relay Head used in `SCNet `_. 11 | 12 | Args: 13 | in_channels (int, optional): number of input channels. Default: 256. 14 | conv_out_channels (int, optional): number of output channels before 15 | classification layer. Default: 256. 16 | roi_feat_size (int, optional): roi feat size at box head. Default: 7. 17 | scale_factor (int, optional): scale factor to match roi feat size 18 | at mask head. Default: 2. 19 | init_cfg (dict or list[dict], optional): Initialization config dict. 20 | """ 21 | 22 | def __init__(self, 23 | in_channels=1024, 24 | out_conv_channels=256, 25 | roi_feat_size=7, 26 | scale_factor=2, 27 | init_cfg=dict(type='Kaiming', layer='Linear')): 28 | super(FeatureRelayHead, self).__init__(init_cfg) 29 | assert isinstance(roi_feat_size, int) 30 | 31 | self.in_channels = in_channels 32 | self.out_conv_channels = out_conv_channels 33 | self.roi_feat_size = roi_feat_size 34 | self.out_channels = (roi_feat_size**2) * out_conv_channels 35 | self.scale_factor = scale_factor 36 | self.fp16_enabled = False 37 | 38 | self.fc = nn.Linear(self.in_channels, self.out_channels) 39 | self.upsample = nn.Upsample( 40 | scale_factor=scale_factor, mode='bilinear', align_corners=True) 41 | 42 | @auto_fp16() 43 | def forward(self, x): 44 | """Forward function.""" 45 | N, in_C = x.shape 46 | if N > 0: 47 | out_C = self.out_conv_channels 48 | out_HW = self.roi_feat_size 49 | x = self.fc(x) 50 | x = x.reshape(N, out_C, out_HW, out_HW) 51 | x = self.upsample(x) 52 | return x 53 | return None 54 | -------------------------------------------------------------------------------- /bands/gmflow/position.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 2 | # https://github.com/facebookresearch/detr/blob/main/models/position_encoding.py 3 | 4 | import torch 5 | import torch.nn as nn 6 | import math 7 | 8 | 9 | class PositionEmbeddingSine(nn.Module): 10 | """ 11 | This is a more standard version of the position embedding, very similar to the one 12 | used by the Attention is all you need paper, generalized to work on images. 13 | """ 14 | 15 | def __init__(self, num_pos_feats=64, temperature=10000, normalize=True, scale=None): 16 | super().__init__() 17 | self.num_pos_feats = num_pos_feats 18 | self.temperature = temperature 19 | self.normalize = normalize 20 | if scale is not None and normalize is False: 21 | raise ValueError("normalize should be True if scale is passed") 22 | if scale is None: 23 | scale = 2 * math.pi 24 | self.scale = scale 25 | 26 | def forward(self, x): 27 | # x = tensor_list.tensors # [B, C, H, W] 28 | # mask = tensor_list.mask # [B, H, W], input with padding, valid as 0 29 | b, c, h, w = x.size() 30 | mask = torch.ones((b, h, w), device=x.device) # [B, H, W] 31 | y_embed = mask.cumsum(1, dtype=torch.float32) 32 | x_embed = mask.cumsum(2, dtype=torch.float32) 33 | if self.normalize: 34 | eps = 1e-6 35 | y_embed = y_embed / (y_embed[:, -1:, :] + eps) * self.scale 36 | x_embed = x_embed / (x_embed[:, :, -1:] + eps) * self.scale 37 | 38 | dim_t = torch.arange(self.num_pos_feats, dtype=torch.float32, device=x.device) 39 | dim_t = self.temperature ** (2 * (dim_t // 2) / self.num_pos_feats) 40 | 41 | pos_x = x_embed[:, :, :, None] / dim_t 42 | pos_y = y_embed[:, :, :, None] / dim_t 43 | pos_x = torch.stack((pos_x[:, :, :, 0::2].sin(), pos_x[:, :, :, 1::2].cos()), dim=4).flatten(3) 44 | pos_y = torch.stack((pos_y[:, :, :, 0::2].sin(), pos_y[:, :, :, 1::2].cos()), dim=4).flatten(3) 45 | pos = torch.cat((pos_y, pos_x), dim=3).permute(0, 3, 1, 2) 46 | return pos 47 | -------------------------------------------------------------------------------- /bands/d_anything/torchhub/facebookresearch_dinov2_main/dinov2/data/collate.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | import torch 8 | import random 9 | 10 | 11 | def collate_data_and_cast(samples_list, mask_ratio_tuple, mask_probability, dtype, n_tokens=None, mask_generator=None): 12 | # dtype = torch.half # TODO: Remove 13 | 14 | n_global_crops = len(samples_list[0][0]["global_crops"]) 15 | n_local_crops = len(samples_list[0][0]["local_crops"]) 16 | 17 | collated_global_crops = torch.stack([s[0]["global_crops"][i] for i in range(n_global_crops) for s in samples_list]) 18 | 19 | collated_local_crops = torch.stack([s[0]["local_crops"][i] for i in range(n_local_crops) for s in samples_list]) 20 | 21 | B = len(collated_global_crops) 22 | N = n_tokens 23 | n_samples_masked = int(B * mask_probability) 24 | probs = torch.linspace(*mask_ratio_tuple, n_samples_masked + 1) 25 | upperbound = 0 26 | masks_list = [] 27 | for i in range(0, n_samples_masked): 28 | prob_min = probs[i] 29 | prob_max = probs[i + 1] 30 | masks_list.append(torch.BoolTensor(mask_generator(int(N * random.uniform(prob_min, prob_max))))) 31 | upperbound += int(N * prob_max) 32 | for i in range(n_samples_masked, B): 33 | masks_list.append(torch.BoolTensor(mask_generator(0))) 34 | 35 | random.shuffle(masks_list) 36 | 37 | collated_masks = torch.stack(masks_list).flatten(1) 38 | mask_indices_list = collated_masks.flatten().nonzero().flatten() 39 | 40 | masks_weight = (1 / collated_masks.sum(-1).clamp(min=1.0)).unsqueeze(-1).expand_as(collated_masks)[collated_masks] 41 | 42 | return { 43 | "collated_global_crops": collated_global_crops.to(dtype), 44 | "collated_local_crops": collated_local_crops.to(dtype), 45 | "collated_masks": collated_masks, 46 | "mask_indices_list": mask_indices_list, 47 | "masks_weight": masks_weight, 48 | "upperbound": upperbound, 49 | "n_masked_patches": torch.full((1,), fill_value=mask_indices_list.shape[0], dtype=torch.long), 50 | } 51 | -------------------------------------------------------------------------------- /bands/mmdet/utils/logger.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | import inspect 3 | import logging 4 | 5 | from mmcv.utils import get_logger 6 | 7 | 8 | def get_root_logger(log_file=None, log_level=logging.INFO): 9 | """Get root logger. 10 | 11 | Args: 12 | log_file (str, optional): File path of log. Defaults to None. 13 | log_level (int, optional): The level of logger. 14 | Defaults to logging.INFO. 15 | 16 | Returns: 17 | :obj:`logging.Logger`: The obtained logger 18 | """ 19 | logger = get_logger(name='mmdet', log_file=log_file, log_level=log_level) 20 | 21 | return logger 22 | 23 | 24 | def get_caller_name(): 25 | """Get name of caller method.""" 26 | # this_func_frame = inspect.stack()[0][0] # i.e., get_caller_name 27 | # callee_frame = inspect.stack()[1][0] # e.g., log_img_scale 28 | caller_frame = inspect.stack()[2][0] # e.g., caller of log_img_scale 29 | caller_method = caller_frame.f_code.co_name 30 | try: 31 | caller_class = caller_frame.f_locals['self'].__class__.__name__ 32 | return f'{caller_class}.{caller_method}' 33 | except KeyError: # caller is a function 34 | return caller_method 35 | 36 | 37 | def log_img_scale(img_scale, shape_order='hw', skip_square=False): 38 | """Log image size. 39 | 40 | Args: 41 | img_scale (tuple): Image size to be logged. 42 | shape_order (str, optional): The order of image shape. 43 | 'hw' for (height, width) and 'wh' for (width, height). 44 | Defaults to 'hw'. 45 | skip_square (bool, optional): Whether to skip logging for square 46 | img_scale. Defaults to False. 47 | 48 | Returns: 49 | bool: Whether to have done logging. 50 | """ 51 | if shape_order == 'hw': 52 | height, width = img_scale 53 | elif shape_order == 'wh': 54 | width, height = img_scale 55 | else: 56 | raise ValueError(f'Invalid shape_order {shape_order}.') 57 | 58 | if skip_square and (height == width): 59 | return False 60 | 61 | logger = get_root_logger() 62 | caller = get_caller_name() 63 | logger.info(f'image shape: height={height}, width={width} in {caller}') 64 | 65 | return True 66 | -------------------------------------------------------------------------------- /bands/mmdet/datasets/samplers/distributed_sampler.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | import math 3 | 4 | import torch 5 | from torch.utils.data import DistributedSampler as _DistributedSampler 6 | 7 | from mmdet.core.utils import sync_random_seed 8 | from mmdet.utils import get_device 9 | 10 | 11 | class DistributedSampler(_DistributedSampler): 12 | 13 | def __init__(self, 14 | dataset, 15 | num_replicas=None, 16 | rank=None, 17 | shuffle=True, 18 | seed=0): 19 | super().__init__( 20 | dataset, num_replicas=num_replicas, rank=rank, shuffle=shuffle) 21 | 22 | # In distributed sampling, different ranks should sample 23 | # non-overlapped data in the dataset. Therefore, this function 24 | # is used to make sure that each rank shuffles the data indices 25 | # in the same order based on the same seed. Then different ranks 26 | # could use different indices to select non-overlapped data from the 27 | # same data list. 28 | device = get_device() 29 | self.seed = sync_random_seed(seed, device) 30 | 31 | def __iter__(self): 32 | # deterministically shuffle based on epoch 33 | if self.shuffle: 34 | g = torch.Generator() 35 | # When :attr:`shuffle=True`, this ensures all replicas 36 | # use a different random ordering for each epoch. 37 | # Otherwise, the next iteration of this sampler will 38 | # yield the same ordering. 39 | g.manual_seed(self.epoch + self.seed) 40 | indices = torch.randperm(len(self.dataset), generator=g).tolist() 41 | else: 42 | indices = torch.arange(len(self.dataset)).tolist() 43 | 44 | # add extra samples to make it evenly divisible 45 | # in case that indices is shorter than half of total_size 46 | indices = (indices * 47 | math.ceil(self.total_size / len(indices)))[:self.total_size] 48 | assert len(indices) == self.total_size 49 | 50 | # subsample 51 | indices = indices[self.rank:self.total_size:self.num_replicas] 52 | assert len(indices) == self.num_samples 53 | 54 | return iter(indices) 55 | -------------------------------------------------------------------------------- /bands/d_anything/torchhub/facebookresearch_dinov2_main/dinov2/layers/dino_head.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | import torch 8 | import torch.nn as nn 9 | from torch.nn.init import trunc_normal_ 10 | from torch.nn.utils import weight_norm 11 | 12 | 13 | class DINOHead(nn.Module): 14 | def __init__( 15 | self, 16 | in_dim, 17 | out_dim, 18 | use_bn=False, 19 | nlayers=3, 20 | hidden_dim=2048, 21 | bottleneck_dim=256, 22 | mlp_bias=True, 23 | ): 24 | super().__init__() 25 | nlayers = max(nlayers, 1) 26 | self.mlp = _build_mlp(nlayers, in_dim, bottleneck_dim, hidden_dim=hidden_dim, use_bn=use_bn, bias=mlp_bias) 27 | self.apply(self._init_weights) 28 | self.last_layer = weight_norm(nn.Linear(bottleneck_dim, out_dim, bias=False)) 29 | self.last_layer.weight_g.data.fill_(1) 30 | 31 | def _init_weights(self, m): 32 | if isinstance(m, nn.Linear): 33 | trunc_normal_(m.weight, std=0.02) 34 | if isinstance(m, nn.Linear) and m.bias is not None: 35 | nn.init.constant_(m.bias, 0) 36 | 37 | def forward(self, x): 38 | x = self.mlp(x) 39 | eps = 1e-6 if x.dtype == torch.float16 else 1e-12 40 | x = nn.functional.normalize(x, dim=-1, p=2, eps=eps) 41 | x = self.last_layer(x) 42 | return x 43 | 44 | 45 | def _build_mlp(nlayers, in_dim, bottleneck_dim, hidden_dim=None, use_bn=False, bias=True): 46 | if nlayers == 1: 47 | return nn.Linear(in_dim, bottleneck_dim, bias=bias) 48 | else: 49 | layers = [nn.Linear(in_dim, hidden_dim, bias=bias)] 50 | if use_bn: 51 | layers.append(nn.BatchNorm1d(hidden_dim)) 52 | layers.append(nn.GELU()) 53 | for _ in range(nlayers - 2): 54 | layers.append(nn.Linear(hidden_dim, hidden_dim, bias=bias)) 55 | if use_bn: 56 | layers.append(nn.BatchNorm1d(hidden_dim)) 57 | layers.append(nn.GELU()) 58 | layers.append(nn.Linear(hidden_dim, bottleneck_dim, bias=bias)) 59 | return nn.Sequential(*layers) 60 | -------------------------------------------------------------------------------- /bands/mmdet/core/bbox/samplers/mask_sampling_result.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | """copy from 3 | https://github.com/ZwwWayne/K-Net/blob/main/knet/det/mask_pseudo_sampler.py.""" 4 | 5 | import torch 6 | 7 | from .sampling_result import SamplingResult 8 | 9 | 10 | class MaskSamplingResult(SamplingResult): 11 | """Mask sampling result.""" 12 | 13 | def __init__(self, pos_inds, neg_inds, masks, gt_masks, assign_result, 14 | gt_flags): 15 | self.pos_inds = pos_inds 16 | self.neg_inds = neg_inds 17 | self.pos_masks = masks[pos_inds] 18 | self.neg_masks = masks[neg_inds] 19 | self.pos_is_gt = gt_flags[pos_inds] 20 | 21 | self.num_gts = gt_masks.shape[0] 22 | self.pos_assigned_gt_inds = assign_result.gt_inds[pos_inds] - 1 23 | 24 | if gt_masks.numel() == 0: 25 | # hack for index error case 26 | assert self.pos_assigned_gt_inds.numel() == 0 27 | self.pos_gt_masks = torch.empty_like(gt_masks) 28 | else: 29 | self.pos_gt_masks = gt_masks[self.pos_assigned_gt_inds, :] 30 | 31 | if assign_result.labels is not None: 32 | self.pos_gt_labels = assign_result.labels[pos_inds] 33 | else: 34 | self.pos_gt_labels = None 35 | 36 | @property 37 | def masks(self): 38 | """torch.Tensor: concatenated positive and negative boxes""" 39 | return torch.cat([self.pos_masks, self.neg_masks]) 40 | 41 | def __nice__(self): 42 | data = self.info.copy() 43 | data['pos_masks'] = data.pop('pos_masks').shape 44 | data['neg_masks'] = data.pop('neg_masks').shape 45 | parts = [f"'{k}': {v!r}" for k, v in sorted(data.items())] 46 | body = ' ' + ',\n '.join(parts) 47 | return '{\n' + body + '\n}' 48 | 49 | @property 50 | def info(self): 51 | """Returns a dictionary of info about the object.""" 52 | return { 53 | 'pos_inds': self.pos_inds, 54 | 'neg_inds': self.neg_inds, 55 | 'pos_masks': self.pos_masks, 56 | 'neg_masks': self.neg_masks, 57 | 'pos_is_gt': self.pos_is_gt, 58 | 'num_gts': self.num_gts, 59 | 'pos_assigned_gt_inds': self.pos_assigned_gt_inds, 60 | } 61 | -------------------------------------------------------------------------------- /bands/patchfusion/zoedepth/models/zoedepth/config_zoedepth_fine.json: -------------------------------------------------------------------------------- 1 | { 2 | "model": { 3 | "name": "ZoeDepth", 4 | "version_name": "v1", 5 | "n_bins": 64, 6 | "bin_embedding_dim": 128, 7 | "bin_centers_type": "softplus", 8 | "n_attractors":[16, 8, 4, 1], 9 | "attractor_alpha": 1000, 10 | "attractor_gamma": 2, 11 | "attractor_kind" : "mean", 12 | "attractor_type" : "inv", 13 | "midas_model_type" : "DPT_BEiT_L_384", 14 | "min_temp": 0.0212, 15 | "max_temp": 50.0, 16 | "output_distribution": "logbinomial", 17 | "memory_efficient": true, 18 | "inverse_midas": false, 19 | "img_size": [384, 512], 20 | "sampled_training": false, 21 | // "do_resize": false // do resize in dataloader to speed up 22 | "do_resize": false, 23 | 24 | "do_normalize": true, 25 | "do_input_resize": true 26 | }, 27 | 28 | "train": { 29 | "train_midas": true, 30 | "use_rgb": true, 31 | "use_pretrained_midas": true, 32 | "trainer": "zoedepth_custom", 33 | "epochs": 5, 34 | "bs": 16, 35 | "optim_kwargs": {"lr": 0.000161, "wd": 0.01}, 36 | "sched_kwargs": {"div_factor": 1, "final_div_factor": 10000, "pct_start": 0.7, "three_phase":false, "cycle_momentum": true}, 37 | "same_lr": false, 38 | "w_si": 1, 39 | "w_domain": 0.2, 40 | "w_reg": 0, 41 | "w_grad": 0, 42 | "avoid_boundary": false, 43 | "random_crop": true, 44 | "input_width": 160, 45 | "input_height": 120, 46 | "midas_lr_factor": 1, 47 | "encoder_lr_factor":10, 48 | "pos_enc_lr_factor":10, 49 | "freeze_midas_bn": true, 50 | "sec_stage": true 51 | 52 | }, 53 | 54 | "infer":{ 55 | "train_midas": false, 56 | "use_pretrained_midas": false, 57 | "pretrained_resource" : "url::https://github.com/isl-org/ZoeDepth/releases/download/v1.0/ZoeD_M12_N.pt", 58 | "force_keep_ar": true 59 | }, 60 | 61 | "eval":{ 62 | "train_midas": false, 63 | "use_pretrained_midas": false, 64 | "pretrained_resource" : "url::https://github.com/isl-org/ZoeDepth/releases/download/v1.0/ZoeD_M12_N.pt" 65 | } 66 | } -------------------------------------------------------------------------------- /bands/patchfusion/zoedepth/trainers/builder.py: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | # Copyright (c) 2022 Intelligent Systems Lab Org 4 | 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | # File author: Shariq Farooq Bhat 24 | 25 | from importlib import import_module 26 | 27 | 28 | def get_trainer(config): 29 | """Builds and returns a trainer based on the config. 30 | 31 | Args: 32 | config (dict): the config dict (typically constructed using utils.config.get_config) 33 | config.trainer (str): the name of the trainer to use. The module named "{config.trainer}_trainer" must exist in trainers root module 34 | 35 | Raises: 36 | ValueError: If the specified trainer does not exist under trainers/ folder 37 | 38 | Returns: 39 | Trainer (inherited from zoedepth.trainers.BaseTrainer): The Trainer object 40 | """ 41 | assert "trainer" in config and config.trainer is not None and config.trainer != '', "Trainer not specified. Config: {0}".format( 42 | config) 43 | try: 44 | Trainer = getattr(import_module( 45 | f"zoedepth.trainers.{config.trainer}_trainer"), 'Trainer') 46 | except ModuleNotFoundError as e: 47 | raise ValueError(f"Trainer {config.trainer}_trainer not found.") from e 48 | return Trainer 49 | -------------------------------------------------------------------------------- /bands/mmdet/core/visualization/palette.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | import mmcv 3 | import numpy as np 4 | 5 | 6 | def palette_val(palette): 7 | """Convert palette to matplotlib palette. 8 | 9 | Args: 10 | palette List[tuple]: A list of color tuples. 11 | 12 | Returns: 13 | List[tuple[float]]: A list of RGB matplotlib color tuples. 14 | """ 15 | new_palette = [] 16 | for color in palette: 17 | color = [c / 255 for c in color] 18 | new_palette.append(tuple(color)) 19 | return new_palette 20 | 21 | 22 | def get_palette(palette, num_classes): 23 | """Get palette from various inputs. 24 | 25 | Args: 26 | palette (list[tuple] | str | tuple | :obj:`Color`): palette inputs. 27 | num_classes (int): the number of classes. 28 | 29 | Returns: 30 | list[tuple[int]]: A list of color tuples. 31 | """ 32 | assert isinstance(num_classes, int) 33 | 34 | if isinstance(palette, list): 35 | dataset_palette = palette 36 | elif isinstance(palette, tuple): 37 | dataset_palette = [palette] * num_classes 38 | elif palette == 'random' or palette is None: 39 | state = np.random.get_state() 40 | # random color 41 | np.random.seed(42) 42 | palette = np.random.randint(0, 256, size=(num_classes, 3)) 43 | np.random.set_state(state) 44 | dataset_palette = [tuple(c) for c in palette] 45 | elif palette == 'coco': 46 | from mmdet.datasets import CocoDataset, CocoPanopticDataset 47 | dataset_palette = CocoDataset.PALETTE 48 | if len(dataset_palette) < num_classes: 49 | dataset_palette = CocoPanopticDataset.PALETTE 50 | elif palette == 'citys': 51 | from mmdet.datasets import CityscapesDataset 52 | dataset_palette = CityscapesDataset.PALETTE 53 | elif palette == 'voc': 54 | from mmdet.datasets import VOCDataset 55 | dataset_palette = VOCDataset.PALETTE 56 | elif mmcv.is_str(palette): 57 | dataset_palette = [mmcv.color_val(palette)[::-1]] * num_classes 58 | else: 59 | raise TypeError(f'Invalid type for palette: {type(palette)}') 60 | 61 | assert len(dataset_palette) >= num_classes, \ 62 | 'The length of palette should not be less than `num_classes`.' 63 | return dataset_palette 64 | -------------------------------------------------------------------------------- /bands/mmdet/core/hook/memory_profiler_hook.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from mmcv.runner.hooks import HOOKS, Hook 3 | 4 | 5 | @HOOKS.register_module() 6 | class MemoryProfilerHook(Hook): 7 | """Memory profiler hook recording memory information including virtual 8 | memory, swap memory, and the memory of the current process. 9 | 10 | Args: 11 | interval (int): Checking interval (every k iterations). 12 | Default: 50. 13 | """ 14 | 15 | def __init__(self, interval=50): 16 | try: 17 | from psutil import swap_memory, virtual_memory 18 | self._swap_memory = swap_memory 19 | self._virtual_memory = virtual_memory 20 | except ImportError: 21 | raise ImportError('psutil is not installed, please install it by: ' 22 | 'pip install psutil') 23 | 24 | try: 25 | from memory_profiler import memory_usage 26 | self._memory_usage = memory_usage 27 | except ImportError: 28 | raise ImportError( 29 | 'memory_profiler is not installed, please install it by: ' 30 | 'pip install memory_profiler') 31 | 32 | self.interval = interval 33 | 34 | def after_iter(self, runner): 35 | if self.every_n_iters(runner, self.interval): 36 | # in Byte 37 | virtual_memory = self._virtual_memory() 38 | swap_memory = self._swap_memory() 39 | # in MB 40 | process_memory = self._memory_usage()[0] 41 | factor = 1024 * 1024 42 | runner.logger.info( 43 | 'Memory information ' 44 | 'available_memory: ' 45 | f'{round(virtual_memory.available / factor)} MB, ' 46 | 'used_memory: ' 47 | f'{round(virtual_memory.used / factor)} MB, ' 48 | f'memory_utilization: {virtual_memory.percent} %, ' 49 | 'available_swap_memory: ' 50 | f'{round((swap_memory.total - swap_memory.used) / factor)}' 51 | ' MB, ' 52 | f'used_swap_memory: {round(swap_memory.used / factor)} MB, ' 53 | f'swap_memory_utilization: {swap_memory.percent} %, ' 54 | 'current_process_memory: ' 55 | f'{round(process_memory)} MB') 56 | -------------------------------------------------------------------------------- /bands/mmdet/models/detectors/fast_rcnn.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from ..builder import DETECTORS 3 | from .two_stage import TwoStageDetector 4 | 5 | 6 | @DETECTORS.register_module() 7 | class FastRCNN(TwoStageDetector): 8 | """Implementation of `Fast R-CNN `_""" 9 | 10 | def __init__(self, 11 | backbone, 12 | roi_head, 13 | train_cfg, 14 | test_cfg, 15 | neck=None, 16 | pretrained=None, 17 | init_cfg=None): 18 | super(FastRCNN, self).__init__( 19 | backbone=backbone, 20 | neck=neck, 21 | roi_head=roi_head, 22 | train_cfg=train_cfg, 23 | test_cfg=test_cfg, 24 | pretrained=pretrained, 25 | init_cfg=init_cfg) 26 | 27 | def forward_test(self, imgs, img_metas, proposals, **kwargs): 28 | """ 29 | Args: 30 | imgs (List[Tensor]): the outer list indicates test-time 31 | augmentations and inner Tensor should have a shape NxCxHxW, 32 | which contains all images in the batch. 33 | img_metas (List[List[dict]]): the outer list indicates test-time 34 | augs (multiscale, flip, etc.) and the inner list indicates 35 | images in a batch. 36 | proposals (List[List[Tensor]]): the outer list indicates test-time 37 | augs (multiscale, flip, etc.) and the inner list indicates 38 | images in a batch. The Tensor should have a shape Px4, where 39 | P is the number of proposals. 40 | """ 41 | for var, name in [(imgs, 'imgs'), (img_metas, 'img_metas')]: 42 | if not isinstance(var, list): 43 | raise TypeError(f'{name} must be a list, but got {type(var)}') 44 | 45 | num_augs = len(imgs) 46 | if num_augs != len(img_metas): 47 | raise ValueError(f'num of augmentations ({len(imgs)}) ' 48 | f'!= num of image meta ({len(img_metas)})') 49 | 50 | if num_augs == 1: 51 | return self.simple_test(imgs[0], img_metas[0], proposals[0], 52 | **kwargs) 53 | else: 54 | # TODO: support test-time augmentation 55 | assert NotImplementedError 56 | -------------------------------------------------------------------------------- /bands/mmdet/models/detectors/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from .atss import ATSS 3 | from .autoassign import AutoAssign 4 | from .base import BaseDetector 5 | from .cascade_rcnn import CascadeRCNN 6 | from .centernet import CenterNet 7 | from .cornernet import CornerNet 8 | from .ddod import DDOD 9 | from .deformable_detr import DeformableDETR 10 | from .detr import DETR 11 | from .fast_rcnn import FastRCNN 12 | from .faster_rcnn import FasterRCNN 13 | from .fcos import FCOS 14 | from .fovea import FOVEA 15 | from .fsaf import FSAF 16 | from .gfl import GFL 17 | from .grid_rcnn import GridRCNN 18 | from .htc import HybridTaskCascade 19 | from .kd_one_stage import KnowledgeDistillationSingleStageDetector 20 | from .lad import LAD 21 | from .mask2former import Mask2Former 22 | from .mask_rcnn import MaskRCNN 23 | from .mask_scoring_rcnn import MaskScoringRCNN 24 | from .maskformer import MaskFormer 25 | from .nasfcos import NASFCOS 26 | from .paa import PAA 27 | from .panoptic_fpn import PanopticFPN 28 | from .panoptic_two_stage_segmentor import TwoStagePanopticSegmentor 29 | from .point_rend import PointRend 30 | from .queryinst import QueryInst 31 | from .reppoints_detector import RepPointsDetector 32 | from .retinanet import RetinaNet 33 | from .rpn import RPN 34 | from .scnet import SCNet 35 | from .single_stage import SingleStageDetector 36 | from .solo import SOLO 37 | from .solov2 import SOLOv2 38 | from .sparse_rcnn import SparseRCNN 39 | from .tood import TOOD 40 | from .trident_faster_rcnn import TridentFasterRCNN 41 | from .two_stage import TwoStageDetector 42 | from .vfnet import VFNet 43 | from .yolact import YOLACT 44 | from .yolo import YOLOV3 45 | from .yolof import YOLOF 46 | from .yolox import YOLOX 47 | 48 | __all__ = [ 49 | 'ATSS', 'BaseDetector', 'SingleStageDetector', 'TwoStageDetector', 'RPN', 50 | 'KnowledgeDistillationSingleStageDetector', 'FastRCNN', 'FasterRCNN', 51 | 'MaskRCNN', 'CascadeRCNN', 'HybridTaskCascade', 'RetinaNet', 'FCOS', 52 | 'GridRCNN', 'MaskScoringRCNN', 'RepPointsDetector', 'FOVEA', 'FSAF', 53 | 'NASFCOS', 'PointRend', 'GFL', 'CornerNet', 'PAA', 'YOLOV3', 'YOLACT', 54 | 'VFNet', 'DETR', 'TridentFasterRCNN', 'SparseRCNN', 'SCNet', 'SOLO', 55 | 'SOLOv2', 'DeformableDETR', 'AutoAssign', 'YOLOF', 'CenterNet', 'YOLOX', 56 | 'TwoStagePanopticSegmentor', 'PanopticFPN', 'QueryInst', 'LAD', 'TOOD', 57 | 'MaskFormer', 'DDOD', 'Mask2Former' 58 | ] 59 | -------------------------------------------------------------------------------- /bands/d_anything/torchhub/facebookresearch_dinov2_main/dinov2/eval/setup.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | import argparse 8 | from typing import Any, List, Optional, Tuple 9 | 10 | import torch 11 | import torch.backends.cudnn as cudnn 12 | 13 | from dinov2.models import build_model_from_cfg 14 | from dinov2.utils.config import setup 15 | import dinov2.utils.utils as dinov2_utils 16 | 17 | 18 | def get_args_parser( 19 | description: Optional[str] = None, 20 | parents: Optional[List[argparse.ArgumentParser]] = None, 21 | add_help: bool = True, 22 | ): 23 | parser = argparse.ArgumentParser( 24 | description=description, 25 | parents=parents or [], 26 | add_help=add_help, 27 | ) 28 | parser.add_argument( 29 | "--config-file", 30 | type=str, 31 | help="Model configuration file", 32 | ) 33 | parser.add_argument( 34 | "--pretrained-weights", 35 | type=str, 36 | help="Pretrained model weights", 37 | ) 38 | parser.add_argument( 39 | "--output-dir", 40 | default="", 41 | type=str, 42 | help="Output directory to write results and logs", 43 | ) 44 | parser.add_argument( 45 | "--opts", 46 | help="Extra configuration options", 47 | default=[], 48 | nargs="+", 49 | ) 50 | return parser 51 | 52 | 53 | def get_autocast_dtype(config): 54 | teacher_dtype_str = config.compute_precision.teacher.backbone.mixed_precision.param_dtype 55 | if teacher_dtype_str == "fp16": 56 | return torch.half 57 | elif teacher_dtype_str == "bf16": 58 | return torch.bfloat16 59 | else: 60 | return torch.float 61 | 62 | 63 | def build_model_for_eval(config, pretrained_weights): 64 | model, _ = build_model_from_cfg(config, only_teacher=True) 65 | dinov2_utils.load_pretrained_weights(model, pretrained_weights, "teacher") 66 | model.eval() 67 | model.cuda() 68 | return model 69 | 70 | 71 | def setup_and_build_model(args) -> Tuple[Any, torch.dtype]: 72 | cudnn.benchmark = True 73 | config = setup(args) 74 | model = build_model_for_eval(config, args.pretrained_weights) 75 | autocast_dtype = get_autocast_dtype(config) 76 | return model, autocast_dtype 77 | -------------------------------------------------------------------------------- /bands/patchfusion/zoedepth/models/zoedepth/color_channel/config_zoedepth_rgb.json: -------------------------------------------------------------------------------- 1 | { 2 | "model": { 3 | "name": "ZoeDepth", 4 | "version_name": "v1", 5 | "n_bins": 64, 6 | "bin_embedding_dim": 128, 7 | "bin_centers_type": "softplus", 8 | "n_attractors":[16, 8, 4, 1], 9 | "attractor_alpha": 1000, 10 | "attractor_gamma": 2, 11 | "attractor_kind" : "mean", 12 | "attractor_type" : "inv", 13 | "midas_model_type" : "DPT_BEiT_L_384", 14 | "min_temp": 0.0212, 15 | "max_temp": 50.0, 16 | "output_distribution": "logbinomial", 17 | "memory_efficient": true, 18 | "inverse_midas": false, 19 | "img_size": [384, 512], 20 | "sampled_training": false, 21 | "do_resize": false // do resize in dataloader to speed up 22 | }, 23 | 24 | "train": { 25 | "use_rbg": true, 26 | "train_midas": true, 27 | "use_pretrained_midas": true, 28 | "trainer": "zoedepth", 29 | // "epochs": 5, 30 | // "epochs": 8, 31 | // "epochs": 12, 32 | "epochs": 16, 33 | "bs": 16, 34 | // "optim_kwargs": {"lr": 0.0001, "wd": 0.01}, 35 | "optim_kwargs": {"lr": 0.000161, "wd": 0.01}, 36 | "sched_kwargs": {"div_factor": 1, "final_div_factor": 10000, "pct_start": 0.5, "three_phase":false, "cycle_momentum": true}, 37 | // "sched_kwargs": {"div_factor": 1, "final_div_factor": 10000, "pct_start": 0.7, "three_phase":false, "cycle_momentum": true}, 38 | "same_lr": false, 39 | "w_si": 1, 40 | "w_domain": 0.2, 41 | "w_reg": 0, 42 | "w_grad": 0, 43 | "avoid_boundary": false, 44 | "random_crop": false, 45 | "input_width": 640, 46 | "input_height": 480, 47 | "midas_lr_factor": 1, 48 | "encoder_lr_factor":10, 49 | "pos_enc_lr_factor":10, 50 | "freeze_midas_bn": true 51 | 52 | }, 53 | 54 | "infer":{ 55 | "train_midas": false, 56 | "use_pretrained_midas": false, 57 | "pretrained_resource" : "url::https://github.com/isl-org/ZoeDepth/releases/download/v1.0/ZoeD_M12_N.pt", 58 | "force_keep_ar": true 59 | }, 60 | 61 | "eval":{ 62 | "train_midas": false, 63 | "use_pretrained_midas": false, 64 | "pretrained_resource" : "url::https://github.com/isl-org/ZoeDepth/releases/download/v1.0/ZoeD_M12_N.pt" 65 | } 66 | } -------------------------------------------------------------------------------- /bands/mmdet/core/hook/yolox_mode_switch_hook.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from mmcv.parallel import is_module_wrapper 3 | from mmcv.runner.hooks import HOOKS, Hook 4 | 5 | 6 | @HOOKS.register_module() 7 | class YOLOXModeSwitchHook(Hook): 8 | """Switch the mode of YOLOX during training. 9 | 10 | This hook turns off the mosaic and mixup data augmentation and switches 11 | to use L1 loss in bbox_head. 12 | 13 | Args: 14 | num_last_epochs (int): The number of latter epochs in the end of the 15 | training to close the data augmentation and switch to L1 loss. 16 | Default: 15. 17 | skip_type_keys (list[str], optional): Sequence of type string to be 18 | skip pipeline. Default: ('Mosaic', 'RandomAffine', 'MixUp') 19 | """ 20 | 21 | def __init__(self, 22 | num_last_epochs=15, 23 | skip_type_keys=('Mosaic', 'RandomAffine', 'MixUp')): 24 | self.num_last_epochs = num_last_epochs 25 | self.skip_type_keys = skip_type_keys 26 | self._restart_dataloader = False 27 | 28 | def before_train_epoch(self, runner): 29 | """Close mosaic and mixup augmentation and switches to use L1 loss.""" 30 | epoch = runner.epoch 31 | train_loader = runner.data_loader 32 | model = runner.model 33 | if is_module_wrapper(model): 34 | model = model.module 35 | if (epoch + 1) == runner.max_epochs - self.num_last_epochs: 36 | runner.logger.info('No mosaic and mixup aug now!') 37 | # The dataset pipeline cannot be updated when persistent_workers 38 | # is True, so we need to force the dataloader's multi-process 39 | # restart. This is a very hacky approach. 40 | train_loader.dataset.update_skip_type_keys(self.skip_type_keys) 41 | if hasattr(train_loader, 'persistent_workers' 42 | ) and train_loader.persistent_workers is True: 43 | train_loader._DataLoader__initialized = False 44 | train_loader._iterator = None 45 | self._restart_dataloader = True 46 | runner.logger.info('Add additional L1 loss now!') 47 | model.bbox_head.use_l1 = True 48 | else: 49 | # Once the restart is complete, we need to restore 50 | # the initialization flag. 51 | if self._restart_dataloader: 52 | train_loader._DataLoader__initialized = True 53 | --------------------------------------------------------------------------------