知识点1、访问optimizer的参数,并修改
知识点2、多个模型下修改参数
知识点3、修改指定epoch下的参数
import numpy as np
import torch
from torch import nn
import torch.nn.functional as F
from torch.autograd import Variable
from torchvision.datasets import CIFAR10
from jc_utils import resnet
from torchvision import transforms as tfs
from datetime import datetime
知识点1
optimizer.param_groups[0][‘lr’] 如果把模型分为好几块,【0】就代表第一块,一般只有一块,[‘lr’]这里是字典 通过这种方式可以访问到optimizer内部的参数,从而做到更改
net = resnet(3, 10)
optimizer = torch.optim.SGD(net.parameters(), lr=0.01, weight_decay=1e-4)
print('learning rate:{}'.format(optimizer.param_groups[0]['lr']))
print('weight decay:{}'.format(optimizer.param_groups[0]['weight_decay']))
optimizer.param_groups[0]['lr'] = 1e-5
print('learning rate:{}'.format(optimizer.param_groups[0]['lr']))