pyTorch lesson_1

pyTorch的tensor 和numpy,各自实现两层简单的网络,迭代500次的速度上的比较

参考# https://pytorch.org/tutorials/beginner/pytorch_with_examples.html

numpy:结果,代码看官网链接

torch的tensor,且手动写前向传播,反向传播,结果

torch的tensor,可以使用定义自动微分,如下:

w1 = torch.randn(D_in, H, device=device, dtype=dtype, requires_grad=True)
w2 = torch.randn(H, D_out, device=device, dtype=dtype, requires_grad=True)

这样就不用手写方向传播,一个loss.backward()搞定

结果:

都是在CPU下跑的,估计GPU下,pytorch会比较好

猜你喜欢

转载自blog.csdn.net/weixin_37697675/article/details/88065360