【发布时间】:2020-07-03 03:47:58
【问题描述】:
我正在尝试实现一个模型,就像我给出的这段代码
input_tensor = Input(shape=(256, 256, 3))
base_model = VGG16(input_tensor=input_tensor,weights='imagenet',pooling=None, include_top=False)
x = base_model.output
x = GlobalAveragePooling2D()(x)
x = tf.math.reduce_max(x,axis=0,keepdims=True)
x = Dense(512,activation='relu')(x)
output_1 = Dense(3, activation='sigmoid')(x)
sagittal_model_abn = Model(inputs=base_model.input, outputs=output_1)
for layer in base_model.layers:
layer.trainable = True
在这段代码中,我使用tf.math.reduce_max 对批处理中的样本取最大值。
如果此tf.math.reduce_max 的输入形状为 (16,6,6,512),则输出为 (1,6,6,512)
对帧进行最大池化是所需的操作。我使用的 16 帧具有相同的标签,即 16 帧构成批次的单个样本。
axis=0 上的最大池化,即在帧上,是我的模型需要做的事情。
这使得批量大小有效地为 1。但由于我无法将 5D 张量提供给模型,所以我将批量大小保持为 1 并将 4D 张量提供给模型,因为我使用的是 2D CNN。
现在,数据集是一个多标签数据集。所以我在最后一层使用 sigmoid 激活和二元交叉熵损失。
但是出现的问题是,对于所有样本,模型的所有预测在每次迭代中都在 0.49-0.51 的范围内。
[0.50119835 0.5004604 0.49988952]
[0.501212 0.5004502 0.49987414]
[0.50122344 0.5004629 0.49987343]
这表明模型没有学习任何东西。
这是因为我使用了tf.math.reduce_max 运算符吗?是否应该使用@tf.function 进行同样的操作来解决这个问题?
我正在使用初始 LR 为 0.00001 的 Adam 优化器。
学习率很小,因为我正在微调预训练的 VGG 网络。
【问题讨论】:
标签: python tensorflow keras deep-learning neural-network