深度学习入门基于python的理论与实现 第五章layer_naive.py加法层乘法层完全解析

# coding: utf-8
#深度学习入门基于python的理论与实现 第五章layer_naive.py加法层乘法层完全解析
#QQ群:476842922
class MulLayer:#乘法层
    def __init__(self):#初始化
        self.x = None
        self.y = None

    def forward(self, x, y):#前向传播
        self.x = x
        self.y = y                
        out = x * y#x*y

        return out

    def backward(self, dout):#反向传播,dout为导数
        dx = dout * self.y#翻转
        dy = dout * self.x#翻转

        return dx, dy

class AddLayer:
    def __init__(self):
        pass

    def forward(self, x, y):#+
        out = x + y#+

        return out

    def backward(self, dout):
        dx = dout * 1
        dy = dout * 1

        return dx, dy

你可能感兴趣的:(代码)