function cnnnumgradcheck(net, x, y)
epsilon = 1e-4;
er = 1e-8;
n = numel(net.layers);
for j = 1 : numel(net.ffb)
net_m = net; net_p = net;
net_p.ffb(j) = net_m.ffb(j) + epsilon;
net_m.ffb(j) = net_m.ffb(j) - epsilon;
net_m = cnnff(net_m, x); net_m = cnnbp(net_m, y);
net_p = cnnff(net_p, x); net_p = cnnbp(net_p, y);
d = (net_p.L - net_m.L) / (2 * epsilon);
e = abs(d - net.dffb(j));
if e > er
error('numerical gradient checking failed');
end
end
for i = 1 : size(net.ffW, 1)
for u = 1 : size(net.ffW, 2)
net_m = net; net_p = net;
net_p.ffW(i, u) = net_m.ffW(i, u) + epsilon;
net_m.ffW(i, u) = net_m.ffW(i, u) - epsilon;
net_m = cnnff(net_m, x); net_m = cnnbp(net_m, y);
net_p = cnnff(net_p, x); net_p = cnnbp(net_p, y);
d = (net_p.L - net_m.L) / (2 * epsilon);
e = abs(d - net.dffW(i, u));
if e > er
error('numerical gradient checking failed');
end
end
end
for l = n : -1 : 2
if strcmp(net.layers{l}.type, 'c')
for j = 1 : numel(net.layers{l}.a)
net_m = net; net_p = net;
net_p.layers{l}.b{j} = net_m.layers{l}.b{j} + epsilon;
net_m.layers{l}.b{j} = net_m.layers{l}.b{j} - epsilon;
net_m = cnnff(net_m, x); net_m = cnnbp(net_m, y);
net_p = cnnff(net_p, x); net_p = cnnbp(net_p, y);
d = (net_p.L - net_m.L) / (2 * epsilon);
e = abs(d - net.layers{l}.db{j});
if e > er
error('numerical gradient checking failed');
end
for i = 1 : numel(net.layers{l - 1}.a)
for u = 1 : size(net.layers{l}.k{i}{j}, 1)
for v = 1 : size(net.layers{l}.k{i}{j}, 2)
net_m = net; net_p = net;
net_p.layers{l}.k{i}{j}(u, v) = net_p.layers{l}.k{i}{j}(u, v) + epsilon;
net_m.layers{l}.k{i}{j}(u, v) = net_m.layers{l}.k{i}{j}(u, v) - epsilon;
net_m = cnnff(net_m, x); net_m = cnnbp(net_m, y);
net_p = cnnff(net_p, x); net_p = cnnbp(net_p, y);
d = (net_p.L - net_m.L) / (2 * epsilon);
e = abs(d - net.layers{l}.dk{i}{j}(u, v));
if e > er
error('numerical gradient checking failed');
end
end
end
end
end
elseif strcmp(net.layers{l}.type, 's')
% for j = 1 : numel(net.layers{l}.a)
% net_m = net; net_p = net;
% net_p.layers{l}.b{j} = net_m.layers{l}.b{j} + epsilon;
% net_m.layers{l}.b{j} = net_m.layers{l}.b{j} - epsilon;
% net_m = cnnff(net_m, x); net_m = cnnbp(net_m, y);
% net_p = cnnff(net_p, x); net_p = cnnbp(net_p, y);
% d = (net_p.L - net_m.L) / (2 * epsilon);
% e = abs(d - net.layers{l}.db{j});
% if e > er
% error('numerical gradient checking failed');
% end
% end
end
end
% keyboard
end
离谱、
- 粉丝: 18
- 资源: 7
最新资源
- 基于labview的图像透明算法 1 将某个水印图片以透明度可调的方式插入另外一张大图 2 水印图片角度大小都可调整 3 纯labview代码
- Linux安全应急响应之日志分析
- 三菱FX3U与3台施耐德ATV12变频器通讯程序三菱FX3U与3台施耐德ATV12变频器通讯案例程序,有注释 并附送程序,有接线方式,设置 同时解决施耐德ATV变频器断电重启后,自准备工作,程序稳
- python基于机器学习SVM、KNN、决策树、朴素贝叶斯等算法数据分析案例(心脏病、癌症、糖尿病预测、数据分析等)集合源码+详细注释.zip
- l3-024 oriol和david 解题思路
- Mongodb客户端~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- 练习题(1.16).doc
- 7_base.apk.1
- stm32f103的Bootloader IAP串口升级stm32固件的资料,支持ymodem协议,aes256通信字段加密技术方案和学习资料,成熟产品方案已经用在批量产品上,资料包括上位机(电脑端)
- 解决Keil uVision5使用ST-LINK调试时软件闪退问题
- 基于微信小程序的后疫情时代高校宿舍管理系统小程序答辩PPT.pptx
- 基于微信小程序的高校报修与互助平台小程序答辩PPT.pptx
- 基于微信小程序的供货服务平台小程序答辩PPT.pptx
- 基于微信小程序的社区养老保险系统小程序答辩PPT.pptx
- 基于微信小程序的私家车位共享系统小程序答辩PPT.pptx
- 基于微信小程序的酒店管理系统小程序答辩PPT.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈