src/pose_net.py
def objective(self, trial):
        """This is an objective function for hyperparameter tuning with Optuna"""

        self.hparam_step += 1
        # Uncomment the following to add hyperparameters:
        # lr = trial.suggest_uniform("lr", 1e-5, 1e-1)
        # self.config.ROT_PROBABILITY = trial.suggest_float("ROT_PROBABILITY", 0, 1, step=0.1)
        # self.config.ROT_MAX_MAGNITUDE = trial.suggest_int("ROT_MAX_MAGNITUDE", 0, 170, step=10)
        # self.config.KERNEL_SIZE = trial.suggest_int("KERNEL_SIZE", 3, 7, step=2)
        # self.config.BRIGHTNESS = trial.suggest_float("BRIGHTNESS", 0, 0.5, step=0.1)
        # self.config.CONTRAST = trial.suggest_float("CONTRAST", 0, 0.5, step=0.1)
        # self.config.SATURATION = trial.suggest_float("SATURATION", 0, 0.5, step=0.1)
        # self.config.HUE = trial.suggest_float("HUE", 0, 0.5, step=0.1)
        # self.config.DROPOUT_RATE = trial.suggest_float("DROPOUT_RATE", 0, 0.5, step=0.1)
        self.config.WEIGHT_DECAY = trial.suggest_float("WEIGHT_DECAY", 0, 1e-2, step=1e-5)

        self.model = self.import_model()
        self.dataloader = self.import_dataset()
        self.ori_criterion, self.pos_criterion = self.set_loss()
        self.optimizer = self.set_optimizer()
        self.scheduler = self.set_scheduler()
        self.scaler = torch.cuda.amp.GradScaler(enabled=self.config.USE_AMP)

        model, loss, score = self.train()

        # Score
        idx = score['valid']['esa'].index(min(score['valid']['esa']))
        # CSV: intermediate_value 0 column
        trial.report(score['real']['esa'][idx], step=0)
        # csv: value column
        score_to_optimize = score['valid']['esa'][idx]
        return score_to_optimize
This is an objective function for hyperparameter tuning with Optuna
This is an objective function for hyperparameter tuning with Optuna
This is an objective function for hyperparameter tuning with Optuna
def objective(self, trial):
        self.hparam_step += 1
        self.config.WEIGHT_DECAY = trial.suggest_float("WEIGHT_DECAY", 0, 1e-2, step=1e-5)
        self.model = self.import_model()
        self.dataloader = self.import_dataset()
        self.ori_criterion, self.pos_criterion = self.set_loss()
        self.optimizer = self.set_optimizer()
        self.scheduler = self.set_scheduler()
        self.scaler = torch.cuda.amp.GradScaler(enabled=self.config.USE_AMP)
        model, loss, score = self.train()
        idx = score['valid']['esa'].index(min(score['valid']['esa']))
        trial.report(score['real']['esa'][idx], step=0)
        score_to_optimize = score['valid']['esa'][idx]
        return score_to_optimize
def objective ( self , trial ) : self . hparam_step += 1 self . config . WEIGHT_DECAY = trial . suggest_float ( "WEIGHT_DECAY" , 0 , 1e-2 , step = 1e-5 ) self . model = self . import_model ( ) self . dataloader = self . import_dataset ( ) self . ori_criterion , self . pos_criterion = self . set_loss ( ) self . optimizer = self . set_optimizer ( ) self . scheduler = self . set_scheduler ( ) self . scaler = torch . cuda . amp . GradScaler ( enabled = self . config . USE_AMP ) model , loss , score = self . train ( ) idx = score [ 'valid' ] [ 'esa' ] . index ( min ( score [ 'valid' ] [ 'esa' ] ) ) trial . report ( score [ 'real' ] [ 'esa' ] [ idx ] , step = 0 ) score_to_optimize = score [ 'valid' ] [ 'esa' ] [ idx ] return score_to_optimize
This is an objective function for hyperparameter tuning with Optuna
This is an objective function for hyperparameter tuning with Optuna
"""This is an objective function for hyperparameter tuning with Optuna""" # Uncomment the following to add hyperparameters: # lr = trial.suggest_uniform("lr", 1e-5, 1e-1) # self.config.ROT_PROBABILITY = trial.suggest_float("ROT_PROBABILITY", 0, 1, step=0.1) # self.config.ROT_MAX_MAGNITUDE = trial.suggest_int("ROT_MAX_MAGNITUDE", 0, 170, step=10) # self.config.KERNEL_SIZE = trial.suggest_int("KERNEL_SIZE", 3, 7, step=2) # self.config.BRIGHTNESS = trial.suggest_float("BRIGHTNESS", 0, 0.5, step=0.1) # self.config.CONTRAST = trial.suggest_float("CONTRAST", 0, 0.5, step=0.1) # self.config.SATURATION = trial.suggest_float("SATURATION", 0, 0.5, step=0.1) # self.config.HUE = trial.suggest_float("HUE", 0, 0.5, step=0.1) # self.config.DROPOUT_RATE = trial.suggest_float("DROPOUT_RATE", 0, 0.5, step=0.1) # Score # CSV: intermediate_value 0 column # csv: value column
self
trial