本文主要是用PyTorch来实现一个简单的分类任务。
编辑器:spyder
1.引入相应的包及建立数据集
import torch
from torch.autograd import Variable
import torch.nn.functional as F
import matplotlib.pyplot as plt
# make fake data
n_data = torch.ones(100, 2)
x0 = torch.normal(2*n_data, 1) # class0 x data (tensor), shape=(100, 2)
y0 = torch.zeros(100) # class0 y data (tensor), shape=(100, 1)
x1 = torch.normal(-2*n_data, 1) # class1 x data (tensor), shape=(100, 2)
y1 = torch.ones(100) # class1 y data (tensor), shape=(100, 1)
x = torch.cat((x0, x1), 0).type(torch.Fl

本文通过PyTorch实现了一个简单的分类任务,详细介绍了数据集创建、神经网络搭建、训练过程以及结果可视化。使用了交叉熵作为损失函数,并在训练过程中进行了可视化展示。
最低0.47元/天 解锁文章
7947

被折叠的 条评论
为什么被折叠?



