0


PyTorch:通过pth文件查看网络结构(查看输入输出维度)

pth模型保存时是按照“整个模型保存”和“只保存模型参数”会影响模型的加载和访问方式

保存方式为“整个模型”(torch.save(model, PATH)):

import torch
if __name__ == '__main__':
    model_pth = r'D:\${modelPath}\${modelName}.pth'
    net = torch.load(model_pth, map_location=torch.device('cpu'))
    for key, value in net["state_dict"].items():
        print(key,value.size(),sep="  ")

输出(部分截图)为:

保存方式为“只保存模型参数”(torch.save(model.state_dict(), PATH)):

待补充


本文转载自: https://blog.csdn.net/dx_fang/article/details/126718679
版权归原作者 dx_fang 所有, 如有侵权,请联系我们删除。

“PyTorch:通过pth文件查看网络结构(查看输入输出维度)”的评论:

还没有评论