如何将x_train和y_train放入模型中进行训练
x_train是一个大小为(3000,13(的张量
y_train的大小为(3000,1(
也就是说,对于x_train(1,13(的每个元素,相应的y标签是y_train中的一位数字。如果我这样做:
train_data = (train_feat, train_labels)
print(train_data[0].shape)
print(train_data[1].shape)
torch.Size([3082092, 13])
torch.Size([3082092, 1])
train_loader = data.DataLoader(dataset=train_data,
batch_size= 7,
shuffle=True)
数据加载器不返回批量大小,而是返回整个数据集,而不是
您可以使用TensorDataset
构造函数:
import torch.utils.data as data_utils
dataset = data_utils.TensorDataset(train_feat, train_labels)
train_loader = data_utils.DataLoader(dataset, batch_size=7, shuffle=True)