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

如何读取静态图的权重的值和名字? #48130

Closed
LitLeo opened this issue Nov 18, 2022 · 3 comments
Closed

如何读取静态图的权重的值和名字? #48130

LitLeo opened this issue Nov 18, 2022 · 3 comments
Assignees
Labels
status/close 已关闭 type/question 用户提问

Comments

@LitLeo
Copy link

LitLeo commented Nov 18, 2022

请提出你的问题 Please ask your question

有一个静态图模型,两个文件,model__和__params,如何获得其中权重的值和名字呢?

类似onnx model.graph.initializer 的功能?

@paddle-bot
Copy link

paddle-bot bot commented Nov 18, 2022

您好,我们已经收到了您的问题,会安排技术人员尽快解答您的问题,请耐心等待。请您再次检查是否提供了清晰的问题描述、复现代码、环境&版本、报错信息等。同时,您也可以通过查看官网API文档常见问题历史IssueAI社区来寻求解答。祝您生活愉快~

Hi! We've received your issue and please be patient to get responded. We will arrange technicians to answer your questions as soon as possible. Please make sure that you have posted enough message to demo your request. You may also check out the APIFAQGithub Issue and AI community to get the answer.Have a nice day!

@ghostxsl
Copy link
Contributor

可以参考:#26519

@LitLeo
Copy link
Author

LitLeo commented Nov 18, 2022

翻了一圈代码摸索出来了

import paddle
import numpy as np

paddle.enable_static()

exe = paddle.static.Executor(paddle.CPUPlace())
path_prefix = "./paddle_infer_model"

[inference_program, feed_target_names, fetch_targets] = (
            paddle.static.load_inference_model(path_prefix, exe, model_filename="__model__", params_filename="__params__"))

# import pdb
# pdb.set_trace()

state_dict = inference_program.state_dict()

for i in state_dict:
    print(i)
    arr = np.array(state_dict[i])
    print(arr.shape)
    print(arr)
    assert 0

@paddle-bot paddle-bot bot added the status/close 已关闭 label Nov 21, 2022
@paddle-bot paddle-bot bot closed this as completed Nov 21, 2022
@paddle-bot paddle-bot bot removed the status/new-issue 新建 label Nov 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/close 已关闭 type/question 用户提问
Projects
None yet
Development

No branches or pull requests

2 participants