多层感知机fashion mnist

import torch
from matplotlib import pyplot as plt
from torch import nn
from d2l import torch as d2l


net=nn.Sequential(nn.Flatten(),nn.Linear(784,256),nn.ReLU(),
                  nn.Linear(256,10))

def init_weights(m):
    if type(m)==nn.Linear:
        nn.init.normal_(m.weight,std=0.01)

net.apply(init_weights);

batch_size,lr,num_epochs=256,0.1,10
loss=nn.CrossEntropyLoss()
loss=nn.CrossEntropyLoss()
trainer=torch.optim.SGD(net.parameters(),lr=lr)

train_iter,test_iter=d2l.load_data_fashion_mnist(batch_size=batch_size)
d2l.train_ch3(net,train_iter,test_iter,loss,num_epochs,trainer)


plt.figure(figsize=(20,8),dpi=100)
plt.show()
上一篇:下载pytorch,import torch显示为false,一篇解决


下一篇:记录一下我这台电脑搭建pytorch的环境