Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'str' object has no attribute 'decode' #1155

Closed
jaried opened this issue Feb 15, 2022 · 6 comments
Closed

AttributeError: 'str' object has no attribute 'decode' #1155

jaried opened this issue Feb 15, 2022 · 6 comments

Comments

@jaried
Copy link

jaried commented Feb 15, 2022

New Issue Checklist

Issue Description

AttributeError: 'str' object has no attribute 'decode'

Reproducible Code

  • Which OS are you using ?
    windows 10 professional
    tensorlayer: 2.2.5
    tensorflow : 2.8
    python:3.7

  • Please provide a reproducible code of your issue. Without any reproducible code, you will probably not receive any help.
    tutorial_PG

I use the trained network to test, and the following error is prompted:

Traceback (most recent call last):
  File "D:\Program Files\JetBrains\PyCharm Community Edition 2021.2.2\plugins\python-ce\helpers\pydev\pydevd.py", line 1483, in _exec
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "D:\Program Files\JetBrains\PyCharm Community Edition 2021.2.2\plugins\python-ce\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "D:/Tony/Documents/yunpan/invest/2022/quant/gym/study PG/PG/pg.py", line 220, in <module>
    agent.load()
  File "D:/Tony/Documents/yunpan/invest/2022/quant/gym/study PG/PG/pg.py", line 162, in load
    tl.files.load_hdf5_to_weights_in_order(os.path.join(path, 'pg_policy.hdf5'), self.model)
  File "D:\Anaconda3\envs\gym_env\lib\site-packages\tensorlayer\files\utils.py", line 2730, in load_hdf5_to_weights_in_order
    _load_weights_from_hdf5_group_in_order(f, network.all_layers)
  File "D:\Anaconda3\envs\gym_env\lib\site-packages\tensorlayer\files\utils.py", line 2605, in _load_weights_from_hdf5_group_in_order
    layer_names = [n.decode('utf8') for n in f.attrs["layer_names"]]
  File "D:\Anaconda3\envs\gym_env\lib\site-packages\tensorlayer\files\utils.py", line 2605, in <listcomp>
    layer_names = [n.decode('utf8') for n in f.attrs["layer_names"]]
AttributeError: 'str' object has no attribute 'decode'
python-BaseException
@Laicheng0830
Copy link
Member

Modify code layer_names = [n.decode('utf8') for n in f.attrs["layer_names"]] to layer_names = [n if isinstance(n, str) else n.decode('utf8') for n in f.attrs["layer_names"]]

@jaried
Copy link
Author

jaried commented Feb 16, 2022

tensorlayer\files\utils.py, line 2617, the same question, I modified。

Traceback (most recent call last):
  File "D:/Tony/Documents/yunpan/invest/2022/quant/gym/study PG/PG/pg.py", line 219, in <module>
    agent.load()
  File "D:/Tony/Documents/yunpan/invest/2022/quant/gym/study PG/PG/pg.py", line 161, in load
    tl.files.load_hdf5_to_weights_in_order(os.path.join(path, 'pg_policy.hdf5'), self.model)
  File "D:\Anaconda3\envs\gym_env\lib\site-packages\tensorlayer\files\utils.py", line 2730, in load_hdf5_to_weights_in_order
    _load_weights_from_hdf5_group_in_order(f, network.all_layers)
  File "D:\Anaconda3\envs\gym_env\lib\site-packages\tensorlayer\files\utils.py", line 2617, in _load_weights_from_hdf5_group_in_order
    weight_names = [n.decode('utf8') for n in g.attrs['weight_names']]
  File "D:\Anaconda3\envs\gym_env\lib\site-packages\tensorlayer\files\utils.py", line 2617, in <listcomp>
    weight_names = [n.decode('utf8') for n in g.attrs['weight_names']]
AttributeError: 'str' object has no attribute 'decode'

深圳?
Keep running, new questions:

Traceback (most recent call last):
  File "D:/Tony/Documents/yunpan/invest/2022/quant/gym/study PG/PG/pg.py", line 219, in <module>
    agent.load()
  File "D:/Tony/Documents/yunpan/invest/2022/quant/gym/study PG/PG/pg.py", line 161, in load
    tl.files.load_hdf5_to_weights_in_order(os.path.join(path, 'pg_policy.hdf5'), self.model)
  File "D:\Anaconda3\envs\gym_env\lib\site-packages\tensorlayer\files\utils.py", line 2729, in load_hdf5_to_weights_in_order
    _load_weights_from_hdf5_group_in_order(f, network.all_layers)
  File "D:\Anaconda3\envs\gym_env\lib\site-packages\tensorlayer\files\utils.py", line 2618, in _load_weights_from_hdf5_group_in_order
    assign_tf_variable(layer.all_weights[iid], np.asarray(g[w_name]))
IndexError: list index out of range

@Laicheng0830
Copy link
Member

Line 2617 of the code also needs to be modified in the same way. Now this is a problem you may need to check if the parameters are imported correctly.This error occurs when the parameter shapes are inconsistent.

@jaried
Copy link
Author

jaried commented Feb 16, 2022

原来的代码是tensorlayer提供的,问题也是tensorlayer产生的。
我在上面的回答中,也提到,2617行我已经改好了。
新的问题是2618行。

我是继续在这个issue提问还是新开一个issue?

The original code is provided by tensorlayer, and the problem is also generated by tensorlayer.
In my answer above, I also mentioned that I have changed line 2617.
The new problem is line 2618.

Do I continue to ask questions in this issue or open a new one?

@waqar3411
Copy link

waqar3411 commented Mar 2, 2022

Hello @jaried... i resolved this issue by downgrading the h5py version to 2.10.0
pip install h5py==2.10.0

hope this helps...

@jaried
Copy link
Author

jaried commented Mar 7, 2022

Thanks for your answer.

@jaried jaried closed this as completed Mar 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants