KeyError:“无法打开属性(无法找到属性:'nb_layers')" [英] KeyError: "Can't open attribute (Can't locate attribute: 'nb_layers')"

查看:312
本文介绍了KeyError:“无法打开属性(无法找到属性:'nb_layers')"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Keras的Python代码.我没有发布代码,因为它有点长,而且问题似乎与代码本身无关.

I have a Python code that uses Keras. I didn't post the code because it is a bit long, and the issue seems not to be related to the code itself.

这是我遇到的错误:

File "h5py\h5a.pyx", line 77, in h5py.h5a.open (D:\Build\h5py\h5py-2.7.0\h5py\h5a.c:2350)
KeyError: "Can't open attribute (Can't locate attribute: 'nb_layers')"

可能是什么问题?与Keras有关吗?我该如何解决这个问题?

What could be the issue? Is it related to Keras? How can I solve this issue?

编辑1

该错误似乎与这部分代码有关:

The error seems to be related to this part of code:

# load VGG16 weights
    f = h5py.File(weights_path)

    for k in range(f.attrs['nb_layers']):
        if k >= len(model.layers):
            break
        g = f['layer_{}'.format(k)]
        weights = [g['param_{}'.format(p)] for p in range(g.attrs['nb_params'])]
        model.layers[k].set_weights(weights)

    f.close()
    print('Model loaded.')

谢谢.

推荐答案

使用来自 https://github.com/fchollet/deep-learning-models/releases

此文件为Keras 2格式.

This file is in Keras 2 format.

这篇关于KeyError:“无法打开属性(无法找到属性:'nb_layers')"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆