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

cwxwcias  于 2022-11-19  发布在  其他
关注(0)|答案(3)|浏览(144)

请提出你的问题 Please ask your question

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

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

jucafojl

jucafojl1#

您好,我们已经收到了您的问题,会安排技术人员尽快解答您的问题,请耐心等待。请您再次检查是否提供了清晰的问题描述、复现代码、环境&版本、报错信息等。同时,您也可以通过查看 官网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!

hgtggwj0

hgtggwj03#

翻了一圈代码摸索出来了

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

相关问题