【问题标题】:Reduce the dimension of a tensor using max-pooling layer使用最大池化层减少张量的维度
【发布时间】:2020-07-27 02:10:09
【问题描述】:

我的问题很简单:

如何使用最大池化层将列表或张量的维度减少到列表中的 512 个元素:

我正在尝试以下代码:

    input_ids = tokenizer.encode(question, text)
    print(input_ids) # input_ids is a list of 700 elements
    m = nn.AdaptiveMaxPool1d(512)
    input_ids = m(torch.tensor([[input_ids]])) # convert the list to tensor and apply max-pooling layer

但我收到以下错误:

RuntimeError: "adaptive_max_pool2d_cpu" not implemented for 'Long'

所以,请帮忙找出错误在哪里

【问题讨论】:

    标签: python pytorch max-pooling


    【解决方案1】:

    问题在于您的 input_ids。您将 long 类型的张量传递给 AdaptiveMaxPool1d,只需将其转换为浮点数。

        input_ids = tokenizer.encode(question, text)
        print(input_ids) # input_ids is a list of 700 elements
        m = nn.AdaptiveMaxPool1d(512)
        input_ids = m(torch.tensor([[input_ids]]).float()) #
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-04-28
      • 1970-01-01
      • 1970-01-01
      • 2018-07-26
      • 2021-11-08
      • 2022-06-30
      • 2019-08-23
      相关资源
      最近更新 更多