在使用 Keras 构建模型时,如果遇到 PyCharm 报错 'ValueError: The name 'activation' is used 2 times in the model',这是因为模型中存在两个使用了相同名称的层。

为了解决这个问题,可以尝试在其中一个层的名称后添加一个后缀,例如:

x = Activation('relu', name='relu_1')(x)
x = GlobalAveragePooling2D()(x)
x = Dense(classNum, activation='softmax', kernel_regularizer=l2(weight_decay), bias_regularizer=l2(weight_decay), name='softmax')(x)

这里我们将第一个激活层的名称从 'activation' 改为 'relu_1',并将最后一个层的名称从 'activation' 改为 'softmax'。这样就能够避免重名问题。

PyCharm 报错: ValueError: The name

原文地址: https://www.cveoy.top/t/topic/no8G 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录