【问题标题】:pretrained densenet/vgg16/resnet50 + gp does not train on cifar10 data预训练的 densenet/vgg16/resnet50 + gp 不在 cifar10 数据上训练
【发布时间】:2019-06-25 20:26:35
【问题描述】:

我正在尝试在使用 CIFAR10 数据的预训练 CNN(Densenet、VGG 和 Resnet)之上使用 GP 训练混合模型,模仿 gpflow 文档中的 ex2 函数。但测试结果总是在 0.1~0.2 之间,这通常意味着随机猜测(Wilson+2016 论文显示 CIFAR10 数据的混合模型应该得到 0.7 的准确度)。谁能给我一个提示可能是什么问题?

我用更简单的 cnn 模型(2 个卷积层或 4 个卷积层)尝试了相同的代码,并且都得到了合理的结果。我尝试过使用不同的 Keras 应用程序:Densenet121、VGG16、ResNet50,都不起作用。我试图冻结预训练模型中的权重仍然无法正常工作。

def cnn_dn(output_dim):
    base_model = DenseNet121(weights='imagenet', include_top=False, input_shape=(32,32,3))
    bout = base_model.output
    fcl = GlobalAveragePooling2D()(bout)
    #for layer in base_model.layers:
    #    layer.trainable = False
    output=Dense(output_dim, activation='relu')(fcl)
    md=Model(inputs=base_model.input, outputs=output)
    return md

#add gp on top, reference:ex2() function in
#https://nbviewer.jupyter.org/github/GPflow/GPflow/blob/develop/doc/source/notebooks/tailor/gp_nn.ipynb
#needs to slightly change build graph part because keras variable #sharing is not the same as tensorflow
#......

## build graph
with tf.variable_scope('cnn'):
    md=cnn_dn(gp_dim)
    f_X = tf.cast(md(X), dtype=float_type)
    f_Xtest = tf.cast(md(Xtest), dtype=float_type)

#......

    ## predict

res=np.argmax(sess.run(my, feed_dict={Xtest:xts}),1).reshape(yts.shape)
correct = res == yts.astype(int)
print(np.average(correct.astype(float)))

【问题讨论】:

  • 你能把它变成一个最小的工作(好吧,失败,但可运行!)示例?能够简单地复制和粘贴脚本来重现问题,这使得对其他人进行调查变得更加容易!

标签: gpflow


【解决方案1】:

我终于发现解决方案是训练更大的迭代。在原始代码中,我只使用 MNIST 数据的 ex2() 函数中使用的 50 次迭代,这对于更复杂的网络和 CIFAR10 数据是不够的。调整一些超参数(例如学习率和激活函数)也有帮助。

【讨论】:

    猜你喜欢
    • 2021-10-14
    • 1970-01-01
    • 2020-02-11
    • 1970-01-01
    • 2018-05-01
    • 2020-06-13
    • 1970-01-01
    • 1970-01-01
    • 2020-05-21
    相关资源
    最近更新 更多