捷徑

ParameterList

class torch.nn.ParameterList(values=None)[原始碼][原始碼]

在列表中保存參數。

ParameterList 可以像使用常規 Python 列表一樣使用,但是 Parameter 的 Tensors 會被正確註冊,並且將被所有 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)[原始碼][原始碼]

將給定的值附加到列表的末尾。

參數

value (Any) – 要附加的值

回傳類型

ParameterList

extend(values)[原始碼][原始碼]

將來自 Python 可迭代對象的值附加到列表的末尾。

參數

values (iterable) – 要附加的值的可迭代對象

回傳類型

Self

文件

取得 PyTorch 的完整開發者文件

檢視文件

教學

取得初學者和進階開發人員的深入教學課程

檢視教學課程

資源

尋找開發資源並獲得您的問題解答

檢視資源