首页 文章

KERAS:将卷积内核从theano转换为tensorflow,OOM

提问于
浏览
0

我有一个真正的问题,转换Keras模型's convolutional kernels and most preferably dense weights (but that is not my priority) from theano to tensorflow. I made some research but I just can'吨处理它 . 首先我使用了这个脚本:Keras: convert pretrained weights between theano and tensorflow

但是我的准确率从85%下降到比随机差(8级中12%),所以我猜它有些不对劲 .

比我试图使用titu1994代码又名:https://github.com/titu1994/Keras-Classification-Models/blob/master/weight_conversion_theano.py

虽然我无法完成它,因为我在脚本中遇到关于在我的起泡虚拟机上运行OOM的错误,我无法访问更好的一个 . 权重是来自fast.ai深度学习课程的vgg16_bn.h5 . 如果您之前遇到类似问题,或者如果某些人将这些权重转换为张量流量格式,我将非常感谢任何帮助,如果您决定分享,我会很高兴 .

或者如果您知道其他重量和模型,我可以成功地执行转移学习,如果您也分享,我将不胜感激 .

1 回答

  • 1

    在Keras 2中,卷积内核的转换在 load_weights() 中自动执行 . 在您的情况下,自动转换失败,因为您没有保存在Keras 1权重文件中的后端信息 .

    所以你需要做的就是将一个名为 backend 的属性放入权重文件中,让Keras负责其余的工作 .

    import h5py
    with h5py.File(weight_file, 'a') as f:
        f.attrs['backend'] = 'theano'.encode('utf8')
    

相关问题