为什么 Optuna CSV 文件在我有多个参数时每个参数只显示 1 个项目?

Why does the Optuna CSV file only display 1 item per parameter when I have multiple?

为了使用 Optuna 优化我的网络,我在 Python 中创建了以下代码。

    activations_1 = trial.suggest_categorical('activation', ['relu', 'sigmoid', 'tanh', 'selu']) 
    activations_2 = trial.suggest_categorical('activation', ['relu', 'sigmoid', 'tanh', 'selu']) 
    activations_3 = trial.suggest_categorical('activation', ['relu', 'sigmoid', 'tanh', 'selu']) 
    activations_4 = trial.suggest_categorical('activation', ['relu', 'sigmoid', 'tanh', 'selu'])

model = Sequential([
            layers.Conv2D(filters=dict_params['num_filters_1'],
                          kernel_size=dict_params['kernel_size_1'],
                          activation=dict_params['activations_1'],
                          strides=dict_params['stride_num_1'],
                          input_shape=self.input_shape),
            layers.BatchNormalization(),
            layers.MaxPooling2D(2, 2),

            layers.Conv2D(filters=dict_params['num_filters_2'],
                          kernel_size=dict_params['kernel_size_2'],
                          activation=dict_params['activations_2'],
                          strides=dict_params['stride_num_2']),

如您所见,我进行了多次激活试验而不是一次,因为我想看看当每一层都有不同的激活函数时模型是否产生更好的结果。如您所见,我对其他参数也做了同样的处理。当我 return study.bestparams 对象时,我开始感到困惑:

{"num_filters": 32, "kernel_size": 4, "strides": 1, "activation": "selu", "num_dense_nodes": 64, "batch_size": 64}

试验中的最佳参数只产生了一个参数。它没有告诉我在哪里使用了参数,也没有显示我使用的其他 3 个激活函数(或与此相关的其他参数)。有没有办法精确显示我的模型使用的最佳设置以及在哪些层? (我知道保存最佳模型和模型摘要,但这对我帮助不大)

问题是您对所有激活使用了相同的参数名称。而不是:

    activations_1 = trial.suggest_categorical('activation', ['relu', 'sigmoid', 'tanh', 'selu']) 
    activations_2 = trial.suggest_categorical('activation', ['relu', 'sigmoid', 'tanh', 'selu']) 
    activations_3 = trial.suggest_categorical('activation', ['relu', 'sigmoid', 'tanh', 'selu']) 
    activations_4 = trial.suggest_categorical('activation', ['relu', 'sigmoid', 'tanh', 'selu'])

尝试:

    activations_1 = trial.suggest_categorical('activation1', ['relu', 'sigmoid', 'tanh', 'selu']) 
    activations_2 = trial.suggest_categorical('activation2', ['relu', 'sigmoid', 'tanh', 'selu']) 
    activations_3 = trial.suggest_categorical('activation3', ['relu', 'sigmoid', 'tanh', 'selu']) 
    activations_4 = trial.suggest_categorical('activation4', ['relu', 'sigmoid', 'tanh', 'selu'])