❖torch.nn Parameters类

PARAMETERS

A kind of Tensor that is to be considered a module parameter.

Parameters are Tensor subclasses, that have a very special property when used with Module s – when they’re assigned as Module attributes they are automatically added to the list of its parameters, and will appear e.g. in parameters() iterator. Assigning a Tensor doesn’t have such effect. This is because one might want to cache some temporary state, like last hidden state of the RNN, in the model. If there was no such class as Parameter, these temporaries would get registered too.
Parameters:

是一种被当作模型参数的Tensor。

Parameters是Tensor的子类,有一个非常特殊的性质:当他们被作为Module类的属性的时候他们被自动加入到参数列表,并且他是以torch.nn.parameters()的形式出现的迭代器。赋值一个tensor没有这样的效果。这是因为有时候需要保存一些暂态。

    原文作者:胡今朝
    原文地址: https://zhuanlan.zhihu.com/p/52702561
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞