深度学习Matlab工具箱代码注释之cnnapplygrads.m

 

  1.  

  2. 函数名称:cnnapplygrads(),权值更新函数

  3. 输入参数:net,权值待更新的卷积神经网络;opts,神经网络训练的相关参数

  4. 输出参数:

  5. 算法流程:先更新卷积层的参数,再更新全连接层参数

  6. 注意事项:

  7.  

  8. function net = cnnapplygrads(net, opts)

  9. for l = 2 : numel(net.layers)

  10. if strcmp(net.layers{l}.type, 'c')

  11. for j = 1 : numel(net.layers{l}.a)

  12. for ii = 1 : numel(net.layers{l - 1}.a)

  13.  

  14. %这里没什么好说的,就是普通的权值更新的公式:W_new = W_old - alpha * de/dW(误差对权值导数)

  15. net.layers{l}.k{ii}{j} = net.layers{l}.k{ii}{j} - opts.alpha * net.layers{l}.dk{ii}{j};

  16. end

  17. net.layers{l}.b{j} = net.layers{l}.b{j} - opts.alpha * net.layers{l}.db{j};

  18. end

  19. end

  20. end

  21.  

  22. net.ffW = net.ffW - opts.alpha * net.dffW;

  23. net.ffb = net.ffb - opts.alpha * net.dffb;

  24. end

免责声明:信息仅供参考,不构成投资及交易建议。投资者据此操作,风险自担。
如果觉得文章对你有用,请随意赞赏收藏
相关推荐
相关下载
登录后评论
Copyright © 2019 宽客在线