you are a super advanced machine learning software engineer that able to deeply understand and debug complex projects and help me enhance creatively and fix issues using most advaced methods, libraries and techniques to have a great performance and accuracy in my project which is using TIFF SAR images to detect vessels and if fishing or not, you do this smartly without removing, ruining or affecting any function , method or file structure!
in this project it used CenterNetUNet model and we upgraded it to integrate NAS, YOLO, FBN, FAN, Optuna and SwinTransformer

so now here's my NAS file and run_nas please understand them deeply and my error and just respond with 'DONE' when you understand everything so we can processed with showing you the train file and config in the next question 

##nas.py

# nas.py

import torch
import torch.nn as nn
import torch.nn.functional as F
import copy
import optuna
from torch.optim import Adam, SGD
from torch.utils.data import DataLoader
from typing import Any, Callable, Dict, Tuple, Optional
import random
from xview3.utils import TorchDevice
from xview3.centernet.bboxer.multilabel_circle_coder import MultilabelCircleNetCoder
import numpy as np
import pandas as pd
import torchmetrics
from xview3.centernet.models.dropath import DropPath
from xview3.centernet.models.custom_encoder import CustomTimmEncoder
from xview3.centernet.models.necks import FeatureAggregationNetwork
from xview3.centernet.models.heads import DecoupledHeadGroupNormLateShuffle, YOLOHead
from xview3.common import FeaturePyramidNetwork
from xview3.centernet.models.unet_blocks import SqueezeExcitation
from xview3.centernet.constants import *
from omegaconf import OmegaConf
device = TorchDevice.choose_torch_device()


class FocalLoss(nn.Module):
    """
    Focal Loss for addressing class imbalance by down-weighting easy examples.
    """
    def __init__(self, alpha=2.0, beta=4.0, eps=1e-6):
        super(FocalLoss, self).__init__()
        self.alpha = alpha
        self.beta = beta
        self.eps = eps

    def forward(self, pred, gt):
        pos_inds = gt.eq(1).float()
        neg_inds = gt.lt(1).float()
        neg_weights = torch.pow(1 - gt, self.beta)

        # Ensure pred and gt have the same spatial dimensions
        if pred.size() != gt.size():
            raise ValueError(f"pred and gt must have the same size, but got pred: {pred.size()} and gt: {gt.size()}")

        pred = torch.clamp(pred, self.eps, 1 - self.eps)
        pos_loss = -torch.log(pred) * torch.pow(1 - pred, self.alpha) * pos_inds
        neg_loss = -torch.log(1 - pred) * torch.pow(pred, self.alpha) * neg_weights * neg_inds

        num_pos = pos_inds.float().sum()
        loss = (pos_loss + neg_loss).sum() / num_pos.clamp(min=1)
        return loss


class OptunaNAS:
    """
    Optuna-based Neural Architecture Search (NAS) for optimizing hyperparameters of the CenterNet-UNet model.
    """
    def __init__(self, search_space: Dict[str, Any], evaluation_function: Callable, max_epochs: int = 10, use_metrics: bool = True, direction='minimize'):
        """
        Initializes the OptunaNAS.

        Args:
            search_space (Dict[str, Any]): Dictionary defining the search space.
            evaluation_function (Callable): Function to evaluate the model, should return a float metric.
            max_epochs (int): Maximum number of epochs for training each trial.
            use_metrics (bool): Whether to compute additional metrics.
        """
        self.search_space = search_space
        self.evaluation_function = evaluation_function
        self.direction = direction
        self.max_epochs = max_epochs
        self.use_metrics = use_metrics
        self.base_model = None

        # Initialize box coder
        self.box_coder = MultilabelCircleNetCoder(
            image_size=(1024, 1024),
            output_stride=2,
            max_objects=512,
            heatmap_encoding="umich",
            labels_encoding="circle",
            ignore_value=-1
        )

    def create_model(self, config: Dict[str, Any], trial: optuna.Trial) -> nn.Module:
        """
        Creates and returns a CenterNet-UNet model based on the given hyperparameters.

        Args:
            config (Dict[str, Any]): Configuration dictionary.
            trial (optuna.Trial): Optuna trial object.

        Returns:
            nn.Module: The instantiated CenterNet-UNet model.
        """
        from xview3.centernet.models.centernet_unet import CenterNetUNetModel 
        # Suggest hyperparameters from the search space
        hyperparams = self.suggest_hyperparameters(trial)

        # Update the configuration with suggested hyperparameters
        updated_config = copy.deepcopy(config)
        for key, value in hyperparams.items():
            OmegaConf.update(updated_config, f"centernet_unet.{key}", value)

        # Instantiate the model from the updated configuration
        model = CenterNetUNetModel.from_config(updated_config.centernet_unet)
        model.to(device)

        return model

    def suggest_hyperparameters(self, trial: optuna.Trial) -> Dict[str, Any]:
        """
        Suggests hyperparameters using Optuna trial.

        Args:
            trial (optuna.Trial): Optuna trial object.

        Returns:
            Dict[str, Any]: Suggested hyperparameters.
        """
        hyperparams = {}
        # Example hyperparameters, adjust based on your search space
        hyperparams['num_layers'] = trial.suggest_int('num_layers', self.search_space['num_layers'][0], self.search_space['num_layers'][1])
        hyperparams['num_filters'] = trial.suggest_categorical('num_filters', self.search_space['num_filters'])
        hyperparams['kernel_size'] = trial.suggest_categorical('kernel_size', self.search_space['kernel_size'])
        hyperparams['activation'] = trial.suggest_categorical('activation', self.search_space['activation'])
        hyperparams['dropout_rate'] = trial.suggest_float('dropout_rate', 0.0, self.search_space['dropout_rate_max'])
        hyperparams['learning_rate'] = trial.suggest_loguniform('learning_rate', 1e-5, 1e-2)
        hyperparams['optimizer'] = trial.suggest_categorical('optimizer', ['Adam', 'SGD'])

        return hyperparams
    
    def optimize(self, n_trials: int = 50) -> optuna.Trial:
        study = optuna.create_study(direction=self.direction)
        study.optimize(self._objective, n_trials=n_trials)
        return study.best_trial

    def objective(self, trial: optuna.Trial, config: Dict[str, Any], train_loader: DataLoader, val_loader: DataLoader) -> float:
        """
        Objective function for each Optuna trial.

        Args:
            trial (optuna.Trial): Optuna trial object.
            config (Dict[str, Any]): Configuration dictionary.
            train_loader (DataLoader): Training data loader.
            val_loader (DataLoader): Validation data loader.

        Returns:
            float: Validation metric to be optimized.
        """
        # Create model with suggested hyperparameters
        trial_config = {}
        for param, space in self.search_space.items():
            if isinstance(space, list):
                trial_config[param] = trial.suggest_categorical(param, space)
            elif isinstance(space, tuple) and len(space) == 3:
                low, high, step = space
                if isinstance(step, int):
                    trial_config[param] = trial.suggest_int(param, low, high, step=step)
                else:
                    trial_config[param] = trial.suggest_float(param, low, high, step=step)
            else:
                raise ValueError(f"Unsupported search space for parameter {param}")

        model = self.create_model(config, trial)

        # Define optimizer
        learning_rate = config.centernet_unet.learning_rate
        optimizer_choice = config.centernet_unet.optimizer

        if optimizer_choice == 'Adam':
            optimizer = Adam(model.parameters(), lr=learning_rate)
        elif optimizer_choice == 'SGD':
            optimizer = SGD(model.parameters(), lr=learning_rate, momentum=0.9, weight_decay=1e-4)
        else:
            raise ValueError(f"Unsupported optimizer type: {optimizer_choice}")

        # Define loss function
        criterion = FocalLoss(alpha=2.0, beta=4.0, eps=1e-6)

        # Initialize mixed precision scaler

        # Initialize mixed precision scaler
        scaler = torch.cuda.amp.GradScaler()

        # Define scheduler (optional)
        scheduler = torch.optim.lr_scheduler.CosineAnnealingLR(optimizer, T_max=self.max_epochs)

        # Initialize metrics
        accuracy_metric = torchmetrics.Accuracy().to(device)
        f1_score = torchmetrics.F1(num_classes=2, average='macro').to(device)

        # Training loop
        for epoch in range(self.max_epochs):
            model.train()
            epoch_loss = 0.0
            for batch in train_loader:
                inputs, targets = self.get_batch(batch)
                inputs = inputs.to(device)
                targets = self.prepare_targets(targets).to(device)

                optimizer.zero_grad()

                with torch.cuda.amp.autocast():
                    outputs = model(inputs)
                    loss = self.calculate_loss(outputs, targets)

                scaler.scale(loss).backward()
                scaler.step(optimizer)
                scaler.update()

                epoch_loss += loss.item()

            avg_epoch_loss = epoch_loss / len(train_loader)
            scheduler.step()

            # Validation
            val_acc, val_f1 = self.evaluate(model, val_loader, accuracy_metric, f1_score)
            print(f"Trial {trial.number} Epoch {epoch+1}/{self.max_epochs} - Loss: {avg_epoch_loss:.4f} Val Acc: {val_acc:.4f} Val F1: {val_f1:.4f}")

            # Report intermediate objective value
            trial.report(val_acc, epoch)

            # Handle pruning based on the intermediate value
            if trial.should_prune():
                raise optuna.exceptions.TrialPruned()

        # Final validation after training
        final_val_acc, final_val_f1 = self.evaluate(model, val_loader, accuracy_metric, f1_score)
        print(f"Trial {trial.number} - Final Validation Accuracy: {final_val_acc:.4f}, F1 Score: {final_val_f1:.4f}")

        return final_val_acc  # Or another metric you wish to optimize

    def calculate_loss(self, outputs: Dict[str, torch.Tensor], targets: Dict[str, torch.Tensor]) -> torch.Tensor:
        """
        Calculates the composite loss for multi-task learning.

        Args:
            outputs (Dict[str, torch.Tensor]): Model outputs.
            targets (Dict[str, torch.Tensor]): Ground truth targets.

        Returns:
            torch.Tensor: Total loss.
        """
        total_loss = 0.0

        # Example loss components, adjust based on your outputs and targets
        # Heatmap loss (Focal Loss)
        if CENTERNET_OUTPUT_OBJECTNESS_MAP in outputs and 'CENTERNET_TARGET_OBJECTNESS_MAP' in targets:
            heatmap_loss = FocalLoss(alpha=2.0, beta=4.0, eps=1e-6)(outputs[CENTERNET_OUTPUT_OBJECTNESS_MAP], targets['CENTERNET_TARGET_OBJECTNESS_MAP'])
            total_loss += heatmap_loss

        # Vessel loss (Binary Cross-Entropy)
        if CENTERNET_OUTPUT_VESSEL_MAP in outputs and 'CENTERNET_TARGET_VESSEL_MAP' in targets:
            vessel_loss = F.binary_cross_entropy_with_logits(outputs[CENTERNET_OUTPUT_VESSEL_MAP], targets['CENTERNET_TARGET_VESSEL_MAP'])
            total_loss += vessel_loss

        # Fishing loss (Binary Cross-Entropy)
        if CENTERNET_OUTPUT_FISHING_MAP in outputs and 'CENTERNET_TARGET_FISHING_MAP' in targets:
            fishing_loss = F.binary_cross_entropy_with_logits(outputs[CENTERNET_OUTPUT_FISHING_MAP], targets['CENTERNET_TARGET_FISHING_MAP'])
            total_loss += fishing_loss

        # Size loss (L1 Loss)
        if CENTERNET_OUTPUT_SIZE in outputs and 'CENTERNET_TARGET_SIZE' in targets:
            size_loss = F.l1_loss(outputs[CENTERNET_OUTPUT_SIZE], targets['CENTERNET_TARGET_SIZE'])
            total_loss += size_loss

        # Offset loss (L1 Loss)
        if CENTERNET_OUTPUT_OFFSET in outputs and 'CENTERNET_TARGET_OFFSET' in targets:
            offset_loss = F.l1_loss(outputs[CENTERNET_OUTPUT_OFFSET], targets['CENTERNET_TARGET_OFFSET'])
            total_loss += offset_loss

        # YOLO loss (Assuming you have YOLO outputs and targets)
        if CENTERNET_OUTPUT_YOLO in outputs and CENTERNET_TARGET_YOLO in targets:
            yolo_loss = self.box_coder.yolo_loss(outputs[CENTERNET_OUTPUT_YOLO], targets[CENTERNET_TARGET_YOLO])
            total_loss += yolo_loss

        return total_loss

    def evaluate(self, model: nn.Module, val_loader: DataLoader, accuracy_metric: torchmetrics.Metric, f1_metric: torchmetrics.Metric) -> Tuple[float, float]:
        """
        Evaluates the model on the validation set and computes the desired metrics.

        Args:
            model (nn.Module): The model to evaluate.
            val_loader (DataLoader): Validation data loader.
            accuracy_metric (torchmetrics.Metric): Accuracy metric instance.
            f1_metric (torchmetrics.Metric): F1 score metric instance.

        Returns:
            Tuple[float, float]: Validation accuracy and F1 score.
        """
        model.eval()
        accuracy_metric.reset()
        f1_metric.reset()
        with torch.no_grad():
            for batch in val_loader:
                inputs, targets = self.get_batch(batch)
                inputs = inputs.to(device)
                targets = self.prepare_targets(targets).to(device)

                outputs = model(inputs)

                # Compute metrics for vessel classification
                if CENTERNET_OUTPUT_VESSEL_MAP in outputs and 'CENTERNET_TARGET_VESSEL_MAP' in targets:
                    preds = torch.sigmoid(outputs[CENTERNET_OUTPUT_VESSEL_MAP]) > 0.5
                    targets_binary = targets['CENTERNET_TARGET_VESSEL_MAP'] > 0.5
                    accuracy_metric.update(preds, targets_binary)
                    f1_metric.update(preds, targets_binary)

        val_acc = accuracy_metric.compute().item()
        val_f1 = f1_metric.compute().item()
        return val_acc, val_f1

    def get_batch(self, batch: Tuple[Any, Any]) -> Tuple[torch.Tensor, Dict[str, torch.Tensor]]:
        """
        Processes a batch from the DataLoader.

        Args:
            batch (Tuple[Any, Any]): A batch from the DataLoader.

        Returns:
            Tuple[torch.Tensor, Dict[str, torch.Tensor]]: Processed inputs and prepared targets.
        """
        inputs, targets = batch
        return inputs, targets
    
    def optimize(self, n_trials=50):
        study = optuna.create_study(direction=self.direction)
        study.optimize(self.evaluation_function, n_trials=n_trials)
        return study.best_trial

    def prepare_targets(self, targets: Dict[str, Any]) -> Dict[str, torch.Tensor]:
        """
        Prepares targets for the loss function.

        Args:
            targets (Dict[str, Any]): Raw targets from the DataLoader.

        Returns:
            Dict[str, torch.Tensor]: Prepared targets as tensors.
        """
        prepared = {}
        for key, value in targets.items():
            prepared[key] = value.to(dtype=torch.float32)
        return prepared

    def run(self, n_trials: int, config: Dict[str, Any], train_loader: DataLoader, val_loader: DataLoader) -> optuna.Study:
        """
        Runs the Optuna optimization process.

        Args:
            n_trials (int): Number of Optuna trials.
            config (Dict[str, Any]): Configuration dictionary.
            train_loader (DataLoader): Training data loader.
            val_loader (DataLoader): Validation data loader.

        Returns:
            optuna.Study: The Optuna study object containing optimization results.
        """
        # Define the Optuna study with advanced sampler and pruner
        sampler = optuna.samplers.TPESampler(n_startup_trials=10, n_ei_candidates=24)
        pruner = optuna.pruners.MedianPruner(n_startup_trials=5, n_warmup_steps=5)
        study = optuna.create_study(direction='maximize', sampler=sampler, pruner=pruner)
        study.optimize(lambda trial: self.objective(trial, config, train_loader, val_loader), n_trials=n_trials)
        return study

##run_nas.py file
# run_nas.py

import argparse
import yaml
import logging
import sys
from pathlib import Path
from typing import Any, Dict, Tuple, Optional

from torch.utils.data import DataLoader
from xview3.dataset import XView3DataModule  # Replace with actual import if different
from nas import OptunaNAS
import joblib
import optuna
from omegaconf import OmegaConf


def setup_logging(log_level: str = 'INFO', log_file: Optional[str] = None):
    """
    Configures the logging module.

    Args:
        log_level (str): Logging level.
        log_file (Optional[str]): File path for logging output. If None, logs to stdout.
    """
    logger = logging.getLogger()
    logger.setLevel(getattr(logging, log_level.upper(), 'INFO'))

    formatter = logging.Formatter('[%(asctime)s] %(levelname)s: %(message)s')

    if log_file:
        fh = logging.FileHandler(log_file)
        fh.setLevel(getattr(logging, log_level.upper(), 'INFO'))
        fh.setFormatter(formatter)
        logger.addHandler(fh)
    else:
        sh = logging.StreamHandler(sys.stdout)
        sh.setLevel(getattr(logging, log_level.upper(), 'INFO'))
        sh.setFormatter(formatter)
        logger.addHandler(sh)


def load_config(config_path: Path) -> Dict[str, Any]:
    """
    Loads YAML configuration from the specified path.

    Args:
        config_path (Path): Path to the YAML config file.

    Returns:
        Dict[str, Any]: Loaded configuration dictionary.
    """
    if not config_path.exists():
        logging.error(f"Configuration file not found at: {config_path}")
        sys.exit(1)

    with open(config_path, 'r') as f:
        try:
            config = yaml.safe_load(f)
            logging.info(f"Configuration loaded from {config_path}")
            return config
        except yaml.YAMLError as e:
            logging.error(f"Error parsing YAML file: {e}")
            sys.exit(1)


def initialize_data_module(config: Dict[str, Any]) -> XView3DataModule:
    """
    Initializes the XView3DataModule based on the configuration.

    Args:
        config (Dict[str, Any]): Configuration dictionary.

    Returns:
        XView3DataModule: Initialized data module.
    """
    try:
        data_module = XView3DataModule.from_config(config['dataset'], config['train'])
        data_module.setup()
        logging.info("Data module initialized and datasets setup completed.")
        return data_module
    except KeyError as e:
        logging.error(f"Missing key in configuration: {e}")
        sys.exit(1)
    except Exception as e:
        logging.error(f"Error initializing data module: {e}")
        sys.exit(1)


def create_data_loaders(data_module: XView3DataModule, batch_size: int, num_workers: int = 4) -> Tuple[DataLoader, DataLoader]:
    """
    Creates DataLoader instances for training and validation datasets.

    Args:
        data_module (XView3DataModule): Initialized data module.
        batch_size (int): Batch size for DataLoaders.
        num_workers (int): Number of subprocesses for data loading.

    Returns:
        Tuple[DataLoader, DataLoader]: Training and validation DataLoaders.
    """
    try:
        train_loader = DataLoader(
            data_module.train_dataset,
            batch_size=batch_size,
            shuffle=True,
            num_workers=num_workers,
            pin_memory=True
        )
        val_loader = DataLoader(
            data_module.val_dataset,
            batch_size=batch_size,
            shuffle=False,
            num_workers=num_workers,
            pin_memory=True
        )
        logging.info("DataLoaders for training and validation created successfully.")
        return train_loader, val_loader
    except Exception as e:
        logging.error(f"Error creating DataLoaders: {e}")
        sys.exit(1)


def main(args):
    """
    Main function to run NAS.

    Args:
        args: Parsed command-line arguments.
    """
    setup_logging(log_level=args.log_level, log_file=args.log_file)

    config_path = Path(args.config)
    config = load_config(config_path)

    data_module = initialize_data_module(config)
    train_loader, val_loader = create_data_loaders(data_module, batch_size=config.get('batch_size', 16), num_workers=args.num_workers)

    # Define search space based on configuration
    search_space = config.get('nas', {}).get('search_space', {})
    if not search_space:
        logging.error("Search space not defined in configuration under 'nas.search_space'.")
        sys.exit(1)

    # Instantiate OptunaNAS
    try:
        nas = OptunaNAS(
            search_space=search_space,
            evaluation_function=None,  # Will be set after model instantiation
            max_epochs=config.get('nas', {}).get('max_epochs', 10),
            use_metrics=config.get('nas', {}).get('use_metrics', True)
        )
        logging.info("OptunaNAS instance created.")
    except Exception as e:
        logging.error(f"Error initializing OptunaNAS: {e}")
        sys.exit(1)

    # Define number of trials
    n_trials = config.get('nas', {}).get('num_trials', 50)


    # Define the evaluation function
    def evaluation_fn(trial_model: nn.Module, train_loader: DataLoader, val_loader: DataLoader) -> float:
        """
        Evaluation function to pass to OptunaNAS.

        Args:
            trial_model (nn.Module): The model to evaluate.
            train_loader (DataLoader): Training data loader.
            val_loader (DataLoader): Validation data loader.

        Returns:
            float: Validation metric to be optimized.
        """
        return nas.evaluate_architecture(trial_model, train_loader, val_loader)

    # Assign the evaluation function
    nas.evaluation_function = evaluation_fn

    # Run the NAS
    try:
        study = nas.run(n_trials=n_trials, config=config, train_loader=train_loader, val_loader=val_loader)
        logging.info("Neural Architecture Search completed.")
    except Exception as e:
        logging.error(f"Error during NAS execution: {e}")
        sys.exit(1)

    # Save the study
    try:
        joblib.dump(study, args.study_output)
        logging.info(f"Optuna study saved to {args.study_output}")
    except Exception as e:
        logging.error(f"Error saving Optuna study: {e}")
        sys.exit(1)

    # Log the best trial
    try:
        best_trial = study.best_trial
        logging.info(f"Best trial value (Val Accuracy): {best_trial.value}")
        logging.info("Best trial parameters:")
        for key, value in best_trial.params.items():
            logging.info(f"  {key}: {value}")
    except Exception as e:
        logging.error(f"Error retrieving best trial: {e}")
        sys.exit(1)


if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="Run Neural Architecture Search for CenterNet-UNet Model.")
    parser.add_argument(
        '--config',
        type=str,
        default='multilabel_circle_net.yaml',
        help='Path to the YAML configuration file.'
    )
    parser.add_argument(
        '--log_level',
        type=str,
        default='INFO',
        choices=['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'],
        help='Logging level.'
    )
    parser.add_argument(
        '--log_file',
        type=str,
        default=None,
        help='File path to save logs. If not provided, logs will be printed to stdout.'
    )
    parser.add_argument(
        '--num_workers',
        type=int,
        default=4,
        help='Number of worker processes for data loading.'
    )
    parser.add_argument(
        '--study_output',
        type=str,
        default='optuna_study.pkl',
        help='File path to save the Optuna study object.'
    )

    args = parser.parse_args()
    main(args)

###the error

DEBUG:rasterio._io:IO window xoff=7559.0 yoff=8060.0 width=512.0 height=512.0
DEBUG:rasterio.env:Exiting env context: <rasterio.env.Env object at 0x36c038fa0>
DEBUG:rasterio.env:Cleared existing <rasterio._env.GDALEnv object at 0x36a0f8e20> options
DEBUG:rasterio._env:Stopped GDALEnv <rasterio._env.GDALEnv object at 0x36a0f8e20>.
DEBUG:rasterio.env:Exiting outermost env
DEBUG:rasterio.env:Exited env context: <rasterio.env.Env object at 0x36c038fa0>
[DEBUG] Channel 0 shape: (512, 512)
[DEBUG] Channel 1 shape: (512, 512)
(256.0, 268.0, 0.0) [<class 'float'>, <class 'float'>, <class 'float'>]
[2024-10-05 14:41:36,633][__main__][INFO] - Building model with config:
[2024-10-05 14:41:36,640][__main__][INFO] - _target_: xview3.centernet.models.CenterNetUNetModel.from_config
slug: b5_unet_s2
weights: IMAGENET1K_V1
pretrained: true
output_stride: 32
image_size:
- 1024
- 1024
window_size:
- 4
- 4
transformer:
  enabled: true
  embed_dim: 96
  depths:
  - 2
  - 2
  - 6
  - 2
  num_heads:
  - 3
  - 6
  - 12
  - 24
  window_size:
  - 4
  - 4
  mlp_ratio: 4.0
  qkv_bias: true
  qk_scale: null
  drop_rate: 0.0
  attn_drop_rate: 0.0
  drop_path_rate: 0.1
  norm_layer: null
  use_dropout: false
  use_custom_pos_embed: false
decoder:
  _target_: xview3.centernet.models.custom_encoder.DebugUNetDecoder
  encoder_channels:
  - 32
  - 24
  - 40
  - 112
  - 320
  channels:
  - 512
  - 384
  - 256
  - 128
  - 64
  unet_block:
    _target_: xview3.centernet.models.unet_blocks.UnetBlock
    _partial_: true
  upsample_block:
    _target_: torch.nn.Upsample
    scale_factor: 2
    mode: bilinear
encoder:
  _target_: pytorch_toolbelt.modules.encoders.TimmEfficientNetV2
  model_name: efficientnetv2_rw_s
  pretrained: true
  activation: silu
  drop_rate: 0.1
  drop_path_rate: 0.1
  layers:
  - 1
  - 2
  - 3
  - 4
nas:
  enabled: true
  search_space:
    num_layers:
    - 2
    - 5
    num_filters:
    - 64
    - 128
    - 256
    kernel_size:
    - 3
    - 5
    activation:
    - relu
    - leaky_relu
    - silu
    dropout_rate:
    - 0.0
    - 0.5
  num_trials: 50
  metric: val_loss
  direction: minimize
num_channels: 2
num_classes: 2
anchors:
- - 10
  - 13
- - 16
  - 30
- - 33
  - 23
input_upsample_factor: 1
neck_out_channels: 256
box_coder:
  _target_: xview3.centernet.bboxer.multilabel_circle_coder.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: ${dataset.ignore_low_confidence_detections}
head:
  decoupled_head:
    _target_: xview3.centernet.models.heads.DecoupledHeadGroupNormLateShuffle
    channels: 256
    classifier_dim: 128
    objectness_dim: 128
    size_dim: 128
    offset_dim: 16
    dropout_rate: 0.1
    activation: silu
    num_blocks: 3
  yolo_head:
    _target_: xview3.centernet.models.heads.yolo_head.YOLOHead
    num_classes: 2
    anchors:
    - - 10
      - 13
    - - 16
      - 30
    - - 33
      - 23
    - - 30
      - 61
    - - 62
      - 45
    - - 59
      - 119
    input_image_size:
    - 1024
    - 1024
    stride: 32
    num_anchors_per_scale: 3
fan:
  enabled: true
  in_channels:
  - 32
  - 64
  - 128
  - 256
  out_channels: 256
  num_layers: 2
config:
  slug: b5_unet_s2
  activation: silu
  num_channels: ${dataset.num_channels}
  num_extra_blocks: 0
  encoder:
    _target_: pytorch_toolbelt.modules.encoders.TimmB5Encoder
    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_groups: 4
    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: ${dataset.ignore_low_confidence_detections}

[I 2024-10-05 14:41:36,640] A new study created in memory with name: no-name-b2468d66-f6c4-4178-98e2-88e7b187fd5f
[W 2024-10-05 14:41:36,641] Trial 0 failed with parameters: {} because of the following error: TypeError("evaluate_architecture() missing 3 required positional arguments: 'model', 'train_loader', and 'val_loader'").
Traceback (most recent call last):
  File "/opt/anaconda3/envs/sam3/lib/python3.9/site-packages/optuna/study/_optimize.py", line 197, in _run_trial
    value_or_values = func(trial)
TypeError: evaluate_architecture() missing 3 required positional arguments: 'model', 'train_loader', and 'val_loader'
[W 2024-10-05 14:41:36,641] Trial 0 failed with value None.
Error executing job with overrides: []
Traceback (most recent call last):
  File "/Volumes/Crucial/SAR-MPS-OptunaNasFbnYoloTransformers/train_multilabel3.py", line 821, in <module>
    main()
  File "/opt/anaconda3/envs/sam3/lib/python3.9/site-packages/hydra/main.py", line 94, in decorated_main
    _run_hydra(
  File "/opt/anaconda3/envs/sam3/lib/python3.9/site-packages/hydra/_internal/utils.py", line 394, in _run_hydra
    _run_app(
  File "/opt/anaconda3/envs/sam3/lib/python3.9/site-packages/hydra/_internal/utils.py", line 457, in _run_app
    run_and_report(
  File "/opt/anaconda3/envs/sam3/lib/python3.9/site-packages/hydra/_internal/utils.py", line 223, in run_and_report
    raise ex
  File "/opt/anaconda3/envs/sam3/lib/python3.9/site-packages/hydra/_internal/utils.py", line 220, in run_and_report
    return func()
  File "/opt/anaconda3/envs/sam3/lib/python3.9/site-packages/hydra/_internal/utils.py", line 458, in <lambda>
    lambda: hydra.run(
  File "/opt/anaconda3/envs/sam3/lib/python3.9/site-packages/hydra/_internal/hydra.py", line 132, in run
    _ = ret.return_value
  File "/opt/anaconda3/envs/sam3/lib/python3.9/site-packages/hydra/core/utils.py", line 260, in return_value
    raise self._return_value
  File "/opt/anaconda3/envs/sam3/lib/python3.9/site-packages/hydra/core/utils.py", line 186, in run_job
    ret.return_value = task_function(task_cfg)
  File "/Volumes/Crucial/SAR-MPS-OptunaNasFbnYoloTransformers/train_multilabel3.py", line 817, in main
    pipeline.train()
  File "/Volumes/Crucial/SAR-MPS-OptunaNasFbnYoloTransformers/train_multilabel3.py", line 535, in train
    self.model = self.build_model(config, train_loader)
  File "/Volumes/Crucial/SAR-MPS-OptunaNasFbnYoloTransformers/train_multilabel3.py", line 339, in build_model
    best_trial = self.nas.optimize(n_trials=config.model.nas.num_trials)
  File "/Volumes/Crucial/SAR-MPS-OptunaNasFbnYoloTransformers/xview3/nas.py", line 332, in optimize
    study.optimize(self.evaluation_function, n_trials=n_trials)
  File "/opt/anaconda3/envs/sam3/lib/python3.9/site-packages/optuna/study/study.py", line 475, in optimize
    _optimize(
  File "/opt/anaconda3/envs/sam3/lib/python3.9/site-packages/optuna/study/_optimize.py", line 63, in _optimize
    _optimize_sequential(
  File "/opt/anaconda3/envs/sam3/lib/python3.9/site-packages/optuna/study/_optimize.py", line 160, in _optimize_sequential
    frozen_trial = _run_trial(study, func, catch)
  File "/opt/anaconda3/envs/sam3/lib/python3.9/site-packages/optuna/study/_optimize.py", line 248, in _run_trial
    raise func_err
  File "/opt/anaconda3/envs/sam3/lib/python3.9/site-packages/optuna/study/_optimize.py", line 197, in _run_trial
    value_or_values = func(trial)
TypeError: evaluate_architecture() missing 3 required positional arguments: 'model', 'train_loader', and 'val_loader'
(sam3) samerkharboush@Samers-MBP SAR-MPS-OptunaNasFbnYoloTransformers %