0

我从论文中知道:efficientnet b0 的输出是 (*,7,7,1280),对吗?如果是这样,那么 globalAveragePooling2D 将得到 ndim = 4,而不是 2。

        model=Sequential()
        inputS=(height,width,depth)
        chanDim=-1
        model.add(EfficientNetB0(inputS, include_top=True, weights='imagenet'))
        model.add(GlobalAveragePooling2D())
        model.add(Dense(1024))
        model.add(Activation("swish"))
        model.add(BatchNormalization(axis=chanDim))
        model.add(Dropout(0.25))
        model.add(Dense(256))
        model.add(Activation("swish"))
        model.add(BatchNormalization(axis=chanDim))
        model.add(Dropout(0.25))
        model.add(Dense(32))
        model.add(Activation("tanh"))
        model.add(BatchNormalization(axis=chanDim))
        model.add(Dropout(0.25))
        model.add(Dense(classes))
        model.add(Activation("softmax"))
        return model
ValueError: Input 0 is incompatible with layer global_average_pooling2d_2: expected ndim=4, found ndim=2
4

1 回答 1

1

那是因为你设置include_topTrue,意味着模型中包含了分类层,所以整个模型的输出形状是(samples, classes),这可能不是你想要的。

当你想要特征图时,你应该include_top在.FalseEfficientNetB0

于 2019-12-30T11:37:19.847 回答