【问题标题】:How should i define loss and performance metric for this CNN?我应该如何定义这个 CNN 的损失和性能指标?
【发布时间】:2020-08-29 11:59:43
【问题描述】:

我已经为 GTSRB 数据集问题实现了一个带有两个输出层的 CNN。一个输出层将图像分类到它们各自的类别中,第二层预测边界框坐标。在数据集中,为训练图像提供了左上和右下坐标。我们必须对测试图像进​​行相同的预测。我如何定义回归层的损失度量(MSE 或任何其他)和性能度量(R-Squared 或任何其他),因为它输出 4 个值(左上角和右下角的 x 和 y 坐标)?下面是模型代码。

def get_model() :
   #Input layer
   input_layer = Input(shape=(IMG_HEIGHT, IMG_WIDTH, N_CHANNELS, ), name="input_layer", dtype='float32')
   #Convolution, maxpool and dropout layers
   conv_1 = Conv2D(filters=8, kernel_size=(3,3), activation=relu, 
            kernel_initializer=he_normal(seed=54), bias_initializer=zeros(), 
            name="first_convolutional_layer") (input_layer)
   maxpool_1 = MaxPool2D(pool_size=(2,2), name = "first_maxpool_layer")(conv_1)

   #Fully connected layers
   flat = Flatten(name="flatten_layer")(maxpool_1)
   d1 = Dense(units=64, activation=relu, kernel_initializer=he_normal(seed=45),
         bias_initializer=zeros(), name="first_dense_layer", kernel_regularizer = l2(0.001))(flat)
   d2 = Dense(units=32, activation=relu, kernel_initializer=he_normal(seed=47),
         bias_initializer=zeros(), name="second_dense_layer", kernel_regularizer = l2(0.001))(d1)

   classification = Dense(units = 43, activation=None, name="classification")(d2)
   regression = Dense(units = 4, activation = 'linear', name = "regression")(d2)
   #Model
   model = Model(inputs = input_layer, outputs = [classification, regression])
   model.summary()
   return model

【问题讨论】:

    标签: python tensorflow deep-learning loss-function conv-neural-network


    【解决方案1】:

    分类输出需要用到softmax。

    classification = Dense(units = 43, activation='softmax', name="classification")(d2)

    您应该使用categorical_crossentropy loss 作为分类输出。

    对于回归,可以使用mseloss。

    【讨论】:

    • 喜欢这个? model.compile(optimizer="adam", loss = {"classification" : loss, "regression" : "mse"}, metrics={"classification" : "acc"}) ?以及如何将回归的 R 平方值作为指标?
    • 这真的很有帮助。谢谢。
    • 当然,兄弟。顺便说一句,您还可以提供在 keras 中计算加权 f1 分数和微 f1 分数的链接吗?谢谢你。 :)
    • 从模型中得到预测后,您可以使用scikit-learn.org/stable/modules/generated/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-01-06
    • 2016-09-05
    • 2013-10-15
    • 2023-01-25
    • 1970-01-01
    • 2018-09-16
    • 1970-01-01
    相关资源
    最近更新 更多