本文共 370 字,大约阅读时间需要 1 分钟。
PyTorch模型加载与权重分析
在当前实验中,我们使用PyTorch框架加载预训练模型,主要目的是分析模型各层的权重参数。以下是具体实现细节:
首先,加载模型及其预训练参数:
model = Net()model.load_state_dict(torch.load(r"C:\Users\admin\Desktop\test1\w.pkl"))
接下来,检查各层权重参数:
print(model.fc1.weight) # 查看第一层全连接层的权重print('/') print(model.fc2.weight) # 查看第二层全连接层的权重print('/')print(model.fc3.weight) # 查看第三层全连接层的权重 通过上述代码,可以观察到模型各层的权重参数,进一步分析模型的结构和特征表达。
转载地址:http://bhpi.baihongyu.com/