Neural network 用python重置神经网络中的连接

Neural network 用python重置神经网络中的连接,neural-network,pytorch,Neural Network,Pytorch,我有一个子类化nn.module的代码 我不知道reset\()函数到底做什么,我在nn.module源代码中没有找到任何reset\()函数 谁知道当神经网络中没有操作,并且父类中的namereset\uuz()中也没有函数时,我如何使用它来重置神经网络中的连接 class Connection(torch.nn.module): super().__init__() def reset_(self) -> None: #Contains

我有一个子类化
nn.module
的代码

我不知道
reset\()
函数到底做什么,我在nn.module源代码中没有找到任何
reset\()
函数

谁知道当神经网络中没有操作,并且父类中的name
reset\uuz()
中也没有函数时,我如何使用它来重置神经网络中的连接


    class Connection(torch.nn.module):
      super().__init__()

      def reset_(self) -> None:

      #Contains resetting logic for the connection.#

      super().reset_()


虽然我不确定PyTorch模块中的
reset()
函数是什么意思,但是,通常在许多NN层中,有一个
reset_parameters()
函数用于重置该层的参数。如果有帮助的话,我给你举个例子

import torch
import torch.nn as nn


class Connection(nn.Module):

    def __init__(self):
        super().__init__()
        # a weight matrix of shape [10 x 100] as parameters
        self.weight = nn.Parameter(torch.Tensor(10, 100))

    def reset_parameters(self) -> None:
        # reset parameters using random values from a uniform distribution
        nn.init.uniform_(self.weight, -0.01, 0.01)


c = Connection()
c.reset_parameters() # reset the weight parameters

这只是一个示例,您可以修改
reset\u参数
功能以满足您的需要。

您所说的重置是什么意思?您的意思是使用关联的前一个参数返回到前一个模型状态吗?这可以通过重新加载
state_dict
来实现,更多信息请参见:另外,我在nn.module中找到了这个reset()函数,但没有找到。谢谢@Blupon。。。我的意思是将记录(连接的状态变量)重置为空torch.Tensors…在这个模块中(几行代码)没有重置方法的定义,它只是传递。。。。我的问题是,为什么在没有操作的情况下,我们必须使用reset_u2;()函数…首先,我认为在nn.Module中可能有一个函数是这个名称,但当我检查源代码时…我没有找到任何具有这个名称的函数…只是在另一个模块中,它定义了reset_2;()但是为什么它没有将该模块导入到该代码中,并且它没有调用??谢谢@Wasi Ahmad…这对我很有用,尽管这不是我的答案,但帮助我了解了更多pytorch:)