HuaWeiCloud_model_arts

一、上传数据至OBS及授权给ModelArts使用 1433065-20190202222231574-1116543681.png

二、ModelArts-Notebook介绍 1433065-20190202221743259-935352049.png

三、ModelArts-训练作业介绍1433065-20190202221600301-1747371507.png

搬几个pytorch教程的例子

Before introducing Pytorch, we will first implement the network using numpy.

在介绍 PyTorch 之前, 我们先使用 numpy 实现网络.

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 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 manully implement the forward and backward pass through the network using numpy operations:

Numpy 提供了一个n维的数组对象, 并提供了许多操纵这个数组对象的函数. Numpy 是科学计算的通用框架; Numpy 数组没有计算图, 也没有深度学习, 也没有梯度下降等方法实现的接口. 但是我们仍然可以很容易地使用 numpy 生成随机数据 并将产生的数据传入双层的神经网络, 并使用 numpy 来实现这个网络的正向传播和反向传播:

# -*- coding: utf-8 -*-

import numpy as np

# N 是一个batch的样本数量; D_in是输入维度;
# H 是隐藏层向量的维度; D_out是输出维度.
N, D_in, H, D_out = 64, 1000, 100, 10

# 创建随机的输入输出数据
x = np.random.randn(N, D_in)
y = np.random.randn(N, D_out)

# 随机初始化权重参数

print("输入维度D_in:", D_in)

print("隐藏层向量维度H:", H)
w1 = np.random.randn(D_in, H)

# print("w1:", w1)
w2 = np.random.randn(H, D_out)
# print("w2:", w2)
learning_rate = 1e-6
for t in range(500):    
    # 前向计算, 算出y的预测值
    h = x.dot(w1)
    h_relu = np.maximum(h, 0)
    y_pred = h_relu.dot(w2)

    # 计算并打印误差值
    loss = np.square(y_pred - y).sum()
#     print(t, loss)

#     print("t:",t)

    # 在反向传播中, 计算出误差关于w1和w2的导数
    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)

    # 更新权重
    w1 -= learning_rate * grad_w1
    w2 -= learning_rate * grad_w2

转载于:https://www.cnblogs.com/hugeng007/p/10349326.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值