# 1128_b5_b4_vs2_fliplr3.yaml

ensemble:
  tta: fliplr
  activation_after: after_model
  softmax_outputs:
  sigmoid_outputs:
    - CENTERNET_OUTPUT_OBJECTNESS_MAP
    - CENTERNET_OUTPUT_VESSEL_MAP
    - CENTERNET_OUTPUT_FISHING_MAP
  with_offset: True
  models:
    - https://github.com/BloodAxe/xView3-The-First-Place-Solution/releases/download/1.0/211117_00_11_b4_unet_s2_leaky_valid_4fold_rfl_soft_bce_mse_regularized_flips_light_medium_fold1.pth
    - https://github.com/BloodAxe/xView3-The-First-Place-Solution/releases/download/1.0/211117_10_52_b4_unet_s2_leaky_valid_4fold_rfl_soft_bce_mse_regularized_flips_light_medium_fold0.pth
    - https://github.com/BloodAxe/xView3-The-First-Place-Solution/releases/download/1.0/211117_17_08_b4_unet_s2_leaky_valid_4fold_rfl_soft_bce_mse_regularized_flips_light_medium_fold2.pth
    - https://github.com/BloodAxe/xView3-The-First-Place-Solution/releases/download/1.0/211118_00_30_b4_unet_s2_leaky_valid_4fold_rfl_soft_bce_mse_regularized_flips_light_medium_fold3.pth

    - https://github.com/BloodAxe/xView3-The-First-Place-Solution/releases/download/1.0/211119_08_05_v2s_unet_s2_leaky_valid_4fold_rfl_soft_bce_mse_regularized_flips_light_medium_fold0.pth
    - https://github.com/BloodAxe/xView3-The-First-Place-Solution/releases/download/1.0/211119_11_35_v2s_unet_s2_leaky_valid_4fold_rfl_soft_bce_mse_regularized_flips_light_medium_fold1.pth
    - https://github.com/BloodAxe/xView3-The-First-Place-Solution/releases/download/1.0/211119_21_11_v2s_unet_s2_leaky_valid_4fold_rfl_soft_bce_mse_regularized_flips_light_medium_fold2.pth
    - https://github.com/BloodAxe/xView3-The-First-Place-Solution/releases/download/1.0/211120_01_38_v2s_unet_s2_leaky_valid_4fold_rfl_soft_bce_mse_regularized_flips_light_medium_fold3.pth

    - https://github.com/BloodAxe/xView3-The-First-Place-Solution/releases/download/1.0/211125_23_57_b5_unet_s2_full_4fold_circlenet_loss_flips_light_medium_fold0.pth
    - https://github.com/BloodAxe/xView3-The-First-Place-Solution/releases/download/1.0/211126_16_53_b5_unet_s2_full_4fold_circlenet_loss_flips_light_medium_fold1.pth
    - https://github.com/BloodAxe/xView3-The-First-Place-Solution/releases/download/1.0/211127_02_14_b5_unet_s2_full_4fold_circlenet_loss_flips_light_medium_fold2.pth
    - https://github.com/BloodAxe/xView3-The-First-Place-Solution/releases/download/1.0/211127_09_29_b5_unet_s2_full_4fold_circlenet_loss_flips_light_medium_fold3.pth
  model:
    type: CenterNetUNet
    encoder:
      _target_: pytorch_toolbelt.modules.encoders.TimmB4Encoder
      pretrained: true
      activation: silu
      layers:
      - 1
      - 2
      - 3
      - 4

    decoder:
      upsample_type: shuffle
      block_type: IRBlock
      channels:
      - 256
      - 384
      - 512

    heads:
      - _target_: xview3.centernet.models.heads.DecoupledHeadGroupNormLateShuffle
        classifier_dim: 128
        objectness_dim: 128
        size_dim: 64
        offset_dim: 16
        dropout_rate: 0.1
        activation: silu
        num_blocks: 3
      - _target_: xview3.centernet.models.heads.yolo_head.YOLOHead
        num_classes: 2
        anchors: [[10, 13], [16, 30], [33, 23]]

    box_coder:
      _target_: xview3.centernet.MultilabelCircleNetCoder
      image_size:
        - 1024
        - 1024
      max_objects: 512
      heatmap_encoding: umich
      labels_encoding: circle
      ignore_value:
        _target_: xview3.ignore_value
      fixed_radius: 3
      labels_radius: 1
      ignore_low_confidence_detections: true



    
inference:
    channels_last: False
    use_traced_model: True
    tile_size: 2048
    tile_step: 1536
    accumulate_on_gpu: False
    batch_size: 1
    fp16: True

thresholds:
  - objectness: 0.300
    is_vessel: 0.338
    is_fishing: 0.350

evaluation:
  objectness_thresholds:
    - 0.35
    - 0.36
    - 0.37
    - 0.38
    - 0.39
    - 0.40
    - 0.41
    - 0.42
    - 0.43
    - 0.44
    - 0.45
    - 0.46
    - 0.47
    - 0.48
    - 0.49
    - 0.50
    - 0.51
    - 0.52
    - 0.53
    - 0.54
    - 0.55
    - 0.56
    - 0.57
    - 0.58
    - 0.59
    - 0.60

submission_dir: submissions/1128_b5_b4_vs2_fliplr

anchors:
  - [10, 13, 16, 30, 33, 23]
  - [30, 61, 62, 45, 59, 119]
  - [116, 90, 156, 198, 373, 326]

channels:
  - vv
  - vh
  - diff(vv,vh)
  - mean(vv,vh)
  - bathymetry
  - wind_direction
  - wind_speed
  - mask

normalization:
  vv:
    _target_: xview3.SigmoidNormalization
    midpoint: -20.0
    temperature: 0.18
  vh:
    _target_: xview3.SigmoidNormalization
    midpoint: -20.0
    temperature: 0.18
  diff(vv,vh):
    _target_: xview3.SigmoidNormalization
    midpoint: -5.0
    temperature: 0.18
  mean(vv,vh):
    _target_: xview3.SigmoidNormalization
    midpoint: -20
    temperature: 0.18
  bathymetry:
    _target_: xview3.CubicRootNormalization
  wind_direction: null
  wind_speed: null
  mask: null


python submit_multilabel_ensemble.py configs/inference/1128_b5_b4_vs2_fliplr3.yaml
Available keys in model config: dict_keys(['slug', 'activation', 'num_channels', 'num_extra_blocks', 'encoder', 'decoder', 'head', 'box_coder'])
Complete model configuration:
 slug: b4_unet_s2
activation: silu
num_channels: 2
num_extra_blocks: 0
encoder:
  _target_: pytorch_toolbelt.modules.encoders.TimmB4Encoder
  pretrained: true
  activation: silu
  layers:
  - 1
  - 2
  - 3
  - 4
decoder:
  upsample_type: shuffle
  block_type: IRBlock
  channels:
  - 256
  - 384
  - 512
head:
  _target_: xview3.centernet.models.heads.DecoupledHeadGroupNormLateShuffle
  classifier_dim: 128
  objectness_dim: 128
  size_dim: 64
  offset_dim: 16
  dropout_rate: 0.1
  activation: silu
  num_blocks: 3
box_coder:
  _target_: xview3.centernet.MultilabelCircleNetCoder
  image_size:
  - 1024
  - 1024
  max_objects: 512
  heatmap_encoding: umich
  labels_encoding: circle
  ignore_value:
    _target_: xview3.ignore_value
  fixed_radius: 3
  labels_radius: 1
  ignore_low_confidence_detections: true

Traceback (most recent call last):
  File "/opt/anaconda3/envs/sam3/lib/python3.9/site-packages/hydra/_internal/instantiate/_instantiate2.py", line 92, in _call_target
    return _target_(*args, **kwargs)
  File "/Users/samerkharboush/Downloads/SAR-MPS-OptunaNasFbnYoloTransformers/xview3/centernet/models/centernet_unet.py", line 295, in from_config
    head_type = head_cfg.type
  File "/opt/anaconda3/envs/sam3/lib/python3.9/site-packages/omegaconf/dictconfig.py", line 355, in __getattr__
    self._format_and_raise(
  File "/opt/anaconda3/envs/sam3/lib/python3.9/site-packages/omegaconf/base.py", line 231, in _format_and_raise
    format_and_raise(
  File "/opt/anaconda3/envs/sam3/lib/python3.9/site-packages/omegaconf/_utils.py", line 899, in format_and_raise
    _raise(ex, cause)
  File "/opt/anaconda3/envs/sam3/lib/python3.9/site-packages/omegaconf/_utils.py", line 797, in _raise
    raise ex.with_traceback(sys.exc_info()[2])  # set env var OC_CAUSE=1 for full trace
  File "/opt/anaconda3/envs/sam3/lib/python3.9/site-packages/omegaconf/dictconfig.py", line 351, in __getattr__
    return self._get_impl(
  File "/opt/anaconda3/envs/sam3/lib/python3.9/site-packages/omegaconf/dictconfig.py", line 442, in _get_impl
    node = self._get_child(
  File "/opt/anaconda3/envs/sam3/lib/python3.9/site-packages/omegaconf/basecontainer.py", line 73, in _get_child
    child = self._get_node(
  File "/opt/anaconda3/envs/sam3/lib/python3.9/site-packages/omegaconf/dictconfig.py", line 480, in _get_node
    raise ConfigKeyError(f"Missing key {key!s}")
omegaconf.errors.ConfigAttributeError: Missing key type
    full_key: config.head.type
    object_type=dict

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/samerkharboush/Downloads/SAR-MPS-OptunaNasFbnYoloTransformers/submit_multilabel_ensemble.py", line 193, in <module>
    Fire(main)
  File "/opt/anaconda3/envs/sam3/lib/python3.9/site-packages/fire/core.py", line 143, in Fire
    component_trace = _Fire(component, args, parsed_flag_args, context, name)
  File "/opt/anaconda3/envs/sam3/lib/python3.9/site-packages/fire/core.py", line 477, in _Fire
    component, remaining_args = _CallAndUpdateTrace(
  File "/opt/anaconda3/envs/sam3/lib/python3.9/site-packages/fire/core.py", line 693, in _CallAndUpdateTrace
    component = fn(*varargs, **kwargs)
  File "/Users/samerkharboush/Downloads/SAR-MPS-OptunaNasFbnYoloTransformers/submit_multilabel_ensemble.py", line 182, in main
    run_multilabel_predict(OmegaConf.load(config), data_dir=data_dir)
  File "/Users/samerkharboush/Downloads/SAR-MPS-OptunaNasFbnYoloTransformers/submit_multilabel_ensemble.py", line 31, in run_multilabel_predict
    model, checkpoints, box_coder = ensemble_from_config(config, map_location=device)
  File "/Users/samerkharboush/Downloads/SAR-MPS-OptunaNasFbnYoloTransformers/xview3/inference.py", line 241, in ensemble_from_config
    model, checkpoints = ensemble_from_checkpoints(
  File "/Users/samerkharboush/Downloads/SAR-MPS-OptunaNasFbnYoloTransformers/xview3/inference.py", line 198, in ensemble_from_checkpoints
    model, checkpoint = model_from_checkpoint(ck, strict=strict, map_location=map_location)
  File "/Users/samerkharboush/Downloads/SAR-MPS-OptunaNasFbnYoloTransformers/xview3/inference.py", line 134, in model_from_checkpoint
    model = instantiate(model_config, _recursive_=False)
  File "/opt/anaconda3/envs/sam3/lib/python3.9/site-packages/hydra/_internal/instantiate/_instantiate2.py", line 226, in instantiate
    return instantiate_node(
  File "/opt/anaconda3/envs/sam3/lib/python3.9/site-packages/hydra/_internal/instantiate/_instantiate2.py", line 347, in instantiate_node
    return _call_target(_target_, partial, args, kwargs, full_key)
  File "/opt/anaconda3/envs/sam3/lib/python3.9/site-packages/hydra/_internal/instantiate/_instantiate2.py", line 97, in _call_target
    raise InstantiationException(msg) from e
hydra.errors.InstantiationException: Error in call to target 'xview3.centernet.models.centernet_unet.CenterNetUNetModel.from_config':
ConfigAttributeError('Missing key type\n    full_key: config.head.type\n    object_type=dict')
(sam3) samerkharboush@Samers-MBP SAR-MPS-OptunaNasFbnYoloTransformers %