如何使用pytorch将系列numpy数组转换为张量

时间:2019-06-08 06:04:50

标签: python numpy pytorch fast-ai

我正在尝试将图像标签转换为张量,但是出现一些错误,请帮助我转换为张量: 这是我的代码:

features_train, features_test, targets_train, targets_test = train_test_split(X,Y,test_size=0.2,
                                                                              random_state=42)
X_train = torch.from_numpy(features_train)
X_test = torch.from_numpy(features_test)

Y_train =torch.from_numpy(targets_train).type(torch.IntTensor) 
Y_test = torch.from_numpy(targets_test).type(torch.IntTensor)
train = torch.utils.data.TensorDataset(X_train,Y_train)
test = torch.utils.data.TensorDataset(X_test,Y_test)


train_loader = torch.utils.data.DataLoader(train, batch_size = train_batch_size, shuffle = False)
test_loader = torch.utils.data.DataLoader(test, batch_size = test_batch_size, shuffle = False)

这是我的错误:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-32-f1578581ff5c> in <module>()
      5 X_test = torch.from_numpy(features_test)
      6 
----> 7 Y_train =torch.from_numpy(targets_train).type(torch.IntTensor)
      8 Y_test = torch.from_numpy(targets_test).type(torch.IntTensor)
      9 train = torch.utils.data.TensorDataset(X_train,Y_train)

TypeError: expected np.ndarray (got Series)

这是我的数组值:

targets_train
478     1
5099    3
1203    2
5674    2
142     1
4836    2
4031    1
1553    3
4416    1
605     5
1194    3
4319    4
1498    5

1 个答案:

答案 0 :(得分:0)

这就是我要做的:

RewriteCond %{QUERY_STRING} !(?:^|&)download_file=(.*)