├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.yml │ └── config.yml └── workflows │ └── tests.yml ├── .gitignore ├── LICENSE ├── README.md ├── annotator ├── binary │ └── __init__.py ├── canny │ └── __init__.py ├── clip │ └── __init__.py ├── color │ └── __init__.py ├── hed │ └── __init__.py ├── informative │ └── __init__.py ├── keypose │ ├── __init__.py │ ├── faster_rcnn_r50_fpn_coco.py │ └── hrnet_w48_coco_256x192.py ├── leres │ ├── __init__.py │ ├── leres │ │ ├── LICENSE │ │ ├── Resnet.py │ │ ├── Resnext_torch.py │ │ ├── depthmap.py │ │ ├── multi_depth_model_woauxi.py │ │ ├── net_tools.py │ │ └── network_auxi.py │ └── pix2pix │ │ ├── LICENSE │ │ ├── models │ │ ├── __init__.py │ │ ├── base_model.py │ │ ├── base_model_hg.py │ │ ├── networks.py │ │ └── pix2pix4depth_model.py │ │ ├── options │ │ ├── __init__.py │ │ ├── base_options.py │ │ └── test_options.py │ │ └── util │ │ ├── __init__.py │ │ ├── get_data.py │ │ ├── guidedfilter.py │ │ ├── html.py │ │ ├── image_pool.py │ │ ├── util.py │ │ └── visualizer.py ├── lineart │ └── __init__.py ├── lineart_anime │ └── __init__.py ├── mediapipe_face │ ├── __init__.py │ └── mediapipe_face_common.py ├── midas │ ├── __init__.py │ ├── api.py │ ├── midas │ │ ├── __init__.py │ │ ├── base_model.py │ │ ├── blocks.py │ │ ├── dpt_depth.py │ │ ├── midas_net.py │ │ ├── midas_net_custom.py │ │ ├── transforms.py │ │ └── vit.py │ └── utils.py ├── mlsd │ ├── __init__.py │ ├── models │ │ ├── mbv2_mlsd_large.py │ │ └── mbv2_mlsd_tiny.py │ └── utils.py ├── mmpkg │ ├── mmcv │ │ ├── __init__.py │ │ ├── arraymisc │ │ │ ├── __init__.py │ │ │ └── quantization.py │ │ ├── cnn │ │ │ ├── __init__.py │ │ │ ├── alexnet.py │ │ │ ├── bricks │ │ │ │ ├── __init__.py │ │ │ │ ├── activation.py │ │ │ │ ├── context_block.py │ │ │ │ ├── conv.py │ │ │ │ ├── conv2d_adaptive_padding.py │ │ │ │ ├── conv_module.py │ │ │ │ ├── conv_ws.py │ │ │ │ ├── depthwise_separable_conv_module.py │ │ │ │ ├── drop.py │ │ │ │ ├── generalized_attention.py │ │ │ │ ├── hsigmoid.py │ │ │ │ ├── hswish.py │ │ │ │ ├── non_local.py │ │ │ │ ├── norm.py │ │ │ │ ├── padding.py │ │ │ │ ├── plugin.py │ │ │ │ ├── registry.py │ │ │ │ ├── scale.py │ │ │ │ ├── swish.py │ │ │ │ ├── transformer.py │ │ │ │ ├── upsample.py │ │ │ │ └── wrappers.py │ │ │ ├── builder.py │ │ │ ├── resnet.py │ │ │ ├── utils │ │ │ │ ├── __init__.py │ │ │ │ ├── flops_counter.py │ │ │ │ ├── fuse_conv_bn.py │ │ │ │ ├── sync_bn.py │ │ │ │ └── weight_init.py │ │ │ └── vgg.py │ │ ├── engine │ │ │ ├── __init__.py │ │ │ └── test.py │ │ ├── fileio │ │ │ ├── __init__.py │ │ │ ├── file_client.py │ │ │ ├── handlers │ │ │ │ ├── __init__.py │ │ │ │ ├── base.py │ │ │ │ ├── json_handler.py │ │ │ │ ├── pickle_handler.py │ │ │ │ └── yaml_handler.py │ │ │ ├── io.py │ │ │ └── parse.py │ │ ├── image │ │ │ ├── __init__.py │ │ │ ├── colorspace.py │ │ │ ├── geometric.py │ │ │ ├── io.py │ │ │ ├── misc.py │ │ │ └── photometric.py │ │ ├── model_zoo │ │ │ ├── deprecated.json │ │ │ ├── mmcls.json │ │ │ └── open_mmlab.json │ │ ├── ops │ │ │ ├── __init__.py │ │ │ ├── assign_score_withk.py │ │ │ ├── ball_query.py │ │ │ ├── bbox.py │ │ │ ├── border_align.py │ │ │ ├── box_iou_rotated.py │ │ │ ├── carafe.py │ │ │ ├── cc_attention.py │ │ │ ├── contour_expand.py │ │ │ ├── corner_pool.py │ │ │ ├── correlation.py │ │ │ ├── deform_conv.py │ │ │ ├── deform_roi_pool.py │ │ │ ├── deprecated_wrappers.py │ │ │ ├── focal_loss.py │ │ │ ├── furthest_point_sample.py │ │ │ ├── fused_bias_leakyrelu.py │ │ │ ├── gather_points.py │ │ │ ├── group_points.py │ │ │ ├── info.py │ │ │ ├── iou3d.py │ │ │ ├── knn.py │ │ │ ├── masked_conv.py │ │ │ ├── merge_cells.py │ │ │ ├── modulated_deform_conv.py │ │ │ ├── multi_scale_deform_attn.py │ │ │ ├── nms.py │ │ │ ├── pixel_group.py │ │ │ ├── point_sample.py │ │ │ ├── points_in_boxes.py │ │ │ ├── points_sampler.py │ │ │ ├── psa_mask.py │ │ │ ├── roi_align.py │ │ │ ├── roi_align_rotated.py │ │ │ ├── roi_pool.py │ │ │ ├── roiaware_pool3d.py │ │ │ ├── roipoint_pool3d.py │ │ │ ├── saconv.py │ │ │ ├── scatter_points.py │ │ │ ├── sync_bn.py │ │ │ ├── three_interpolate.py │ │ │ ├── three_nn.py │ │ │ ├── tin_shift.py │ │ │ ├── upfirdn2d.py │ │ │ └── voxelize.py │ │ ├── parallel │ │ │ ├── __init__.py │ │ │ ├── _functions.py │ │ │ ├── collate.py │ │ │ ├── data_container.py │ │ │ ├── data_parallel.py │ │ │ ├── distributed.py │ │ │ ├── distributed_deprecated.py │ │ │ ├── registry.py │ │ │ ├── scatter_gather.py │ │ │ └── utils.py │ │ ├── runner │ │ │ ├── __init__.py │ │ │ ├── base_module.py │ │ │ ├── base_runner.py │ │ │ ├── builder.py │ │ │ ├── checkpoint.py │ │ │ ├── default_constructor.py │ │ │ ├── dist_utils.py │ │ │ ├── epoch_based_runner.py │ │ │ ├── fp16_utils.py │ │ │ ├── hooks │ │ │ │ ├── __init__.py │ │ │ │ ├── checkpoint.py │ │ │ │ ├── closure.py │ │ │ │ ├── ema.py │ │ │ │ ├── evaluation.py │ │ │ │ ├── hook.py │ │ │ │ ├── iter_timer.py │ │ │ │ ├── logger │ │ │ │ │ ├── __init__.py │ │ │ │ │ ├── base.py │ │ │ │ │ ├── dvclive.py │ │ │ │ │ ├── mlflow.py │ │ │ │ │ ├── neptune.py │ │ │ │ │ ├── pavi.py │ │ │ │ │ ├── tensorboard.py │ │ │ │ │ ├── text.py │ │ │ │ │ └── wandb.py │ │ │ │ ├── lr_updater.py │ │ │ │ ├── memory.py │ │ │ │ ├── momentum_updater.py │ │ │ │ ├── optimizer.py │ │ │ │ ├── profiler.py │ │ │ │ ├── sampler_seed.py │ │ │ │ └── sync_buffer.py │ │ │ ├── iter_based_runner.py │ │ │ ├── log_buffer.py │ │ │ ├── optimizer │ │ │ │ ├── __init__.py │ │ │ │ ├── builder.py │ │ │ │ └── default_constructor.py │ │ │ ├── priority.py │ │ │ └── utils.py │ │ ├── utils │ │ │ ├── __init__.py │ │ │ ├── config.py │ │ │ ├── env.py │ │ │ ├── ext_loader.py │ │ │ ├── logging.py │ │ │ ├── misc.py │ │ │ ├── parrots_jit.py │ │ │ ├── parrots_wrapper.py │ │ │ ├── path.py │ │ │ ├── progressbar.py │ │ │ ├── registry.py │ │ │ ├── testing.py │ │ │ ├── timer.py │ │ │ ├── trace.py │ │ │ └── version_utils.py │ │ ├── version.py │ │ ├── video │ │ │ ├── __init__.py │ │ │ ├── io.py │ │ │ ├── optflow.py │ │ │ └── processing.py │ │ └── visualization │ │ │ ├── __init__.py │ │ │ ├── color.py │ │ │ ├── image.py │ │ │ └── optflow.py │ └── mmseg │ │ ├── apis │ │ ├── __init__.py │ │ ├── inference.py │ │ ├── test.py │ │ └── train.py │ │ ├── core │ │ ├── __init__.py │ │ ├── evaluation │ │ │ ├── __init__.py │ │ │ ├── class_names.py │ │ │ ├── eval_hooks.py │ │ │ └── metrics.py │ │ ├── seg │ │ │ ├── __init__.py │ │ │ ├── builder.py │ │ │ └── sampler │ │ │ │ ├── __init__.py │ │ │ │ ├── base_pixel_sampler.py │ │ │ │ └── ohem_pixel_sampler.py │ │ └── utils │ │ │ ├── __init__.py │ │ │ └── misc.py │ │ ├── datasets │ │ ├── __init__.py │ │ ├── ade.py │ │ ├── builder.py │ │ ├── chase_db1.py │ │ ├── cityscapes.py │ │ ├── custom.py │ │ ├── dataset_wrappers.py │ │ ├── drive.py │ │ ├── hrf.py │ │ ├── pascal_context.py │ │ ├── pipelines │ │ │ ├── __init__.py │ │ │ ├── compose.py │ │ │ ├── formating.py │ │ │ ├── loading.py │ │ │ ├── test_time_aug.py │ │ │ └── transforms.py │ │ ├── stare.py │ │ └── voc.py │ │ ├── models │ │ ├── __init__.py │ │ ├── backbones │ │ │ ├── __init__.py │ │ │ ├── cgnet.py │ │ │ ├── fast_scnn.py │ │ │ ├── hrnet.py │ │ │ ├── mobilenet_v2.py │ │ │ ├── mobilenet_v3.py │ │ │ ├── resnest.py │ │ │ ├── resnet.py │ │ │ ├── resnext.py │ │ │ ├── unet.py │ │ │ └── vit.py │ │ ├── builder.py │ │ ├── decode_heads │ │ │ ├── __init__.py │ │ │ ├── ann_head.py │ │ │ ├── apc_head.py │ │ │ ├── aspp_head.py │ │ │ ├── cascade_decode_head.py │ │ │ ├── cc_head.py │ │ │ ├── da_head.py │ │ │ ├── decode_head.py │ │ │ ├── dm_head.py │ │ │ ├── dnl_head.py │ │ │ ├── ema_head.py │ │ │ ├── enc_head.py │ │ │ ├── fcn_head.py │ │ │ ├── fpn_head.py │ │ │ ├── gc_head.py │ │ │ ├── lraspp_head.py │ │ │ ├── nl_head.py │ │ │ ├── ocr_head.py │ │ │ ├── point_head.py │ │ │ ├── psa_head.py │ │ │ ├── psp_head.py │ │ │ ├── sep_aspp_head.py │ │ │ ├── sep_fcn_head.py │ │ │ └── uper_head.py │ │ ├── losses │ │ │ ├── __init__.py │ │ │ ├── accuracy.py │ │ │ ├── cross_entropy_loss.py │ │ │ ├── dice_loss.py │ │ │ ├── lovasz_loss.py │ │ │ └── utils.py │ │ ├── necks │ │ │ ├── __init__.py │ │ │ ├── fpn.py │ │ │ └── multilevel_neck.py │ │ ├── segmentors │ │ │ ├── __init__.py │ │ │ ├── base.py │ │ │ ├── cascade_encoder_decoder.py │ │ │ └── encoder_decoder.py │ │ └── utils │ │ │ ├── __init__.py │ │ │ ├── drop.py │ │ │ ├── inverted_residual.py │ │ │ ├── make_divisible.py │ │ │ ├── res_layer.py │ │ │ ├── se_layer.py │ │ │ ├── self_attention_block.py │ │ │ ├── up_conv_block.py │ │ │ └── weight_init.py │ │ ├── ops │ │ ├── __init__.py │ │ ├── encoding.py │ │ └── wrappers.py │ │ └── utils │ │ ├── __init__.py │ │ ├── collect_env.py │ │ └── logger.py ├── normalbae │ ├── __init__.py │ └── models │ │ ├── NNET.py │ │ ├── baseline.py │ │ └── submodules │ │ ├── decoder.py │ │ ├── efficientnet_repo │ │ ├── .gitignore │ │ ├── BENCHMARK.md │ │ ├── LICENSE │ │ ├── README.md │ │ ├── caffe2_benchmark.py │ │ ├── caffe2_validate.py │ │ ├── geffnet │ │ │ ├── __init__.py │ │ │ ├── activations │ │ │ │ ├── __init__.py │ │ │ │ ├── activations.py │ │ │ │ ├── activations_jit.py │ │ │ │ └── activations_me.py │ │ │ ├── config.py │ │ │ ├── conv2d_layers.py │ │ │ ├── efficientnet_builder.py │ │ │ ├── gen_efficientnet.py │ │ │ ├── helpers.py │ │ │ ├── mobilenetv3.py │ │ │ ├── model_factory.py │ │ │ └── version.py │ │ ├── hubconf.py │ │ ├── onnx_export.py │ │ ├── onnx_optimize.py │ │ ├── onnx_to_caffe.py │ │ ├── onnx_validate.py │ │ ├── requirements.txt │ │ ├── setup.py │ │ ├── utils.py │ │ └── validate.py │ │ ├── encoder.py │ │ └── submodules.py ├── oneformer │ ├── __init__.py │ ├── api.py │ ├── configs │ │ ├── ade20k │ │ │ ├── Base-ADE20K-UnifiedSegmentation.yaml │ │ │ ├── oneformer_R50_bs16_160k.yaml │ │ │ └── oneformer_swin_large_IN21k_384_bs16_160k.yaml │ │ └── coco │ │ │ ├── Base-COCO-UnifiedSegmentation.yaml │ │ │ ├── oneformer_R50_bs16_50ep.yaml │ │ │ └── oneformer_swin_large_IN21k_384_bs16_100ep.yaml │ ├── detectron2 │ │ ├── __init__.py │ │ ├── checkpoint │ │ │ ├── __init__.py │ │ │ ├── c2_model_loading.py │ │ │ ├── catalog.py │ │ │ └── detection_checkpoint.py │ │ ├── config │ │ │ ├── __init__.py │ │ │ ├── compat.py │ │ │ ├── config.py │ │ │ ├── defaults.py │ │ │ ├── instantiate.py │ │ │ └── lazy.py │ │ ├── data │ │ │ ├── __init__.py │ │ │ ├── benchmark.py │ │ │ ├── build.py │ │ │ ├── catalog.py │ │ │ ├── common.py │ │ │ ├── dataset_mapper.py │ │ │ ├── datasets │ │ │ │ ├── README.md │ │ │ │ ├── __init__.py │ │ │ │ ├── builtin.py │ │ │ │ ├── builtin_meta.py │ │ │ │ ├── cityscapes.py │ │ │ │ ├── cityscapes_panoptic.py │ │ │ │ ├── coco.py │ │ │ │ ├── coco_panoptic.py │ │ │ │ ├── lvis.py │ │ │ │ ├── lvis_v0_5_categories.py │ │ │ │ ├── lvis_v1_categories.py │ │ │ │ ├── lvis_v1_category_image_count.py │ │ │ │ ├── pascal_voc.py │ │ │ │ └── register_coco.py │ │ │ ├── detection_utils.py │ │ │ ├── samplers │ │ │ │ ├── __init__.py │ │ │ │ ├── distributed_sampler.py │ │ │ │ └── grouped_batch_sampler.py │ │ │ └── transforms │ │ │ │ ├── __init__.py │ │ │ │ ├── augmentation.py │ │ │ │ ├── augmentation_impl.py │ │ │ │ └── transform.py │ │ ├── engine │ │ │ ├── __init__.py │ │ │ ├── defaults.py │ │ │ ├── hooks.py │ │ │ ├── launch.py │ │ │ └── train_loop.py │ │ ├── evaluation │ │ │ ├── __init__.py │ │ │ ├── cityscapes_evaluation.py │ │ │ ├── coco_evaluation.py │ │ │ ├── evaluator.py │ │ │ ├── fast_eval_api.py │ │ │ ├── lvis_evaluation.py │ │ │ ├── panoptic_evaluation.py │ │ │ ├── pascal_voc_evaluation.py │ │ │ ├── rotated_coco_evaluation.py │ │ │ ├── sem_seg_evaluation.py │ │ │ └── testing.py │ │ ├── export │ │ │ ├── README.md │ │ │ ├── __init__.py │ │ │ ├── api.py │ │ │ ├── c10.py │ │ │ ├── caffe2_export.py │ │ │ ├── caffe2_inference.py │ │ │ ├── caffe2_modeling.py │ │ │ ├── caffe2_patch.py │ │ │ ├── flatten.py │ │ │ ├── shared.py │ │ │ ├── torchscript.py │ │ │ └── torchscript_patch.py │ │ ├── layers │ │ │ ├── __init__.py │ │ │ ├── aspp.py │ │ │ ├── batch_norm.py │ │ │ ├── blocks.py │ │ │ ├── csrc │ │ │ │ ├── README.md │ │ │ │ ├── ROIAlignRotated │ │ │ │ │ ├── ROIAlignRotated.h │ │ │ │ │ ├── ROIAlignRotated_cpu.cpp │ │ │ │ │ └── ROIAlignRotated_cuda.cu │ │ │ │ ├── box_iou_rotated │ │ │ │ │ ├── box_iou_rotated.h │ │ │ │ │ ├── box_iou_rotated_cpu.cpp │ │ │ │ │ ├── box_iou_rotated_cuda.cu │ │ │ │ │ └── box_iou_rotated_utils.h │ │ │ │ ├── cocoeval │ │ │ │ │ ├── cocoeval.cpp │ │ │ │ │ └── cocoeval.h │ │ │ │ ├── cuda_version.cu │ │ │ │ ├── deformable │ │ │ │ │ ├── deform_conv.h │ │ │ │ │ ├── deform_conv_cuda.cu │ │ │ │ │ └── deform_conv_cuda_kernel.cu │ │ │ │ ├── nms_rotated │ │ │ │ │ ├── nms_rotated.h │ │ │ │ │ ├── nms_rotated_cpu.cpp │ │ │ │ │ └── nms_rotated_cuda.cu │ │ │ │ └── vision.cpp │ │ │ ├── deform_conv.py │ │ │ ├── losses.py │ │ │ ├── mask_ops.py │ │ │ ├── nms.py │ │ │ ├── roi_align.py │ │ │ ├── roi_align_rotated.py │ │ │ ├── rotated_boxes.py │ │ │ ├── shape_spec.py │ │ │ └── wrappers.py │ │ ├── model_zoo │ │ │ ├── __init__.py │ │ │ └── model_zoo.py │ │ ├── modeling │ │ │ ├── __init__.py │ │ │ ├── anchor_generator.py │ │ │ ├── backbone │ │ │ │ ├── __init__.py │ │ │ │ ├── backbone.py │ │ │ │ ├── build.py │ │ │ │ ├── fpn.py │ │ │ │ ├── mvit.py │ │ │ │ ├── regnet.py │ │ │ │ ├── resnet.py │ │ │ │ ├── swin.py │ │ │ │ ├── utils.py │ │ │ │ └── vit.py │ │ │ ├── box_regression.py │ │ │ ├── matcher.py │ │ │ ├── meta_arch │ │ │ │ ├── __init__.py │ │ │ │ ├── build.py │ │ │ │ ├── dense_detector.py │ │ │ │ ├── fcos.py │ │ │ │ ├── panoptic_fpn.py │ │ │ │ ├── rcnn.py │ │ │ │ ├── retinanet.py │ │ │ │ └── semantic_seg.py │ │ │ ├── mmdet_wrapper.py │ │ │ ├── poolers.py │ │ │ ├── postprocessing.py │ │ │ ├── proposal_generator │ │ │ │ ├── __init__.py │ │ │ │ ├── build.py │ │ │ │ ├── proposal_utils.py │ │ │ │ ├── rpn.py │ │ │ │ └── rrpn.py │ │ │ ├── roi_heads │ │ │ │ ├── __init__.py │ │ │ │ ├── box_head.py │ │ │ │ ├── cascade_rcnn.py │ │ │ │ ├── fast_rcnn.py │ │ │ │ ├── keypoint_head.py │ │ │ │ ├── mask_head.py │ │ │ │ ├── roi_heads.py │ │ │ │ └── rotated_fast_rcnn.py │ │ │ ├── sampling.py │ │ │ └── test_time_augmentation.py │ │ ├── projects │ │ │ ├── README.md │ │ │ ├── __init__.py │ │ │ └── deeplab │ │ │ │ ├── __init__.py │ │ │ │ ├── build_solver.py │ │ │ │ ├── config.py │ │ │ │ ├── loss.py │ │ │ │ ├── lr_scheduler.py │ │ │ │ ├── resnet.py │ │ │ │ └── semantic_seg.py │ │ ├── solver │ │ │ ├── __init__.py │ │ │ ├── build.py │ │ │ └── lr_scheduler.py │ │ ├── structures │ │ │ ├── __init__.py │ │ │ ├── boxes.py │ │ │ ├── image_list.py │ │ │ ├── instances.py │ │ │ ├── keypoints.py │ │ │ ├── masks.py │ │ │ └── rotated_boxes.py │ │ ├── tracking │ │ │ ├── __init__.py │ │ │ ├── base_tracker.py │ │ │ ├── bbox_iou_tracker.py │ │ │ ├── hungarian_tracker.py │ │ │ ├── iou_weighted_hungarian_bbox_iou_tracker.py │ │ │ ├── utils.py │ │ │ └── vanilla_hungarian_bbox_iou_tracker.py │ │ └── utils │ │ │ ├── README.md │ │ │ ├── __init__.py │ │ │ ├── analysis.py │ │ │ ├── collect_env.py │ │ │ ├── colormap.py │ │ │ ├── comm.py │ │ │ ├── develop.py │ │ │ ├── env.py │ │ │ ├── events.py │ │ │ ├── file_io.py │ │ │ ├── logger.py │ │ │ ├── memory.py │ │ │ ├── registry.py │ │ │ ├── serialize.py │ │ │ ├── testing.py │ │ │ ├── tracing.py │ │ │ ├── video_visualizer.py │ │ │ └── visualizer.py │ ├── oneformer │ │ ├── __init__.py │ │ ├── config.py │ │ ├── data │ │ │ ├── __init__.py │ │ │ ├── bpe_simple_vocab_16e6.txt.gz │ │ │ ├── build.py │ │ │ ├── dataset_mappers │ │ │ │ ├── __init__.py │ │ │ │ ├── coco_unified_new_baseline_dataset_mapper.py │ │ │ │ ├── dataset_mapper.py │ │ │ │ └── oneformer_unified_dataset_mapper.py │ │ │ ├── datasets │ │ │ │ ├── __init__.py │ │ │ │ ├── register_ade20k_instance.py │ │ │ │ ├── register_ade20k_panoptic.py │ │ │ │ ├── register_cityscapes_panoptic.py │ │ │ │ ├── register_coco_panoptic2instance.py │ │ │ │ └── register_coco_panoptic_annos_semseg.py │ │ │ └── tokenizer.py │ │ ├── demo │ │ │ ├── colormap.py │ │ │ ├── defaults.py │ │ │ ├── predictor.py │ │ │ └── visualizer.py │ │ ├── evaluation │ │ │ ├── __init__.py │ │ │ ├── cityscapes_evaluation.py │ │ │ ├── coco_evaluator.py │ │ │ ├── detection_coco_evaluator.py │ │ │ ├── evaluator.py │ │ │ └── instance_evaluation.py │ │ ├── modeling │ │ │ ├── __init__.py │ │ │ ├── backbone │ │ │ │ ├── __init__.py │ │ │ │ ├── dinat.py │ │ │ │ └── swin.py │ │ │ ├── matcher.py │ │ │ ├── meta_arch │ │ │ │ ├── __init__.py │ │ │ │ └── oneformer_head.py │ │ │ ├── pixel_decoder │ │ │ │ ├── __init__.py │ │ │ │ ├── fpn.py │ │ │ │ ├── msdeformattn.py │ │ │ │ └── ops │ │ │ │ │ ├── functions │ │ │ │ │ ├── __init__.py │ │ │ │ │ └── ms_deform_attn_func.py │ │ │ │ │ ├── make.sh │ │ │ │ │ ├── modules │ │ │ │ │ ├── __init__.py │ │ │ │ │ └── ms_deform_attn.py │ │ │ │ │ ├── setup.py │ │ │ │ │ ├── src │ │ │ │ │ ├── cpu │ │ │ │ │ │ ├── ms_deform_attn_cpu.cpp │ │ │ │ │ │ └── ms_deform_attn_cpu.h │ │ │ │ │ ├── cuda │ │ │ │ │ │ ├── ms_deform_attn_cuda.cu │ │ │ │ │ │ ├── ms_deform_attn_cuda.h │ │ │ │ │ │ └── ms_deform_im2col_cuda.cuh │ │ │ │ │ ├── ms_deform_attn.h │ │ │ │ │ └── vision.cpp │ │ │ │ │ └── test.py │ │ │ └── transformer_decoder │ │ │ │ ├── __init__.py │ │ │ │ ├── oneformer_transformer_decoder.py │ │ │ │ ├── position_encoding.py │ │ │ │ ├── text_transformer.py │ │ │ │ └── transformer.py │ │ ├── oneformer_model.py │ │ └── utils │ │ │ ├── __init__.py │ │ │ ├── box_ops.py │ │ │ ├── events.py │ │ │ ├── misc.py │ │ │ └── pos_embed.py │ └── pycocotools │ │ ├── __init__.py │ │ ├── coco.py │ │ ├── cocoeval.py │ │ └── mask.py ├── openpose │ ├── __init__.py │ ├── body.py │ ├── face.py │ ├── hand.py │ ├── model.py │ └── util.py ├── pidinet │ ├── __init__.py │ └── model.py ├── shuffle │ └── __init__.py ├── uniformer │ ├── __init__.py │ ├── configs │ │ └── _base_ │ │ │ ├── datasets │ │ │ ├── ade20k.py │ │ │ ├── chase_db1.py │ │ │ ├── cityscapes.py │ │ │ ├── cityscapes_769x769.py │ │ │ ├── drive.py │ │ │ ├── hrf.py │ │ │ ├── pascal_context.py │ │ │ ├── pascal_context_59.py │ │ │ ├── pascal_voc12.py │ │ │ ├── pascal_voc12_aug.py │ │ │ └── stare.py │ │ │ ├── default_runtime.py │ │ │ ├── models │ │ │ ├── ann_r50-d8.py │ │ │ ├── apcnet_r50-d8.py │ │ │ ├── ccnet_r50-d8.py │ │ │ ├── cgnet.py │ │ │ ├── danet_r50-d8.py │ │ │ ├── deeplabv3_r50-d8.py │ │ │ ├── deeplabv3_unet_s5-d16.py │ │ │ ├── deeplabv3plus_r50-d8.py │ │ │ ├── dmnet_r50-d8.py │ │ │ ├── dnl_r50-d8.py │ │ │ ├── emanet_r50-d8.py │ │ │ ├── encnet_r50-d8.py │ │ │ ├── fast_scnn.py │ │ │ ├── fcn_hr18.py │ │ │ ├── fcn_r50-d8.py │ │ │ ├── fcn_unet_s5-d16.py │ │ │ ├── fpn_r50.py │ │ │ ├── fpn_uniformer.py │ │ │ ├── gcnet_r50-d8.py │ │ │ ├── lraspp_m-v3-d8.py │ │ │ ├── nonlocal_r50-d8.py │ │ │ ├── ocrnet_hr18.py │ │ │ ├── ocrnet_r50-d8.py │ │ │ ├── pointrend_r50.py │ │ │ ├── psanet_r50-d8.py │ │ │ ├── pspnet_r50-d8.py │ │ │ ├── pspnet_unet_s5-d16.py │ │ │ ├── upernet_r50.py │ │ │ └── upernet_uniformer.py │ │ │ └── schedules │ │ │ ├── schedule_160k.py │ │ │ ├── schedule_20k.py │ │ │ ├── schedule_40k.py │ │ │ └── schedule_80k.py │ ├── inference.py │ ├── mmcv_custom │ │ ├── __init__.py │ │ └── checkpoint.py │ ├── uniformer.py │ └── upernet_global_small.py ├── util.py └── zoe │ ├── __init__.py │ └── zoedepth │ ├── models │ ├── __init__.py │ ├── base_models │ │ ├── __init__.py │ │ ├── midas.py │ │ └── midas_repo │ │ │ ├── .gitignore │ │ │ ├── Dockerfile │ │ │ ├── LICENSE │ │ │ ├── README.md │ │ │ ├── environment.yaml │ │ │ ├── hubconf.py │ │ │ ├── input │ │ │ └── .placeholder │ │ │ ├── midas │ │ │ ├── backbones │ │ │ │ ├── beit.py │ │ │ │ ├── levit.py │ │ │ │ ├── next_vit.py │ │ │ │ ├── swin.py │ │ │ │ ├── swin2.py │ │ │ │ ├── swin_common.py │ │ │ │ ├── utils.py │ │ │ │ └── vit.py │ │ │ ├── base_model.py │ │ │ ├── blocks.py │ │ │ ├── dpt_depth.py │ │ │ ├── midas_net.py │ │ │ ├── midas_net_custom.py │ │ │ ├── model_loader.py │ │ │ └── transforms.py │ │ │ ├── output │ │ │ └── .placeholder │ │ │ ├── ros │ │ │ ├── LICENSE │ │ │ ├── README.md │ │ │ ├── additions │ │ │ │ ├── do_catkin_make.sh │ │ │ │ ├── downloads.sh │ │ │ │ ├── install_ros_melodic_ubuntu_17_18.sh │ │ │ │ ├── install_ros_noetic_ubuntu_20.sh │ │ │ │ └── make_package_cpp.sh │ │ │ ├── launch_midas_cpp.sh │ │ │ ├── midas_cpp │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── launch │ │ │ │ │ ├── midas_cpp.launch │ │ │ │ │ └── midas_talker_listener.launch │ │ │ │ ├── package.xml │ │ │ │ ├── scripts │ │ │ │ │ ├── listener.py │ │ │ │ │ ├── listener_original.py │ │ │ │ │ └── talker.py │ │ │ │ └── src │ │ │ │ │ └── main.cpp │ │ │ └── run_talker_listener_test.sh │ │ │ ├── run.py │ │ │ ├── tf │ │ │ ├── README.md │ │ │ ├── input │ │ │ │ └── .placeholder │ │ │ ├── make_onnx_model.py │ │ │ ├── output │ │ │ │ └── .placeholder │ │ │ ├── run_onnx.py │ │ │ ├── run_pb.py │ │ │ ├── transforms.py │ │ │ └── utils.py │ │ │ ├── utils.py │ │ │ └── weights │ │ │ └── .placeholder │ ├── builder.py │ ├── depth_model.py │ ├── layers │ │ ├── attractor.py │ │ ├── dist_layers.py │ │ ├── localbins_layers.py │ │ └── patch_transformer.py │ ├── model_io.py │ ├── zoedepth │ │ ├── __init__.py │ │ ├── config_zoedepth.json │ │ ├── config_zoedepth_kitti.json │ │ └── zoedepth_v1.py │ └── zoedepth_nk │ │ ├── __init__.py │ │ ├── config_zoedepth_nk.json │ │ └── zoedepth_nk_v1.py │ └── utils │ ├── __init__.py │ ├── arg_utils.py │ ├── config.py │ ├── easydict │ └── __init__.py │ ├── geometry.py │ └── misc.py ├── example ├── api_img2img.ipynb ├── api_txt2img.ipynb ├── chatgpt.py └── visual_chatgpt.ipynb ├── extract_controlnet.py ├── extract_controlnet_diff.py ├── install.py ├── models ├── cldm_v15.yaml ├── cldm_v21.yaml ├── control_v11e_sd15_ip2p.yaml ├── control_v11e_sd15_shuffle.yaml ├── control_v11f1p_sd15_depth.yaml ├── control_v11p_sd15_canny.yaml ├── control_v11p_sd15_inpaint.yaml ├── control_v11p_sd15_lineart.yaml ├── control_v11p_sd15_mlsd.yaml ├── control_v11p_sd15_normalbae.yaml ├── control_v11p_sd15_openpose.yaml ├── control_v11p_sd15_scribble.yaml ├── control_v11p_sd15_seg.yaml ├── control_v11p_sd15_softedge.yaml ├── control_v11p_sd15s2_lineart_anime.yaml ├── control_v11u_sd15_tile.yaml ├── image_adapter_v14.yaml ├── sketch_adapter_v14.yaml ├── t2iadapter_canny_sd14v1.yaml ├── t2iadapter_canny_sd15v2.yaml ├── t2iadapter_color_sd14v1.yaml ├── t2iadapter_depth_sd14v1.yaml ├── t2iadapter_depth_sd15v2.yaml ├── t2iadapter_keypose_sd14v1.yaml ├── t2iadapter_openpose_sd14v1.yaml ├── t2iadapter_seg_sd14v1.yaml ├── t2iadapter_sketch_sd14v1.yaml ├── t2iadapter_sketch_sd15v2.yaml ├── t2iadapter_style_sd14v1.yaml └── t2iadapter_zoedepth_sd15v1.yaml ├── preload.py ├── requirements.txt ├── samples ├── an-gen.png ├── an-pose.png ├── an-source.jpg ├── bal-gen.png ├── bal-source.png ├── cat_out-2.png ├── cat_sk-2.png ├── dog_out-2.png ├── dog_rel.jpg ├── dog_rel.png ├── dog_sk-2.png ├── evt_gen.png ├── evt_hed.png ├── evt_source.jpg ├── fs_input.png ├── fs_output.png ├── kp_a-2.png ├── kp_a2-2.png ├── kp_o-2.png ├── kp_o2-2.png ├── mahiro-out.png ├── mahiro_canny.png ├── mahiro_input.png ├── nm-gen.png ├── nm-out.png ├── nm-src.png ├── sk-b-dep.png ├── sk-b-out.png └── sk-b-src.png ├── scripts ├── adapter.py ├── api.py ├── cldm.py ├── controlnet.py ├── external_code.py ├── global_state.py ├── hook.py ├── movie2movie.py ├── processor.py ├── utils.py └── xyz_grid_support.py └── tests ├── external_code_api ├── __init__.py ├── external_code_test.py └── script_args_test.py ├── utils.py └── web_api ├── __init__.py └── txt2img_test.py /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: true 2 | -------------------------------------------------------------------------------- /.github/workflows/tests.yml: -------------------------------------------------------------------------------- 1 | name: Run basic features tests on CPU 2 | 3 | on: 4 | - push 5 | - pull_request 6 | 7 | jobs: 8 | build: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - name: Checkout Code 12 | uses: actions/checkout@v3 13 | with: 14 | repository: 'AUTOMATIC1111/stable-diffusion-webui' 15 | path: 'stable-diffusion-webui' 16 | 17 | - name: Checkout Code 18 | uses: actions/checkout@v3 19 | with: 20 | repository: 'Mikubill/sd-webui-controlnet' 21 | path: 'stable-diffusion-webui/extensions/sd-webui-controlnet' 22 | 23 | - name: Set up Python 3.10 24 | uses: actions/setup-python@v4 25 | with: 26 | python-version: 3.10.6 27 | cache: pip 28 | cache-dependency-path: | 29 | **/requirements*txt 30 | stable-diffusion-webui/requirements*txt 31 | 32 | - run: | 33 | curl -Lo stable-diffusion-webui/extensions/sd-webui-controlnet/models/control_canny-fp16.safetensors https://huggingface.co/webui/ControlNet-modules-safetensors/resolve/main/control_canny-fp16.safetensors 34 | cd stable-diffusion-webui && IGNORE_CMD_ARGS_ERRORS=1 python launch.py --no-half --disable-opt-split-attention --use-cpu all --skip-torch-cuda-test --api --tests ./extensions/sd-webui-controlnet/tests 35 | rm -fr stable-diffusion-webui/extensions/sd-webui-controlnet/models/control_canny-fp16.safetensors 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Kakigōri Maker 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 | -------------------------------------------------------------------------------- /annotator/binary/__init__.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | 3 | 4 | def apply_binary(img, bin_threshold): 5 | img_gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY) 6 | 7 | if bin_threshold == 0 or bin_threshold == 255: 8 | # Otsu's threshold 9 | otsu_threshold, img_bin = cv2.threshold(img_gray, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU) 10 | print("Otsu threshold:", otsu_threshold) 11 | else: 12 | _, img_bin = cv2.threshold(img_gray, bin_threshold, 255, cv2.THRESH_BINARY_INV) 13 | 14 | return cv2.cvtColor(img_bin, cv2.COLOR_GRAY2RGB) 15 | -------------------------------------------------------------------------------- /annotator/canny/__init__.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | 3 | 4 | def apply_canny(img, low_threshold, high_threshold): 5 | return cv2.Canny(img, low_threshold, high_threshold) 6 | -------------------------------------------------------------------------------- /annotator/clip/__init__.py: -------------------------------------------------------------------------------- 1 | from transformers import CLIPProcessor, CLIPVisionModel 2 | from modules import devices 3 | 4 | version = 'openai/clip-vit-large-patch14' 5 | clip_proc = None 6 | clip_vision_model = None 7 | 8 | def apply_clip(img): 9 | global clip_proc, clip_vision_model 10 | 11 | if clip_vision_model is None: 12 | clip_proc = CLIPProcessor.from_pretrained(version) 13 | clip_vision_model = CLIPVisionModel.from_pretrained(version) 14 | 15 | clip_vision_model = clip_vision_model.to(devices.get_device_for("controlnet")) 16 | style_for_clip = clip_proc(images=img, return_tensors="pt")['pixel_values'] 17 | style_feat = clip_vision_model(style_for_clip.to(devices.get_device_for("controlnet")))['last_hidden_state'] 18 | return style_feat 19 | 20 | def unload_clip_model(): 21 | global clip_proc, clip_vision_model 22 | if clip_vision_model is not None: 23 | clip_vision_model.cpu() -------------------------------------------------------------------------------- /annotator/color/__init__.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | 3 | def cv2_resize_shortest_edge(image, size): 4 | h, w = image.shape[:2] 5 | if h < w: 6 | new_h = size 7 | new_w = int(round(w / h * size)) 8 | else: 9 | new_w = size 10 | new_h = int(round(h / w * size)) 11 | resized_image = cv2.resize(image, (new_w, new_h), interpolation=cv2.INTER_AREA) 12 | return resized_image 13 | 14 | def apply_color(img, res=512): 15 | img = cv2_resize_shortest_edge(img, res) 16 | h, w = img.shape[:2] 17 | 18 | input_img_color = cv2.resize(img, (w//64, h//64), interpolation=cv2.INTER_CUBIC) 19 | input_img_color = cv2.resize(input_img_color, (w, h), interpolation=cv2.INTER_NEAREST) 20 | return input_img_color -------------------------------------------------------------------------------- /annotator/leres/leres/LICENSE: -------------------------------------------------------------------------------- 1 | https://github.com/thygate/stable-diffusion-webui-depthmap-script 2 | 3 | MIT License 4 | 5 | Copyright (c) 2023 Bob Thiry 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. -------------------------------------------------------------------------------- /annotator/leres/leres/multi_depth_model_woauxi.py: -------------------------------------------------------------------------------- 1 | from . import network_auxi as network 2 | from .net_tools import get_func 3 | import torch 4 | import torch.nn as nn 5 | from modules import devices 6 | 7 | class RelDepthModel(nn.Module): 8 | def __init__(self, backbone='resnet50'): 9 | super(RelDepthModel, self).__init__() 10 | if backbone == 'resnet50': 11 | encoder = 'resnet50_stride32' 12 | elif backbone == 'resnext101': 13 | encoder = 'resnext101_stride32x8d' 14 | self.depth_model = DepthModel(encoder) 15 | 16 | def inference(self, rgb): 17 | with torch.no_grad(): 18 | input = rgb.to(self.depth_model.device) 19 | depth = self.depth_model(input) 20 | #pred_depth_out = depth - depth.min() + 0.01 21 | return depth #pred_depth_out 22 | 23 | 24 | class DepthModel(nn.Module): 25 | def __init__(self, encoder): 26 | super(DepthModel, self).__init__() 27 | backbone = network.__name__.split('.')[-1] + '.' + encoder 28 | self.encoder_modules = get_func(backbone)() 29 | self.decoder_modules = network.Decoder() 30 | 31 | def forward(self, x): 32 | lateral_out = self.encoder_modules(x) 33 | out_logit = self.decoder_modules(lateral_out) 34 | return out_logit -------------------------------------------------------------------------------- /annotator/leres/pix2pix/LICENSE: -------------------------------------------------------------------------------- 1 | https://github.com/compphoto/BoostingMonocularDepth 2 | 3 | Copyright 2021, Seyed Mahdi Hosseini Miangoleh, Sebastian Dille, Computational Photography Laboratory. All rights reserved. 4 | 5 | This software is for academic use only. A redistribution of this 6 | software, with or without modifications, has to be for academic 7 | use only, while giving the appropriate credit to the original 8 | authors of the software. The methods implemented as a part of 9 | this software may be covered under patents or patent applications. 10 | 11 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED 12 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 13 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR 14 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 15 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 16 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 17 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 18 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 19 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /annotator/leres/pix2pix/options/__init__.py: -------------------------------------------------------------------------------- 1 | """This package options includes option modules: training options, test options, and basic options (used in both training and test).""" 2 | -------------------------------------------------------------------------------- /annotator/leres/pix2pix/options/test_options.py: -------------------------------------------------------------------------------- 1 | from .base_options import BaseOptions 2 | 3 | 4 | class TestOptions(BaseOptions): 5 | """This class includes test options. 6 | 7 | It also includes shared options defined in BaseOptions. 8 | """ 9 | 10 | def initialize(self, parser): 11 | parser = BaseOptions.initialize(self, parser) # define shared options 12 | parser.add_argument('--aspect_ratio', type=float, default=1.0, help='aspect ratio of result images') 13 | parser.add_argument('--phase', type=str, default='test', help='train, val, test, etc') 14 | # Dropout and Batchnorm has different behavioir during training and test. 15 | parser.add_argument('--eval', action='store_true', help='use eval mode during test time.') 16 | parser.add_argument('--num_test', type=int, default=50, help='how many test images to run') 17 | # rewrite devalue values 18 | parser.set_defaults(model='pix2pix4depth') 19 | # To avoid cropping, the load_size should be the same as crop_size 20 | parser.set_defaults(load_size=parser.get_default('crop_size')) 21 | self.isTrain = False 22 | return parser 23 | -------------------------------------------------------------------------------- /annotator/leres/pix2pix/util/__init__.py: -------------------------------------------------------------------------------- 1 | """This package includes a miscellaneous collection of useful helper functions.""" 2 | -------------------------------------------------------------------------------- /annotator/mediapipe_face/__init__.py: -------------------------------------------------------------------------------- 1 | from .mediapipe_face_common import generate_annotation 2 | 3 | 4 | def apply_mediapipe_face(image, max_faces: int = 1, min_confidence: float = 0.5): 5 | return generate_annotation(image, max_faces, min_confidence) 6 | -------------------------------------------------------------------------------- /annotator/midas/midas/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crucible-ai/sd-webui-controlnet/385b67c2e310b7ee71aed3d61ec04a83c1efba0f/annotator/midas/midas/__init__.py -------------------------------------------------------------------------------- /annotator/midas/midas/base_model.py: -------------------------------------------------------------------------------- 1 | import torch 2 | 3 | 4 | class BaseModel(torch.nn.Module): 5 | def load(self, path): 6 | """Load model from file. 7 | 8 | Args: 9 | path (str): file path 10 | """ 11 | parameters = torch.load(path, map_location=torch.device('cpu')) 12 | 13 | if "optimizer" in parameters: 14 | parameters = parameters["model"] 15 | 16 | self.load_state_dict(parameters) 17 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmcv/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | # flake8: noqa 3 | from .arraymisc import * 4 | from .fileio import * 5 | from .image import * 6 | from .utils import * 7 | from .version import * 8 | from .video import * 9 | from .visualization import * 10 | 11 | # The following modules are not imported to this level, so mmcv may be used 12 | # without PyTorch. 13 | # - runner 14 | # - parallel 15 | # - op 16 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmcv/arraymisc/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from .quantization import dequantize, quantize 3 | 4 | __all__ = ['quantize', 'dequantize'] 5 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmcv/cnn/bricks/conv.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from torch import nn 3 | 4 | from .registry import CONV_LAYERS 5 | 6 | CONV_LAYERS.register_module('Conv1d', module=nn.Conv1d) 7 | CONV_LAYERS.register_module('Conv2d', module=nn.Conv2d) 8 | CONV_LAYERS.register_module('Conv3d', module=nn.Conv3d) 9 | CONV_LAYERS.register_module('Conv', module=nn.Conv2d) 10 | 11 | 12 | def build_conv_layer(cfg, *args, **kwargs): 13 | """Build convolution layer. 14 | 15 | Args: 16 | cfg (None or dict): The conv layer config, which should contain: 17 | - type (str): Layer type. 18 | - layer args: Args needed to instantiate an conv layer. 19 | args (argument list): Arguments passed to the `__init__` 20 | method of the corresponding conv layer. 21 | kwargs (keyword arguments): Keyword arguments passed to the `__init__` 22 | method of the corresponding conv layer. 23 | 24 | Returns: 25 | nn.Module: Created conv layer. 26 | """ 27 | if cfg is None: 28 | cfg_ = dict(type='Conv2d') 29 | else: 30 | if not isinstance(cfg, dict): 31 | raise TypeError('cfg must be a dict') 32 | if 'type' not in cfg: 33 | raise KeyError('the cfg dict must contain the key "type"') 34 | cfg_ = cfg.copy() 35 | 36 | layer_type = cfg_.pop('type') 37 | if layer_type not in CONV_LAYERS: 38 | raise KeyError(f'Unrecognized norm type {layer_type}') 39 | else: 40 | conv_layer = CONV_LAYERS.get(layer_type) 41 | 42 | layer = conv_layer(*args, **kwargs, **cfg_) 43 | 44 | return layer 45 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmcv/cnn/bricks/hsigmoid.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | import torch.nn as nn 3 | 4 | from .registry import ACTIVATION_LAYERS 5 | 6 | 7 | @ACTIVATION_LAYERS.register_module() 8 | class HSigmoid(nn.Module): 9 | """Hard Sigmoid Module. Apply the hard sigmoid function: 10 | Hsigmoid(x) = min(max((x + bias) / divisor, min_value), max_value) 11 | Default: Hsigmoid(x) = min(max((x + 1) / 2, 0), 1) 12 | 13 | Args: 14 | bias (float): Bias of the input feature map. Default: 1.0. 15 | divisor (float): Divisor of the input feature map. Default: 2.0. 16 | min_value (float): Lower bound value. Default: 0.0. 17 | max_value (float): Upper bound value. Default: 1.0. 18 | 19 | Returns: 20 | Tensor: The output tensor. 21 | """ 22 | 23 | def __init__(self, bias=1.0, divisor=2.0, min_value=0.0, max_value=1.0): 24 | super(HSigmoid, self).__init__() 25 | self.bias = bias 26 | self.divisor = divisor 27 | assert self.divisor != 0 28 | self.min_value = min_value 29 | self.max_value = max_value 30 | 31 | def forward(self, x): 32 | x = (x + self.bias) / self.divisor 33 | 34 | return x.clamp_(self.min_value, self.max_value) 35 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmcv/cnn/bricks/hswish.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | import torch.nn as nn 3 | 4 | from .registry import ACTIVATION_LAYERS 5 | 6 | 7 | @ACTIVATION_LAYERS.register_module() 8 | class HSwish(nn.Module): 9 | """Hard Swish Module. 10 | 11 | This module applies the hard swish function: 12 | 13 | .. math:: 14 | Hswish(x) = x * ReLU6(x + 3) / 6 15 | 16 | Args: 17 | inplace (bool): can optionally do the operation in-place. 18 | Default: False. 19 | 20 | Returns: 21 | Tensor: The output tensor. 22 | """ 23 | 24 | def __init__(self, inplace=False): 25 | super(HSwish, self).__init__() 26 | self.act = nn.ReLU6(inplace) 27 | 28 | def forward(self, x): 29 | return x * self.act(x + 3) / 6 30 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmcv/cnn/bricks/padding.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | import torch.nn as nn 3 | 4 | from .registry import PADDING_LAYERS 5 | 6 | PADDING_LAYERS.register_module('zero', module=nn.ZeroPad2d) 7 | PADDING_LAYERS.register_module('reflect', module=nn.ReflectionPad2d) 8 | PADDING_LAYERS.register_module('replicate', module=nn.ReplicationPad2d) 9 | 10 | 11 | def build_padding_layer(cfg, *args, **kwargs): 12 | """Build padding layer. 13 | 14 | Args: 15 | cfg (None or dict): The padding layer config, which should contain: 16 | - type (str): Layer type. 17 | - layer args: Args needed to instantiate a padding layer. 18 | 19 | Returns: 20 | nn.Module: Created padding layer. 21 | """ 22 | if not isinstance(cfg, dict): 23 | raise TypeError('cfg must be a dict') 24 | if 'type' not in cfg: 25 | raise KeyError('the cfg dict must contain the key "type"') 26 | 27 | cfg_ = cfg.copy() 28 | padding_type = cfg_.pop('type') 29 | if padding_type not in PADDING_LAYERS: 30 | raise KeyError(f'Unrecognized padding type {padding_type}.') 31 | else: 32 | padding_layer = PADDING_LAYERS.get(padding_type) 33 | 34 | layer = padding_layer(*args, **kwargs, **cfg_) 35 | 36 | return layer 37 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmcv/cnn/bricks/registry.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from annotator.mmpkg.mmcv.utils import Registry 3 | 4 | CONV_LAYERS = Registry('conv layer') 5 | NORM_LAYERS = Registry('norm layer') 6 | ACTIVATION_LAYERS = Registry('activation layer') 7 | PADDING_LAYERS = Registry('padding layer') 8 | UPSAMPLE_LAYERS = Registry('upsample layer') 9 | PLUGIN_LAYERS = Registry('plugin layer') 10 | 11 | DROPOUT_LAYERS = Registry('drop out layers') 12 | POSITIONAL_ENCODING = Registry('position encoding') 13 | ATTENTION = Registry('attention') 14 | FEEDFORWARD_NETWORK = Registry('feed-forward Network') 15 | TRANSFORMER_LAYER = Registry('transformerLayer') 16 | TRANSFORMER_LAYER_SEQUENCE = Registry('transformer-layers sequence') 17 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmcv/cnn/bricks/scale.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | import torch 3 | import torch.nn as nn 4 | 5 | 6 | class Scale(nn.Module): 7 | """A learnable scale parameter. 8 | 9 | This layer scales the input by a learnable factor. It multiplies a 10 | learnable scale parameter of shape (1,) with input of any shape. 11 | 12 | Args: 13 | scale (float): Initial value of scale factor. Default: 1.0 14 | """ 15 | 16 | def __init__(self, scale=1.0): 17 | super(Scale, self).__init__() 18 | self.scale = nn.Parameter(torch.tensor(scale, dtype=torch.float)) 19 | 20 | def forward(self, x): 21 | return x * self.scale 22 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmcv/cnn/bricks/swish.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | import torch 3 | import torch.nn as nn 4 | 5 | from .registry import ACTIVATION_LAYERS 6 | 7 | 8 | @ACTIVATION_LAYERS.register_module() 9 | class Swish(nn.Module): 10 | """Swish Module. 11 | 12 | This module applies the swish function: 13 | 14 | .. math:: 15 | Swish(x) = x * Sigmoid(x) 16 | 17 | Returns: 18 | Tensor: The output tensor. 19 | """ 20 | 21 | def __init__(self): 22 | super(Swish, self).__init__() 23 | 24 | def forward(self, x): 25 | return x * torch.sigmoid(x) 26 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmcv/cnn/builder.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from ..runner import Sequential 3 | from ..utils import Registry, build_from_cfg 4 | 5 | 6 | def build_model_from_cfg(cfg, registry, default_args=None): 7 | """Build a PyTorch model from config dict(s). Different from 8 | ``build_from_cfg``, if cfg is a list, a ``nn.Sequential`` will be built. 9 | 10 | Args: 11 | cfg (dict, list[dict]): The config of modules, is is either a config 12 | dict or a list of config dicts. If cfg is a list, a 13 | the built modules will be wrapped with ``nn.Sequential``. 14 | registry (:obj:`Registry`): A registry the module belongs to. 15 | default_args (dict, optional): Default arguments to build the module. 16 | Defaults to None. 17 | 18 | Returns: 19 | nn.Module: A built nn module. 20 | """ 21 | if isinstance(cfg, list): 22 | modules = [ 23 | build_from_cfg(cfg_, registry, default_args) for cfg_ in cfg 24 | ] 25 | return Sequential(*modules) 26 | else: 27 | return build_from_cfg(cfg, registry, default_args) 28 | 29 | 30 | MODELS = Registry('model', build_func=build_model_from_cfg) 31 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmcv/cnn/utils/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from .flops_counter import get_model_complexity_info 3 | from .fuse_conv_bn import fuse_conv_bn 4 | from .sync_bn import revert_sync_batchnorm 5 | from .weight_init import (INITIALIZERS, Caffe2XavierInit, ConstantInit, 6 | KaimingInit, NormalInit, PretrainedInit, 7 | TruncNormalInit, UniformInit, XavierInit, 8 | bias_init_with_prob, caffe2_xavier_init, 9 | constant_init, initialize, kaiming_init, normal_init, 10 | trunc_normal_init, uniform_init, xavier_init) 11 | 12 | __all__ = [ 13 | 'get_model_complexity_info', 'bias_init_with_prob', 'caffe2_xavier_init', 14 | 'constant_init', 'kaiming_init', 'normal_init', 'trunc_normal_init', 15 | 'uniform_init', 'xavier_init', 'fuse_conv_bn', 'initialize', 16 | 'INITIALIZERS', 'ConstantInit', 'XavierInit', 'NormalInit', 17 | 'TruncNormalInit', 'UniformInit', 'KaimingInit', 'PretrainedInit', 18 | 'Caffe2XavierInit', 'revert_sync_batchnorm' 19 | ] 20 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmcv/engine/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from .test import (collect_results_cpu, collect_results_gpu, multi_gpu_test, 3 | single_gpu_test) 4 | 5 | __all__ = [ 6 | 'collect_results_cpu', 'collect_results_gpu', 'multi_gpu_test', 7 | 'single_gpu_test' 8 | ] 9 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmcv/fileio/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from .file_client import BaseStorageBackend, FileClient 3 | from .handlers import BaseFileHandler, JsonHandler, PickleHandler, YamlHandler 4 | from .io import dump, load, register_handler 5 | from .parse import dict_from_file, list_from_file 6 | 7 | __all__ = [ 8 | 'BaseStorageBackend', 'FileClient', 'load', 'dump', 'register_handler', 9 | 'BaseFileHandler', 'JsonHandler', 'PickleHandler', 'YamlHandler', 10 | 'list_from_file', 'dict_from_file' 11 | ] 12 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmcv/fileio/handlers/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from .base import BaseFileHandler 3 | from .json_handler import JsonHandler 4 | from .pickle_handler import PickleHandler 5 | from .yaml_handler import YamlHandler 6 | 7 | __all__ = ['BaseFileHandler', 'JsonHandler', 'PickleHandler', 'YamlHandler'] 8 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmcv/fileio/handlers/base.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from abc import ABCMeta, abstractmethod 3 | 4 | 5 | class BaseFileHandler(metaclass=ABCMeta): 6 | # `str_like` is a flag to indicate whether the type of file object is 7 | # str-like object or bytes-like object. Pickle only processes bytes-like 8 | # objects but json only processes str-like object. If it is str-like 9 | # object, `StringIO` will be used to process the buffer. 10 | str_like = True 11 | 12 | @abstractmethod 13 | def load_from_fileobj(self, file, **kwargs): 14 | pass 15 | 16 | @abstractmethod 17 | def dump_to_fileobj(self, obj, file, **kwargs): 18 | pass 19 | 20 | @abstractmethod 21 | def dump_to_str(self, obj, **kwargs): 22 | pass 23 | 24 | def load_from_path(self, filepath, mode='r', **kwargs): 25 | with open(filepath, mode) as f: 26 | return self.load_from_fileobj(f, **kwargs) 27 | 28 | def dump_to_path(self, obj, filepath, mode='w', **kwargs): 29 | with open(filepath, mode) as f: 30 | self.dump_to_fileobj(obj, f, **kwargs) 31 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmcv/fileio/handlers/json_handler.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | import json 3 | 4 | import numpy as np 5 | 6 | from .base import BaseFileHandler 7 | 8 | 9 | def set_default(obj): 10 | """Set default json values for non-serializable values. 11 | 12 | It helps convert ``set``, ``range`` and ``np.ndarray`` data types to list. 13 | It also converts ``np.generic`` (including ``np.int32``, ``np.float32``, 14 | etc.) into plain numbers of plain python built-in types. 15 | """ 16 | if isinstance(obj, (set, range)): 17 | return list(obj) 18 | elif isinstance(obj, np.ndarray): 19 | return obj.tolist() 20 | elif isinstance(obj, np.generic): 21 | return obj.item() 22 | raise TypeError(f'{type(obj)} is unsupported for json dump') 23 | 24 | 25 | class JsonHandler(BaseFileHandler): 26 | 27 | def load_from_fileobj(self, file): 28 | return json.load(file) 29 | 30 | def dump_to_fileobj(self, obj, file, **kwargs): 31 | kwargs.setdefault('default', set_default) 32 | json.dump(obj, file, **kwargs) 33 | 34 | def dump_to_str(self, obj, **kwargs): 35 | kwargs.setdefault('default', set_default) 36 | return json.dumps(obj, **kwargs) 37 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmcv/fileio/handlers/pickle_handler.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | import pickle 3 | 4 | from .base import BaseFileHandler 5 | 6 | 7 | class PickleHandler(BaseFileHandler): 8 | 9 | str_like = False 10 | 11 | def load_from_fileobj(self, file, **kwargs): 12 | return pickle.load(file, **kwargs) 13 | 14 | def load_from_path(self, filepath, **kwargs): 15 | return super(PickleHandler, self).load_from_path( 16 | filepath, mode='rb', **kwargs) 17 | 18 | def dump_to_str(self, obj, **kwargs): 19 | kwargs.setdefault('protocol', 2) 20 | return pickle.dumps(obj, **kwargs) 21 | 22 | def dump_to_fileobj(self, obj, file, **kwargs): 23 | kwargs.setdefault('protocol', 2) 24 | pickle.dump(obj, file, **kwargs) 25 | 26 | def dump_to_path(self, obj, filepath, **kwargs): 27 | super(PickleHandler, self).dump_to_path( 28 | obj, filepath, mode='wb', **kwargs) 29 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmcv/fileio/handlers/yaml_handler.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | import yaml 3 | 4 | try: 5 | from yaml import CLoader as Loader, CDumper as Dumper 6 | except ImportError: 7 | from yaml import Loader, Dumper 8 | 9 | from .base import BaseFileHandler # isort:skip 10 | 11 | 12 | class YamlHandler(BaseFileHandler): 13 | 14 | def load_from_fileobj(self, file, **kwargs): 15 | kwargs.setdefault('Loader', Loader) 16 | return yaml.load(file, **kwargs) 17 | 18 | def dump_to_fileobj(self, obj, file, **kwargs): 19 | kwargs.setdefault('Dumper', Dumper) 20 | yaml.dump(obj, file, **kwargs) 21 | 22 | def dump_to_str(self, obj, **kwargs): 23 | kwargs.setdefault('Dumper', Dumper) 24 | return yaml.dump(obj, **kwargs) 25 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmcv/image/misc.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | import numpy as np 3 | 4 | import annotator.mmpkg.mmcv as mmcv 5 | 6 | try: 7 | import torch 8 | except ImportError: 9 | torch = None 10 | 11 | 12 | def tensor2imgs(tensor, mean=(0, 0, 0), std=(1, 1, 1), to_rgb=True): 13 | """Convert tensor to 3-channel images. 14 | 15 | Args: 16 | tensor (torch.Tensor): Tensor that contains multiple images, shape ( 17 | N, C, H, W). 18 | mean (tuple[float], optional): Mean of images. Defaults to (0, 0, 0). 19 | std (tuple[float], optional): Standard deviation of images. 20 | Defaults to (1, 1, 1). 21 | to_rgb (bool, optional): Whether the tensor was converted to RGB 22 | format in the first place. If so, convert it back to BGR. 23 | Defaults to True. 24 | 25 | Returns: 26 | list[np.ndarray]: A list that contains multiple images. 27 | """ 28 | 29 | if torch is None: 30 | raise RuntimeError('pytorch is not installed') 31 | assert torch.is_tensor(tensor) and tensor.ndim == 4 32 | assert len(mean) == 3 33 | assert len(std) == 3 34 | 35 | num_imgs = tensor.size(0) 36 | mean = np.array(mean, dtype=np.float32) 37 | std = np.array(std, dtype=np.float32) 38 | imgs = [] 39 | for img_id in range(num_imgs): 40 | img = tensor[img_id, ...].cpu().numpy().transpose(1, 2, 0) 41 | img = mmcv.imdenormalize( 42 | img, mean, std, to_bgr=to_rgb).astype(np.uint8) 43 | imgs.append(np.ascontiguousarray(img)) 44 | return imgs 45 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmcv/model_zoo/deprecated.json: -------------------------------------------------------------------------------- 1 | { 2 | "resnet50_caffe": "detectron/resnet50_caffe", 3 | "resnet50_caffe_bgr": "detectron2/resnet50_caffe_bgr", 4 | "resnet101_caffe": "detectron/resnet101_caffe", 5 | "resnet101_caffe_bgr": "detectron2/resnet101_caffe_bgr" 6 | } 7 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmcv/ops/deprecated_wrappers.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | # This file is for backward compatibility. 3 | # Module wrappers for empty tensor have been moved to mmcv.cnn.bricks. 4 | import warnings 5 | 6 | from ..cnn.bricks.wrappers import Conv2d, ConvTranspose2d, Linear, MaxPool2d 7 | 8 | 9 | class Conv2d_deprecated(Conv2d): 10 | 11 | def __init__(self, *args, **kwargs): 12 | super().__init__(*args, **kwargs) 13 | warnings.warn( 14 | 'Importing Conv2d wrapper from "mmcv.ops" will be deprecated in' 15 | ' the future. Please import them from "mmcv.cnn" instead') 16 | 17 | 18 | class ConvTranspose2d_deprecated(ConvTranspose2d): 19 | 20 | def __init__(self, *args, **kwargs): 21 | super().__init__(*args, **kwargs) 22 | warnings.warn( 23 | 'Importing ConvTranspose2d wrapper from "mmcv.ops" will be ' 24 | 'deprecated in the future. Please import them from "mmcv.cnn" ' 25 | 'instead') 26 | 27 | 28 | class MaxPool2d_deprecated(MaxPool2d): 29 | 30 | def __init__(self, *args, **kwargs): 31 | super().__init__(*args, **kwargs) 32 | warnings.warn( 33 | 'Importing MaxPool2d wrapper from "mmcv.ops" will be deprecated in' 34 | ' the future. Please import them from "mmcv.cnn" instead') 35 | 36 | 37 | class Linear_deprecated(Linear): 38 | 39 | def __init__(self, *args, **kwargs): 40 | super().__init__(*args, **kwargs) 41 | warnings.warn( 42 | 'Importing Linear wrapper from "mmcv.ops" will be deprecated in' 43 | ' the future. Please import them from "mmcv.cnn" instead') 44 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmcv/ops/info.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | import glob 3 | import os 4 | 5 | import torch 6 | 7 | if torch.__version__ == 'parrots': 8 | import parrots 9 | 10 | def get_compiler_version(): 11 | return 'GCC ' + parrots.version.compiler 12 | 13 | def get_compiling_cuda_version(): 14 | return parrots.version.cuda 15 | else: 16 | from ..utils import ext_loader 17 | ext_module = ext_loader.load_ext( 18 | '_ext', ['get_compiler_version', 'get_compiling_cuda_version']) 19 | 20 | def get_compiler_version(): 21 | return ext_module.get_compiler_version() 22 | 23 | def get_compiling_cuda_version(): 24 | return ext_module.get_compiling_cuda_version() 25 | 26 | 27 | def get_onnxruntime_op_path(): 28 | wildcard = os.path.join( 29 | os.path.abspath(os.path.dirname(os.path.dirname(__file__))), 30 | '_ext_ort.*.so') 31 | 32 | paths = glob.glob(wildcard) 33 | if len(paths) > 0: 34 | return paths[0] 35 | else: 36 | return '' 37 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmcv/parallel/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from .collate import collate 3 | from .data_container import DataContainer 4 | from .data_parallel import MMDataParallel 5 | from .distributed import MMDistributedDataParallel 6 | from .registry import MODULE_WRAPPERS 7 | from .scatter_gather import scatter, scatter_kwargs 8 | from .utils import is_module_wrapper 9 | 10 | __all__ = [ 11 | 'collate', 'DataContainer', 'MMDataParallel', 'MMDistributedDataParallel', 12 | 'scatter', 'scatter_kwargs', 'is_module_wrapper', 'MODULE_WRAPPERS' 13 | ] 14 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmcv/parallel/registry.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from torch.nn.parallel import DataParallel, DistributedDataParallel 3 | 4 | from annotator.mmpkg.mmcv.utils import Registry 5 | 6 | MODULE_WRAPPERS = Registry('module wrapper') 7 | MODULE_WRAPPERS.register_module(module=DataParallel) 8 | MODULE_WRAPPERS.register_module(module=DistributedDataParallel) 9 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmcv/parallel/utils.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from .registry import MODULE_WRAPPERS 3 | 4 | 5 | def is_module_wrapper(module): 6 | """Check if a module is a module wrapper. 7 | 8 | The following 3 modules in MMCV (and their subclasses) are regarded as 9 | module wrappers: DataParallel, DistributedDataParallel, 10 | MMDistributedDataParallel (the deprecated version). You may add you own 11 | module wrapper by registering it to mmcv.parallel.MODULE_WRAPPERS. 12 | 13 | Args: 14 | module (nn.Module): The module to be checked. 15 | 16 | Returns: 17 | bool: True if the input module is a module wrapper. 18 | """ 19 | module_wrappers = tuple(MODULE_WRAPPERS.module_dict.values()) 20 | return isinstance(module, module_wrappers) 21 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmcv/runner/builder.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | import copy 3 | 4 | from ..utils import Registry 5 | 6 | RUNNERS = Registry('runner') 7 | RUNNER_BUILDERS = Registry('runner builder') 8 | 9 | 10 | def build_runner_constructor(cfg): 11 | return RUNNER_BUILDERS.build(cfg) 12 | 13 | 14 | def build_runner(cfg, default_args=None): 15 | runner_cfg = copy.deepcopy(cfg) 16 | constructor_type = runner_cfg.pop('constructor', 17 | 'DefaultRunnerConstructor') 18 | runner_constructor = build_runner_constructor( 19 | dict( 20 | type=constructor_type, 21 | runner_cfg=runner_cfg, 22 | default_args=default_args)) 23 | runner = runner_constructor() 24 | return runner 25 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmcv/runner/hooks/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from .checkpoint import CheckpointHook 3 | from .closure import ClosureHook 4 | from .ema import EMAHook 5 | from .evaluation import DistEvalHook, EvalHook 6 | from .hook import HOOKS, Hook 7 | from .iter_timer import IterTimerHook 8 | from .logger import (DvcliveLoggerHook, LoggerHook, MlflowLoggerHook, 9 | NeptuneLoggerHook, PaviLoggerHook, TensorboardLoggerHook, 10 | TextLoggerHook, WandbLoggerHook) 11 | from .lr_updater import LrUpdaterHook 12 | from .memory import EmptyCacheHook 13 | from .momentum_updater import MomentumUpdaterHook 14 | from .optimizer import (Fp16OptimizerHook, GradientCumulativeFp16OptimizerHook, 15 | GradientCumulativeOptimizerHook, OptimizerHook) 16 | from .profiler import ProfilerHook 17 | from .sampler_seed import DistSamplerSeedHook 18 | from .sync_buffer import SyncBuffersHook 19 | 20 | __all__ = [ 21 | 'HOOKS', 'Hook', 'CheckpointHook', 'ClosureHook', 'LrUpdaterHook', 22 | 'OptimizerHook', 'Fp16OptimizerHook', 'IterTimerHook', 23 | 'DistSamplerSeedHook', 'EmptyCacheHook', 'LoggerHook', 'MlflowLoggerHook', 24 | 'PaviLoggerHook', 'TextLoggerHook', 'TensorboardLoggerHook', 25 | 'NeptuneLoggerHook', 'WandbLoggerHook', 'DvcliveLoggerHook', 26 | 'MomentumUpdaterHook', 'SyncBuffersHook', 'EMAHook', 'EvalHook', 27 | 'DistEvalHook', 'ProfilerHook', 'GradientCumulativeOptimizerHook', 28 | 'GradientCumulativeFp16OptimizerHook' 29 | ] 30 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmcv/runner/hooks/closure.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from .hook import HOOKS, Hook 3 | 4 | 5 | @HOOKS.register_module() 6 | class ClosureHook(Hook): 7 | 8 | def __init__(self, fn_name, fn): 9 | assert hasattr(self, fn_name) 10 | assert callable(fn) 11 | setattr(self, fn_name, fn) 12 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmcv/runner/hooks/iter_timer.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | import time 3 | 4 | from .hook import HOOKS, Hook 5 | 6 | 7 | @HOOKS.register_module() 8 | class IterTimerHook(Hook): 9 | 10 | def before_epoch(self, runner): 11 | self.t = time.time() 12 | 13 | def before_iter(self, runner): 14 | runner.log_buffer.update({'data_time': time.time() - self.t}) 15 | 16 | def after_iter(self, runner): 17 | runner.log_buffer.update({'time': time.time() - self.t}) 18 | self.t = time.time() 19 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmcv/runner/hooks/logger/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from .base import LoggerHook 3 | from .dvclive import DvcliveLoggerHook 4 | from .mlflow import MlflowLoggerHook 5 | from .neptune import NeptuneLoggerHook 6 | from .pavi import PaviLoggerHook 7 | from .tensorboard import TensorboardLoggerHook 8 | from .text import TextLoggerHook 9 | from .wandb import WandbLoggerHook 10 | 11 | __all__ = [ 12 | 'LoggerHook', 'MlflowLoggerHook', 'PaviLoggerHook', 13 | 'TensorboardLoggerHook', 'TextLoggerHook', 'WandbLoggerHook', 14 | 'NeptuneLoggerHook', 'DvcliveLoggerHook' 15 | ] 16 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmcv/runner/hooks/memory.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | import torch 3 | 4 | from .hook import HOOKS, Hook 5 | 6 | 7 | @HOOKS.register_module() 8 | class EmptyCacheHook(Hook): 9 | 10 | def __init__(self, before_epoch=False, after_epoch=True, after_iter=False): 11 | self._before_epoch = before_epoch 12 | self._after_epoch = after_epoch 13 | self._after_iter = after_iter 14 | 15 | def after_iter(self, runner): 16 | if self._after_iter: 17 | torch.cuda.empty_cache() 18 | 19 | def before_epoch(self, runner): 20 | if self._before_epoch: 21 | torch.cuda.empty_cache() 22 | 23 | def after_epoch(self, runner): 24 | if self._after_epoch: 25 | torch.cuda.empty_cache() 26 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmcv/runner/hooks/sampler_seed.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from .hook import HOOKS, Hook 3 | 4 | 5 | @HOOKS.register_module() 6 | class DistSamplerSeedHook(Hook): 7 | """Data-loading sampler for distributed training. 8 | 9 | When distributed training, it is only useful in conjunction with 10 | :obj:`EpochBasedRunner`, while :obj:`IterBasedRunner` achieves the same 11 | purpose with :obj:`IterLoader`. 12 | """ 13 | 14 | def before_epoch(self, runner): 15 | if hasattr(runner.data_loader.sampler, 'set_epoch'): 16 | # in case the data loader uses `SequentialSampler` in Pytorch 17 | runner.data_loader.sampler.set_epoch(runner.epoch) 18 | elif hasattr(runner.data_loader.batch_sampler.sampler, 'set_epoch'): 19 | # batch sampler in pytorch warps the sampler as its attributes. 20 | runner.data_loader.batch_sampler.sampler.set_epoch(runner.epoch) 21 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmcv/runner/hooks/sync_buffer.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from ..dist_utils import allreduce_params 3 | from .hook import HOOKS, Hook 4 | 5 | 6 | @HOOKS.register_module() 7 | class SyncBuffersHook(Hook): 8 | """Synchronize model buffers such as running_mean and running_var in BN at 9 | the end of each epoch. 10 | 11 | Args: 12 | distributed (bool): Whether distributed training is used. It is 13 | effective only for distributed training. Defaults to True. 14 | """ 15 | 16 | def __init__(self, distributed=True): 17 | self.distributed = distributed 18 | 19 | def after_epoch(self, runner): 20 | """All-reduce model buffers at the end of each epoch.""" 21 | if self.distributed: 22 | allreduce_params(runner.model.buffers()) 23 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmcv/runner/log_buffer.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from collections import OrderedDict 3 | 4 | import numpy as np 5 | 6 | 7 | class LogBuffer: 8 | 9 | def __init__(self): 10 | self.val_history = OrderedDict() 11 | self.n_history = OrderedDict() 12 | self.output = OrderedDict() 13 | self.ready = False 14 | 15 | def clear(self): 16 | self.val_history.clear() 17 | self.n_history.clear() 18 | self.clear_output() 19 | 20 | def clear_output(self): 21 | self.output.clear() 22 | self.ready = False 23 | 24 | def update(self, vars, count=1): 25 | assert isinstance(vars, dict) 26 | for key, var in vars.items(): 27 | if key not in self.val_history: 28 | self.val_history[key] = [] 29 | self.n_history[key] = [] 30 | self.val_history[key].append(var) 31 | self.n_history[key].append(count) 32 | 33 | def average(self, n=0): 34 | """Average latest n values or all values.""" 35 | assert n >= 0 36 | for key in self.val_history: 37 | values = np.array(self.val_history[key][-n:]) 38 | nums = np.array(self.n_history[key][-n:]) 39 | avg = np.sum(values * nums) / np.sum(nums) 40 | self.output[key] = avg 41 | self.ready = True 42 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmcv/runner/optimizer/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from .builder import (OPTIMIZER_BUILDERS, OPTIMIZERS, build_optimizer, 3 | build_optimizer_constructor) 4 | from .default_constructor import DefaultOptimizerConstructor 5 | 6 | __all__ = [ 7 | 'OPTIMIZER_BUILDERS', 'OPTIMIZERS', 'DefaultOptimizerConstructor', 8 | 'build_optimizer', 'build_optimizer_constructor' 9 | ] 10 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmcv/runner/optimizer/builder.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | import copy 3 | import inspect 4 | 5 | import torch 6 | 7 | from ...utils import Registry, build_from_cfg 8 | 9 | OPTIMIZERS = Registry('optimizer') 10 | OPTIMIZER_BUILDERS = Registry('optimizer builder') 11 | 12 | 13 | def register_torch_optimizers(): 14 | torch_optimizers = [] 15 | for module_name in dir(torch.optim): 16 | if module_name.startswith('__'): 17 | continue 18 | _optim = getattr(torch.optim, module_name) 19 | if inspect.isclass(_optim) and issubclass(_optim, 20 | torch.optim.Optimizer): 21 | OPTIMIZERS.register_module()(_optim) 22 | torch_optimizers.append(module_name) 23 | return torch_optimizers 24 | 25 | 26 | TORCH_OPTIMIZERS = register_torch_optimizers() 27 | 28 | 29 | def build_optimizer_constructor(cfg): 30 | return build_from_cfg(cfg, OPTIMIZER_BUILDERS) 31 | 32 | 33 | def build_optimizer(model, cfg): 34 | optimizer_cfg = copy.deepcopy(cfg) 35 | constructor_type = optimizer_cfg.pop('constructor', 36 | 'DefaultOptimizerConstructor') 37 | paramwise_cfg = optimizer_cfg.pop('paramwise_cfg', None) 38 | optim_constructor = build_optimizer_constructor( 39 | dict( 40 | type=constructor_type, 41 | optimizer_cfg=optimizer_cfg, 42 | paramwise_cfg=paramwise_cfg)) 43 | optimizer = optim_constructor(model) 44 | return optimizer 45 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmcv/utils/parrots_jit.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | import os 3 | 4 | from .parrots_wrapper import TORCH_VERSION 5 | 6 | parrots_jit_option = os.getenv('PARROTS_JIT_OPTION') 7 | 8 | if TORCH_VERSION == 'parrots' and parrots_jit_option == 'ON': 9 | from parrots.jit import pat as jit 10 | else: 11 | 12 | def jit(func=None, 13 | check_input=None, 14 | full_shape=True, 15 | derivate=False, 16 | coderize=False, 17 | optimize=False): 18 | 19 | def wrapper(func): 20 | 21 | def wrapper_inner(*args, **kargs): 22 | return func(*args, **kargs) 23 | 24 | return wrapper_inner 25 | 26 | if func is None: 27 | return wrapper 28 | else: 29 | return func 30 | 31 | 32 | if TORCH_VERSION == 'parrots': 33 | from parrots.utils.tester import skip_no_elena 34 | else: 35 | 36 | def skip_no_elena(func): 37 | 38 | def wrapper(*args, **kargs): 39 | return func(*args, **kargs) 40 | 41 | return wrapper 42 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmcv/utils/trace.py: -------------------------------------------------------------------------------- 1 | import warnings 2 | 3 | import torch 4 | 5 | from annotator.mmpkg.mmcv.utils import digit_version 6 | 7 | 8 | def is_jit_tracing() -> bool: 9 | if (torch.__version__ != 'parrots' 10 | and digit_version(torch.__version__) >= digit_version('1.6.0')): 11 | on_trace = torch.jit.is_tracing() 12 | # In PyTorch 1.6, torch.jit.is_tracing has a bug. 13 | # Refers to https://github.com/pytorch/pytorch/issues/42448 14 | if isinstance(on_trace, bool): 15 | return on_trace 16 | else: 17 | return torch._C._is_tracing() 18 | else: 19 | warnings.warn( 20 | 'torch.jit.is_tracing is only supported after v1.6.0. ' 21 | 'Therefore is_tracing returns False automatically. Please ' 22 | 'set on_trace manually if you are using trace.', UserWarning) 23 | return False 24 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmcv/version.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | __version__ = '1.3.17' 3 | 4 | 5 | def parse_version_info(version_str: str, length: int = 4) -> tuple: 6 | """Parse a version string into a tuple. 7 | 8 | Args: 9 | version_str (str): The version string. 10 | length (int): The maximum number of version levels. Default: 4. 11 | 12 | Returns: 13 | tuple[int | str]: The version info, e.g., "1.3.0" is parsed into 14 | (1, 3, 0, 0, 0, 0), and "2.0.0rc1" is parsed into 15 | (2, 0, 0, 0, 'rc', 1) (when length is set to 4). 16 | """ 17 | from packaging.version import parse 18 | version = parse(version_str) 19 | assert version.release, f'failed to parse version {version_str}' 20 | release = list(version.release) 21 | release = release[:length] 22 | if len(release) < length: 23 | release = release + [0] * (length - len(release)) 24 | if version.is_prerelease: 25 | release.extend(list(version.pre)) 26 | elif version.is_postrelease: 27 | release.extend(list(version.post)) 28 | else: 29 | release.extend([0, 0]) 30 | return tuple(release) 31 | 32 | 33 | version_info = tuple(int(x) for x in __version__.split('.')[:3]) 34 | 35 | __all__ = ['__version__', 'version_info', 'parse_version_info'] 36 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmcv/video/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from .io import Cache, VideoReader, frames2video 3 | from .optflow import (dequantize_flow, flow_from_bytes, flow_warp, flowread, 4 | flowwrite, quantize_flow, sparse_flow_from_bytes) 5 | from .processing import concat_video, convert_video, cut_video, resize_video 6 | 7 | __all__ = [ 8 | 'Cache', 'VideoReader', 'frames2video', 'convert_video', 'resize_video', 9 | 'cut_video', 'concat_video', 'flowread', 'flowwrite', 'quantize_flow', 10 | 'dequantize_flow', 'flow_warp', 'flow_from_bytes', 'sparse_flow_from_bytes' 11 | ] 12 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmcv/visualization/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from .color import Color, color_val 3 | from .image import imshow, imshow_bboxes, imshow_det_bboxes 4 | from .optflow import flow2rgb, flowshow, make_color_wheel 5 | 6 | __all__ = [ 7 | 'Color', 'color_val', 'imshow', 'imshow_bboxes', 'imshow_det_bboxes', 8 | 'flowshow', 'flow2rgb', 'make_color_wheel' 9 | ] 10 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmcv/visualization/color.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) OpenMMLab. All rights reserved. 2 | from enum import Enum 3 | 4 | import numpy as np 5 | 6 | from annotator.mmpkg.mmcv.utils import is_str 7 | 8 | 9 | class Color(Enum): 10 | """An enum that defines common colors. 11 | 12 | Contains red, green, blue, cyan, yellow, magenta, white and black. 13 | """ 14 | red = (0, 0, 255) 15 | green = (0, 255, 0) 16 | blue = (255, 0, 0) 17 | cyan = (255, 255, 0) 18 | yellow = (0, 255, 255) 19 | magenta = (255, 0, 255) 20 | white = (255, 255, 255) 21 | black = (0, 0, 0) 22 | 23 | 24 | def color_val(color): 25 | """Convert various input to color tuples. 26 | 27 | Args: 28 | color (:obj:`Color`/str/tuple/int/ndarray): Color inputs 29 | 30 | Returns: 31 | tuple[int]: A tuple of 3 integers indicating BGR channels. 32 | """ 33 | if is_str(color): 34 | return Color[color].value 35 | elif isinstance(color, Color): 36 | return color.value 37 | elif isinstance(color, tuple): 38 | assert len(color) == 3 39 | for channel in color: 40 | assert 0 <= channel <= 255 41 | return color 42 | elif isinstance(color, int): 43 | assert 0 <= color <= 255 44 | return color, color, color 45 | elif isinstance(color, np.ndarray): 46 | assert color.ndim == 1 and color.size == 3 47 | assert np.all((color >= 0) & (color <= 255)) 48 | color = color.astype(np.uint8) 49 | return tuple(color) 50 | else: 51 | raise TypeError(f'Invalid type for color: {type(color)}') 52 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmseg/apis/__init__.py: -------------------------------------------------------------------------------- 1 | from .inference import inference_segmentor, init_segmentor, show_result_pyplot 2 | from .test import multi_gpu_test, single_gpu_test 3 | from .train import get_root_logger, set_random_seed, train_segmentor 4 | 5 | __all__ = [ 6 | 'get_root_logger', 'set_random_seed', 'train_segmentor', 'init_segmentor', 7 | 'inference_segmentor', 'multi_gpu_test', 'single_gpu_test', 8 | 'show_result_pyplot' 9 | ] 10 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmseg/core/__init__.py: -------------------------------------------------------------------------------- 1 | from .evaluation import * # noqa: F401, F403 2 | from .seg import * # noqa: F401, F403 3 | from .utils import * # noqa: F401, F403 4 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmseg/core/evaluation/__init__.py: -------------------------------------------------------------------------------- 1 | from .class_names import get_classes, get_palette 2 | from .eval_hooks import DistEvalHook, EvalHook 3 | from .metrics import eval_metrics, mean_dice, mean_fscore, mean_iou 4 | 5 | __all__ = [ 6 | 'EvalHook', 'DistEvalHook', 'mean_dice', 'mean_iou', 'mean_fscore', 7 | 'eval_metrics', 'get_classes', 'get_palette' 8 | ] 9 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmseg/core/seg/__init__.py: -------------------------------------------------------------------------------- 1 | from .builder import build_pixel_sampler 2 | from .sampler import BasePixelSampler, OHEMPixelSampler 3 | 4 | __all__ = ['build_pixel_sampler', 'BasePixelSampler', 'OHEMPixelSampler'] 5 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmseg/core/seg/builder.py: -------------------------------------------------------------------------------- 1 | from annotator.mmpkg.mmcv.utils import Registry, build_from_cfg 2 | 3 | PIXEL_SAMPLERS = Registry('pixel sampler') 4 | 5 | 6 | def build_pixel_sampler(cfg, **default_args): 7 | """Build pixel sampler for segmentation map.""" 8 | return build_from_cfg(cfg, PIXEL_SAMPLERS, default_args) 9 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmseg/core/seg/sampler/__init__.py: -------------------------------------------------------------------------------- 1 | from .base_pixel_sampler import BasePixelSampler 2 | from .ohem_pixel_sampler import OHEMPixelSampler 3 | 4 | __all__ = ['BasePixelSampler', 'OHEMPixelSampler'] 5 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmseg/core/seg/sampler/base_pixel_sampler.py: -------------------------------------------------------------------------------- 1 | from abc import ABCMeta, abstractmethod 2 | 3 | 4 | class BasePixelSampler(metaclass=ABCMeta): 5 | """Base class of pixel sampler.""" 6 | 7 | def __init__(self, **kwargs): 8 | pass 9 | 10 | @abstractmethod 11 | def sample(self, seg_logit, seg_label): 12 | """Placeholder for sample function.""" 13 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmseg/core/utils/__init__.py: -------------------------------------------------------------------------------- 1 | from .misc import add_prefix 2 | 3 | __all__ = ['add_prefix'] 4 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmseg/core/utils/misc.py: -------------------------------------------------------------------------------- 1 | def add_prefix(inputs, prefix): 2 | """Add prefix for dict. 3 | 4 | Args: 5 | inputs (dict): The input dict with str keys. 6 | prefix (str): The prefix to add. 7 | 8 | Returns: 9 | 10 | dict: The dict with keys updated with ``prefix``. 11 | """ 12 | 13 | outputs = dict() 14 | for name, value in inputs.items(): 15 | outputs[f'{prefix}.{name}'] = value 16 | 17 | return outputs 18 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmseg/datasets/__init__.py: -------------------------------------------------------------------------------- 1 | from .ade import ADE20KDataset 2 | from .builder import DATASETS, PIPELINES, build_dataloader, build_dataset 3 | from .chase_db1 import ChaseDB1Dataset 4 | from .cityscapes import CityscapesDataset 5 | from .custom import CustomDataset 6 | from .dataset_wrappers import ConcatDataset, RepeatDataset 7 | from .drive import DRIVEDataset 8 | from .hrf import HRFDataset 9 | from .pascal_context import PascalContextDataset, PascalContextDataset59 10 | from .stare import STAREDataset 11 | from .voc import PascalVOCDataset 12 | 13 | __all__ = [ 14 | 'CustomDataset', 'build_dataloader', 'ConcatDataset', 'RepeatDataset', 15 | 'DATASETS', 'build_dataset', 'PIPELINES', 'CityscapesDataset', 16 | 'PascalVOCDataset', 'ADE20KDataset', 'PascalContextDataset', 17 | 'PascalContextDataset59', 'ChaseDB1Dataset', 'DRIVEDataset', 'HRFDataset', 18 | 'STAREDataset' 19 | ] 20 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmseg/datasets/chase_db1.py: -------------------------------------------------------------------------------- 1 | import os.path as osp 2 | 3 | from .builder import DATASETS 4 | from .custom import CustomDataset 5 | 6 | 7 | @DATASETS.register_module() 8 | class ChaseDB1Dataset(CustomDataset): 9 | """Chase_db1 dataset. 10 | 11 | In segmentation map annotation for Chase_db1, 0 stands for background, 12 | which is included in 2 categories. ``reduce_zero_label`` is fixed to False. 13 | The ``img_suffix`` is fixed to '.png' and ``seg_map_suffix`` is fixed to 14 | '_1stHO.png'. 15 | """ 16 | 17 | CLASSES = ('background', 'vessel') 18 | 19 | PALETTE = [[120, 120, 120], [6, 230, 230]] 20 | 21 | def __init__(self, **kwargs): 22 | super(ChaseDB1Dataset, self).__init__( 23 | img_suffix='.png', 24 | seg_map_suffix='_1stHO.png', 25 | reduce_zero_label=False, 26 | **kwargs) 27 | assert osp.exists(self.img_dir) 28 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmseg/datasets/drive.py: -------------------------------------------------------------------------------- 1 | import os.path as osp 2 | 3 | from .builder import DATASETS 4 | from .custom import CustomDataset 5 | 6 | 7 | @DATASETS.register_module() 8 | class DRIVEDataset(CustomDataset): 9 | """DRIVE dataset. 10 | 11 | In segmentation map annotation for DRIVE, 0 stands for background, which is 12 | included in 2 categories. ``reduce_zero_label`` is fixed to False. The 13 | ``img_suffix`` is fixed to '.png' and ``seg_map_suffix`` is fixed to 14 | '_manual1.png'. 15 | """ 16 | 17 | CLASSES = ('background', 'vessel') 18 | 19 | PALETTE = [[120, 120, 120], [6, 230, 230]] 20 | 21 | def __init__(self, **kwargs): 22 | super(DRIVEDataset, self).__init__( 23 | img_suffix='.png', 24 | seg_map_suffix='_manual1.png', 25 | reduce_zero_label=False, 26 | **kwargs) 27 | assert osp.exists(self.img_dir) 28 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmseg/datasets/hrf.py: -------------------------------------------------------------------------------- 1 | import os.path as osp 2 | 3 | from .builder import DATASETS 4 | from .custom import CustomDataset 5 | 6 | 7 | @DATASETS.register_module() 8 | class HRFDataset(CustomDataset): 9 | """HRF dataset. 10 | 11 | In segmentation map annotation for HRF, 0 stands for background, which is 12 | included in 2 categories. ``reduce_zero_label`` is fixed to False. The 13 | ``img_suffix`` is fixed to '.png' and ``seg_map_suffix`` is fixed to 14 | '.png'. 15 | """ 16 | 17 | CLASSES = ('background', 'vessel') 18 | 19 | PALETTE = [[120, 120, 120], [6, 230, 230]] 20 | 21 | def __init__(self, **kwargs): 22 | super(HRFDataset, self).__init__( 23 | img_suffix='.png', 24 | seg_map_suffix='.png', 25 | reduce_zero_label=False, 26 | **kwargs) 27 | assert osp.exists(self.img_dir) 28 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmseg/datasets/pipelines/__init__.py: -------------------------------------------------------------------------------- 1 | from .compose import Compose 2 | from .formating import (Collect, ImageToTensor, ToDataContainer, ToTensor, 3 | Transpose, to_tensor) 4 | from .loading import LoadAnnotations, LoadImageFromFile 5 | from .test_time_aug import MultiScaleFlipAug 6 | from .transforms import (CLAHE, AdjustGamma, Normalize, Pad, 7 | PhotoMetricDistortion, RandomCrop, RandomFlip, 8 | RandomRotate, Rerange, Resize, RGB2Gray, SegRescale) 9 | 10 | __all__ = [ 11 | 'Compose', 'to_tensor', 'ToTensor', 'ImageToTensor', 'ToDataContainer', 12 | 'Transpose', 'Collect', 'LoadAnnotations', 'LoadImageFromFile', 13 | 'MultiScaleFlipAug', 'Resize', 'RandomFlip', 'Pad', 'RandomCrop', 14 | 'Normalize', 'SegRescale', 'PhotoMetricDistortion', 'RandomRotate', 15 | 'AdjustGamma', 'CLAHE', 'Rerange', 'RGB2Gray' 16 | ] 17 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmseg/datasets/stare.py: -------------------------------------------------------------------------------- 1 | import os.path as osp 2 | 3 | from .builder import DATASETS 4 | from .custom import CustomDataset 5 | 6 | 7 | @DATASETS.register_module() 8 | class STAREDataset(CustomDataset): 9 | """STARE dataset. 10 | 11 | In segmentation map annotation for STARE, 0 stands for background, which is 12 | included in 2 categories. ``reduce_zero_label`` is fixed to False. The 13 | ``img_suffix`` is fixed to '.png' and ``seg_map_suffix`` is fixed to 14 | '.ah.png'. 15 | """ 16 | 17 | CLASSES = ('background', 'vessel') 18 | 19 | PALETTE = [[120, 120, 120], [6, 230, 230]] 20 | 21 | def __init__(self, **kwargs): 22 | super(STAREDataset, self).__init__( 23 | img_suffix='.png', 24 | seg_map_suffix='.ah.png', 25 | reduce_zero_label=False, 26 | **kwargs) 27 | assert osp.exists(self.img_dir) 28 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmseg/datasets/voc.py: -------------------------------------------------------------------------------- 1 | import os.path as osp 2 | 3 | from .builder import DATASETS 4 | from .custom import CustomDataset 5 | 6 | 7 | @DATASETS.register_module() 8 | class PascalVOCDataset(CustomDataset): 9 | """Pascal VOC dataset. 10 | 11 | Args: 12 | split (str): Split txt file for Pascal VOC. 13 | """ 14 | 15 | CLASSES = ('background', 'aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 16 | 'bus', 'car', 'cat', 'chair', 'cow', 'diningtable', 'dog', 17 | 'horse', 'motorbike', 'person', 'pottedplant', 'sheep', 'sofa', 18 | 'train', 'tvmonitor') 19 | 20 | PALETTE = [[0, 0, 0], [128, 0, 0], [0, 128, 0], [128, 128, 0], [0, 0, 128], 21 | [128, 0, 128], [0, 128, 128], [128, 128, 128], [64, 0, 0], 22 | [192, 0, 0], [64, 128, 0], [192, 128, 0], [64, 0, 128], 23 | [192, 0, 128], [64, 128, 128], [192, 128, 128], [0, 64, 0], 24 | [128, 64, 0], [0, 192, 0], [128, 192, 0], [0, 64, 128]] 25 | 26 | def __init__(self, split, **kwargs): 27 | super(PascalVOCDataset, self).__init__( 28 | img_suffix='.jpg', seg_map_suffix='.png', split=split, **kwargs) 29 | assert osp.exists(self.img_dir) and self.split is not None 30 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmseg/models/__init__.py: -------------------------------------------------------------------------------- 1 | from .backbones import * # noqa: F401,F403 2 | from .builder import (BACKBONES, HEADS, LOSSES, SEGMENTORS, build_backbone, 3 | build_head, build_loss, build_segmentor) 4 | from .decode_heads import * # noqa: F401,F403 5 | from .losses import * # noqa: F401,F403 6 | from .necks import * # noqa: F401,F403 7 | from .segmentors import * # noqa: F401,F403 8 | 9 | __all__ = [ 10 | 'BACKBONES', 'HEADS', 'LOSSES', 'SEGMENTORS', 'build_backbone', 11 | 'build_head', 'build_loss', 'build_segmentor' 12 | ] 13 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmseg/models/backbones/__init__.py: -------------------------------------------------------------------------------- 1 | from .cgnet import CGNet 2 | # from .fast_scnn import FastSCNN 3 | from .hrnet import HRNet 4 | from .mobilenet_v2 import MobileNetV2 5 | from .mobilenet_v3 import MobileNetV3 6 | from .resnest import ResNeSt 7 | from .resnet import ResNet, ResNetV1c, ResNetV1d 8 | from .resnext import ResNeXt 9 | from .unet import UNet 10 | from .vit import VisionTransformer 11 | 12 | __all__ = [ 13 | 'ResNet', 'ResNetV1c', 'ResNetV1d', 'ResNeXt', 'HRNet', 14 | 'ResNeSt', 'MobileNetV2', 'UNet', 'CGNet', 'MobileNetV3', 15 | 'VisionTransformer' 16 | ] 17 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmseg/models/builder.py: -------------------------------------------------------------------------------- 1 | import warnings 2 | 3 | from annotator.mmpkg.mmcv.cnn import MODELS as MMCV_MODELS 4 | from annotator.mmpkg.mmcv.utils import Registry 5 | 6 | MODELS = Registry('models', parent=MMCV_MODELS) 7 | 8 | BACKBONES = MODELS 9 | NECKS = MODELS 10 | HEADS = MODELS 11 | LOSSES = MODELS 12 | SEGMENTORS = MODELS 13 | 14 | 15 | def build_backbone(cfg): 16 | """Build backbone.""" 17 | return BACKBONES.build(cfg) 18 | 19 | 20 | def build_neck(cfg): 21 | """Build neck.""" 22 | return NECKS.build(cfg) 23 | 24 | 25 | def build_head(cfg): 26 | """Build head.""" 27 | return HEADS.build(cfg) 28 | 29 | 30 | def build_loss(cfg): 31 | """Build loss.""" 32 | return LOSSES.build(cfg) 33 | 34 | 35 | def build_segmentor(cfg, train_cfg=None, test_cfg=None): 36 | """Build segmentor.""" 37 | if train_cfg is not None or test_cfg is not None: 38 | warnings.warn( 39 | 'train_cfg and test_cfg is deprecated, ' 40 | 'please specify them in model', UserWarning) 41 | assert cfg.get('train_cfg') is None or train_cfg is None, \ 42 | 'train_cfg specified in both outer field and model field ' 43 | assert cfg.get('test_cfg') is None or test_cfg is None, \ 44 | 'test_cfg specified in both outer field and model field ' 45 | return SEGMENTORS.build( 46 | cfg, default_args=dict(train_cfg=train_cfg, test_cfg=test_cfg)) 47 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmseg/models/decode_heads/__init__.py: -------------------------------------------------------------------------------- 1 | from .ann_head import ANNHead 2 | from .apc_head import APCHead 3 | from .aspp_head import ASPPHead 4 | from .cc_head import CCHead 5 | from .da_head import DAHead 6 | from .dm_head import DMHead 7 | from .dnl_head import DNLHead 8 | from .ema_head import EMAHead 9 | from .enc_head import EncHead 10 | from .fcn_head import FCNHead 11 | from .fpn_head import FPNHead 12 | from .gc_head import GCHead 13 | from .lraspp_head import LRASPPHead 14 | from .nl_head import NLHead 15 | from .ocr_head import OCRHead 16 | # from .point_head import PointHead 17 | from .psa_head import PSAHead 18 | from .psp_head import PSPHead 19 | from .sep_aspp_head import DepthwiseSeparableASPPHead 20 | from .sep_fcn_head import DepthwiseSeparableFCNHead 21 | from .uper_head import UPerHead 22 | 23 | __all__ = [ 24 | 'FCNHead', 'PSPHead', 'ASPPHead', 'PSAHead', 'NLHead', 'GCHead', 'CCHead', 25 | 'UPerHead', 'DepthwiseSeparableASPPHead', 'ANNHead', 'DAHead', 'OCRHead', 26 | 'EncHead', 'DepthwiseSeparableFCNHead', 'FPNHead', 'EMAHead', 'DNLHead', 27 | 'APCHead', 'DMHead', 'LRASPPHead' 28 | ] 29 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmseg/models/decode_heads/cc_head.py: -------------------------------------------------------------------------------- 1 | import torch 2 | 3 | from ..builder import HEADS 4 | from .fcn_head import FCNHead 5 | 6 | try: 7 | try: 8 | from mmcv.ops import CrissCrossAttention 9 | except ImportError: 10 | from annotator.mmpkg.mmcv.ops import CrissCrossAttention 11 | except ModuleNotFoundError: 12 | CrissCrossAttention = None 13 | 14 | 15 | @HEADS.register_module() 16 | class CCHead(FCNHead): 17 | """CCNet: Criss-Cross Attention for Semantic Segmentation. 18 | 19 | This head is the implementation of `CCNet 20 | `_. 21 | 22 | Args: 23 | recurrence (int): Number of recurrence of Criss Cross Attention 24 | module. Default: 2. 25 | """ 26 | 27 | def __init__(self, recurrence=2, **kwargs): 28 | if CrissCrossAttention is None: 29 | raise RuntimeError('Please install mmcv-full for ' 30 | 'CrissCrossAttention ops') 31 | super(CCHead, self).__init__(num_convs=2, **kwargs) 32 | self.recurrence = recurrence 33 | self.cca = CrissCrossAttention(self.channels) 34 | 35 | def forward(self, inputs): 36 | """Forward function.""" 37 | x = self._transform_inputs(inputs) 38 | output = self.convs[0](x) 39 | for _ in range(self.recurrence): 40 | output = self.cca(output) 41 | output = self.convs[1](output) 42 | if self.concat_input: 43 | output = self.conv_cat(torch.cat([x, output], dim=1)) 44 | output = self.cls_seg(output) 45 | return output 46 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmseg/models/losses/__init__.py: -------------------------------------------------------------------------------- 1 | from .accuracy import Accuracy, accuracy 2 | from .cross_entropy_loss import (CrossEntropyLoss, binary_cross_entropy, 3 | cross_entropy, mask_cross_entropy) 4 | from .dice_loss import DiceLoss 5 | from .lovasz_loss import LovaszLoss 6 | from .utils import reduce_loss, weight_reduce_loss, weighted_loss 7 | 8 | __all__ = [ 9 | 'accuracy', 'Accuracy', 'cross_entropy', 'binary_cross_entropy', 10 | 'mask_cross_entropy', 'CrossEntropyLoss', 'reduce_loss', 11 | 'weight_reduce_loss', 'weighted_loss', 'LovaszLoss', 'DiceLoss' 12 | ] 13 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmseg/models/necks/__init__.py: -------------------------------------------------------------------------------- 1 | from .fpn import FPN 2 | from .multilevel_neck import MultiLevelNeck 3 | 4 | __all__ = ['FPN', 'MultiLevelNeck'] 5 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmseg/models/segmentors/__init__.py: -------------------------------------------------------------------------------- 1 | from .base import BaseSegmentor 2 | from .cascade_encoder_decoder import CascadeEncoderDecoder 3 | from .encoder_decoder import EncoderDecoder 4 | 5 | __all__ = ['BaseSegmentor', 'EncoderDecoder', 'CascadeEncoderDecoder'] 6 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmseg/models/utils/__init__.py: -------------------------------------------------------------------------------- 1 | from .drop import DropPath 2 | from .inverted_residual import InvertedResidual, InvertedResidualV3 3 | from .make_divisible import make_divisible 4 | from .res_layer import ResLayer 5 | from .se_layer import SELayer 6 | from .self_attention_block import SelfAttentionBlock 7 | from .up_conv_block import UpConvBlock 8 | from .weight_init import trunc_normal_ 9 | 10 | __all__ = [ 11 | 'ResLayer', 'SelfAttentionBlock', 'make_divisible', 'InvertedResidual', 12 | 'UpConvBlock', 'InvertedResidualV3', 'SELayer', 'DropPath', 'trunc_normal_' 13 | ] 14 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmseg/models/utils/drop.py: -------------------------------------------------------------------------------- 1 | """Modified from https://github.com/rwightman/pytorch-image- 2 | models/blob/master/timm/models/layers/drop.py.""" 3 | 4 | import torch 5 | from torch import nn 6 | 7 | 8 | class DropPath(nn.Module): 9 | """Drop paths (Stochastic Depth) per sample (when applied in main path of 10 | residual blocks). 11 | 12 | Args: 13 | drop_prob (float): Drop rate for paths of model. Dropout rate has 14 | to be between 0 and 1. Default: 0. 15 | """ 16 | 17 | def __init__(self, drop_prob=0.): 18 | super(DropPath, self).__init__() 19 | self.drop_prob = drop_prob 20 | self.keep_prob = 1 - drop_prob 21 | 22 | def forward(self, x): 23 | if self.drop_prob == 0. or not self.training: 24 | return x 25 | shape = (x.shape[0], ) + (1, ) * ( 26 | x.ndim - 1) # work with diff dim tensors, not just 2D ConvNets 27 | random_tensor = self.keep_prob + torch.rand( 28 | shape, dtype=x.dtype, device=x.device) 29 | random_tensor.floor_() # binarize 30 | output = x.div(self.keep_prob) * random_tensor 31 | return output 32 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmseg/models/utils/make_divisible.py: -------------------------------------------------------------------------------- 1 | def make_divisible(value, divisor, min_value=None, min_ratio=0.9): 2 | """Make divisible function. 3 | 4 | This function rounds the channel number to the nearest value that can be 5 | divisible by the divisor. It is taken from the original tf repo. It ensures 6 | that all layers have a channel number that is divisible by divisor. It can 7 | be seen here: https://github.com/tensorflow/models/blob/master/research/slim/nets/mobilenet/mobilenet.py # noqa 8 | 9 | Args: 10 | value (int): The original channel number. 11 | divisor (int): The divisor to fully divide the channel number. 12 | min_value (int): The minimum value of the output channel. 13 | Default: None, means that the minimum value equal to the divisor. 14 | min_ratio (float): The minimum ratio of the rounded channel number to 15 | the original channel number. Default: 0.9. 16 | 17 | Returns: 18 | int: The modified output channel number. 19 | """ 20 | 21 | if min_value is None: 22 | min_value = divisor 23 | new_value = max(min_value, int(value + divisor / 2) // divisor * divisor) 24 | # Make sure that round down does not go down by more than (1-min_ratio). 25 | if new_value < min_ratio * value: 26 | new_value += divisor 27 | return new_value 28 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmseg/ops/__init__.py: -------------------------------------------------------------------------------- 1 | from .encoding import Encoding 2 | from .wrappers import Upsample, resize 3 | 4 | __all__ = ['Upsample', 'resize', 'Encoding'] 5 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmseg/utils/__init__.py: -------------------------------------------------------------------------------- 1 | from .collect_env import collect_env 2 | from .logger import get_root_logger 3 | 4 | __all__ = ['get_root_logger', 'collect_env'] 5 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmseg/utils/collect_env.py: -------------------------------------------------------------------------------- 1 | from annotator.mmpkg.mmcv.utils import collect_env as collect_base_env 2 | from annotator.mmpkg.mmcv.utils import get_git_hash 3 | 4 | import annotator.mmpkg.mmseg as mmseg 5 | 6 | 7 | def collect_env(): 8 | """Collect the information of the running environments.""" 9 | env_info = collect_base_env() 10 | env_info['MMSegmentation'] = f'{mmseg.__version__}+{get_git_hash()[:7]}' 11 | 12 | return env_info 13 | 14 | 15 | if __name__ == '__main__': 16 | for name, val in collect_env().items(): 17 | print('{}: {}'.format(name, val)) 18 | -------------------------------------------------------------------------------- /annotator/mmpkg/mmseg/utils/logger.py: -------------------------------------------------------------------------------- 1 | import logging 2 | 3 | from annotator.mmpkg.mmcv.utils import get_logger 4 | 5 | 6 | def get_root_logger(log_file=None, log_level=logging.INFO): 7 | """Get the root logger. 8 | 9 | The logger will be initialized if it has not been initialized. By default a 10 | StreamHandler will be added. If `log_file` is specified, a FileHandler will 11 | also be added. The name of the root logger is the top-level package name, 12 | e.g., "mmseg". 13 | 14 | Args: 15 | log_file (str | None): The log filename. If specified, a FileHandler 16 | will be added to the root logger. 17 | log_level (int): The root logger level. Note that only the process of 18 | rank 0 is affected, while other processes will set the level to 19 | "Error" and be silent most of the time. 20 | 21 | Returns: 22 | logging.Logger: The root logger. 23 | """ 24 | 25 | logger = get_logger(name='mmseg', log_file=log_file, log_level=log_level) 26 | 27 | return logger 28 | -------------------------------------------------------------------------------- /annotator/normalbae/models/NNET.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import torch.nn as nn 3 | import torch.nn.functional as F 4 | 5 | from .submodules.encoder import Encoder 6 | from .submodules.decoder import Decoder 7 | 8 | 9 | class NNET(nn.Module): 10 | def __init__(self, args): 11 | super(NNET, self).__init__() 12 | self.encoder = Encoder() 13 | self.decoder = Decoder(args) 14 | 15 | def get_1x_lr_params(self): # lr/10 learning rate 16 | return self.encoder.parameters() 17 | 18 | def get_10x_lr_params(self): # lr learning rate 19 | return self.decoder.parameters() 20 | 21 | def forward(self, img, **kwargs): 22 | return self.decoder(self.encoder(img), **kwargs) -------------------------------------------------------------------------------- /annotator/normalbae/models/submodules/efficientnet_repo/geffnet/__init__.py: -------------------------------------------------------------------------------- 1 | from .gen_efficientnet import * 2 | from .mobilenetv3 import * 3 | from .model_factory import create_model 4 | from .config import is_exportable, is_scriptable, set_exportable, set_scriptable 5 | from .activations import * -------------------------------------------------------------------------------- /annotator/normalbae/models/submodules/efficientnet_repo/geffnet/model_factory.py: -------------------------------------------------------------------------------- 1 | from .config import set_layer_config 2 | from .helpers import load_checkpoint 3 | 4 | from .gen_efficientnet import * 5 | from .mobilenetv3 import * 6 | 7 | 8 | def create_model( 9 | model_name='mnasnet_100', 10 | pretrained=None, 11 | num_classes=1000, 12 | in_chans=3, 13 | checkpoint_path='', 14 | **kwargs): 15 | 16 | model_kwargs = dict(num_classes=num_classes, in_chans=in_chans, pretrained=pretrained, **kwargs) 17 | 18 | if model_name in globals(): 19 | create_fn = globals()[model_name] 20 | model = create_fn(**model_kwargs) 21 | else: 22 | raise RuntimeError('Unknown model (%s)' % model_name) 23 | 24 | if checkpoint_path and not pretrained: 25 | load_checkpoint(model, checkpoint_path) 26 | 27 | return model 28 | -------------------------------------------------------------------------------- /annotator/normalbae/models/submodules/efficientnet_repo/geffnet/version.py: -------------------------------------------------------------------------------- 1 | __version__ = '1.0.2' 2 | -------------------------------------------------------------------------------- /annotator/normalbae/models/submodules/efficientnet_repo/onnx_to_caffe.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | 3 | import onnx 4 | from caffe2.python.onnx.backend import Caffe2Backend 5 | 6 | 7 | parser = argparse.ArgumentParser(description="Convert ONNX to Caffe2") 8 | 9 | parser.add_argument("model", help="The ONNX model") 10 | parser.add_argument("--c2-prefix", required=True, 11 | help="The output file prefix for the caffe2 model init and predict file. ") 12 | 13 | 14 | def main(): 15 | args = parser.parse_args() 16 | onnx_model = onnx.load(args.model) 17 | caffe2_init, caffe2_predict = Caffe2Backend.onnx_graph_to_caffe2_net(onnx_model) 18 | caffe2_init_str = caffe2_init.SerializeToString() 19 | with open(args.c2_prefix + '.init.pb', "wb") as f: 20 | f.write(caffe2_init_str) 21 | caffe2_predict_str = caffe2_predict.SerializeToString() 22 | with open(args.c2_prefix + '.predict.pb', "wb") as f: 23 | f.write(caffe2_predict_str) 24 | 25 | 26 | if __name__ == "__main__": 27 | main() 28 | -------------------------------------------------------------------------------- /annotator/normalbae/models/submodules/efficientnet_repo/requirements.txt: -------------------------------------------------------------------------------- 1 | torch>=1.2.0 2 | torchvision>=0.4.0 3 | -------------------------------------------------------------------------------- /annotator/normalbae/models/submodules/efficientnet_repo/utils.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | 4 | class AverageMeter: 5 | """Computes and stores the average and current value""" 6 | def __init__(self): 7 | self.reset() 8 | 9 | def reset(self): 10 | self.val = 0 11 | self.avg = 0 12 | self.sum = 0 13 | self.count = 0 14 | 15 | def update(self, val, n=1): 16 | self.val = val 17 | self.sum += val * n 18 | self.count += n 19 | self.avg = self.sum / self.count 20 | 21 | 22 | def accuracy(output, target, topk=(1,)): 23 | """Computes the precision@k for the specified values of k""" 24 | maxk = max(topk) 25 | batch_size = target.size(0) 26 | 27 | _, pred = output.topk(maxk, 1, True, True) 28 | pred = pred.t() 29 | correct = pred.eq(target.view(1, -1).expand_as(pred)) 30 | 31 | res = [] 32 | for k in topk: 33 | correct_k = correct[:k].reshape(-1).float().sum(0) 34 | res.append(correct_k.mul_(100.0 / batch_size)) 35 | return res 36 | 37 | 38 | def get_outdir(path, *paths, inc=False): 39 | outdir = os.path.join(path, *paths) 40 | if not os.path.exists(outdir): 41 | os.makedirs(outdir) 42 | elif inc: 43 | count = 1 44 | outdir_inc = outdir + '-' + str(count) 45 | while os.path.exists(outdir_inc): 46 | count = count + 1 47 | outdir_inc = outdir + '-' + str(count) 48 | assert count < 100 49 | outdir = outdir_inc 50 | os.makedirs(outdir) 51 | return outdir 52 | 53 | -------------------------------------------------------------------------------- /annotator/normalbae/models/submodules/encoder.py: -------------------------------------------------------------------------------- 1 | import os 2 | import torch 3 | import torch.nn as nn 4 | import torch.nn.functional as F 5 | 6 | 7 | class Encoder(nn.Module): 8 | def __init__(self): 9 | super(Encoder, self).__init__() 10 | 11 | basemodel_name = 'tf_efficientnet_b5_ap' 12 | print('Loading base model ()...'.format(basemodel_name), end='') 13 | repo_path = os.path.join(os.path.dirname(__file__), 'efficientnet_repo') 14 | basemodel = torch.hub.load(repo_path, basemodel_name, pretrained=False, source='local') 15 | print('Done.') 16 | 17 | # Remove last layer 18 | print('Removing last two layers (global_pool & classifier).') 19 | basemodel.global_pool = nn.Identity() 20 | basemodel.classifier = nn.Identity() 21 | 22 | self.original_model = basemodel 23 | 24 | def forward(self, x): 25 | features = [x] 26 | for k, v in self.original_model._modules.items(): 27 | if (k == 'blocks'): 28 | for ki, vi in v._modules.items(): 29 | features.append(vi(features[-1])) 30 | else: 31 | features.append(v(features[-1])) 32 | return features 33 | 34 | 35 | -------------------------------------------------------------------------------- /annotator/oneformer/api.py: -------------------------------------------------------------------------------- 1 | import os 2 | os.environ["KMP_DUPLICATE_LIB_OK"] = "TRUE" 3 | 4 | import torch 5 | 6 | from annotator.oneformer.detectron2.config import get_cfg 7 | from annotator.oneformer.detectron2.projects.deeplab import add_deeplab_config 8 | from annotator.oneformer.detectron2.data import MetadataCatalog 9 | 10 | from annotator.oneformer.oneformer import ( 11 | add_oneformer_config, 12 | add_common_config, 13 | add_swin_config, 14 | add_dinat_config, 15 | ) 16 | 17 | from annotator.oneformer.oneformer.demo.defaults import DefaultPredictor 18 | from annotator.oneformer.oneformer.demo.visualizer import Visualizer, ColorMode 19 | 20 | 21 | def make_detectron2_model(config_path, ckpt_path): 22 | cfg = get_cfg() 23 | add_deeplab_config(cfg) 24 | add_common_config(cfg) 25 | add_swin_config(cfg) 26 | add_oneformer_config(cfg) 27 | add_dinat_config(cfg) 28 | cfg.merge_from_file(config_path) 29 | cfg.MODEL.WEIGHTS = ckpt_path 30 | cfg.freeze() 31 | metadata = MetadataCatalog.get(cfg.DATASETS.TEST_PANOPTIC[0] if len(cfg.DATASETS.TEST_PANOPTIC) else "__unused") 32 | return DefaultPredictor(cfg), metadata 33 | 34 | 35 | def semantic_run(img, predictor, metadata): 36 | predictions = predictor(img[:, :, ::-1], "semantic") # Predictor of OneFormer must use BGR image !!! 37 | visualizer_map = Visualizer(img, is_img=False, metadata=metadata, instance_mode=ColorMode.IMAGE) 38 | out_map = visualizer_map.draw_sem_seg(predictions["sem_seg"].argmax(dim=0).cpu(), alpha=1, is_text=False).get_image() 39 | return out_map 40 | -------------------------------------------------------------------------------- /annotator/oneformer/configs/ade20k/oneformer_swin_large_IN21k_384_bs16_160k.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: oneformer_R50_bs16_160k.yaml 2 | MODEL: 3 | BACKBONE: 4 | NAME: "D2SwinTransformer" 5 | SWIN: 6 | EMBED_DIM: 192 7 | DEPTHS: [2, 2, 18, 2] 8 | NUM_HEADS: [6, 12, 24, 48] 9 | WINDOW_SIZE: 12 10 | APE: False 11 | DROP_PATH_RATE: 0.3 12 | PATCH_NORM: True 13 | PRETRAIN_IMG_SIZE: 384 14 | WEIGHTS: "swin_large_patch4_window12_384_22k.pkl" 15 | PIXEL_MEAN: [123.675, 116.280, 103.530] 16 | PIXEL_STD: [58.395, 57.120, 57.375] 17 | ONE_FORMER: 18 | NUM_OBJECT_QUERIES: 250 19 | INPUT: 20 | MIN_SIZE_TRAIN: !!python/object/apply:eval ["[int(x * 0.1 * 640) for x in range(5, 21)]"] 21 | MIN_SIZE_TRAIN_SAMPLING: "choice" 22 | MIN_SIZE_TEST: 640 23 | MAX_SIZE_TRAIN: 2560 24 | MAX_SIZE_TEST: 2560 25 | CROP: 26 | ENABLED: True 27 | TYPE: "absolute" 28 | SIZE: (640, 640) 29 | SINGLE_CATEGORY_MAX_AREA: 1.0 30 | COLOR_AUG_SSD: True 31 | SIZE_DIVISIBILITY: 640 # used in dataset mapper 32 | FORMAT: "RGB" 33 | TEST: 34 | DETECTIONS_PER_IMAGE: 250 35 | EVAL_PERIOD: 5000 36 | AUG: 37 | ENABLED: False 38 | MIN_SIZES: [320, 480, 640, 800, 960, 1120] 39 | MAX_SIZE: 4480 40 | FLIP: True 41 | -------------------------------------------------------------------------------- /annotator/oneformer/configs/coco/oneformer_swin_large_IN21k_384_bs16_100ep.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: oneformer_R50_bs16_50ep.yaml 2 | MODEL: 3 | BACKBONE: 4 | NAME: "D2SwinTransformer" 5 | SWIN: 6 | EMBED_DIM: 192 7 | DEPTHS: [2, 2, 18, 2] 8 | NUM_HEADS: [6, 12, 24, 48] 9 | WINDOW_SIZE: 12 10 | APE: False 11 | DROP_PATH_RATE: 0.3 12 | PATCH_NORM: True 13 | PRETRAIN_IMG_SIZE: 384 14 | WEIGHTS: "swin_large_patch4_window12_384_22k.pkl" 15 | PIXEL_MEAN: [123.675, 116.280, 103.530] 16 | PIXEL_STD: [58.395, 57.120, 57.375] 17 | ONE_FORMER: 18 | NUM_OBJECT_QUERIES: 150 19 | SOLVER: 20 | STEPS: (655556, 735184) 21 | MAX_ITER: 737500 22 | AMP: 23 | ENABLED: False 24 | TEST: 25 | DETECTIONS_PER_IMAGE: 150 26 | -------------------------------------------------------------------------------- /annotator/oneformer/detectron2/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | 3 | from .utils.env import setup_environment 4 | 5 | setup_environment() 6 | 7 | 8 | # This line will be programatically read/write by setup.py. 9 | # Leave them at the bottom of this file and don't touch them. 10 | __version__ = "0.6" 11 | -------------------------------------------------------------------------------- /annotator/oneformer/detectron2/checkpoint/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Copyright (c) Facebook, Inc. and its affiliates. 3 | # File: 4 | 5 | 6 | from . import catalog as _UNUSED # register the handler 7 | from .detection_checkpoint import DetectionCheckpointer 8 | from fvcore.common.checkpoint import Checkpointer, PeriodicCheckpointer 9 | 10 | __all__ = ["Checkpointer", "PeriodicCheckpointer", "DetectionCheckpointer"] 11 | -------------------------------------------------------------------------------- /annotator/oneformer/detectron2/config/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | from .compat import downgrade_config, upgrade_config 3 | from .config import CfgNode, get_cfg, global_cfg, set_global_cfg, configurable 4 | from .instantiate import instantiate 5 | from .lazy import LazyCall, LazyConfig 6 | 7 | __all__ = [ 8 | "CfgNode", 9 | "get_cfg", 10 | "global_cfg", 11 | "set_global_cfg", 12 | "downgrade_config", 13 | "upgrade_config", 14 | "configurable", 15 | "instantiate", 16 | "LazyCall", 17 | "LazyConfig", 18 | ] 19 | 20 | 21 | from annotator.oneformer.detectron2.utils.env import fixup_module_metadata 22 | 23 | fixup_module_metadata(__name__, globals(), __all__) 24 | del fixup_module_metadata 25 | -------------------------------------------------------------------------------- /annotator/oneformer/detectron2/data/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | from . import transforms # isort:skip 3 | 4 | from .build import ( 5 | build_batch_data_loader, 6 | build_detection_test_loader, 7 | build_detection_train_loader, 8 | get_detection_dataset_dicts, 9 | load_proposals_into_dataset, 10 | print_instances_class_histogram, 11 | ) 12 | from .catalog import DatasetCatalog, MetadataCatalog, Metadata 13 | from .common import DatasetFromList, MapDataset, ToIterableDataset 14 | from .dataset_mapper import DatasetMapper 15 | 16 | # ensure the builtin datasets are registered 17 | from . import datasets, samplers # isort:skip 18 | 19 | __all__ = [k for k in globals().keys() if not k.startswith("_")] 20 | -------------------------------------------------------------------------------- /annotator/oneformer/detectron2/data/datasets/README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ### Common Datasets 4 | 5 | The dataset implemented here do not need to load the data into the final format. 6 | It should provide the minimal data structure needed to use the dataset, so it can be very efficient. 7 | 8 | For example, for an image dataset, just provide the file names and labels, but don't read the images. 9 | Let the downstream decide how to read. 10 | -------------------------------------------------------------------------------- /annotator/oneformer/detectron2/data/datasets/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | from .coco import load_coco_json, load_sem_seg, register_coco_instances, convert_to_coco_json 3 | from .coco_panoptic import register_coco_panoptic, register_coco_panoptic_separated 4 | from .lvis import load_lvis_json, register_lvis_instances, get_lvis_instances_meta 5 | from .pascal_voc import load_voc_instances, register_pascal_voc 6 | from . import builtin as _builtin # ensure the builtin datasets are registered 7 | 8 | 9 | __all__ = [k for k in globals().keys() if not k.startswith("_")] 10 | -------------------------------------------------------------------------------- /annotator/oneformer/detectron2/data/datasets/register_coco.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | from .coco import register_coco_instances # noqa 3 | from .coco_panoptic import register_coco_panoptic_separated # noqa 4 | -------------------------------------------------------------------------------- /annotator/oneformer/detectron2/data/samplers/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | from .distributed_sampler import ( 3 | InferenceSampler, 4 | RandomSubsetTrainingSampler, 5 | RepeatFactorTrainingSampler, 6 | TrainingSampler, 7 | ) 8 | 9 | from .grouped_batch_sampler import GroupedBatchSampler 10 | 11 | __all__ = [ 12 | "GroupedBatchSampler", 13 | "TrainingSampler", 14 | "RandomSubsetTrainingSampler", 15 | "InferenceSampler", 16 | "RepeatFactorTrainingSampler", 17 | ] 18 | -------------------------------------------------------------------------------- /annotator/oneformer/detectron2/data/transforms/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | from fvcore.transforms.transform import Transform, TransformList # order them first 3 | from fvcore.transforms.transform import * 4 | from .transform import * 5 | from .augmentation import * 6 | from .augmentation_impl import * 7 | 8 | __all__ = [k for k in globals().keys() if not k.startswith("_")] 9 | 10 | 11 | from annotator.oneformer.detectron2.utils.env import fixup_module_metadata 12 | 13 | fixup_module_metadata(__name__, globals(), __all__) 14 | del fixup_module_metadata 15 | -------------------------------------------------------------------------------- /annotator/oneformer/detectron2/engine/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | 3 | from .launch import * 4 | from .train_loop import * 5 | 6 | __all__ = [k for k in globals().keys() if not k.startswith("_")] 7 | 8 | 9 | # prefer to let hooks and defaults live in separate namespaces (therefore not in __all__) 10 | # but still make them available here 11 | from .hooks import * 12 | from .defaults import * 13 | -------------------------------------------------------------------------------- /annotator/oneformer/detectron2/evaluation/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | from .cityscapes_evaluation import CityscapesInstanceEvaluator, CityscapesSemSegEvaluator 3 | from .coco_evaluation import COCOEvaluator 4 | from .rotated_coco_evaluation import RotatedCOCOEvaluator 5 | from .evaluator import DatasetEvaluator, DatasetEvaluators, inference_context, inference_on_dataset 6 | from .lvis_evaluation import LVISEvaluator 7 | from .panoptic_evaluation import COCOPanopticEvaluator 8 | from .pascal_voc_evaluation import PascalVOCDetectionEvaluator 9 | from .sem_seg_evaluation import SemSegEvaluator 10 | from .testing import print_csv_format, verify_results 11 | 12 | __all__ = [k for k in globals().keys() if not k.startswith("_")] 13 | -------------------------------------------------------------------------------- /annotator/oneformer/detectron2/export/README.md: -------------------------------------------------------------------------------- 1 | 2 | This directory contains code to prepare a detectron2 model for deployment. 3 | Currently it supports exporting a detectron2 model to TorchScript, ONNX, or (deprecated) Caffe2 format. 4 | 5 | Please see [documentation](https://detectron2.readthedocs.io/tutorials/deployment.html) for its usage. 6 | 7 | 8 | ### Acknowledgements 9 | 10 | Thanks to Mobile Vision team at Facebook for developing the Caffe2 conversion tools. 11 | 12 | Thanks to Computing Platform Department - PAI team at Alibaba Group (@bddpqq, @chenbohua3) who 13 | help export Detectron2 models to TorchScript. 14 | 15 | Thanks to ONNX Converter team at Microsoft who help export Detectron2 models to ONNX. 16 | -------------------------------------------------------------------------------- /annotator/oneformer/detectron2/export/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import warnings 4 | 5 | from .flatten import TracingAdapter 6 | from .torchscript import dump_torchscript_IR, scripting_with_instances 7 | 8 | try: 9 | from caffe2.proto import caffe2_pb2 as _tmp 10 | from caffe2.python import core 11 | 12 | # caffe2 is optional 13 | except ImportError: 14 | pass 15 | else: 16 | from .api import * 17 | 18 | 19 | # TODO: Update ONNX Opset version and run tests when a newer PyTorch is supported 20 | STABLE_ONNX_OPSET_VERSION = 11 21 | 22 | 23 | def add_export_config(cfg): 24 | warnings.warn( 25 | "add_export_config has been deprecated and behaves as no-op function.", DeprecationWarning 26 | ) 27 | return cfg 28 | 29 | 30 | __all__ = [k for k in globals().keys() if not k.startswith("_")] 31 | -------------------------------------------------------------------------------- /annotator/oneformer/detectron2/layers/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | from .batch_norm import FrozenBatchNorm2d, get_norm, NaiveSyncBatchNorm, CycleBatchNormList 3 | from .deform_conv import DeformConv, ModulatedDeformConv 4 | from .mask_ops import paste_masks_in_image 5 | from .nms import batched_nms, batched_nms_rotated, nms, nms_rotated 6 | from .roi_align import ROIAlign, roi_align 7 | from .roi_align_rotated import ROIAlignRotated, roi_align_rotated 8 | from .shape_spec import ShapeSpec 9 | from .wrappers import ( 10 | BatchNorm2d, 11 | Conv2d, 12 | ConvTranspose2d, 13 | cat, 14 | interpolate, 15 | Linear, 16 | nonzero_tuple, 17 | cross_entropy, 18 | empty_input_loss_func_wrapper, 19 | shapes_to_tensor, 20 | move_device_like, 21 | ) 22 | from .blocks import CNNBlockBase, DepthwiseSeparableConv2d 23 | from .aspp import ASPP 24 | from .losses import ciou_loss, diou_loss 25 | 26 | __all__ = [k for k in globals().keys() if not k.startswith("_")] 27 | -------------------------------------------------------------------------------- /annotator/oneformer/detectron2/layers/csrc/README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | To add a new Op: 4 | 5 | 1. Create a new directory 6 | 2. Implement new ops there 7 | 3. Delcare its Python interface in `vision.cpp`. 8 | -------------------------------------------------------------------------------- /annotator/oneformer/detectron2/layers/csrc/box_iou_rotated/box_iou_rotated.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Facebook, Inc. and its affiliates. 2 | #pragma once 3 | #include 4 | 5 | namespace detectron2 { 6 | 7 | at::Tensor box_iou_rotated_cpu( 8 | const at::Tensor& boxes1, 9 | const at::Tensor& boxes2); 10 | 11 | #if defined(WITH_CUDA) || defined(WITH_HIP) 12 | at::Tensor box_iou_rotated_cuda( 13 | const at::Tensor& boxes1, 14 | const at::Tensor& boxes2); 15 | #endif 16 | 17 | // Interface for Python 18 | // inline is needed to prevent multiple function definitions when this header is 19 | // included by different cpps 20 | inline at::Tensor box_iou_rotated( 21 | const at::Tensor& boxes1, 22 | const at::Tensor& boxes2) { 23 | assert(boxes1.device().is_cuda() == boxes2.device().is_cuda()); 24 | if (boxes1.device().is_cuda()) { 25 | #if defined(WITH_CUDA) || defined(WITH_HIP) 26 | return box_iou_rotated_cuda(boxes1.contiguous(), boxes2.contiguous()); 27 | #else 28 | AT_ERROR("Detectron2 is not compiled with GPU support!"); 29 | #endif 30 | } 31 | 32 | return box_iou_rotated_cpu(boxes1.contiguous(), boxes2.contiguous()); 33 | } 34 | 35 | } // namespace detectron2 36 | -------------------------------------------------------------------------------- /annotator/oneformer/detectron2/layers/csrc/box_iou_rotated/box_iou_rotated_cpu.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Facebook, Inc. and its affiliates. 2 | #include "box_iou_rotated.h" 3 | #include "box_iou_rotated_utils.h" 4 | 5 | namespace detectron2 { 6 | 7 | template 8 | void box_iou_rotated_cpu_kernel( 9 | const at::Tensor& boxes1, 10 | const at::Tensor& boxes2, 11 | at::Tensor& ious) { 12 | auto num_boxes1 = boxes1.size(0); 13 | auto num_boxes2 = boxes2.size(0); 14 | 15 | for (int i = 0; i < num_boxes1; i++) { 16 | for (int j = 0; j < num_boxes2; j++) { 17 | ious[i * num_boxes2 + j] = single_box_iou_rotated( 18 | boxes1[i].data_ptr(), boxes2[j].data_ptr()); 19 | } 20 | } 21 | } 22 | 23 | at::Tensor box_iou_rotated_cpu( 24 | // input must be contiguous: 25 | const at::Tensor& boxes1, 26 | const at::Tensor& boxes2) { 27 | auto num_boxes1 = boxes1.size(0); 28 | auto num_boxes2 = boxes2.size(0); 29 | at::Tensor ious = 30 | at::empty({num_boxes1 * num_boxes2}, boxes1.options().dtype(at::kFloat)); 31 | 32 | box_iou_rotated_cpu_kernel(boxes1, boxes2, ious); 33 | 34 | // reshape from 1d array to 2d array 35 | auto shape = std::vector{num_boxes1, num_boxes2}; 36 | return ious.reshape(shape); 37 | } 38 | 39 | } // namespace detectron2 40 | -------------------------------------------------------------------------------- /annotator/oneformer/detectron2/layers/csrc/cuda_version.cu: -------------------------------------------------------------------------------- 1 | // Copyright (c) Facebook, Inc. and its affiliates. 2 | 3 | #include 4 | 5 | namespace detectron2 { 6 | int get_cudart_version() { 7 | // Not a ROCM platform: Either HIP is not used, or 8 | // it is used, but platform is not ROCM (i.e. it is CUDA) 9 | #if !defined(__HIP_PLATFORM_HCC__) 10 | return CUDART_VERSION; 11 | #else 12 | int version = 0; 13 | 14 | #if HIP_VERSION_MAJOR != 0 15 | // Create a convention similar to that of CUDA, as assumed by other 16 | // parts of the code. 17 | 18 | version = HIP_VERSION_MINOR; 19 | version += (HIP_VERSION_MAJOR * 100); 20 | #else 21 | hipRuntimeGetVersion(&version); 22 | #endif 23 | return version; 24 | #endif 25 | } 26 | } // namespace detectron2 27 | -------------------------------------------------------------------------------- /annotator/oneformer/detectron2/layers/csrc/nms_rotated/nms_rotated.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Facebook, Inc. and its affiliates. 2 | #pragma once 3 | #include 4 | 5 | namespace detectron2 { 6 | 7 | at::Tensor nms_rotated_cpu( 8 | const at::Tensor& dets, 9 | const at::Tensor& scores, 10 | const double iou_threshold); 11 | 12 | #if defined(WITH_CUDA) || defined(WITH_HIP) 13 | at::Tensor nms_rotated_cuda( 14 | const at::Tensor& dets, 15 | const at::Tensor& scores, 16 | const double iou_threshold); 17 | #endif 18 | 19 | // Interface for Python 20 | // inline is needed to prevent multiple function definitions when this header is 21 | // included by different cpps 22 | inline at::Tensor nms_rotated( 23 | const at::Tensor& dets, 24 | const at::Tensor& scores, 25 | const double iou_threshold) { 26 | assert(dets.device().is_cuda() == scores.device().is_cuda()); 27 | if (dets.device().is_cuda()) { 28 | #if defined(WITH_CUDA) || defined(WITH_HIP) 29 | return nms_rotated_cuda( 30 | dets.contiguous(), scores.contiguous(), iou_threshold); 31 | #else 32 | AT_ERROR("Detectron2 is not compiled with GPU support!"); 33 | #endif 34 | } 35 | 36 | return nms_rotated_cpu(dets.contiguous(), scores.contiguous(), iou_threshold); 37 | } 38 | 39 | } // namespace detectron2 40 | -------------------------------------------------------------------------------- /annotator/oneformer/detectron2/layers/rotated_boxes.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | from __future__ import absolute_import, division, print_function, unicode_literals 3 | import torch 4 | 5 | 6 | def pairwise_iou_rotated(boxes1, boxes2): 7 | """ 8 | Return intersection-over-union (Jaccard index) of boxes. 9 | 10 | Both sets of boxes are expected to be in 11 | (x_center, y_center, width, height, angle) format. 12 | 13 | Arguments: 14 | boxes1 (Tensor[N, 5]) 15 | boxes2 (Tensor[M, 5]) 16 | 17 | Returns: 18 | iou (Tensor[N, M]): the NxM matrix containing the pairwise 19 | IoU values for every element in boxes1 and boxes2 20 | """ 21 | return torch.ops.detectron2.box_iou_rotated(boxes1, boxes2) 22 | -------------------------------------------------------------------------------- /annotator/oneformer/detectron2/layers/shape_spec.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Copyright (c) Facebook, Inc. and its affiliates. 3 | from dataclasses import dataclass 4 | from typing import Optional 5 | 6 | 7 | @dataclass 8 | class ShapeSpec: 9 | """ 10 | A simple structure that contains basic shape specification about a tensor. 11 | It is often used as the auxiliary inputs/outputs of models, 12 | to complement the lack of shape inference ability among pytorch modules. 13 | """ 14 | 15 | channels: Optional[int] = None 16 | height: Optional[int] = None 17 | width: Optional[int] = None 18 | stride: Optional[int] = None 19 | -------------------------------------------------------------------------------- /annotator/oneformer/detectron2/model_zoo/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | """ 3 | Model Zoo API for Detectron2: a collection of functions to create common model architectures 4 | listed in `MODEL_ZOO.md `_, 5 | and optionally load their pre-trained weights. 6 | """ 7 | 8 | from .model_zoo import get, get_config_file, get_checkpoint_url, get_config 9 | 10 | __all__ = ["get_checkpoint_url", "get", "get_config_file", "get_config"] 11 | -------------------------------------------------------------------------------- /annotator/oneformer/detectron2/modeling/backbone/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | from .build import build_backbone, BACKBONE_REGISTRY # noqa F401 isort:skip 3 | 4 | from .backbone import Backbone 5 | from .fpn import FPN 6 | from .regnet import RegNet 7 | from .resnet import ( 8 | BasicStem, 9 | ResNet, 10 | ResNetBlockBase, 11 | build_resnet_backbone, 12 | make_stage, 13 | BottleneckBlock, 14 | ) 15 | from .vit import ViT, SimpleFeaturePyramid, get_vit_lr_decay_rate 16 | from .mvit import MViT 17 | from .swin import SwinTransformer 18 | 19 | __all__ = [k for k in globals().keys() if not k.startswith("_")] 20 | # TODO can expose more resnet blocks after careful consideration 21 | -------------------------------------------------------------------------------- /annotator/oneformer/detectron2/modeling/backbone/build.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | from annotator.oneformer.detectron2.layers import ShapeSpec 3 | from annotator.oneformer.detectron2.utils.registry import Registry 4 | 5 | from .backbone import Backbone 6 | 7 | BACKBONE_REGISTRY = Registry("BACKBONE") 8 | BACKBONE_REGISTRY.__doc__ = """ 9 | Registry for backbones, which extract feature maps from images 10 | 11 | The registered object must be a callable that accepts two arguments: 12 | 13 | 1. A :class:`detectron2.config.CfgNode` 14 | 2. A :class:`detectron2.layers.ShapeSpec`, which contains the input shape specification. 15 | 16 | Registered object must return instance of :class:`Backbone`. 17 | """ 18 | 19 | 20 | def build_backbone(cfg, input_shape=None): 21 | """ 22 | Build a backbone from `cfg.MODEL.BACKBONE.NAME`. 23 | 24 | Returns: 25 | an instance of :class:`Backbone` 26 | """ 27 | if input_shape is None: 28 | input_shape = ShapeSpec(channels=len(cfg.MODEL.PIXEL_MEAN)) 29 | 30 | backbone_name = cfg.MODEL.BACKBONE.NAME 31 | backbone = BACKBONE_REGISTRY.get(backbone_name)(cfg, input_shape) 32 | assert isinstance(backbone, Backbone) 33 | return backbone 34 | -------------------------------------------------------------------------------- /annotator/oneformer/detectron2/modeling/meta_arch/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Copyright (c) Facebook, Inc. and its affiliates. 3 | 4 | from .build import META_ARCH_REGISTRY, build_model # isort:skip 5 | 6 | from .panoptic_fpn import PanopticFPN 7 | 8 | # import all the meta_arch, so they will be registered 9 | from .rcnn import GeneralizedRCNN, ProposalNetwork 10 | from .dense_detector import DenseDetector 11 | from .retinanet import RetinaNet 12 | from .fcos import FCOS 13 | from .semantic_seg import SEM_SEG_HEADS_REGISTRY, SemanticSegmentor, build_sem_seg_head 14 | 15 | 16 | __all__ = list(globals().keys()) 17 | -------------------------------------------------------------------------------- /annotator/oneformer/detectron2/modeling/meta_arch/build.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | import torch 3 | 4 | from annotator.oneformer.detectron2.utils.logger import _log_api_usage 5 | from annotator.oneformer.detectron2.utils.registry import Registry 6 | 7 | META_ARCH_REGISTRY = Registry("META_ARCH") # noqa F401 isort:skip 8 | META_ARCH_REGISTRY.__doc__ = """ 9 | Registry for meta-architectures, i.e. the whole model. 10 | 11 | The registered object will be called with `obj(cfg)` 12 | and expected to return a `nn.Module` object. 13 | """ 14 | 15 | 16 | def build_model(cfg): 17 | """ 18 | Build the whole model architecture, defined by ``cfg.MODEL.META_ARCHITECTURE``. 19 | Note that it does not load any weights from ``cfg``. 20 | """ 21 | meta_arch = cfg.MODEL.META_ARCHITECTURE 22 | model = META_ARCH_REGISTRY.get(meta_arch)(cfg) 23 | _log_api_usage("modeling.meta_arch." + meta_arch) 24 | return model 25 | -------------------------------------------------------------------------------- /annotator/oneformer/detectron2/modeling/proposal_generator/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | from .build import PROPOSAL_GENERATOR_REGISTRY, build_proposal_generator 3 | from .rpn import RPN_HEAD_REGISTRY, build_rpn_head, RPN, StandardRPNHead 4 | 5 | __all__ = list(globals().keys()) 6 | -------------------------------------------------------------------------------- /annotator/oneformer/detectron2/modeling/proposal_generator/build.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | from annotator.oneformer.detectron2.utils.registry import Registry 3 | 4 | PROPOSAL_GENERATOR_REGISTRY = Registry("PROPOSAL_GENERATOR") 5 | PROPOSAL_GENERATOR_REGISTRY.__doc__ = """ 6 | Registry for proposal generator, which produces object proposals from feature maps. 7 | 8 | The registered object will be called with `obj(cfg, input_shape)`. 9 | The call should return a `nn.Module` object. 10 | """ 11 | 12 | from . import rpn, rrpn # noqa F401 isort:skip 13 | 14 | 15 | def build_proposal_generator(cfg, input_shape): 16 | """ 17 | Build a proposal generator from `cfg.MODEL.PROPOSAL_GENERATOR.NAME`. 18 | The name can be "PrecomputedProposals" to use no proposal generator. 19 | """ 20 | name = cfg.MODEL.PROPOSAL_GENERATOR.NAME 21 | if name == "PrecomputedProposals": 22 | return None 23 | 24 | return PROPOSAL_GENERATOR_REGISTRY.get(name)(cfg, input_shape) 25 | -------------------------------------------------------------------------------- /annotator/oneformer/detectron2/modeling/roi_heads/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | from .box_head import ROI_BOX_HEAD_REGISTRY, build_box_head, FastRCNNConvFCHead 3 | from .keypoint_head import ( 4 | ROI_KEYPOINT_HEAD_REGISTRY, 5 | build_keypoint_head, 6 | BaseKeypointRCNNHead, 7 | KRCNNConvDeconvUpsampleHead, 8 | ) 9 | from .mask_head import ( 10 | ROI_MASK_HEAD_REGISTRY, 11 | build_mask_head, 12 | BaseMaskRCNNHead, 13 | MaskRCNNConvUpsampleHead, 14 | ) 15 | from .roi_heads import ( 16 | ROI_HEADS_REGISTRY, 17 | ROIHeads, 18 | Res5ROIHeads, 19 | StandardROIHeads, 20 | build_roi_heads, 21 | select_foreground_proposals, 22 | ) 23 | from .cascade_rcnn import CascadeROIHeads 24 | from .rotated_fast_rcnn import RROIHeads 25 | from .fast_rcnn import FastRCNNOutputLayers 26 | 27 | from . import cascade_rcnn # isort:skip 28 | 29 | __all__ = list(globals().keys()) 30 | -------------------------------------------------------------------------------- /annotator/oneformer/detectron2/projects/README.md: -------------------------------------------------------------------------------- 1 | 2 | Projects live in the [`projects` directory](../../projects) under the root of this repository, but not here. 3 | -------------------------------------------------------------------------------- /annotator/oneformer/detectron2/projects/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | import importlib.abc 3 | import importlib.util 4 | from pathlib import Path 5 | 6 | __all__ = [] 7 | 8 | _PROJECTS = { 9 | "point_rend": "PointRend", 10 | "deeplab": "DeepLab", 11 | "panoptic_deeplab": "Panoptic-DeepLab", 12 | } 13 | _PROJECT_ROOT = Path(__file__).resolve().parent.parent.parent / "projects" 14 | 15 | if _PROJECT_ROOT.is_dir(): 16 | # This is true only for in-place installation (pip install -e, setup.py develop), 17 | # where setup(package_dir=) does not work: https://github.com/pypa/setuptools/issues/230 18 | 19 | class _D2ProjectsFinder(importlib.abc.MetaPathFinder): 20 | def find_spec(self, name, path, target=None): 21 | if not name.startswith("detectron2.projects."): 22 | return 23 | project_name = name.split(".")[-1] 24 | project_dir = _PROJECTS.get(project_name) 25 | if not project_dir: 26 | return 27 | target_file = _PROJECT_ROOT / f"{project_dir}/{project_name}/__init__.py" 28 | if not target_file.is_file(): 29 | return 30 | return importlib.util.spec_from_file_location(name, target_file) 31 | 32 | import sys 33 | 34 | sys.meta_path.append(_D2ProjectsFinder()) 35 | -------------------------------------------------------------------------------- /annotator/oneformer/detectron2/projects/deeplab/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | from .build_solver import build_lr_scheduler 3 | from .config import add_deeplab_config 4 | from .resnet import build_resnet_deeplab_backbone 5 | from .semantic_seg import DeepLabV3Head, DeepLabV3PlusHead 6 | -------------------------------------------------------------------------------- /annotator/oneformer/detectron2/projects/deeplab/build_solver.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | import torch 3 | 4 | from annotator.oneformer.detectron2.config import CfgNode 5 | from annotator.oneformer.detectron2.solver import LRScheduler 6 | from annotator.oneformer.detectron2.solver import build_lr_scheduler as build_d2_lr_scheduler 7 | 8 | from .lr_scheduler import WarmupPolyLR 9 | 10 | 11 | def build_lr_scheduler(cfg: CfgNode, optimizer: torch.optim.Optimizer) -> LRScheduler: 12 | """ 13 | Build a LR scheduler from config. 14 | """ 15 | name = cfg.SOLVER.LR_SCHEDULER_NAME 16 | if name == "WarmupPolyLR": 17 | return WarmupPolyLR( 18 | optimizer, 19 | cfg.SOLVER.MAX_ITER, 20 | warmup_factor=cfg.SOLVER.WARMUP_FACTOR, 21 | warmup_iters=cfg.SOLVER.WARMUP_ITERS, 22 | warmup_method=cfg.SOLVER.WARMUP_METHOD, 23 | power=cfg.SOLVER.POLY_LR_POWER, 24 | constant_ending=cfg.SOLVER.POLY_LR_CONSTANT_ENDING, 25 | ) 26 | else: 27 | return build_d2_lr_scheduler(cfg, optimizer) 28 | -------------------------------------------------------------------------------- /annotator/oneformer/detectron2/projects/deeplab/config.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Copyright (c) Facebook, Inc. and its affiliates. 3 | 4 | 5 | def add_deeplab_config(cfg): 6 | """ 7 | Add config for DeepLab. 8 | """ 9 | # We retry random cropping until no single category in semantic segmentation GT occupies more 10 | # than `SINGLE_CATEGORY_MAX_AREA` part of the crop. 11 | cfg.INPUT.CROP.SINGLE_CATEGORY_MAX_AREA = 1.0 12 | # Used for `poly` learning rate schedule. 13 | cfg.SOLVER.POLY_LR_POWER = 0.9 14 | cfg.SOLVER.POLY_LR_CONSTANT_ENDING = 0.0 15 | # Loss type, choose from `cross_entropy`, `hard_pixel_mining`. 16 | cfg.MODEL.SEM_SEG_HEAD.LOSS_TYPE = "hard_pixel_mining" 17 | # DeepLab settings 18 | cfg.MODEL.SEM_SEG_HEAD.PROJECT_FEATURES = ["res2"] 19 | cfg.MODEL.SEM_SEG_HEAD.PROJECT_CHANNELS = [48] 20 | cfg.MODEL.SEM_SEG_HEAD.ASPP_CHANNELS = 256 21 | cfg.MODEL.SEM_SEG_HEAD.ASPP_DILATIONS = [6, 12, 18] 22 | cfg.MODEL.SEM_SEG_HEAD.ASPP_DROPOUT = 0.1 23 | cfg.MODEL.SEM_SEG_HEAD.USE_DEPTHWISE_SEPARABLE_CONV = False 24 | # Backbone new configs 25 | cfg.MODEL.RESNETS.RES4_DILATION = 1 26 | cfg.MODEL.RESNETS.RES5_MULTI_GRID = [1, 2, 4] 27 | # ResNet stem type from: `basic`, `deeplab` 28 | cfg.MODEL.RESNETS.STEM_TYPE = "deeplab" 29 | -------------------------------------------------------------------------------- /annotator/oneformer/detectron2/solver/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | from .build import build_lr_scheduler, build_optimizer, get_default_optimizer_params 3 | from .lr_scheduler import ( 4 | LRMultiplier, 5 | LRScheduler, 6 | WarmupCosineLR, 7 | WarmupMultiStepLR, 8 | WarmupParamScheduler, 9 | ) 10 | 11 | __all__ = [k for k in globals().keys() if not k.startswith("_")] 12 | -------------------------------------------------------------------------------- /annotator/oneformer/detectron2/structures/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | from .boxes import Boxes, BoxMode, pairwise_iou, pairwise_ioa, pairwise_point_box_distance 3 | from .image_list import ImageList 4 | 5 | from .instances import Instances 6 | from .keypoints import Keypoints, heatmaps_to_keypoints 7 | from .masks import BitMasks, PolygonMasks, polygons_to_bitmask, ROIMasks 8 | from .rotated_boxes import RotatedBoxes 9 | from .rotated_boxes import pairwise_iou as pairwise_iou_rotated 10 | 11 | __all__ = [k for k in globals().keys() if not k.startswith("_")] 12 | 13 | 14 | from annotator.oneformer.detectron2.utils.env import fixup_module_metadata 15 | 16 | fixup_module_metadata(__name__, globals(), __all__) 17 | del fixup_module_metadata 18 | -------------------------------------------------------------------------------- /annotator/oneformer/detectron2/tracking/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | from .base_tracker import ( # noqa 3 | BaseTracker, 4 | build_tracker_head, 5 | TRACKER_HEADS_REGISTRY, 6 | ) 7 | from .bbox_iou_tracker import BBoxIOUTracker # noqa 8 | from .hungarian_tracker import BaseHungarianTracker # noqa 9 | from .iou_weighted_hungarian_bbox_iou_tracker import ( # noqa 10 | IOUWeightedHungarianBBoxIOUTracker, 11 | ) 12 | from .utils import create_prediction_pairs # noqa 13 | from .vanilla_hungarian_bbox_iou_tracker import VanillaHungarianBBoxIOUTracker # noqa 14 | 15 | __all__ = [k for k in globals().keys() if not k.startswith("_")] 16 | -------------------------------------------------------------------------------- /annotator/oneformer/detectron2/tracking/utils.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import numpy as np 3 | from typing import List 4 | 5 | from annotator.oneformer.detectron2.structures import Instances 6 | 7 | 8 | def create_prediction_pairs( 9 | instances: Instances, 10 | prev_instances: Instances, 11 | iou_all: np.ndarray, 12 | threshold: float = 0.5, 13 | ) -> List: 14 | """ 15 | Args: 16 | instances: predictions from current frame 17 | prev_instances: predictions from previous frame 18 | iou_all: 2D numpy array containing iou for each bbox pair 19 | threshold: below the threshold, doesn't consider the pair of bbox is valid 20 | Return: 21 | List of bbox pairs 22 | """ 23 | bbox_pairs = [] 24 | for i in range(len(instances)): 25 | for j in range(len(prev_instances)): 26 | if iou_all[i, j] < threshold: 27 | continue 28 | bbox_pairs.append( 29 | { 30 | "idx": i, 31 | "prev_idx": j, 32 | "prev_id": prev_instances.ID[j], 33 | "IoU": iou_all[i, j], 34 | "prev_period": prev_instances.ID_period[j], 35 | } 36 | ) 37 | return bbox_pairs 38 | 39 | 40 | LARGE_COST_VALUE = 100000 41 | -------------------------------------------------------------------------------- /annotator/oneformer/detectron2/utils/README.md: -------------------------------------------------------------------------------- 1 | # Utility functions 2 | 3 | This folder contain utility functions that are not used in the 4 | core library, but are useful for building models or training 5 | code using the config system. 6 | -------------------------------------------------------------------------------- /annotator/oneformer/detectron2/utils/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | -------------------------------------------------------------------------------- /annotator/oneformer/detectron2/utils/file_io.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | from iopath.common.file_io import HTTPURLHandler, OneDrivePathHandler, PathHandler 3 | from iopath.common.file_io import PathManager as PathManagerBase 4 | 5 | __all__ = ["PathManager", "PathHandler"] 6 | 7 | 8 | PathManager = PathManagerBase() 9 | """ 10 | This is a detectron2 project-specific PathManager. 11 | We try to stay away from global PathManager in fvcore as it 12 | introduces potential conflicts among other libraries. 13 | """ 14 | 15 | 16 | class Detectron2Handler(PathHandler): 17 | """ 18 | Resolve anything that's hosted under detectron2's namespace. 19 | """ 20 | 21 | PREFIX = "detectron2://" 22 | S3_DETECTRON2_PREFIX = "https://dl.fbaipublicfiles.com/detectron2/" 23 | 24 | def _get_supported_prefixes(self): 25 | return [self.PREFIX] 26 | 27 | def _get_local_path(self, path, **kwargs): 28 | name = path[len(self.PREFIX) :] 29 | return PathManager.get_local_path(self.S3_DETECTRON2_PREFIX + name, **kwargs) 30 | 31 | def _open(self, path, mode="r", **kwargs): 32 | return PathManager.open( 33 | self.S3_DETECTRON2_PREFIX + path[len(self.PREFIX) :], mode, **kwargs 34 | ) 35 | 36 | 37 | PathManager.register_handler(HTTPURLHandler()) 38 | PathManager.register_handler(OneDrivePathHandler()) 39 | PathManager.register_handler(Detectron2Handler()) 40 | -------------------------------------------------------------------------------- /annotator/oneformer/detectron2/utils/serialize.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | # import cloudpickle 3 | 4 | 5 | class PicklableWrapper(object): 6 | """ 7 | Wrap an object to make it more picklable, note that it uses 8 | heavy weight serialization libraries that are slower than pickle. 9 | It's best to use it only on closures (which are usually not picklable). 10 | 11 | This is a simplified version of 12 | https://github.com/joblib/joblib/blob/master/joblib/externals/loky/cloudpickle_wrapper.py 13 | """ 14 | 15 | def __init__(self, obj): 16 | while isinstance(obj, PicklableWrapper): 17 | # Wrapping an object twice is no-op 18 | obj = obj._obj 19 | self._obj = obj 20 | 21 | # def __reduce__(self): 22 | # s = cloudpickle.dumps(self._obj) 23 | # return cloudpickle.loads, (s,) 24 | 25 | def __call__(self, *args, **kwargs): 26 | return self._obj(*args, **kwargs) 27 | 28 | def __getattr__(self, attr): 29 | # Ensure that the wrapped object can be used seamlessly as the previous object. 30 | if attr not in ["_obj"]: 31 | return getattr(self._obj, attr) 32 | return getattr(self, attr) 33 | -------------------------------------------------------------------------------- /annotator/oneformer/oneformer/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | from . import data # register all new datasets 3 | from . import modeling 4 | 5 | # config 6 | from .config import * 7 | 8 | # models 9 | from .oneformer_model import OneFormer -------------------------------------------------------------------------------- /annotator/oneformer/oneformer/data/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | from . import datasets 3 | -------------------------------------------------------------------------------- /annotator/oneformer/oneformer/data/bpe_simple_vocab_16e6.txt.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crucible-ai/sd-webui-controlnet/385b67c2e310b7ee71aed3d61ec04a83c1efba0f/annotator/oneformer/oneformer/data/bpe_simple_vocab_16e6.txt.gz -------------------------------------------------------------------------------- /annotator/oneformer/oneformer/data/dataset_mappers/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /annotator/oneformer/oneformer/data/datasets/__init__.py: -------------------------------------------------------------------------------- 1 | from . import ( 2 | register_ade20k_panoptic, 3 | register_cityscapes_panoptic, 4 | register_coco_panoptic_annos_semseg, 5 | register_ade20k_instance, 6 | register_coco_panoptic2instance, 7 | ) 8 | -------------------------------------------------------------------------------- /annotator/oneformer/oneformer/evaluation/__init__.py: -------------------------------------------------------------------------------- 1 | from .detection_coco_evaluator import * 2 | from .coco_evaluator import * 3 | from .cityscapes_evaluation import CityscapesInstanceEvaluator -------------------------------------------------------------------------------- /annotator/oneformer/oneformer/modeling/__init__.py: -------------------------------------------------------------------------------- 1 | from .backbone.swin import D2SwinTransformer 2 | from .backbone.dinat import D2DiNAT 3 | from .pixel_decoder.fpn import BasePixelDecoder 4 | from .pixel_decoder.msdeformattn import MSDeformAttnPixelDecoder 5 | from .meta_arch.oneformer_head import OneFormerHead 6 | -------------------------------------------------------------------------------- /annotator/oneformer/oneformer/modeling/backbone/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | -------------------------------------------------------------------------------- /annotator/oneformer/oneformer/modeling/meta_arch/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /annotator/oneformer/oneformer/modeling/pixel_decoder/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | -------------------------------------------------------------------------------- /annotator/oneformer/oneformer/modeling/pixel_decoder/ops/functions/__init__.py: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------------------------------ 2 | # Deformable DETR 3 | # Copyright (c) 2020 SenseTime. All Rights Reserved. 4 | # Licensed under the Apache License, Version 2.0 [see LICENSE for details] 5 | # ------------------------------------------------------------------------------------------------ 6 | # Modified from https://github.com/chengdazhi/Deformable-Convolution-V2-PyTorch/tree/pytorch_1.0.0 7 | # ------------------------------------------------------------------------------------------------ 8 | 9 | # Copyright (c) Facebook, Inc. and its affiliates. 10 | # Modified by Bowen Cheng from https://github.com/fundamentalvision/Deformable-DETR 11 | 12 | from .ms_deform_attn_func import MSDeformAttnFunction 13 | 14 | -------------------------------------------------------------------------------- /annotator/oneformer/oneformer/modeling/pixel_decoder/ops/make.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # ------------------------------------------------------------------------------------------------ 3 | # Deformable DETR 4 | # Copyright (c) 2020 SenseTime. All Rights Reserved. 5 | # Licensed under the Apache License, Version 2.0 [see LICENSE for details] 6 | # ------------------------------------------------------------------------------------------------ 7 | # Modified from https://github.com/chengdazhi/Deformable-Convolution-V2-PyTorch/tree/pytorch_1.0.0 8 | # ------------------------------------------------------------------------------------------------ 9 | 10 | # Copyright (c) Facebook, Inc. and its affiliates. 11 | # Modified by Bowen Cheng from https://github.com/fundamentalvision/Deformable-DETR 12 | 13 | FORCE_CUDA=1 python setup.py build install 14 | -------------------------------------------------------------------------------- /annotator/oneformer/oneformer/modeling/pixel_decoder/ops/modules/__init__.py: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------------------------------ 2 | # Deformable DETR 3 | # Copyright (c) 2020 SenseTime. All Rights Reserved. 4 | # Licensed under the Apache License, Version 2.0 [see LICENSE for details] 5 | # ------------------------------------------------------------------------------------------------ 6 | # Modified from https://github.com/chengdazhi/Deformable-Convolution-V2-PyTorch/tree/pytorch_1.0.0 7 | # ------------------------------------------------------------------------------------------------ 8 | 9 | # Copyright (c) Facebook, Inc. and its affiliates. 10 | # Modified by Bowen Cheng from https://github.com/fundamentalvision/Deformable-DETR 11 | 12 | from .ms_deform_attn import MSDeformAttn 13 | -------------------------------------------------------------------------------- /annotator/oneformer/oneformer/modeling/pixel_decoder/ops/src/cpu/ms_deform_attn_cpu.h: -------------------------------------------------------------------------------- 1 | /*! 2 | ************************************************************************************************** 3 | * Deformable DETR 4 | * Copyright (c) 2020 SenseTime. All Rights Reserved. 5 | * Licensed under the Apache License, Version 2.0 [see LICENSE for details] 6 | ************************************************************************************************** 7 | * Modified from https://github.com/chengdazhi/Deformable-Convolution-V2-PyTorch/tree/pytorch_1.0.0 8 | ************************************************************************************************** 9 | */ 10 | 11 | /*! 12 | * Copyright (c) Facebook, Inc. and its affiliates. 13 | * Modified by Bowen Cheng from https://github.com/fundamentalvision/Deformable-DETR 14 | */ 15 | 16 | #pragma once 17 | #include 18 | 19 | at::Tensor 20 | ms_deform_attn_cpu_forward( 21 | const at::Tensor &value, 22 | const at::Tensor &spatial_shapes, 23 | const at::Tensor &level_start_index, 24 | const at::Tensor &sampling_loc, 25 | const at::Tensor &attn_weight, 26 | const int im2col_step); 27 | 28 | std::vector 29 | ms_deform_attn_cpu_backward( 30 | const at::Tensor &value, 31 | const at::Tensor &spatial_shapes, 32 | const at::Tensor &level_start_index, 33 | const at::Tensor &sampling_loc, 34 | const at::Tensor &attn_weight, 35 | const at::Tensor &grad_output, 36 | const int im2col_step); 37 | 38 | 39 | -------------------------------------------------------------------------------- /annotator/oneformer/oneformer/modeling/pixel_decoder/ops/src/cuda/ms_deform_attn_cuda.h: -------------------------------------------------------------------------------- 1 | /*! 2 | ************************************************************************************************** 3 | * Deformable DETR 4 | * Copyright (c) 2020 SenseTime. All Rights Reserved. 5 | * Licensed under the Apache License, Version 2.0 [see LICENSE for details] 6 | ************************************************************************************************** 7 | * Modified from https://github.com/chengdazhi/Deformable-Convolution-V2-PyTorch/tree/pytorch_1.0.0 8 | ************************************************************************************************** 9 | */ 10 | 11 | /*! 12 | * Copyright (c) Facebook, Inc. and its affiliates. 13 | * Modified by Bowen Cheng from https://github.com/fundamentalvision/Deformable-DETR 14 | */ 15 | 16 | #pragma once 17 | #include 18 | 19 | at::Tensor ms_deform_attn_cuda_forward( 20 | const at::Tensor &value, 21 | const at::Tensor &spatial_shapes, 22 | const at::Tensor &level_start_index, 23 | const at::Tensor &sampling_loc, 24 | const at::Tensor &attn_weight, 25 | const int im2col_step); 26 | 27 | std::vector ms_deform_attn_cuda_backward( 28 | const at::Tensor &value, 29 | const at::Tensor &spatial_shapes, 30 | const at::Tensor &level_start_index, 31 | const at::Tensor &sampling_loc, 32 | const at::Tensor &attn_weight, 33 | const at::Tensor &grad_output, 34 | const int im2col_step); 35 | 36 | -------------------------------------------------------------------------------- /annotator/oneformer/oneformer/modeling/pixel_decoder/ops/src/vision.cpp: -------------------------------------------------------------------------------- 1 | /*! 2 | ************************************************************************************************** 3 | * Deformable DETR 4 | * Copyright (c) 2020 SenseTime. All Rights Reserved. 5 | * Licensed under the Apache License, Version 2.0 [see LICENSE for details] 6 | ************************************************************************************************** 7 | * Modified from https://github.com/chengdazhi/Deformable-Convolution-V2-PyTorch/tree/pytorch_1.0.0 8 | ************************************************************************************************** 9 | */ 10 | 11 | /*! 12 | * Copyright (c) Facebook, Inc. and its affiliates. 13 | * Modified by Bowen Cheng from https://github.com/fundamentalvision/Deformable-DETR 14 | */ 15 | 16 | #include "ms_deform_attn.h" 17 | 18 | PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) { 19 | m.def("ms_deform_attn_forward", &ms_deform_attn_forward, "ms_deform_attn_forward"); 20 | m.def("ms_deform_attn_backward", &ms_deform_attn_backward, "ms_deform_attn_backward"); 21 | } 22 | -------------------------------------------------------------------------------- /annotator/oneformer/oneformer/modeling/transformer_decoder/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | from .oneformer_transformer_decoder import ContrastiveMultiScaleMaskedTransformerDecoder -------------------------------------------------------------------------------- /annotator/oneformer/oneformer/utils/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | from .events import setup_wandb, WandbWriter -------------------------------------------------------------------------------- /annotator/oneformer/pycocotools/__init__.py: -------------------------------------------------------------------------------- 1 | __author__ = 'tylin' 2 | -------------------------------------------------------------------------------- /annotator/uniformer/configs/_base_/datasets/cityscapes_769x769.py: -------------------------------------------------------------------------------- 1 | _base_ = './cityscapes.py' 2 | img_norm_cfg = dict( 3 | mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True) 4 | crop_size = (769, 769) 5 | train_pipeline = [ 6 | dict(type='LoadImageFromFile'), 7 | dict(type='LoadAnnotations'), 8 | dict(type='Resize', img_scale=(2049, 1025), ratio_range=(0.5, 2.0)), 9 | dict(type='RandomCrop', crop_size=crop_size, cat_max_ratio=0.75), 10 | dict(type='RandomFlip', prob=0.5), 11 | dict(type='PhotoMetricDistortion'), 12 | dict(type='Normalize', **img_norm_cfg), 13 | dict(type='Pad', size=crop_size, pad_val=0, seg_pad_val=255), 14 | dict(type='DefaultFormatBundle'), 15 | dict(type='Collect', keys=['img', 'gt_semantic_seg']), 16 | ] 17 | test_pipeline = [ 18 | dict(type='LoadImageFromFile'), 19 | dict( 20 | type='MultiScaleFlipAug', 21 | img_scale=(2049, 1025), 22 | # img_ratios=[0.5, 0.75, 1.0, 1.25, 1.5, 1.75], 23 | flip=False, 24 | transforms=[ 25 | dict(type='Resize', keep_ratio=True), 26 | dict(type='RandomFlip'), 27 | dict(type='Normalize', **img_norm_cfg), 28 | dict(type='ImageToTensor', keys=['img']), 29 | dict(type='Collect', keys=['img']), 30 | ]) 31 | ] 32 | data = dict( 33 | train=dict(pipeline=train_pipeline), 34 | val=dict(pipeline=test_pipeline), 35 | test=dict(pipeline=test_pipeline)) 36 | -------------------------------------------------------------------------------- /annotator/uniformer/configs/_base_/datasets/pascal_voc12_aug.py: -------------------------------------------------------------------------------- 1 | _base_ = './pascal_voc12.py' 2 | # dataset settings 3 | data = dict( 4 | train=dict( 5 | ann_dir=['SegmentationClass', 'SegmentationClassAug'], 6 | split=[ 7 | 'ImageSets/Segmentation/train.txt', 8 | 'ImageSets/Segmentation/aug.txt' 9 | ])) 10 | -------------------------------------------------------------------------------- /annotator/uniformer/configs/_base_/default_runtime.py: -------------------------------------------------------------------------------- 1 | # yapf:disable 2 | log_config = dict( 3 | interval=50, 4 | hooks=[ 5 | dict(type='TextLoggerHook', by_epoch=False), 6 | # dict(type='TensorboardLoggerHook') 7 | ]) 8 | # yapf:enable 9 | dist_params = dict(backend='nccl') 10 | log_level = 'INFO' 11 | load_from = None 12 | resume_from = None 13 | workflow = [('train', 1)] 14 | cudnn_benchmark = True 15 | -------------------------------------------------------------------------------- /annotator/uniformer/configs/_base_/models/ann_r50-d8.py: -------------------------------------------------------------------------------- 1 | # model settings 2 | norm_cfg = dict(type='SyncBN', requires_grad=True) 3 | model = dict( 4 | type='EncoderDecoder', 5 | pretrained='open-mmlab://resnet50_v1c', 6 | backbone=dict( 7 | type='ResNetV1c', 8 | depth=50, 9 | num_stages=4, 10 | out_indices=(0, 1, 2, 3), 11 | dilations=(1, 1, 2, 4), 12 | strides=(1, 2, 1, 1), 13 | norm_cfg=norm_cfg, 14 | norm_eval=False, 15 | style='pytorch', 16 | contract_dilation=True), 17 | decode_head=dict( 18 | type='ANNHead', 19 | in_channels=[1024, 2048], 20 | in_index=[2, 3], 21 | channels=512, 22 | project_channels=256, 23 | query_scales=(1, ), 24 | key_pool_scales=(1, 3, 6, 8), 25 | dropout_ratio=0.1, 26 | num_classes=19, 27 | norm_cfg=norm_cfg, 28 | align_corners=False, 29 | loss_decode=dict( 30 | type='CrossEntropyLoss', use_sigmoid=False, loss_weight=1.0)), 31 | auxiliary_head=dict( 32 | type='FCNHead', 33 | in_channels=1024, 34 | in_index=2, 35 | channels=256, 36 | num_convs=1, 37 | concat_input=False, 38 | dropout_ratio=0.1, 39 | num_classes=19, 40 | norm_cfg=norm_cfg, 41 | align_corners=False, 42 | loss_decode=dict( 43 | type='CrossEntropyLoss', use_sigmoid=False, loss_weight=0.4)), 44 | # model training and testing settings 45 | train_cfg=dict(), 46 | test_cfg=dict(mode='whole')) 47 | -------------------------------------------------------------------------------- /annotator/uniformer/configs/_base_/models/apcnet_r50-d8.py: -------------------------------------------------------------------------------- 1 | # model settings 2 | norm_cfg = dict(type='SyncBN', requires_grad=True) 3 | model = dict( 4 | type='EncoderDecoder', 5 | pretrained='open-mmlab://resnet50_v1c', 6 | backbone=dict( 7 | type='ResNetV1c', 8 | depth=50, 9 | num_stages=4, 10 | out_indices=(0, 1, 2, 3), 11 | dilations=(1, 1, 2, 4), 12 | strides=(1, 2, 1, 1), 13 | norm_cfg=norm_cfg, 14 | norm_eval=False, 15 | style='pytorch', 16 | contract_dilation=True), 17 | decode_head=dict( 18 | type='APCHead', 19 | in_channels=2048, 20 | in_index=3, 21 | channels=512, 22 | pool_scales=(1, 2, 3, 6), 23 | dropout_ratio=0.1, 24 | num_classes=19, 25 | norm_cfg=dict(type='SyncBN', requires_grad=True), 26 | align_corners=False, 27 | loss_decode=dict( 28 | type='CrossEntropyLoss', use_sigmoid=False, loss_weight=1.0)), 29 | auxiliary_head=dict( 30 | type='FCNHead', 31 | in_channels=1024, 32 | in_index=2, 33 | channels=256, 34 | num_convs=1, 35 | concat_input=False, 36 | dropout_ratio=0.1, 37 | num_classes=19, 38 | norm_cfg=norm_cfg, 39 | align_corners=False, 40 | loss_decode=dict( 41 | type='CrossEntropyLoss', use_sigmoid=False, loss_weight=0.4)), 42 | # model training and testing settings 43 | train_cfg=dict(), 44 | test_cfg=dict(mode='whole')) 45 | -------------------------------------------------------------------------------- /annotator/uniformer/configs/_base_/models/ccnet_r50-d8.py: -------------------------------------------------------------------------------- 1 | # model settings 2 | norm_cfg = dict(type='SyncBN', requires_grad=True) 3 | model = dict( 4 | type='EncoderDecoder', 5 | pretrained='open-mmlab://resnet50_v1c', 6 | backbone=dict( 7 | type='ResNetV1c', 8 | depth=50, 9 | num_stages=4, 10 | out_indices=(0, 1, 2, 3), 11 | dilations=(1, 1, 2, 4), 12 | strides=(1, 2, 1, 1), 13 | norm_cfg=norm_cfg, 14 | norm_eval=False, 15 | style='pytorch', 16 | contract_dilation=True), 17 | decode_head=dict( 18 | type='CCHead', 19 | in_channels=2048, 20 | in_index=3, 21 | channels=512, 22 | recurrence=2, 23 | dropout_ratio=0.1, 24 | num_classes=19, 25 | norm_cfg=norm_cfg, 26 | align_corners=False, 27 | loss_decode=dict( 28 | type='CrossEntropyLoss', use_sigmoid=False, loss_weight=1.0)), 29 | auxiliary_head=dict( 30 | type='FCNHead', 31 | in_channels=1024, 32 | in_index=2, 33 | channels=256, 34 | num_convs=1, 35 | concat_input=False, 36 | dropout_ratio=0.1, 37 | num_classes=19, 38 | norm_cfg=norm_cfg, 39 | align_corners=False, 40 | loss_decode=dict( 41 | type='CrossEntropyLoss', use_sigmoid=False, loss_weight=0.4)), 42 | # model training and testing settings 43 | train_cfg=dict(), 44 | test_cfg=dict(mode='whole')) 45 | -------------------------------------------------------------------------------- /annotator/uniformer/configs/_base_/models/cgnet.py: -------------------------------------------------------------------------------- 1 | # model settings 2 | norm_cfg = dict(type='SyncBN', eps=1e-03, requires_grad=True) 3 | model = dict( 4 | type='EncoderDecoder', 5 | backbone=dict( 6 | type='CGNet', 7 | norm_cfg=norm_cfg, 8 | in_channels=3, 9 | num_channels=(32, 64, 128), 10 | num_blocks=(3, 21), 11 | dilations=(2, 4), 12 | reductions=(8, 16)), 13 | decode_head=dict( 14 | type='FCNHead', 15 | in_channels=256, 16 | in_index=2, 17 | channels=256, 18 | num_convs=0, 19 | concat_input=False, 20 | dropout_ratio=0, 21 | num_classes=19, 22 | norm_cfg=norm_cfg, 23 | loss_decode=dict( 24 | type='CrossEntropyLoss', 25 | use_sigmoid=False, 26 | loss_weight=1.0, 27 | class_weight=[ 28 | 2.5959933, 6.7415504, 3.5354059, 9.8663225, 9.690899, 9.369352, 29 | 10.289121, 9.953208, 4.3097677, 9.490387, 7.674431, 9.396905, 30 | 10.347791, 6.3927646, 10.226669, 10.241062, 10.280587, 31 | 10.396974, 10.055647 32 | ])), 33 | # model training and testing settings 34 | train_cfg=dict(sampler=None), 35 | test_cfg=dict(mode='whole')) 36 | -------------------------------------------------------------------------------- /annotator/uniformer/configs/_base_/models/danet_r50-d8.py: -------------------------------------------------------------------------------- 1 | # model settings 2 | norm_cfg = dict(type='SyncBN', requires_grad=True) 3 | model = dict( 4 | type='EncoderDecoder', 5 | pretrained='open-mmlab://resnet50_v1c', 6 | backbone=dict( 7 | type='ResNetV1c', 8 | depth=50, 9 | num_stages=4, 10 | out_indices=(0, 1, 2, 3), 11 | dilations=(1, 1, 2, 4), 12 | strides=(1, 2, 1, 1), 13 | norm_cfg=norm_cfg, 14 | norm_eval=False, 15 | style='pytorch', 16 | contract_dilation=True), 17 | decode_head=dict( 18 | type='DAHead', 19 | in_channels=2048, 20 | in_index=3, 21 | channels=512, 22 | pam_channels=64, 23 | dropout_ratio=0.1, 24 | num_classes=19, 25 | norm_cfg=norm_cfg, 26 | align_corners=False, 27 | loss_decode=dict( 28 | type='CrossEntropyLoss', use_sigmoid=False, loss_weight=1.0)), 29 | auxiliary_head=dict( 30 | type='FCNHead', 31 | in_channels=1024, 32 | in_index=2, 33 | channels=256, 34 | num_convs=1, 35 | concat_input=False, 36 | dropout_ratio=0.1, 37 | num_classes=19, 38 | norm_cfg=norm_cfg, 39 | align_corners=False, 40 | loss_decode=dict( 41 | type='CrossEntropyLoss', use_sigmoid=False, loss_weight=0.4)), 42 | # model training and testing settings 43 | train_cfg=dict(), 44 | test_cfg=dict(mode='whole')) 45 | -------------------------------------------------------------------------------- /annotator/uniformer/configs/_base_/models/deeplabv3_r50-d8.py: -------------------------------------------------------------------------------- 1 | # model settings 2 | norm_cfg = dict(type='SyncBN', requires_grad=True) 3 | model = dict( 4 | type='EncoderDecoder', 5 | pretrained='open-mmlab://resnet50_v1c', 6 | backbone=dict( 7 | type='ResNetV1c', 8 | depth=50, 9 | num_stages=4, 10 | out_indices=(0, 1, 2, 3), 11 | dilations=(1, 1, 2, 4), 12 | strides=(1, 2, 1, 1), 13 | norm_cfg=norm_cfg, 14 | norm_eval=False, 15 | style='pytorch', 16 | contract_dilation=True), 17 | decode_head=dict( 18 | type='ASPPHead', 19 | in_channels=2048, 20 | in_index=3, 21 | channels=512, 22 | dilations=(1, 12, 24, 36), 23 | dropout_ratio=0.1, 24 | num_classes=19, 25 | norm_cfg=norm_cfg, 26 | align_corners=False, 27 | loss_decode=dict( 28 | type='CrossEntropyLoss', use_sigmoid=False, loss_weight=1.0)), 29 | auxiliary_head=dict( 30 | type='FCNHead', 31 | in_channels=1024, 32 | in_index=2, 33 | channels=256, 34 | num_convs=1, 35 | concat_input=False, 36 | dropout_ratio=0.1, 37 | num_classes=19, 38 | norm_cfg=norm_cfg, 39 | align_corners=False, 40 | loss_decode=dict( 41 | type='CrossEntropyLoss', use_sigmoid=False, loss_weight=0.4)), 42 | # model training and testing settings 43 | train_cfg=dict(), 44 | test_cfg=dict(mode='whole')) 45 | -------------------------------------------------------------------------------- /annotator/uniformer/configs/_base_/models/deeplabv3plus_r50-d8.py: -------------------------------------------------------------------------------- 1 | # model settings 2 | norm_cfg = dict(type='SyncBN', requires_grad=True) 3 | model = dict( 4 | type='EncoderDecoder', 5 | pretrained='open-mmlab://resnet50_v1c', 6 | backbone=dict( 7 | type='ResNetV1c', 8 | depth=50, 9 | num_stages=4, 10 | out_indices=(0, 1, 2, 3), 11 | dilations=(1, 1, 2, 4), 12 | strides=(1, 2, 1, 1), 13 | norm_cfg=norm_cfg, 14 | norm_eval=False, 15 | style='pytorch', 16 | contract_dilation=True), 17 | decode_head=dict( 18 | type='DepthwiseSeparableASPPHead', 19 | in_channels=2048, 20 | in_index=3, 21 | channels=512, 22 | dilations=(1, 12, 24, 36), 23 | c1_in_channels=256, 24 | c1_channels=48, 25 | dropout_ratio=0.1, 26 | num_classes=19, 27 | norm_cfg=norm_cfg, 28 | align_corners=False, 29 | loss_decode=dict( 30 | type='CrossEntropyLoss', use_sigmoid=False, loss_weight=1.0)), 31 | auxiliary_head=dict( 32 | type='FCNHead', 33 | in_channels=1024, 34 | in_index=2, 35 | channels=256, 36 | num_convs=1, 37 | concat_input=False, 38 | dropout_ratio=0.1, 39 | num_classes=19, 40 | norm_cfg=norm_cfg, 41 | align_corners=False, 42 | loss_decode=dict( 43 | type='CrossEntropyLoss', use_sigmoid=False, loss_weight=0.4)), 44 | # model training and testing settings 45 | train_cfg=dict(), 46 | test_cfg=dict(mode='whole')) 47 | -------------------------------------------------------------------------------- /annotator/uniformer/configs/_base_/models/dmnet_r50-d8.py: -------------------------------------------------------------------------------- 1 | # model settings 2 | norm_cfg = dict(type='SyncBN', requires_grad=True) 3 | model = dict( 4 | type='EncoderDecoder', 5 | pretrained='open-mmlab://resnet50_v1c', 6 | backbone=dict( 7 | type='ResNetV1c', 8 | depth=50, 9 | num_stages=4, 10 | out_indices=(0, 1, 2, 3), 11 | dilations=(1, 1, 2, 4), 12 | strides=(1, 2, 1, 1), 13 | norm_cfg=norm_cfg, 14 | norm_eval=False, 15 | style='pytorch', 16 | contract_dilation=True), 17 | decode_head=dict( 18 | type='DMHead', 19 | in_channels=2048, 20 | in_index=3, 21 | channels=512, 22 | filter_sizes=(1, 3, 5, 7), 23 | dropout_ratio=0.1, 24 | num_classes=19, 25 | norm_cfg=dict(type='SyncBN', requires_grad=True), 26 | align_corners=False, 27 | loss_decode=dict( 28 | type='CrossEntropyLoss', use_sigmoid=False, loss_weight=1.0)), 29 | auxiliary_head=dict( 30 | type='FCNHead', 31 | in_channels=1024, 32 | in_index=2, 33 | channels=256, 34 | num_convs=1, 35 | concat_input=False, 36 | dropout_ratio=0.1, 37 | num_classes=19, 38 | norm_cfg=norm_cfg, 39 | align_corners=False, 40 | loss_decode=dict( 41 | type='CrossEntropyLoss', use_sigmoid=False, loss_weight=0.4)), 42 | # model training and testing settings 43 | train_cfg=dict(), 44 | test_cfg=dict(mode='whole')) 45 | -------------------------------------------------------------------------------- /annotator/uniformer/configs/_base_/models/dnl_r50-d8.py: -------------------------------------------------------------------------------- 1 | # model settings 2 | norm_cfg = dict(type='SyncBN', requires_grad=True) 3 | model = dict( 4 | type='EncoderDecoder', 5 | pretrained='open-mmlab://resnet50_v1c', 6 | backbone=dict( 7 | type='ResNetV1c', 8 | depth=50, 9 | num_stages=4, 10 | out_indices=(0, 1, 2, 3), 11 | dilations=(1, 1, 2, 4), 12 | strides=(1, 2, 1, 1), 13 | norm_cfg=norm_cfg, 14 | norm_eval=False, 15 | style='pytorch', 16 | contract_dilation=True), 17 | decode_head=dict( 18 | type='DNLHead', 19 | in_channels=2048, 20 | in_index=3, 21 | channels=512, 22 | dropout_ratio=0.1, 23 | reduction=2, 24 | use_scale=True, 25 | mode='embedded_gaussian', 26 | num_classes=19, 27 | norm_cfg=norm_cfg, 28 | align_corners=False, 29 | loss_decode=dict( 30 | type='CrossEntropyLoss', use_sigmoid=False, loss_weight=1.0)), 31 | auxiliary_head=dict( 32 | type='FCNHead', 33 | in_channels=1024, 34 | in_index=2, 35 | channels=256, 36 | num_convs=1, 37 | concat_input=False, 38 | dropout_ratio=0.1, 39 | num_classes=19, 40 | norm_cfg=norm_cfg, 41 | align_corners=False, 42 | loss_decode=dict( 43 | type='CrossEntropyLoss', use_sigmoid=False, loss_weight=0.4)), 44 | # model training and testing settings 45 | train_cfg=dict(), 46 | test_cfg=dict(mode='whole')) 47 | -------------------------------------------------------------------------------- /annotator/uniformer/configs/_base_/models/emanet_r50-d8.py: -------------------------------------------------------------------------------- 1 | # model settings 2 | norm_cfg = dict(type='SyncBN', requires_grad=True) 3 | model = dict( 4 | type='EncoderDecoder', 5 | pretrained='open-mmlab://resnet50_v1c', 6 | backbone=dict( 7 | type='ResNetV1c', 8 | depth=50, 9 | num_stages=4, 10 | out_indices=(0, 1, 2, 3), 11 | dilations=(1, 1, 2, 4), 12 | strides=(1, 2, 1, 1), 13 | norm_cfg=norm_cfg, 14 | norm_eval=False, 15 | style='pytorch', 16 | contract_dilation=True), 17 | decode_head=dict( 18 | type='EMAHead', 19 | in_channels=2048, 20 | in_index=3, 21 | channels=256, 22 | ema_channels=512, 23 | num_bases=64, 24 | num_stages=3, 25 | momentum=0.1, 26 | dropout_ratio=0.1, 27 | num_classes=19, 28 | norm_cfg=norm_cfg, 29 | align_corners=False, 30 | loss_decode=dict( 31 | type='CrossEntropyLoss', use_sigmoid=False, loss_weight=1.0)), 32 | auxiliary_head=dict( 33 | type='FCNHead', 34 | in_channels=1024, 35 | in_index=2, 36 | channels=256, 37 | num_convs=1, 38 | concat_input=False, 39 | dropout_ratio=0.1, 40 | num_classes=19, 41 | norm_cfg=norm_cfg, 42 | align_corners=False, 43 | loss_decode=dict( 44 | type='CrossEntropyLoss', use_sigmoid=False, loss_weight=0.4)), 45 | # model training and testing settings 46 | train_cfg=dict(), 47 | test_cfg=dict(mode='whole')) 48 | -------------------------------------------------------------------------------- /annotator/uniformer/configs/_base_/models/fcn_r50-d8.py: -------------------------------------------------------------------------------- 1 | # model settings 2 | norm_cfg = dict(type='SyncBN', requires_grad=True) 3 | model = dict( 4 | type='EncoderDecoder', 5 | pretrained='open-mmlab://resnet50_v1c', 6 | backbone=dict( 7 | type='ResNetV1c', 8 | depth=50, 9 | num_stages=4, 10 | out_indices=(0, 1, 2, 3), 11 | dilations=(1, 1, 2, 4), 12 | strides=(1, 2, 1, 1), 13 | norm_cfg=norm_cfg, 14 | norm_eval=False, 15 | style='pytorch', 16 | contract_dilation=True), 17 | decode_head=dict( 18 | type='FCNHead', 19 | in_channels=2048, 20 | in_index=3, 21 | channels=512, 22 | num_convs=2, 23 | concat_input=True, 24 | dropout_ratio=0.1, 25 | num_classes=19, 26 | norm_cfg=norm_cfg, 27 | align_corners=False, 28 | loss_decode=dict( 29 | type='CrossEntropyLoss', use_sigmoid=False, loss_weight=1.0)), 30 | auxiliary_head=dict( 31 | type='FCNHead', 32 | in_channels=1024, 33 | in_index=2, 34 | channels=256, 35 | num_convs=1, 36 | concat_input=False, 37 | dropout_ratio=0.1, 38 | num_classes=19, 39 | norm_cfg=norm_cfg, 40 | align_corners=False, 41 | loss_decode=dict( 42 | type='CrossEntropyLoss', use_sigmoid=False, loss_weight=0.4)), 43 | # model training and testing settings 44 | train_cfg=dict(), 45 | test_cfg=dict(mode='whole')) 46 | -------------------------------------------------------------------------------- /annotator/uniformer/configs/_base_/models/fpn_r50.py: -------------------------------------------------------------------------------- 1 | # model settings 2 | norm_cfg = dict(type='SyncBN', requires_grad=True) 3 | model = dict( 4 | type='EncoderDecoder', 5 | pretrained='open-mmlab://resnet50_v1c', 6 | backbone=dict( 7 | type='ResNetV1c', 8 | depth=50, 9 | num_stages=4, 10 | out_indices=(0, 1, 2, 3), 11 | dilations=(1, 1, 1, 1), 12 | strides=(1, 2, 2, 2), 13 | norm_cfg=norm_cfg, 14 | norm_eval=False, 15 | style='pytorch', 16 | contract_dilation=True), 17 | neck=dict( 18 | type='FPN', 19 | in_channels=[256, 512, 1024, 2048], 20 | out_channels=256, 21 | num_outs=4), 22 | decode_head=dict( 23 | type='FPNHead', 24 | in_channels=[256, 256, 256, 256], 25 | in_index=[0, 1, 2, 3], 26 | feature_strides=[4, 8, 16, 32], 27 | channels=128, 28 | dropout_ratio=0.1, 29 | num_classes=19, 30 | norm_cfg=norm_cfg, 31 | align_corners=False, 32 | loss_decode=dict( 33 | type='CrossEntropyLoss', use_sigmoid=False, loss_weight=1.0)), 34 | # model training and testing settings 35 | train_cfg=dict(), 36 | test_cfg=dict(mode='whole')) 37 | -------------------------------------------------------------------------------- /annotator/uniformer/configs/_base_/models/fpn_uniformer.py: -------------------------------------------------------------------------------- 1 | # model settings 2 | norm_cfg = dict(type='SyncBN', requires_grad=True) 3 | model = dict( 4 | type='EncoderDecoder', 5 | backbone=dict( 6 | type='UniFormer', 7 | embed_dim=[64, 128, 320, 512], 8 | layers=[3, 4, 8, 3], 9 | head_dim=64, 10 | mlp_ratio=4., 11 | qkv_bias=True, 12 | drop_rate=0., 13 | attn_drop_rate=0., 14 | drop_path_rate=0.1), 15 | neck=dict( 16 | type='FPN', 17 | in_channels=[64, 128, 320, 512], 18 | out_channels=256, 19 | num_outs=4), 20 | decode_head=dict( 21 | type='FPNHead', 22 | in_channels=[256, 256, 256, 256], 23 | in_index=[0, 1, 2, 3], 24 | feature_strides=[4, 8, 16, 32], 25 | channels=128, 26 | dropout_ratio=0.1, 27 | num_classes=150, 28 | norm_cfg=norm_cfg, 29 | align_corners=False, 30 | loss_decode=dict( 31 | type='CrossEntropyLoss', use_sigmoid=False, loss_weight=1.0)), 32 | # model training and testing settings 33 | train_cfg=dict(), 34 | test_cfg=dict(mode='whole') 35 | ) 36 | -------------------------------------------------------------------------------- /annotator/uniformer/configs/_base_/models/gcnet_r50-d8.py: -------------------------------------------------------------------------------- 1 | # model settings 2 | norm_cfg = dict(type='SyncBN', requires_grad=True) 3 | model = dict( 4 | type='EncoderDecoder', 5 | pretrained='open-mmlab://resnet50_v1c', 6 | backbone=dict( 7 | type='ResNetV1c', 8 | depth=50, 9 | num_stages=4, 10 | out_indices=(0, 1, 2, 3), 11 | dilations=(1, 1, 2, 4), 12 | strides=(1, 2, 1, 1), 13 | norm_cfg=norm_cfg, 14 | norm_eval=False, 15 | style='pytorch', 16 | contract_dilation=True), 17 | decode_head=dict( 18 | type='GCHead', 19 | in_channels=2048, 20 | in_index=3, 21 | channels=512, 22 | ratio=1 / 4., 23 | pooling_type='att', 24 | fusion_types=('channel_add', ), 25 | dropout_ratio=0.1, 26 | num_classes=19, 27 | norm_cfg=norm_cfg, 28 | align_corners=False, 29 | loss_decode=dict( 30 | type='CrossEntropyLoss', use_sigmoid=False, loss_weight=1.0)), 31 | auxiliary_head=dict( 32 | type='FCNHead', 33 | in_channels=1024, 34 | in_index=2, 35 | channels=256, 36 | num_convs=1, 37 | concat_input=False, 38 | dropout_ratio=0.1, 39 | num_classes=19, 40 | norm_cfg=norm_cfg, 41 | align_corners=False, 42 | loss_decode=dict( 43 | type='CrossEntropyLoss', use_sigmoid=False, loss_weight=0.4)), 44 | # model training and testing settings 45 | train_cfg=dict(), 46 | test_cfg=dict(mode='whole')) 47 | -------------------------------------------------------------------------------- /annotator/uniformer/configs/_base_/models/lraspp_m-v3-d8.py: -------------------------------------------------------------------------------- 1 | # model settings 2 | norm_cfg = dict(type='SyncBN', eps=0.001, requires_grad=True) 3 | model = dict( 4 | type='EncoderDecoder', 5 | backbone=dict( 6 | type='MobileNetV3', 7 | arch='large', 8 | out_indices=(1, 3, 16), 9 | norm_cfg=norm_cfg), 10 | decode_head=dict( 11 | type='LRASPPHead', 12 | in_channels=(16, 24, 960), 13 | in_index=(0, 1, 2), 14 | channels=128, 15 | input_transform='multiple_select', 16 | dropout_ratio=0.1, 17 | num_classes=19, 18 | norm_cfg=norm_cfg, 19 | act_cfg=dict(type='ReLU'), 20 | align_corners=False, 21 | loss_decode=dict( 22 | type='CrossEntropyLoss', use_sigmoid=False, loss_weight=1.0)), 23 | # model training and testing settings 24 | train_cfg=dict(), 25 | test_cfg=dict(mode='whole')) 26 | -------------------------------------------------------------------------------- /annotator/uniformer/configs/_base_/models/nonlocal_r50-d8.py: -------------------------------------------------------------------------------- 1 | # model settings 2 | norm_cfg = dict(type='SyncBN', requires_grad=True) 3 | model = dict( 4 | type='EncoderDecoder', 5 | pretrained='open-mmlab://resnet50_v1c', 6 | backbone=dict( 7 | type='ResNetV1c', 8 | depth=50, 9 | num_stages=4, 10 | out_indices=(0, 1, 2, 3), 11 | dilations=(1, 1, 2, 4), 12 | strides=(1, 2, 1, 1), 13 | norm_cfg=norm_cfg, 14 | norm_eval=False, 15 | style='pytorch', 16 | contract_dilation=True), 17 | decode_head=dict( 18 | type='NLHead', 19 | in_channels=2048, 20 | in_index=3, 21 | channels=512, 22 | dropout_ratio=0.1, 23 | reduction=2, 24 | use_scale=True, 25 | mode='embedded_gaussian', 26 | num_classes=19, 27 | norm_cfg=norm_cfg, 28 | align_corners=False, 29 | loss_decode=dict( 30 | type='CrossEntropyLoss', use_sigmoid=False, loss_weight=1.0)), 31 | auxiliary_head=dict( 32 | type='FCNHead', 33 | in_channels=1024, 34 | in_index=2, 35 | channels=256, 36 | num_convs=1, 37 | concat_input=False, 38 | dropout_ratio=0.1, 39 | num_classes=19, 40 | norm_cfg=norm_cfg, 41 | align_corners=False, 42 | loss_decode=dict( 43 | type='CrossEntropyLoss', use_sigmoid=False, loss_weight=0.4)), 44 | # model training and testing settings 45 | train_cfg=dict(), 46 | test_cfg=dict(mode='whole')) 47 | -------------------------------------------------------------------------------- /annotator/uniformer/configs/_base_/models/ocrnet_r50-d8.py: -------------------------------------------------------------------------------- 1 | # model settings 2 | norm_cfg = dict(type='SyncBN', requires_grad=True) 3 | model = dict( 4 | type='CascadeEncoderDecoder', 5 | num_stages=2, 6 | pretrained='open-mmlab://resnet50_v1c', 7 | backbone=dict( 8 | type='ResNetV1c', 9 | depth=50, 10 | num_stages=4, 11 | out_indices=(0, 1, 2, 3), 12 | dilations=(1, 1, 2, 4), 13 | strides=(1, 2, 1, 1), 14 | norm_cfg=norm_cfg, 15 | norm_eval=False, 16 | style='pytorch', 17 | contract_dilation=True), 18 | decode_head=[ 19 | dict( 20 | type='FCNHead', 21 | in_channels=1024, 22 | in_index=2, 23 | channels=256, 24 | num_convs=1, 25 | concat_input=False, 26 | dropout_ratio=0.1, 27 | num_classes=19, 28 | norm_cfg=norm_cfg, 29 | align_corners=False, 30 | loss_decode=dict( 31 | type='CrossEntropyLoss', use_sigmoid=False, loss_weight=0.4)), 32 | dict( 33 | type='OCRHead', 34 | in_channels=2048, 35 | in_index=3, 36 | channels=512, 37 | ocr_channels=256, 38 | dropout_ratio=0.1, 39 | num_classes=19, 40 | norm_cfg=norm_cfg, 41 | align_corners=False, 42 | loss_decode=dict( 43 | type='CrossEntropyLoss', use_sigmoid=False, loss_weight=1.0)) 44 | ], 45 | # model training and testing settings 46 | train_cfg=dict(), 47 | test_cfg=dict(mode='whole')) 48 | -------------------------------------------------------------------------------- /annotator/uniformer/configs/_base_/models/psanet_r50-d8.py: -------------------------------------------------------------------------------- 1 | # model settings 2 | norm_cfg = dict(type='SyncBN', requires_grad=True) 3 | model = dict( 4 | type='EncoderDecoder', 5 | pretrained='open-mmlab://resnet50_v1c', 6 | backbone=dict( 7 | type='ResNetV1c', 8 | depth=50, 9 | num_stages=4, 10 | out_indices=(0, 1, 2, 3), 11 | dilations=(1, 1, 2, 4), 12 | strides=(1, 2, 1, 1), 13 | norm_cfg=norm_cfg, 14 | norm_eval=False, 15 | style='pytorch', 16 | contract_dilation=True), 17 | decode_head=dict( 18 | type='PSAHead', 19 | in_channels=2048, 20 | in_index=3, 21 | channels=512, 22 | mask_size=(97, 97), 23 | psa_type='bi-direction', 24 | compact=False, 25 | shrink_factor=2, 26 | normalization_factor=1.0, 27 | psa_softmax=True, 28 | dropout_ratio=0.1, 29 | num_classes=19, 30 | norm_cfg=norm_cfg, 31 | align_corners=False, 32 | loss_decode=dict( 33 | type='CrossEntropyLoss', use_sigmoid=False, loss_weight=1.0)), 34 | auxiliary_head=dict( 35 | type='FCNHead', 36 | in_channels=1024, 37 | in_index=2, 38 | channels=256, 39 | num_convs=1, 40 | concat_input=False, 41 | dropout_ratio=0.1, 42 | num_classes=19, 43 | norm_cfg=norm_cfg, 44 | align_corners=False, 45 | loss_decode=dict( 46 | type='CrossEntropyLoss', use_sigmoid=False, loss_weight=0.4)), 47 | # model training and testing settings 48 | train_cfg=dict(), 49 | test_cfg=dict(mode='whole')) 50 | -------------------------------------------------------------------------------- /annotator/uniformer/configs/_base_/models/pspnet_r50-d8.py: -------------------------------------------------------------------------------- 1 | # model settings 2 | norm_cfg = dict(type='SyncBN', requires_grad=True) 3 | model = dict( 4 | type='EncoderDecoder', 5 | pretrained='open-mmlab://resnet50_v1c', 6 | backbone=dict( 7 | type='ResNetV1c', 8 | depth=50, 9 | num_stages=4, 10 | out_indices=(0, 1, 2, 3), 11 | dilations=(1, 1, 2, 4), 12 | strides=(1, 2, 1, 1), 13 | norm_cfg=norm_cfg, 14 | norm_eval=False, 15 | style='pytorch', 16 | contract_dilation=True), 17 | decode_head=dict( 18 | type='PSPHead', 19 | in_channels=2048, 20 | in_index=3, 21 | channels=512, 22 | pool_scales=(1, 2, 3, 6), 23 | dropout_ratio=0.1, 24 | num_classes=19, 25 | norm_cfg=norm_cfg, 26 | align_corners=False, 27 | loss_decode=dict( 28 | type='CrossEntropyLoss', use_sigmoid=False, loss_weight=1.0)), 29 | auxiliary_head=dict( 30 | type='FCNHead', 31 | in_channels=1024, 32 | in_index=2, 33 | channels=256, 34 | num_convs=1, 35 | concat_input=False, 36 | dropout_ratio=0.1, 37 | num_classes=19, 38 | norm_cfg=norm_cfg, 39 | align_corners=False, 40 | loss_decode=dict( 41 | type='CrossEntropyLoss', use_sigmoid=False, loss_weight=0.4)), 42 | # model training and testing settings 43 | train_cfg=dict(), 44 | test_cfg=dict(mode='whole')) 45 | -------------------------------------------------------------------------------- /annotator/uniformer/configs/_base_/models/upernet_r50.py: -------------------------------------------------------------------------------- 1 | # model settings 2 | norm_cfg = dict(type='SyncBN', requires_grad=True) 3 | model = dict( 4 | type='EncoderDecoder', 5 | pretrained='open-mmlab://resnet50_v1c', 6 | backbone=dict( 7 | type='ResNetV1c', 8 | depth=50, 9 | num_stages=4, 10 | out_indices=(0, 1, 2, 3), 11 | dilations=(1, 1, 1, 1), 12 | strides=(1, 2, 2, 2), 13 | norm_cfg=norm_cfg, 14 | norm_eval=False, 15 | style='pytorch', 16 | contract_dilation=True), 17 | decode_head=dict( 18 | type='UPerHead', 19 | in_channels=[256, 512, 1024, 2048], 20 | in_index=[0, 1, 2, 3], 21 | pool_scales=(1, 2, 3, 6), 22 | channels=512, 23 | dropout_ratio=0.1, 24 | num_classes=19, 25 | norm_cfg=norm_cfg, 26 | align_corners=False, 27 | loss_decode=dict( 28 | type='CrossEntropyLoss', use_sigmoid=False, loss_weight=1.0)), 29 | auxiliary_head=dict( 30 | type='FCNHead', 31 | in_channels=1024, 32 | in_index=2, 33 | channels=256, 34 | num_convs=1, 35 | concat_input=False, 36 | dropout_ratio=0.1, 37 | num_classes=19, 38 | norm_cfg=norm_cfg, 39 | align_corners=False, 40 | loss_decode=dict( 41 | type='CrossEntropyLoss', use_sigmoid=False, loss_weight=0.4)), 42 | # model training and testing settings 43 | train_cfg=dict(), 44 | test_cfg=dict(mode='whole')) 45 | -------------------------------------------------------------------------------- /annotator/uniformer/configs/_base_/models/upernet_uniformer.py: -------------------------------------------------------------------------------- 1 | # model settings 2 | norm_cfg = dict(type='BN', requires_grad=True) 3 | model = dict( 4 | type='EncoderDecoder', 5 | pretrained=None, 6 | backbone=dict( 7 | type='UniFormer', 8 | embed_dim=[64, 128, 320, 512], 9 | layers=[3, 4, 8, 3], 10 | head_dim=64, 11 | mlp_ratio=4., 12 | qkv_bias=True, 13 | drop_rate=0., 14 | attn_drop_rate=0., 15 | drop_path_rate=0.1), 16 | decode_head=dict( 17 | type='UPerHead', 18 | in_channels=[64, 128, 320, 512], 19 | in_index=[0, 1, 2, 3], 20 | pool_scales=(1, 2, 3, 6), 21 | channels=512, 22 | dropout_ratio=0.1, 23 | num_classes=19, 24 | norm_cfg=norm_cfg, 25 | align_corners=False, 26 | loss_decode=dict( 27 | type='CrossEntropyLoss', use_sigmoid=False, loss_weight=1.0)), 28 | auxiliary_head=dict( 29 | type='FCNHead', 30 | in_channels=320, 31 | in_index=2, 32 | channels=256, 33 | num_convs=1, 34 | concat_input=False, 35 | dropout_ratio=0.1, 36 | num_classes=19, 37 | norm_cfg=norm_cfg, 38 | align_corners=False, 39 | loss_decode=dict( 40 | type='CrossEntropyLoss', use_sigmoid=False, loss_weight=0.4)), 41 | # model training and testing settings 42 | train_cfg=dict(), 43 | test_cfg=dict(mode='whole')) -------------------------------------------------------------------------------- /annotator/uniformer/configs/_base_/schedules/schedule_160k.py: -------------------------------------------------------------------------------- 1 | # optimizer 2 | optimizer = dict(type='SGD', lr=0.01, momentum=0.9, weight_decay=0.0005) 3 | optimizer_config = dict() 4 | # learning policy 5 | lr_config = dict(policy='poly', power=0.9, min_lr=1e-4, by_epoch=False) 6 | # runtime settings 7 | runner = dict(type='IterBasedRunner', max_iters=160000) 8 | checkpoint_config = dict(by_epoch=False, interval=16000) 9 | evaluation = dict(interval=16000, metric='mIoU') 10 | -------------------------------------------------------------------------------- /annotator/uniformer/configs/_base_/schedules/schedule_20k.py: -------------------------------------------------------------------------------- 1 | # optimizer 2 | optimizer = dict(type='SGD', lr=0.01, momentum=0.9, weight_decay=0.0005) 3 | optimizer_config = dict() 4 | # learning policy 5 | lr_config = dict(policy='poly', power=0.9, min_lr=1e-4, by_epoch=False) 6 | # runtime settings 7 | runner = dict(type='IterBasedRunner', max_iters=20000) 8 | checkpoint_config = dict(by_epoch=False, interval=2000) 9 | evaluation = dict(interval=2000, metric='mIoU') 10 | -------------------------------------------------------------------------------- /annotator/uniformer/configs/_base_/schedules/schedule_40k.py: -------------------------------------------------------------------------------- 1 | # optimizer 2 | optimizer = dict(type='SGD', lr=0.01, momentum=0.9, weight_decay=0.0005) 3 | optimizer_config = dict() 4 | # learning policy 5 | lr_config = dict(policy='poly', power=0.9, min_lr=1e-4, by_epoch=False) 6 | # runtime settings 7 | runner = dict(type='IterBasedRunner', max_iters=40000) 8 | checkpoint_config = dict(by_epoch=False, interval=4000) 9 | evaluation = dict(interval=4000, metric='mIoU') 10 | -------------------------------------------------------------------------------- /annotator/uniformer/configs/_base_/schedules/schedule_80k.py: -------------------------------------------------------------------------------- 1 | # optimizer 2 | optimizer = dict(type='SGD', lr=0.01, momentum=0.9, weight_decay=0.0005) 3 | optimizer_config = dict() 4 | # learning policy 5 | lr_config = dict(policy='poly', power=0.9, min_lr=1e-4, by_epoch=False) 6 | # runtime settings 7 | runner = dict(type='IterBasedRunner', max_iters=80000) 8 | checkpoint_config = dict(by_epoch=False, interval=8000) 9 | evaluation = dict(interval=8000, metric='mIoU') 10 | -------------------------------------------------------------------------------- /annotator/uniformer/mmcv_custom/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from .checkpoint import load_checkpoint 4 | 5 | __all__ = ['load_checkpoint'] -------------------------------------------------------------------------------- /annotator/uniformer/upernet_global_small.py: -------------------------------------------------------------------------------- 1 | _base_ = [ 2 | 'configs/_base_/models/upernet_uniformer.py', 3 | 'configs/_base_/datasets/ade20k.py', 4 | 'configs/_base_/default_runtime.py', 5 | 'configs/_base_/schedules/schedule_160k.py' 6 | ] 7 | 8 | custom_imports = dict( 9 | imports=['annotator.uniformer.uniformer'], 10 | allow_failed_imports=False 11 | ) 12 | 13 | model = dict( 14 | backbone=dict( 15 | type='UniFormer', 16 | embed_dim=[64, 128, 320, 512], 17 | layers=[3, 4, 8, 3], 18 | head_dim=64, 19 | drop_path_rate=0.25, 20 | windows=False, 21 | hybrid=False 22 | ), 23 | decode_head=dict( 24 | in_channels=[64, 128, 320, 512], 25 | num_classes=150 26 | ), 27 | auxiliary_head=dict( 28 | in_channels=320, 29 | num_classes=150 30 | )) 31 | 32 | # AdamW optimizer, no weight decay for position embedding & layer norm in backbone 33 | optimizer = dict(_delete_=True, type='AdamW', lr=0.00006, betas=(0.9, 0.999), weight_decay=0.01, 34 | paramwise_cfg=dict(custom_keys={'absolute_pos_embed': dict(decay_mult=0.), 35 | 'relative_position_bias_table': dict(decay_mult=0.), 36 | 'norm': dict(decay_mult=0.)})) 37 | 38 | lr_config = dict(_delete_=True, policy='poly', 39 | warmup='linear', 40 | warmup_iters=1500, 41 | warmup_ratio=1e-6, 42 | power=1.0, min_lr=0.0, by_epoch=False) 43 | 44 | data=dict(samples_per_gpu=2) -------------------------------------------------------------------------------- /annotator/zoe/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 | -------------------------------------------------------------------------------- /annotator/zoe/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 | -------------------------------------------------------------------------------- /annotator/zoe/zoedepth/models/base_models/midas_repo/Dockerfile: -------------------------------------------------------------------------------- 1 | # enables cuda support in docker 2 | FROM nvidia/cuda:10.2-cudnn7-runtime-ubuntu18.04 3 | 4 | # install python 3.6, pip and requirements for opencv-python 5 | # (see https://github.com/NVIDIA/nvidia-docker/issues/864) 6 | RUN apt-get update && apt-get -y install \ 7 | python3 \ 8 | python3-pip \ 9 | libsm6 \ 10 | libxext6 \ 11 | libxrender-dev \ 12 | curl \ 13 | && rm -rf /var/lib/apt/lists/* 14 | 15 | # install python dependencies 16 | RUN pip3 install --upgrade pip 17 | RUN pip3 install torch~=1.8 torchvision opencv-python-headless~=3.4 timm 18 | 19 | # copy inference code 20 | WORKDIR /opt/MiDaS 21 | COPY ./midas ./midas 22 | COPY ./*.py ./ 23 | 24 | # download model weights so the docker image can be used offline 25 | RUN cd weights && {curl -OL https://github.com/isl-org/MiDaS/releases/download/v3/dpt_hybrid_384.pt; cd -; } 26 | RUN python3 run.py --model_type dpt_hybrid; exit 0 27 | 28 | # entrypoint (dont forget to mount input and output directories) 29 | CMD python3 run.py --model_type dpt_hybrid 30 | -------------------------------------------------------------------------------- /annotator/zoe/zoedepth/models/base_models/midas_repo/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 | -------------------------------------------------------------------------------- /annotator/zoe/zoedepth/models/base_models/midas_repo/environment.yaml: -------------------------------------------------------------------------------- 1 | name: midas-py310 2 | channels: 3 | - pytorch 4 | - defaults 5 | dependencies: 6 | - nvidia::cudatoolkit=11.7 7 | - python=3.10.8 8 | - pytorch::pytorch=1.13.0 9 | - torchvision=0.14.0 10 | - pip=22.3.1 11 | - numpy=1.23.4 12 | - pip: 13 | - opencv-python==4.6.0.66 14 | - imutils==0.5.4 15 | - timm==0.6.12 16 | - einops==0.6.0 -------------------------------------------------------------------------------- /annotator/zoe/zoedepth/models/base_models/midas_repo/input/.placeholder: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crucible-ai/sd-webui-controlnet/385b67c2e310b7ee71aed3d61ec04a83c1efba0f/annotator/zoe/zoedepth/models/base_models/midas_repo/input/.placeholder -------------------------------------------------------------------------------- /annotator/zoe/zoedepth/models/base_models/midas_repo/midas/backbones/next_vit.py: -------------------------------------------------------------------------------- 1 | import timm 2 | 3 | import torch.nn as nn 4 | 5 | from pathlib import Path 6 | from .utils import activations, forward_default, get_activation 7 | 8 | from ..external.next_vit.classification.nextvit import * 9 | 10 | 11 | def forward_next_vit(pretrained, x): 12 | return forward_default(pretrained, x, "forward") 13 | 14 | 15 | def _make_next_vit_backbone( 16 | model, 17 | hooks=[2, 6, 36, 39], 18 | ): 19 | pretrained = nn.Module() 20 | 21 | pretrained.model = model 22 | pretrained.model.features[hooks[0]].register_forward_hook(get_activation("1")) 23 | pretrained.model.features[hooks[1]].register_forward_hook(get_activation("2")) 24 | pretrained.model.features[hooks[2]].register_forward_hook(get_activation("3")) 25 | pretrained.model.features[hooks[3]].register_forward_hook(get_activation("4")) 26 | 27 | pretrained.activations = activations 28 | 29 | return pretrained 30 | 31 | 32 | def _make_pretrained_next_vit_large_6m(hooks=None): 33 | model = timm.create_model("nextvit_large") 34 | 35 | hooks = [2, 6, 36, 39] if hooks == None else hooks 36 | return _make_next_vit_backbone( 37 | model, 38 | hooks=hooks, 39 | ) 40 | -------------------------------------------------------------------------------- /annotator/zoe/zoedepth/models/base_models/midas_repo/midas/backbones/swin.py: -------------------------------------------------------------------------------- 1 | import timm 2 | 3 | from .swin_common import _make_swin_backbone 4 | 5 | 6 | def _make_pretrained_swinl12_384(pretrained, hooks=None): 7 | model = timm.create_model("swin_large_patch4_window12_384", pretrained=pretrained) 8 | 9 | hooks = [1, 1, 17, 1] if hooks == None else hooks 10 | return _make_swin_backbone( 11 | model, 12 | hooks=hooks 13 | ) 14 | -------------------------------------------------------------------------------- /annotator/zoe/zoedepth/models/base_models/midas_repo/midas/backbones/swin2.py: -------------------------------------------------------------------------------- 1 | import timm 2 | 3 | from .swin_common import _make_swin_backbone 4 | 5 | 6 | def _make_pretrained_swin2l24_384(pretrained, hooks=None): 7 | model = timm.create_model("swinv2_large_window12to24_192to384_22kft1k", pretrained=pretrained) 8 | 9 | hooks = [1, 1, 17, 1] if hooks == None else hooks 10 | return _make_swin_backbone( 11 | model, 12 | hooks=hooks 13 | ) 14 | 15 | 16 | def _make_pretrained_swin2b24_384(pretrained, hooks=None): 17 | model = timm.create_model("swinv2_base_window12to24_192to384_22kft1k", pretrained=pretrained) 18 | 19 | hooks = [1, 1, 17, 1] if hooks == None else hooks 20 | return _make_swin_backbone( 21 | model, 22 | hooks=hooks 23 | ) 24 | 25 | 26 | def _make_pretrained_swin2t16_256(pretrained, hooks=None): 27 | model = timm.create_model("swinv2_tiny_window16_256", pretrained=pretrained) 28 | 29 | hooks = [1, 1, 5, 1] if hooks == None else hooks 30 | return _make_swin_backbone( 31 | model, 32 | hooks=hooks, 33 | patch_grid=[64, 64] 34 | ) 35 | -------------------------------------------------------------------------------- /annotator/zoe/zoedepth/models/base_models/midas_repo/midas/base_model.py: -------------------------------------------------------------------------------- 1 | import torch 2 | 3 | 4 | class BaseModel(torch.nn.Module): 5 | def load(self, path): 6 | """Load model from file. 7 | 8 | Args: 9 | path (str): file path 10 | """ 11 | parameters = torch.load(path, map_location=torch.device('cpu')) 12 | 13 | if "optimizer" in parameters: 14 | parameters = parameters["model"] 15 | 16 | self.load_state_dict(parameters) 17 | -------------------------------------------------------------------------------- /annotator/zoe/zoedepth/models/base_models/midas_repo/output/.placeholder: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crucible-ai/sd-webui-controlnet/385b67c2e310b7ee71aed3d61ec04a83c1efba0f/annotator/zoe/zoedepth/models/base_models/midas_repo/output/.placeholder -------------------------------------------------------------------------------- /annotator/zoe/zoedepth/models/base_models/midas_repo/ros/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Alexey 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 | -------------------------------------------------------------------------------- /annotator/zoe/zoedepth/models/base_models/midas_repo/ros/additions/do_catkin_make.sh: -------------------------------------------------------------------------------- 1 | mkdir src 2 | catkin_make 3 | source devel/setup.bash 4 | echo $ROS_PACKAGE_PATH 5 | chmod +x ./devel/setup.bash 6 | -------------------------------------------------------------------------------- /annotator/zoe/zoedepth/models/base_models/midas_repo/ros/additions/downloads.sh: -------------------------------------------------------------------------------- 1 | mkdir ~/.ros 2 | wget https://github.com/isl-org/MiDaS/releases/download/v2_1/model-small-traced.pt 3 | cp ./model-small-traced.pt ~/.ros/model-small-traced.pt 4 | 5 | 6 | -------------------------------------------------------------------------------- /annotator/zoe/zoedepth/models/base_models/midas_repo/ros/additions/install_ros_melodic_ubuntu_17_18.sh: -------------------------------------------------------------------------------- 1 | #@title { display-mode: "code" } 2 | 3 | #from http://wiki.ros.org/indigo/Installation/Ubuntu 4 | 5 | #1.2 Setup sources.list 6 | sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list' 7 | 8 | # 1.3 Setup keys 9 | sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654 10 | sudo apt-key adv --keyserver 'hkp://ha.pool.sks-keyservers.net:80' --recv-key 421C365BD9FF1F717815A3895523BAEEB01FA116 11 | 12 | curl -sSL 'http://keyserver.ubuntu.com/pks/lookup?op=get&search=0xC1CF6E31E6BADE8868B172B4F42ED6FBAB17C654' | sudo apt-key add - 13 | 14 | # 1.4 Installation 15 | sudo apt-get update 16 | sudo apt-get upgrade 17 | 18 | # Desktop-Full Install: 19 | sudo apt-get install ros-melodic-desktop-full 20 | 21 | printf "\nsource /opt/ros/melodic/setup.bash\n" >> ~/.bashrc 22 | 23 | # 1.5 Initialize rosdep 24 | sudo rosdep init 25 | rosdep update 26 | 27 | 28 | # 1.7 Getting rosinstall (python) 29 | sudo apt-get install python-rosinstall 30 | sudo apt-get install python-catkin-tools 31 | sudo apt-get install python-rospy 32 | sudo apt-get install python-rosdep 33 | sudo apt-get install python-roscd 34 | sudo apt-get install python-pip -------------------------------------------------------------------------------- /annotator/zoe/zoedepth/models/base_models/midas_repo/ros/additions/install_ros_noetic_ubuntu_20.sh: -------------------------------------------------------------------------------- 1 | #@title { display-mode: "code" } 2 | 3 | #from http://wiki.ros.org/indigo/Installation/Ubuntu 4 | 5 | #1.2 Setup sources.list 6 | sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list' 7 | 8 | # 1.3 Setup keys 9 | sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654 10 | 11 | curl -sSL 'http://keyserver.ubuntu.com/pks/lookup?op=get&search=0xC1CF6E31E6BADE8868B172B4F42ED6FBAB17C654' | sudo apt-key add - 12 | 13 | # 1.4 Installation 14 | sudo apt-get update 15 | sudo apt-get upgrade 16 | 17 | # Desktop-Full Install: 18 | sudo apt-get install ros-noetic-desktop-full 19 | 20 | printf "\nsource /opt/ros/noetic/setup.bash\n" >> ~/.bashrc 21 | 22 | # 1.5 Initialize rosdep 23 | sudo rosdep init 24 | rosdep update 25 | 26 | 27 | # 1.7 Getting rosinstall (python) 28 | sudo apt-get install python3-rosinstall 29 | sudo apt-get install python3-catkin-tools 30 | sudo apt-get install python3-rospy 31 | sudo apt-get install python3-rosdep 32 | sudo apt-get install python3-roscd 33 | sudo apt-get install python3-pip -------------------------------------------------------------------------------- /annotator/zoe/zoedepth/models/base_models/midas_repo/ros/additions/make_package_cpp.sh: -------------------------------------------------------------------------------- 1 | cd ~/catkin_ws/src 2 | catkin_create_pkg midas_cpp std_msgs roscpp cv_bridge sensor_msgs image_transport 3 | cd ~/catkin_ws 4 | catkin_make 5 | 6 | chmod +x ~/catkin_ws/devel/setup.bash 7 | printf "\nsource ~/catkin_ws/devel/setup.bash" >> ~/.bashrc 8 | source ~/catkin_ws/devel/setup.bash 9 | 10 | 11 | sudo rosdep init 12 | rosdep update 13 | #rospack depends1 midas_cpp 14 | roscd midas_cpp 15 | #cat package.xml 16 | #rospack depends midas_cpp -------------------------------------------------------------------------------- /annotator/zoe/zoedepth/models/base_models/midas_repo/ros/launch_midas_cpp.sh: -------------------------------------------------------------------------------- 1 | source ~/catkin_ws/devel/setup.bash 2 | roslaunch midas_cpp midas_cpp.launch model_name:="model-small-traced.pt" input_topic:="image_topic" output_topic:="midas_topic" out_orig_size:="true" -------------------------------------------------------------------------------- /annotator/zoe/zoedepth/models/base_models/midas_repo/ros/midas_cpp/launch/midas_cpp.launch: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /annotator/zoe/zoedepth/models/base_models/midas_repo/ros/midas_cpp/launch/midas_talker_listener.launch: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /annotator/zoe/zoedepth/models/base_models/midas_repo/ros/run_talker_listener_test.sh: -------------------------------------------------------------------------------- 1 | # place any test.mp4 file near with this file 2 | 3 | # roscore 4 | # rosnode kill -a 5 | 6 | source ~/catkin_ws/devel/setup.bash 7 | 8 | roscore & 9 | P1=$! 10 | rosrun midas_cpp talker.py & 11 | P2=$! 12 | rosrun midas_cpp listener_original.py & 13 | P3=$! 14 | rosrun midas_cpp listener.py & 15 | P4=$! 16 | wait $P1 $P2 $P3 $P4 -------------------------------------------------------------------------------- /annotator/zoe/zoedepth/models/base_models/midas_repo/tf/input/.placeholder: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crucible-ai/sd-webui-controlnet/385b67c2e310b7ee71aed3d61ec04a83c1efba0f/annotator/zoe/zoedepth/models/base_models/midas_repo/tf/input/.placeholder -------------------------------------------------------------------------------- /annotator/zoe/zoedepth/models/base_models/midas_repo/tf/output/.placeholder: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crucible-ai/sd-webui-controlnet/385b67c2e310b7ee71aed3d61ec04a83c1efba0f/annotator/zoe/zoedepth/models/base_models/midas_repo/tf/output/.placeholder -------------------------------------------------------------------------------- /annotator/zoe/zoedepth/models/base_models/midas_repo/weights/.placeholder: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crucible-ai/sd-webui-controlnet/385b67c2e310b7ee71aed3d61ec04a83c1efba0f/annotator/zoe/zoedepth/models/base_models/midas_repo/weights/.placeholder -------------------------------------------------------------------------------- /annotator/zoe/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] -------------------------------------------------------------------------------- /annotator/zoe/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 | } -------------------------------------------------------------------------------- /annotator/zoe/zoedepth/models/zoedepth_nk/__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_nk_v1 import ZoeDepthNK 26 | 27 | all_versions = { 28 | "v1": ZoeDepthNK, 29 | } 30 | 31 | get_version = lambda v : all_versions[v] -------------------------------------------------------------------------------- /annotator/zoe/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 | -------------------------------------------------------------------------------- /annotator/zoe/zoedepth/utils/arg_utils.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | def infer_type(x): # hacky way to infer type from string args 4 | if not isinstance(x, str): 5 | return x 6 | 7 | try: 8 | x = int(x) 9 | return x 10 | except ValueError: 11 | pass 12 | 13 | try: 14 | x = float(x) 15 | return x 16 | except ValueError: 17 | pass 18 | 19 | return x 20 | 21 | 22 | def parse_unknown(unknown_args): 23 | clean = [] 24 | for a in unknown_args: 25 | if "=" in a: 26 | k, v = a.split("=") 27 | clean.extend([k, v]) 28 | else: 29 | clean.append(a) 30 | 31 | keys = clean[::2] 32 | values = clean[1::2] 33 | return {k.replace("--", ""): infer_type(v) for k, v in zip(keys, values)} 34 | -------------------------------------------------------------------------------- /example/visual_chatgpt.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "# Run WebUI in API mode\n", 10 | "nohup python launch.py --api --xformers &\n", 11 | "\n", 12 | "# Wait until webui fully startup\n", 13 | "tail -f nohup.out" 14 | ] 15 | }, 16 | { 17 | "cell_type": "code", 18 | "execution_count": null, 19 | "metadata": {}, 20 | "outputs": [], 21 | "source": [ 22 | "# Install/Upgrade transformers\n", 23 | "pip install -U transformers\n", 24 | "\n", 25 | "# Install deps\n", 26 | "pip install langchain==0.0.101 openai \n", 27 | "\n", 28 | "# Run exmaple\n", 29 | "python example/chatgpt.py" 30 | ] 31 | } 32 | ], 33 | "metadata": { 34 | "kernelspec": { 35 | "display_name": "pynb", 36 | "language": "python", 37 | "name": "python3" 38 | }, 39 | "language_info": { 40 | "codemirror_mode": { 41 | "name": "ipython", 42 | "version": 3 43 | }, 44 | "file_extension": ".py", 45 | "mimetype": "text/x-python", 46 | "name": "python", 47 | "nbconvert_exporter": "python", 48 | "pygments_lexer": "ipython3", 49 | "version": "3.10.9" 50 | }, 51 | "orig_nbformat": 4, 52 | "vscode": { 53 | "interpreter": { 54 | "hash": "d73345514d8c18d9a1da7351d222dbd2834c7f4a09e728a0d1f4c4580fbec206" 55 | } 56 | } 57 | }, 58 | "nbformat": 4, 59 | "nbformat_minor": 2 60 | } 61 | -------------------------------------------------------------------------------- /extract_controlnet.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | import torch 3 | from safetensors.torch import load_file, save_file 4 | 5 | if __name__ == "__main__": 6 | parser = argparse.ArgumentParser() 7 | parser.add_argument("--src", default=None, type=str, required=True, help="Path to the model to convert.") 8 | parser.add_argument("--dst", default=None, type=str, required=True, help="Path to the output model.") 9 | parser.add_argument("--half", action="store_true", help="Cast to FP16.") 10 | args = parser.parse_args() 11 | 12 | assert args.src is not None, "Must provide a model path!" 13 | assert args.dst is not None, "Must provide a checkpoint path!" 14 | 15 | if args.src.endswith(".safetensors"): 16 | state_dict = load_file(args.src) 17 | else: 18 | state_dict = torch.load(args.src) 19 | 20 | if any([k.startswith("control_model.") for k, v in state_dict.items()]): 21 | dtype = torch.float16 if args.half else torch.float32 22 | state_dict = {k.replace("control_model.", ""): v.to(dtype) for k, v in state_dict.items() if k.startswith("control_model.")} 23 | 24 | if args.dst.endswith(".safetensors"): 25 | save_file(state_dict, args.dst) 26 | else: 27 | torch.save({"state_dict": state_dict}, args.dst) 28 | -------------------------------------------------------------------------------- /install.py: -------------------------------------------------------------------------------- 1 | import launch 2 | import os 3 | 4 | req_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), "requirements.txt") 5 | 6 | with open(req_file) as file: 7 | for lib in file: 8 | lib = lib.strip() 9 | if not launch.is_installed(lib): 10 | launch.run_pip(f"install {lib}", f"sd-webui-controlnet requirement: {lib}") -------------------------------------------------------------------------------- /models/image_adapter_v14.yaml: -------------------------------------------------------------------------------- 1 | model: 2 | target: tencentarc.t21_adapter 3 | params: 4 | channels: [320, 640, 1280, 1280] 5 | nums_rb: 2 6 | ksize: 1 7 | sk: true 8 | cin: 192 9 | use_conv: false -------------------------------------------------------------------------------- /models/sketch_adapter_v14.yaml: -------------------------------------------------------------------------------- 1 | model: 2 | target: tencentarc.t21_adapter 3 | params: 4 | channels: [320, 640, 1280, 1280] 5 | nums_rb: 2 6 | ksize: 1 7 | sk: true 8 | cin: 64 9 | use_conv: false -------------------------------------------------------------------------------- /models/t2iadapter_canny_sd14v1.yaml: -------------------------------------------------------------------------------- 1 | model: 2 | target: tencentarc.t21_adapter 3 | params: 4 | channels: [320, 640, 1280, 1280] 5 | nums_rb: 2 6 | ksize: 1 7 | sk: true 8 | cin: 64 9 | use_conv: false -------------------------------------------------------------------------------- /models/t2iadapter_canny_sd15v2.yaml: -------------------------------------------------------------------------------- 1 | model: 2 | target: tencentarc.t21_adapter 3 | params: 4 | channels: [320, 640, 1280, 1280] 5 | nums_rb: 2 6 | ksize: 1 7 | sk: true 8 | cin: 64 9 | use_conv: false -------------------------------------------------------------------------------- /models/t2iadapter_color_sd14v1.yaml: -------------------------------------------------------------------------------- 1 | model: 2 | target: scripts.adapter.Adapter_light 3 | params: 4 | channels: [320, 640, 1280, 1280] 5 | nums_rb: 4 6 | cin: 192 -------------------------------------------------------------------------------- /models/t2iadapter_depth_sd14v1.yaml: -------------------------------------------------------------------------------- 1 | model: 2 | target: tencentarc.t21_adapter 3 | params: 4 | channels: [320, 640, 1280, 1280] 5 | nums_rb: 2 6 | ksize: 1 7 | sk: true 8 | cin: 192 9 | use_conv: false -------------------------------------------------------------------------------- /models/t2iadapter_depth_sd15v2.yaml: -------------------------------------------------------------------------------- 1 | model: 2 | target: tencentarc.t21_adapter 3 | params: 4 | channels: [320, 640, 1280, 1280] 5 | nums_rb: 2 6 | ksize: 1 7 | sk: true 8 | cin: 192 9 | use_conv: false -------------------------------------------------------------------------------- /models/t2iadapter_keypose_sd14v1.yaml: -------------------------------------------------------------------------------- 1 | model: 2 | target: tencentarc.t21_adapter 3 | params: 4 | channels: [320, 640, 1280, 1280] 5 | nums_rb: 2 6 | ksize: 1 7 | sk: true 8 | cin: 192 9 | use_conv: false -------------------------------------------------------------------------------- /models/t2iadapter_openpose_sd14v1.yaml: -------------------------------------------------------------------------------- 1 | model: 2 | target: tencentarc.t21_adapter 3 | params: 4 | channels: [320, 640, 1280, 1280] 5 | nums_rb: 2 6 | ksize: 1 7 | sk: true 8 | cin: 192 9 | use_conv: false -------------------------------------------------------------------------------- /models/t2iadapter_seg_sd14v1.yaml: -------------------------------------------------------------------------------- 1 | model: 2 | target: tencentarc.t21_adapter 3 | params: 4 | channels: [320, 640, 1280, 1280] 5 | nums_rb: 2 6 | ksize: 1 7 | sk: true 8 | cin: 192 9 | use_conv: false -------------------------------------------------------------------------------- /models/t2iadapter_sketch_sd14v1.yaml: -------------------------------------------------------------------------------- 1 | model: 2 | target: tencentarc.t21_adapter 3 | params: 4 | channels: [320, 640, 1280, 1280] 5 | nums_rb: 2 6 | ksize: 1 7 | sk: true 8 | cin: 64 9 | use_conv: false -------------------------------------------------------------------------------- /models/t2iadapter_sketch_sd15v2.yaml: -------------------------------------------------------------------------------- 1 | model: 2 | target: tencentarc.t21_adapter 3 | params: 4 | channels: [320, 640, 1280, 1280] 5 | nums_rb: 2 6 | ksize: 1 7 | sk: true 8 | cin: 64 9 | use_conv: false -------------------------------------------------------------------------------- /models/t2iadapter_style_sd14v1.yaml: -------------------------------------------------------------------------------- 1 | model: 2 | target: scripts.adapter.StyleAdapter 3 | params: 4 | width: 1024 5 | context_dim: 768 6 | num_head: 8 7 | n_layes: 3 8 | num_token: 8 -------------------------------------------------------------------------------- /models/t2iadapter_zoedepth_sd15v1.yaml: -------------------------------------------------------------------------------- 1 | model: 2 | target: tencentarc.t21_adapter 3 | params: 4 | channels: [320, 640, 1280, 1280] 5 | nums_rb: 2 6 | ksize: 1 7 | sk: true 8 | cin: 192 9 | use_conv: false -------------------------------------------------------------------------------- /preload.py: -------------------------------------------------------------------------------- 1 | def preload(parser): 2 | parser.add_argument("--controlnet-dir", type=str, help="Path to directory with ControlNet models", default=None) 3 | parser.add_argument("--no-half-controlnet", action='store_true', help="do not switch the ControlNet models to 16-bit floats (only needed without --no-half)", default=None) 4 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | mediapipe==0.9.1.0 2 | svglib 3 | fvcore 4 | opencv-contrib-python==4.7.0.68 5 | -------------------------------------------------------------------------------- /samples/an-gen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crucible-ai/sd-webui-controlnet/385b67c2e310b7ee71aed3d61ec04a83c1efba0f/samples/an-gen.png -------------------------------------------------------------------------------- /samples/an-pose.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crucible-ai/sd-webui-controlnet/385b67c2e310b7ee71aed3d61ec04a83c1efba0f/samples/an-pose.png -------------------------------------------------------------------------------- /samples/an-source.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crucible-ai/sd-webui-controlnet/385b67c2e310b7ee71aed3d61ec04a83c1efba0f/samples/an-source.jpg -------------------------------------------------------------------------------- /samples/bal-gen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crucible-ai/sd-webui-controlnet/385b67c2e310b7ee71aed3d61ec04a83c1efba0f/samples/bal-gen.png -------------------------------------------------------------------------------- /samples/bal-source.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crucible-ai/sd-webui-controlnet/385b67c2e310b7ee71aed3d61ec04a83c1efba0f/samples/bal-source.png -------------------------------------------------------------------------------- /samples/cat_out-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crucible-ai/sd-webui-controlnet/385b67c2e310b7ee71aed3d61ec04a83c1efba0f/samples/cat_out-2.png -------------------------------------------------------------------------------- /samples/cat_sk-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crucible-ai/sd-webui-controlnet/385b67c2e310b7ee71aed3d61ec04a83c1efba0f/samples/cat_sk-2.png -------------------------------------------------------------------------------- /samples/dog_out-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crucible-ai/sd-webui-controlnet/385b67c2e310b7ee71aed3d61ec04a83c1efba0f/samples/dog_out-2.png -------------------------------------------------------------------------------- /samples/dog_rel.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crucible-ai/sd-webui-controlnet/385b67c2e310b7ee71aed3d61ec04a83c1efba0f/samples/dog_rel.jpg -------------------------------------------------------------------------------- /samples/dog_rel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crucible-ai/sd-webui-controlnet/385b67c2e310b7ee71aed3d61ec04a83c1efba0f/samples/dog_rel.png -------------------------------------------------------------------------------- /samples/dog_sk-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crucible-ai/sd-webui-controlnet/385b67c2e310b7ee71aed3d61ec04a83c1efba0f/samples/dog_sk-2.png -------------------------------------------------------------------------------- /samples/evt_gen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crucible-ai/sd-webui-controlnet/385b67c2e310b7ee71aed3d61ec04a83c1efba0f/samples/evt_gen.png -------------------------------------------------------------------------------- /samples/evt_hed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crucible-ai/sd-webui-controlnet/385b67c2e310b7ee71aed3d61ec04a83c1efba0f/samples/evt_hed.png -------------------------------------------------------------------------------- /samples/evt_source.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crucible-ai/sd-webui-controlnet/385b67c2e310b7ee71aed3d61ec04a83c1efba0f/samples/evt_source.jpg -------------------------------------------------------------------------------- /samples/fs_input.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crucible-ai/sd-webui-controlnet/385b67c2e310b7ee71aed3d61ec04a83c1efba0f/samples/fs_input.png -------------------------------------------------------------------------------- /samples/fs_output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crucible-ai/sd-webui-controlnet/385b67c2e310b7ee71aed3d61ec04a83c1efba0f/samples/fs_output.png -------------------------------------------------------------------------------- /samples/kp_a-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crucible-ai/sd-webui-controlnet/385b67c2e310b7ee71aed3d61ec04a83c1efba0f/samples/kp_a-2.png -------------------------------------------------------------------------------- /samples/kp_a2-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crucible-ai/sd-webui-controlnet/385b67c2e310b7ee71aed3d61ec04a83c1efba0f/samples/kp_a2-2.png -------------------------------------------------------------------------------- /samples/kp_o-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crucible-ai/sd-webui-controlnet/385b67c2e310b7ee71aed3d61ec04a83c1efba0f/samples/kp_o-2.png -------------------------------------------------------------------------------- /samples/kp_o2-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crucible-ai/sd-webui-controlnet/385b67c2e310b7ee71aed3d61ec04a83c1efba0f/samples/kp_o2-2.png -------------------------------------------------------------------------------- /samples/mahiro-out.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crucible-ai/sd-webui-controlnet/385b67c2e310b7ee71aed3d61ec04a83c1efba0f/samples/mahiro-out.png -------------------------------------------------------------------------------- /samples/mahiro_canny.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crucible-ai/sd-webui-controlnet/385b67c2e310b7ee71aed3d61ec04a83c1efba0f/samples/mahiro_canny.png -------------------------------------------------------------------------------- /samples/mahiro_input.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crucible-ai/sd-webui-controlnet/385b67c2e310b7ee71aed3d61ec04a83c1efba0f/samples/mahiro_input.png -------------------------------------------------------------------------------- /samples/nm-gen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crucible-ai/sd-webui-controlnet/385b67c2e310b7ee71aed3d61ec04a83c1efba0f/samples/nm-gen.png -------------------------------------------------------------------------------- /samples/nm-out.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crucible-ai/sd-webui-controlnet/385b67c2e310b7ee71aed3d61ec04a83c1efba0f/samples/nm-out.png -------------------------------------------------------------------------------- /samples/nm-src.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crucible-ai/sd-webui-controlnet/385b67c2e310b7ee71aed3d61ec04a83c1efba0f/samples/nm-src.png -------------------------------------------------------------------------------- /samples/sk-b-dep.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crucible-ai/sd-webui-controlnet/385b67c2e310b7ee71aed3d61ec04a83c1efba0f/samples/sk-b-dep.png -------------------------------------------------------------------------------- /samples/sk-b-out.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crucible-ai/sd-webui-controlnet/385b67c2e310b7ee71aed3d61ec04a83c1efba0f/samples/sk-b-out.png -------------------------------------------------------------------------------- /samples/sk-b-src.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crucible-ai/sd-webui-controlnet/385b67c2e310b7ee71aed3d61ec04a83c1efba0f/samples/sk-b-src.png -------------------------------------------------------------------------------- /scripts/utils.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import os 3 | 4 | 5 | def load_state_dict(ckpt_path, location='cpu'): 6 | _, extension = os.path.splitext(ckpt_path) 7 | if extension.lower() == ".safetensors": 8 | import safetensors.torch 9 | state_dict = safetensors.torch.load_file(ckpt_path, device=location) 10 | else: 11 | state_dict = get_state_dict(torch.load( 12 | ckpt_path, map_location=torch.device(location))) 13 | state_dict = get_state_dict(state_dict) 14 | print(f'Loaded state_dict from [{ckpt_path}]') 15 | return state_dict 16 | 17 | 18 | def get_state_dict(d): 19 | return d.get('state_dict', d) -------------------------------------------------------------------------------- /tests/external_code_api/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crucible-ai/sd-webui-controlnet/385b67c2e310b7ee71aed3d61ec04a83c1efba0f/tests/external_code_api/__init__.py -------------------------------------------------------------------------------- /tests/external_code_api/script_args_test.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | import importlib 3 | utils = importlib.import_module('extensions.sd-webui-controlnet.tests.utils', 'utils') 4 | utils.setup_test_env() 5 | 6 | from scripts import external_code 7 | 8 | 9 | class TestGetAllUnitsFrom(unittest.TestCase): 10 | def setUp(self): 11 | self.flat_control_unit = [ 12 | True, "none", utils.get_model(), 1.0, 13 | utils.readImage("test/test_files/img2img_basic.png"), 14 | False, "Inner Fit (Scale to Fit)", False, False, 15 | 64, 64, 64, 0.0, 1.0, False 16 | ] 17 | self.object_unit = external_code.ControlNetUnit(*self.flat_control_unit) 18 | 19 | def test_empty_converts(self): 20 | script_args = [] 21 | units = external_code.get_all_units_from(script_args) 22 | self.assertListEqual(units, []) 23 | 24 | def test_flattened_converts(self): 25 | script_args = self.flat_control_unit 26 | units = external_code.get_all_units_from(script_args) 27 | self.assertListEqual(units, [self.object_unit]) 28 | 29 | def test_object_forwards(self): 30 | script_args = [self.object_unit] 31 | units = external_code.get_all_units_from(script_args) 32 | self.assertListEqual(units, [self.object_unit]) 33 | 34 | def test_mixed_converts(self): 35 | script_args = [self.object_unit] + self.flat_control_unit + [self.object_unit] + self.flat_control_unit 36 | units = external_code.get_all_units_from(script_args) 37 | self.assertListEqual(units, [self.object_unit] * 4) 38 | 39 | 40 | if __name__ == '__main__': 41 | unittest.main() -------------------------------------------------------------------------------- /tests/utils.py: -------------------------------------------------------------------------------- 1 | import os, sys, cv2 2 | from base64 import b64encode 3 | 4 | import requests 5 | 6 | 7 | def setup_test_env(): 8 | ext_root = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) 9 | if ext_root not in sys.path: 10 | sys.path.append(ext_root) 11 | 12 | 13 | def readImage(path): 14 | img = cv2.imread(path) 15 | retval, buffer = cv2.imencode('.jpg', img) 16 | b64img = b64encode(buffer).decode("utf-8") 17 | return b64img 18 | 19 | 20 | def get_model(): 21 | r = requests.get("http://localhost:7860/controlnet/model_list") 22 | result = r.json() 23 | if "model_list" in result: 24 | result = result["model_list"] 25 | for item in result: 26 | print("Using model: ", item) 27 | return item 28 | return "None" 29 | -------------------------------------------------------------------------------- /tests/web_api/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crucible-ai/sd-webui-controlnet/385b67c2e310b7ee71aed3d61ec04a83c1efba0f/tests/web_api/__init__.py --------------------------------------------------------------------------------