state_dict

时间:2025-03-29 10:00:05

参考 state_dict - 云+社区 - 腾讯云



(Python method, in Module)

state_dict(destination=None, prefix='', keep_vars=False)[source]

返回一个包含整个模型状态的字典。包含参数和现在的缓冲器(例如,运行平均值)。键对应着参数和缓冲器的名字。

返回值:

  • 包含整个模型的字典。

a dictionary containing a whole state of the module

例:

  1. >>> module.state_dict().keys()
  2. ['bias', 'weight']

.state_dict (Python method, in )

state_dict()[source]

以字典的形式返回优化器的状态。

包含两个词目:

  • state - 保持当前优化状态的字典,它的内容和优化器类不同。

  • param_groups - 包含所有参数组的字典

.lr_scheduler.LambdaLR.state_dict (Python method, in )

class .lr_scheduler.MultiplicativeLR(optimizer, lr_lambda, last_epoch=-1)[source]

将每个参数组的学习率乘以指定函数中给定的因子。当last_epoch = -1时,设置学习率为初始学习率。

参数:

  • optimizer (Optimizer) – 包裹的优化器

  • lr_lambda (function or list) – A function which computes a multiplicative factor given an integer parameter epoch, or a list of such functions, one for each group in optimizer.param_groups.

  • lr_lambda (function or list) – 给定整数参数epoch计算乘法因子的函数,或者这个函数的列表,在optimizer.param_groups中,每个组都有一个。

  • last_epoch (int) – 最后一个epoch的指数,默认是-1。

例:

  1. >>> lmbda = lambda epoch: 0.95
  2. >>> scheduler = MultiplicativeLR(optimizer, lr_lambda=lmbda)
  3. >>> for epoch in range(100):
  4. >>> train(...)
  5. >>> validate(...)
  6. >>> ()

load_state_dict(state_dict)[source]

加载策略状态

参数:

  • state_dict (dict) –策略状态。应该是调用state_dict()返回的对象。

state_dict()[source]

Returns the state of the scheduler as a dict.It contains an entry for every variable in self.__dict__ which is not the optimizer. The learning rate lambda functions will only be saved if they are callable objects and not if they are functions or lambdas.

以字典的形式返回策略的状态。对每个变量它包含self.__dict__中的实体,这不是优化器。如果它们是可以调用的对象的话,学习率lambda函数就保存,如果他们是函数或者lambdas的话就不保存。