{"id":32995346,"url":"https://github.com/guanfuchen/cnn_np","last_synced_at":"2025-11-18T06:02:10.223Z","repository":{"id":134008123,"uuid":"129031866","full_name":"guanfuchen/cnn_np","owner":"guanfuchen","description":"使用numpy构建cnn复习深度学习知识","archived":false,"fork":false,"pushed_at":"2018-09-11T00:20:42.000Z","size":57,"stargazers_count":36,"open_issues_count":0,"forks_count":9,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-05-03T08:02:33.975Z","etag":null,"topics":["convolution","deep-learning","numpy"],"latest_commit_sha":null,"homepage":null,"language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/guanfuchen.png","metadata":{"files":{"readme":"ReadMe.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2018-04-11T03:56:49.000Z","updated_at":"2023-12-15T11:40:24.000Z","dependencies_parsed_at":null,"dependency_job_id":"17b2b206-af4d-49bc-b896-191f42d57f71","html_url":"https://github.com/guanfuchen/cnn_np","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/guanfuchen/cnn_np","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guanfuchen%2Fcnn_np","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guanfuchen%2Fcnn_np/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guanfuchen%2Fcnn_np/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guanfuchen%2Fcnn_np/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/guanfuchen","download_url":"https://codeload.github.com/guanfuchen/cnn_np/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guanfuchen%2Fcnn_np/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":285013741,"owners_count":27100053,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-11-18T02:00:05.759Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["convolution","deep-learning","numpy"],"created_at":"2025-11-13T12:00:21.873Z","updated_at":"2025-11-18T06:02:10.217Z","avatar_url":"https://github.com/guanfuchen.png","language":"Jupyter Notebook","funding_links":[],"categories":["Tutorials"],"sub_categories":["Tools Guidance"],"readme":"# cnn_np\n\n本仓库主要使用numpy来实现深度学习中常用的网络结构，复习深度学习相关知识。\n\n使用构造的网络模块搭建LeNet-5（结构参考Caffe实现）训练手写数字识别。\n\n![](http://chenguanfuqq.gitee.io/tuquan2/img_2018_4/lenet_caffe.png)\n\n---\n## 卷积\n\n卷积模块实现时，使用标准模块测试输入输出。\n\n卷积前向传播较为简单，只需要将权值转换为列向量，图像转换为列向量，然后按照矩阵乘法同时加上偏置在转换为图像即可。\n\n卷积反向传播较难，首先通过误差计算权值和偏置的梯度，然后计算该误差下一传播过程中的误差，该计算中注意误差需要通过pad然后转换为列向量，和权重上下翻转后相乘即可。\n\n[pytorch卷积实现conv.py](https://github.com/pytorch/pytorch/blob/master/torch/nn/modules/conv.py)\n\n[在 Caffe 中如何计算卷积？](https://www.zhihu.com/question/28385679/answer/44297845) 贾扬清讲解caffe中如何计算卷积。\n\n[Convolutional Neural Networks backpropagation: from intuition to derivation](https://grzegorzgwardys.wordpress.com/2016/04/22/8/)\n\n\n---\n# 池化层\n\n本仓库实现了MaxPool2d。\n\n[Convnet: Implementing Maxpool Layer with Numpy](https://wiseodd.github.io/techblog/2016/07/18/convnet-maxpool-layer/)\n\n---\n## 全连接层\n\n全连接层\n\n[linear.py](https://github.com/pytorch/pytorch/blob/master/torch/nn/modules/linear.py)\n\n\n---\n## Softmax层\n\nSoftmax层当前神经元的输出对当前的神经元的导数之和$-a_i*a_j$以及$a_i*(1-a_i)$。\n\n[softmax函数与交叉熵的反向梯度传导](https://blog.csdn.net/fireflychh/article/details/73794270) 本文介绍了softmax层的反向传播。\n\n\n---\n## 激活函数层\n\n[activation.py](https://github.com/pytorch/pytorch/blob/master/torch/nn/modules/activation.py) pytorch中激活函数设计参考。\n\n---\n## 损失函数层\n\nCrossEntropy层使用了one-hot编码的target。\n\n[pytorch loss function 总结](https://blog.csdn.net/zhangxb35/article/details/72464152) 其中介绍了pytorch中各个损失函数的关系，本仓库实现CrossEntropy包含LogSoftmax。\n\n[loss.py](https://github.com/pytorch/pytorch/blob/master/torch/nn/modules/loss.py) pytorch中相应的loss设计参考。\n\n[One Hot Encoding using numpy](https://stackoverflow.com/questions/38592324/one-hot-encoding-using-numpy)\n\n[numpy之one-hot](https://blog.csdn.net/he_wen_jie/article/details/78190517)\n\n---\n## 实现日志\n\n- [x] Conv2d\n- [x] Pool2d\n- [x] Linear\n- [x] Softmax\n- [x] CrossEntropy\n- [x] ReLU\n- [ ] LReLU\n\n---\n## 参考链接\n\n- [手把手带你用Numpy实现CNN \u003c零\u003e](https://zhuanlan.zhihu.com/p/33773140) 作者也是基于这个思路讲解项目思路。\n- [CNN-Numpy](https://github.com/wuziheng/CNN-Numpy) 代码可以参考。\n- [贾扬清分享_深度学习框架caffe](http://www.datakit.cn/blog/2015/06/12/online_meet_up_with_yangqing_jia.html) 贾扬清关于caffe的一些分享。\n- [Convolutional Neural Networks (CNNs / ConvNets)](http://cs231n.github.io/convolutional-networks/) cs231n中关于卷积的教程。\n- [Implementing convolution as a matrix multiplication](https://buptldy.github.io/2016/10/01/2016-10-01-im2col/) 实现卷积操作。\n- [lenet.prototxt](https://github.com/BVLC/caffe/blob/master/examples/mnist/lenet.prototxt) Caffe中关于LeNet-5的相关实现。\n- [Netscope](http://ethereon.github.io/netscope/quickstart.html) Netscope一款开源的网络可视化框架（支持caffe）。\n- [pytorch mnist code](https://github.com/pytorch/examples/blob/master/mnist/main.py) pytorch中mnist代码参考。\n- [pytorch modules](https://github.com/pytorch/pytorch/tree/master/torch/nn/modules) pytorch中深度学习模块实现列表。\n- [NumPyCNN](https://github.com/ahmedfgad/NumPyCNN) 使用np实现了卷积层、ReLU和最大池化层。\n- [nnet](https://github.com/andersbll/deeppy/tree/master/deeppy/expr/nnet) 用deeppy深度学习框架实现的细节。\n- [brainforge](https://github.com/csxeba/brainforge)，这是一个仅仅基于np实现的NN库，其中layers和optimization等，可以作为后期实现参考。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguanfuchen%2Fcnn_np","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fguanfuchen%2Fcnn_np","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguanfuchen%2Fcnn_np/lists"}