使用ModuleDict,我有。输入类型(torch.cuda.FloatTensor)和权重类型(torch.FloatTensor)应该是一样的。

问题描述 投票:0回答:1

我正在努力 __init__ 功能。


        self.downscale_time_conv = np.empty(8, dtype=object)
        for i in range(8):
            self.downscale_time_conv[i] = torch.nn.ModuleDict({})

但在我看来 forward,我有。

        down_out = False
        for i in range(8):
            if not down_out:
                down_out = self.downscale_time_conv[i][side](inputs)
            else:
                down_out += self.downscale_time_conv[i][side](inputs)

然后我得到:

RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor) should be the same
python pytorch tensor
1个回答
1
投票
        self.downscale_time_conv = torch.nn.ModuleList()
        for i in range(8):
            self.downscale_time_conv.append(torch.nn.ModuleDict({}))

这就解决了。显然,我需要使用一个 ModuleList

© www.soinside.com 2019 - 2024. All rights reserved.