栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

state

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

state

state_dict字典状态

state_dict字典状态本质就是一个Python字典,键值对是每个网络层和其对应的参数张量。

state-dict包含带有学习参数的网络层和注册的缓存

优化器对象包含一个状态字典,包含优化器状态的信息和使用的超参数。

import torch.nn as nn
import torch.optim as optim

class ModelClass(nn.Module):
    def __init__(self):
        super(ModelClass,self).__init__()
        self.convolution_1 = nn.Conv2d(3,6,5)
        self.pool = nn.MaxPool2d(2,2)
        self.convolution_2 = nn.Conv2d(6,16,5)
        self.full_connection_1 = nn.Linear(16*5*5,120)
        self.full_connection_2 = nn.Linear(120,84)
        self.full_connection_3 = nn.Linear(84,10)

    def forward(self,x):
        x = self.pool(F.relu(self.convolution_1(x)))
        x = self.pool(F.relu(self.convolution_2(x)))
        x = x.view(-1,16*5*5)
        x = F.relu(self.full_connection_1(x))
        x = F.relu(self.full_connection_2(x))
        x = self.full_connection_3(x)
        return x

# Initialize model
model = ModelClass()

#Initialize optimizer
optimizer = optim.SGD(model.parameters(),lr = 0.001,momentum = 0.9)

for paramter_tensor in model.state_dict():
    print(paramter_tensor,"t",model.state_dict()[paramter_tensor].size)

输出:

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/870749.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号