Skip to content

There are errors in the source code(源代码写的有错误) #1163

@SB-Moloo

Description

@SB-Moloo

In English:
tensorlayer2.2.5
function _load_weights_from_hdf5_group_in_order() have errors in:
layer_names = [n.decode('utf8') for n in f.attrs["layer_names"]].
Need to be modified to:
layer_names = [n if isinstance(n, str) else n.decode('utf8') for n in f.attrs["layer_names"]].
in line 2605 and 2617.

In Chinese:
tensorlayer2.2.5源码错误:
tl.files.load_hdf5_to_weights_in_order()
这个库的读取模型的代码编写有误,就是上面这个函数,他会报错说:AttributeError: 'str' object has no attribute 'decode'
我们可以点进去上面这个函数去看看,注意不要点错了,这个函数里面还调用了一个函数:_load_weights_from_hdf5_group_in_order
就是这个内部调用的函数写的有问题。
我们可以看看他这个不带_前缀的函数,代码是怎么写的:
layer_names = [n if isinstance(n, str) else n.decode('utf8') for n in f.attrs["layer_names"]]
他n.decode('utf8')前先做了个判断,而带_前缀的函数里面点进去看看,它是这么写的:
layer_names = [n.decode('utf8') for n in f.attrs["layer_names"]]
这就是错误所在,把这个带_前缀的函数里所有的 n.decode('utf8') 替换成 n if isinstance(n, str) else n.decode('utf8') 即可
应该是两处需要改,即:2605行 2617行

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions