首页 > 编程知识 正文

神经网络与深度学习,深度学习框架

时间:2023-05-04 11:05:19 阅读:260621 作者:4495

神经网络的正向传播中进行的矩阵乘积运算在几何学领域被称为“仿射变换(Affine)”

1. 输入为单个数据

2. 批版本的Affine

# coding: utf-8import numpy as npclass Affine: """定义仿射层(矩阵乘积)""" def __init__(self, W, b): self.W = W self.b = b self.x = None self.dW = None self.db = None def forward(self, x): self.x = x out = np.dot(x, self.W) + self.b return out def backward(self, dout): dx = np.dot(dout, self.W.T) # T代表转置 self.dW = np.dot(self.x.T, dout) # x要在前面乘 self.db = np.sum(dout, axis=0) # 偏置反向传播需要汇总为偏置的元素 return dx

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。