在一个张量中读取多个 .gz 文件并 return
Read multiple .gz file and return it in one tensor
我正在尝试读取多个 .gz 文件和 return 它在一个张量中的内容,如下所示:
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(): argument 'tensors' (position 1) must be tuple of Tensors, not Tensor
正如错误消息所解释的那样,c
是一个张量。要使用 torch.cat()
,您必须传递一组张量或一个列表。要解决您的问题,您可以使用:
temp = list()
for key, b in reader:
temp.append(torch.from_numpy(b))
labels = torch.cat(temp)
更多可以查看the manual here
我正在尝试读取多个 .gz 文件和 return 它在一个张量中的内容,如下所示:
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(): argument 'tensors' (position 1) must be tuple of Tensors, not Tensor
正如错误消息所解释的那样,c
是一个张量。要使用 torch.cat()
,您必须传递一组张量或一个列表。要解决您的问题,您可以使用:
temp = list()
for key, b in reader:
temp.append(torch.from_numpy(b))
labels = torch.cat(temp)
更多可以查看the manual here