为什么我移除过滤器及其相关权重时CNN的准确性会下降?

问题描述 投票:0回答:1

model架构为Conv2D with 32 filters-> Flatten-> Dense-> Compile-> Fit

enter image description here

我使用此模型从第一层和相应的完全连接层中删除了最后一个过滤器

w,b = model.layers[0].get_weights()
w = np.delete(w, [32], -1)
b = np.delete(b, [32], 0)

w_2,b_2 = model.layers[2].get_weights()
w_2 = w_2[:20956,:]

我使用20956,因为第一层的输出是26 x 26 x 31,这是2D图像尺寸乘以通道数。

我使用以下方法创建了一个名为model_1的新模型:

# Input stays the same
model_1 = Sequential()

# New modified conv layer
model_1.add(Conv2D(31, kernel_size=(3, 3),
                 activation='relu',
                 input_shape=input_shape,
                 kernel_initializer='he_normal'))

model_1.add(Flatten())
model_1.add(Dense(10, activation='softmax'))


model_1.layers[0].set_weights([w,b])
model_1.layers[2].set_weights([w_2,b_2])

model_1.compile(loss="categorical_crossentropy",
              optimizer="Adam",
              metrics=['accuracy'])

我可以通过执行model_1.layers[0].get_weights()[0] == model.layers[0].get_weights()[0][:,:,:,:31]model_1.layers[2].get_weights()[0] == model.layers[2].get_weights()[0][:20956,:]并返回True来确定权重相同。

enter image description here

我做的时候

score = model_1.evaluate(x_test_reshape, y_test)

print('Test loss:', score[0])
print('Test accuracy:', score[1])

score = model.evaluate(x_test_reshape, y_test)

print('Test loss:', score[0])
print('Test accuracy:', score[1])

准确度从98%下降到10%,有什么想法吗?

keras deep-learning conv-neural-network tensor
1个回答
0
投票

您基本上要做的是从最后一个卷积层中删除一个通道。直觉上听起来好像没什么大不了的,剩下的31个通道仍将使网络性能良好。实际上,所有卷积通道都在紧随其后的密集层中相互交互,但是由于这种交互丢失了信息通道之一,因此对其准确性进行了优化的数字将下降。

另一种思考方式是将网络视为顺序步骤的功能,该步骤将输入图像和输出标签的准确度提高到98%。删除此函数中的一小部分(1/32)计算将更改结果,并且可能会给出更差的结果,因为该函数在仍存在这些计算的情况下进行了优化。您正在删除该功能的一部分,这显然对于实现高精度至关重要。

您可以通过短时间训练31个频道的新模型来进行测试。由于新模型仅需要重新学习已删除频道的功能,因此它应该可以很快再次达到高性能。

© www.soinside.com 2019 - 2024. All rights reserved.