【问题标题】:Read multiple .gz file and return it in one tensor读取多个 .gz 文件并以一个张量返回
【发布时间】:2020-06-01 12:53:55
【问题描述】:

我正在尝试读取多个 .gz 文件并在一个张量中返回其内容,如下所示:

with ReadHelper('ark: gunzip -c /home/mnabih/kaldi/egs/timit/s5/exp/mono_ali/*.gz|') as reader:
    for key, b in reader:
        #print(type(b))
        c = torch.from_numpy(b)
        labels = torch.cat(c)

不幸的是,它给了我这个错误:

cat(): 参数“张量”(位置 1)必须是张量的元组,而不是张量

【问题讨论】:

    标签: python numpy pytorch torch


    【解决方案1】:

    正如错误消息所解释的,c 是一个张量。要使用torch.cat(),您必须传递一组张量或一个列表。为了解决您的问题,您可以使用:

    temp = list()
    for key, b in reader:
        temp.append(torch.from_numpy(b))
    labels = torch.cat(temp)
    

    更多内容可以查看the manual here

    【讨论】:

      猜你喜欢
      • 2017-01-27
      • 2022-11-16
      • 2021-06-10
      • 2020-10-06
      • 2020-01-03
      • 2012-10-23
      • 1970-01-01
      • 1970-01-01
      • 2020-04-26
      相关资源
      最近更新 更多