【问题标题】:Using ModuleDict, I have: Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor) should be the same使用 ModuleDict,我有:输入类型 (torch.cuda.FloatTensor) 和权重类型 (torch.FloatTensor) 应该相同
【发布时间】:2020-08-05 19:03:53
【问题描述】:

我正在尝试我的 __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】:
        self.downscale_time_conv = torch.nn.ModuleList()
        for i in range(8):
            self.downscale_time_conv.append(torch.nn.ModuleDict({}))

这解决了它。显然我需要使用ModuleList

【讨论】:

    猜你喜欢
    • 2020-09-29
    • 2021-01-03
    • 2023-03-27
    • 2022-11-11
    • 2021-07-19
    • 2021-12-30
    • 2021-12-06
    • 1970-01-01
    • 2023-04-10
    相关资源
    最近更新 更多