PyTorch 实战-用 Numpy 热身
来源:互联网 发布:oracle数据库如何备份 编辑:程序博客网 时间:2024/06/08 06:39
Numpy provides an n-dimensional array object, and many functions for manipulating these arrays. Numpy is a generic framework for scientific computing; it does not know anything about computation graphs, or deep learning, or gradients. However we can easily use numpy to fit a two-layer network to random data by manually implementing the forward and backward passes through the network using numpy operations:
# -*- coding: utf-8 -*-import numpy as np# N is batch size; D_in is input dimension;# H is hidden dimension; D_out is output dimension.N, D_in, H, D_out = 64, 1000, 100, 10# Create random input and output datax = np.random.randn(N, D_in)y = np.random.randn(N, D_out)# Randomly initialize weightsw1 = np.random.randn(D_in, H)w2 = np.random.randn(H, D_out)learning_rate = 1e-6for t in range(500): # Forward pass: compute predicted y h = x.dot(w1) h_relu = np.maximum(h, 0) y_pred = h_relu.dot(w2) # Compute and print loss loss = np.square(y_pred - y).sum() print(t, loss) # Backprop to compute gradients of w1 and w2 with respect to loss grad_y_pred = 2.0 * (y_pred - y) grad_w2 = h_relu.T.dot(grad_y_pred) grad_h_relu = grad_y_pred.dot(w2.T) grad_h = grad_h_relu.copy() grad_h[h < 0] = 0 grad_w1 = x.T.dot(grad_h) # Update weights w1 -= learning_rate * grad_w1 w2 -= learning_rate * grad_w2
阅读全文
0 0
- PyTorch 实战-用 Numpy 热身
- PyTorch 实战-张量
- PyTorch的入门教程实战
- Pytorch中文视频教程,Pytorch实战视频教程
- Pytorch学习笔记(2)---Numpy桥
- python-numpy实战
- PyTorch基本用法(一)——Numpy,Torch对比
- 莫烦PyTorch学习笔记(一)——Torch或Numpy
- NumPy实战:Chapter-1(初识NumPy)
- PyTorch
- PyTorch
- PyTorch
- pytorch
- pytorch
- Pytorch
- Pytorch实战指南---使用Pytorch完成Kaggle上的经典比赛:Dogs vs Cats---updating
- NumPy实战:Chapter-2(Matplotlib入门)
- 《机器学习实战》之Numpy函数库基础
- logsig函数和tansig函数 matlab实现
- 要解析的bin包
- codevs 1029 遍历问题
- python获取自己发的说说内容
- oop2
- PyTorch 实战-用 Numpy 热身
- Linux常用小知识
- C控制语句之分支和跳转(一)
- 要解析的bin包
- 百度之星2017 资格赛 1003 度度熊与邪恶大魔王
- 统计公司员工喜欢吃的水果,并打印出最喜欢吃的前K中水果【map关联式容器,k/V结构】
- API学习Float
- Python实战之Oracle数据库操作
- UBOOT 2010 访问 GD 跑飞卡住