快捷方式

ParameterList

class torch.nn.ParameterList(values=None)[source][source]

以列表形式持有引數。

ParameterList 可以像常規的 Python 列表一樣使用,但作為 Parameter 的 Tensor 會被正確註冊,並對所有 Module 方法可見。

請注意,建構函式、給列表元素賦值、append() 方法和 extend() 方法會將任何 Tensor 轉換為 Parameter

引數

parameters (iterable, optional) – 要新增到列表中的元素的可迭代物件。

示例

class MyModule(nn.Module):
    def __init__(self) -> None:
        super().__init__()
        self.params = nn.ParameterList([nn.Parameter(torch.randn(10, 10)) for i in range(10)])

    def forward(self, x):
        # ParameterList can act as an iterable, or be indexed using ints
        for i, p in enumerate(self.params):
            x = self.params[i // 2].mm(x) + p.mm(x)
        return x
append(value)[source][source]

在列表末尾新增給定值。

引數

value (Any) – 要新增的值

返回型別

ParameterList

extend(values)[source][source]

將 Python 可迭代物件中的值新增到列表末尾。

引數

values (iterable) – 要新增值的可迭代物件

返回型別

Self

文件

訪問 PyTorch 全面的開發者文件

檢視文件

教程

獲取面向初學者和高階開發者的深度教程

檢視教程

資源

查詢開發資源並獲得問題解答

檢視資源