转载自https://blog.csdn.net/zhiyongbo/article/details/113348535
import numpy as np
from torch.utils.data import Dataset,DataLoader,TensorDataset
import math
import os
import torch
import torch.nn as nn
import torch.nn.functional as F
from torchvision import datasets, transforms
import torch.utils.data
import matplotlib.pyplot as plt
加载csv文件,直接就是矩阵
with open("./data/benign_and_male/x_train_m2.csv", encoding='utf-8') as path_x_train_m,
open("./data/benign_and_male/x_test_m2.csv", encoding='utf-8') as path_x_test_m,
open("./data/benign_and_male/y_train_m2.csv", encoding='utf-8') as path_y_train_m,
open("./data/benign_and_male/y_test_m2.csv", encoding='utf-8')as path_y_test_m:
x_train = np.loadtxt(path_x_train_m, delimiter=",")
x_test = np.loadtxt(path_x_test_m, delimiter=",")
y_train = np.loadtxt(path_y_train_m, delimiter=",")
y_test = np.loadtxt(path_y_test_m, delimiter=",")
转换为tensor
x_train=torch.from_numpy(x_train)
y_train=torch.from_numpy(y_train)
x_test=torch.from_numpy(x_test)
y_test=torch.from_numpy(y_test)
x_train=x_train.float()
x_test=x_train.float()
y_train=y_train.long()
y_test=y_train.long()
train_dataset=TensorDataset(x_train,y_train)
test_dataset=TensorDataset(x_test,y_test)
train_loader = torch.utils.data.DataLoader(dataset=train_dataset,batch_size=batch_size, shuffle=True)
test_loader = torch.utils.data.DataLoader(dataset=test_dataset,batch_size=batch_size, shuffle=True)
版权声明:本文为CSDN博主「飞翔的代码人」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/zhiyongbo/article/details/113348535