リスト形式で格納されている、0,1のラベルデータをpytorchでtorch tensorに変換したいのですが、エラーがでてうまくいきません。
どうすればよいのでしょうか?
動作環境はGoogle Colabです。
#ソースコード
python
1#torchのインストール 2!pip install torch torchvision 3import torch 4import torch.nn as nn 5import torchvision.datasets as dsets 6import torchvision.transforms as transforms 7import torch.utils.data as utils 8from torch.autograd import Variable 9import numpy as np 10 11a = [0,0,0,1,1,0,1,0] 12tensor = torch.stack([torch.Tensor(i) for i in a])
#エラーメッセージ
--------------------------------------------------------------------------- RuntimeError Traceback (most recent call last) <ipython-input-27-8c9f22f1d75a> in <module>() 1 a = [0,0,0,1,1,0,1,0] ----> 2 tensor = torch.stack([torch.Tensor(i) for i in a]) RuntimeError: cannot unsqueeze empty tensor
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。