当前位置:网站首页>Deep learning and image recognition: principle and practice notes day_ thirteen
Deep learning and image recognition: principle and practice notes day_ thirteen
2022-04-22 03:24:00 【Effort volume】
Error back propagation
1、 Activate the implementation of the function layer
1.1 Relu Back propagation implementation
The code is as follows :
class Relu():
def __init__(self):
self.x = None
def forward(self, x):
self.x = np.maximum(0,x)
out = self.x
return out
# dout Is the derivative from the upper layer
def backward(self, dout):
dx = dout
dx[self.x <=0] =0
return dx
1.2 Sigmoid Back propagation implementation
The code is as follows :
class _sigmoid:
def __init__(self):
self.out = None
def forward(self,x):
out = 1/(1+np.exp(-x))
self.out = out
return out
def backward(self, dout):
dx = dout * self.out *(1-self.out)
return dx
2、Affine The realization of the layer ( Fully connected layer )
Affine The general form of layer is , among x It's layer input ,w Is the parameter ,b Is an offset ,f It's a nonlinear activation function .
about X( matrix ) The derivation of , You can refer to the following formula , It should be noted that ,X and The same shape ,W and
The same shape
The code implementation is as follows :
class 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)
self.dW = np.dot(self.x.T, dout)
self.db = np.sum(dout, axis=0)
return dx
3、Softmaxwithloss The realization of the layer
Suppose the output of the last layer of the network is z, after Softmax Post output is p, The real label is y(ont-hot code ), among C Express C Categories , So the loss function is :
because p yes z after Softmax Output after function calculation , namely p=softmax(z), among
Loss Yes z The derivative of is :
The code implementation is as follows :
class SoftmaxWithLoss():
def __init__(self):
self.loss = None
self.p = None
self.y = None
def forward(self,x,y):
self.y = y
self.p = softmax(x)
self.loss = cross_entropy_error(self.p,self.y)
return self.loss
def backward(self, dout= 1):
batch_size = self.y.shape[0]
dx = (self.p - self.y) / batch_size
return dx
版权声明
本文为[Effort volume]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204211347167454.html
边栏推荐
- Workplace etiquette How to write email
- Promise me not to empty if (obj = null)
- go语言实战-----31-----流媒体架构设计之直播架构、音视频通话(常见 流媒体协议 解释)
- Uninstall Oracle
- Ros2 learning notes (V) -- Summary of common instructions for ros2 command line operation (I)
- Oracle database management
- 税法18个税种全总结附记忆小口诀
- 关于TP5出现的一些错误
- Unmanned virtual simulation (XV) -- obstacle detection and recognition 1
- Database Basics
猜你喜欢

Alipay two faces: how to use UDP to achieve reliable transmission?

ONEFLOW's global tensor study notes and internship summary

解决方案| 快对讲调度系统:高效协作

Let others connect to their own MySQL database and share the MySQL database

嘉戎技術深交所上市破發:公司市值41億 應收賬款2.8億
Analysis of five data structures of redis
![[bjdctf2020] cookie is so stable (detailed explanation of vulnerability principle)](/img/ef/e05de7a94dc9c2398d714cbf30c4ec.png)
[bjdctf2020] cookie is so stable (detailed explanation of vulnerability principle)

An article gives you a preliminary understanding of the basic knowledge of C language operators

Knowledge of power system

Zabbix5 series - making topology map (XIII)
随机推荐
Ali II: can the main method be inherited?
Rasa对话机器人连载一 第121课:Rasa对话机器人Debugging项目实战之电商零售对话机器人运行流程调试全程演示-1
[bjdctf2020] cookie is so stable (detailed explanation of vulnerability principle)
Computer wechat built-in browser turns on debugging mode
wangEditor富文本编辑器使用、编辑器内容转json格式
Some errors in TP5
Third season recruitment of cognitive computing neuroscience online reading club
【云计算】3台虚拟机完成Spark Yarn集群部署并编写Scala应用程序实现单词计数统计
C language daily question -- [noip2008] ISBN number (question 76 of niuke.com)
Guitar music theory finishing
Alipay two faces: how to use UDP to achieve reliable transmission?
ECMAScript 6 -- Deconstruction and assignment of variables
The original test engineers who were promoted and raised were good at interface testing
别人写的叫博客,自己写的叫笔记
The wangeditor rich text editor uses and converts the content of the editor to JSON format
Volatile keyword
Oracle instance management
ForkJoin
Brief introduction of Bluetooth protocol stack
JS force deduction daily question (2022 / 4 / 21) --824 Goat Latin