{"id":16932959,"url":"https://github.com/drryanhuang/mcnn_paddlepaddle","last_synced_at":"2025-10-07T04:35:51.262Z","repository":{"id":54146093,"uuid":"282385853","full_name":"DrRyanHuang/MCNN_Paddlepaddle","owner":"DrRyanHuang","description":"使用paddlepaddle复现人群计数论文MCNN","archived":false,"fork":false,"pushed_at":"2021-03-08T01:22:02.000Z","size":15162,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-11T18:53:12.958Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DrRyanHuang.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-07-25T06:29:49.000Z","updated_at":"2024-09-13T09:36:06.000Z","dependencies_parsed_at":"2022-08-13T07:31:29.148Z","dependency_job_id":null,"html_url":"https://github.com/DrRyanHuang/MCNN_Paddlepaddle","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/DrRyanHuang/MCNN_Paddlepaddle","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DrRyanHuang%2FMCNN_Paddlepaddle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DrRyanHuang%2FMCNN_Paddlepaddle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DrRyanHuang%2FMCNN_Paddlepaddle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DrRyanHuang%2FMCNN_Paddlepaddle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DrRyanHuang","download_url":"https://codeload.github.com/DrRyanHuang/MCNN_Paddlepaddle/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DrRyanHuang%2FMCNN_Paddlepaddle/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278722727,"owners_count":26034461,"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-10-07T02:00:06.786Z","response_time":59,"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":[],"created_at":"2024-10-13T20:48:08.441Z","updated_at":"2025-10-07T04:35:51.231Z","avatar_url":"https://github.com/DrRyanHuang.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e- MCNN论文复现 -\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"https://img.shields.io/badge/version-2020.07.27-green.svg?longCache=true\u0026style=for-the-badge\"\u003e\n\u003cimg src=\"https://img.shields.io/badge/license-GPL%20(%3E%3D%202)-blue.svg?longCache=true\u0026style=for-the-badge\"\u003e\n\u003c/p\u003e\n\n\n\u003cbr/\u003e\n\u003cbr/\u003e\n\n\u003cimg src=\"https://github.com/DrRyanHuang/MCNN_Paddlepaddle/blob/master/src/author.png\"  alt=\"author\" /\u003e\n\n\u003cbr/\u003e\n\u003cbr/\u003e\n\n\u003cp\u003e\n\u003ca href=https://www.cv-foundation.org/openaccess/content_cvpr_2016/papers/Zhang_Single-Image_Crowd_Counting_CVPR_2016_paper.pdf\u003eMCNN\u003c/a\u003e是CVPR2016年的一篇论文, 作者提出了一种简单而有效的\u003cb\u003e多列卷积神经网络架构(Multi-column Convolutional Neural Network, MCNN)\u003c/b\u003e，通过使用大小不同的卷积核去适应人/头部大小的变化，以将图片映射为人群密度图。作者在文章中使用了\u003cb\u003e几何自适应高斯核\u003c/b\u003e去计算人群密度图(Ground Truth)，同时收集并标记了一个大型的新数据集(ShanghaiTech数据集)，其中包括1198幅图像，数据集可以在AI Studio上下载到: https://aistudio.baidu.com/aistudio/datasetdetail/10675 .\n\u003c/p\u003e\n\n\n\u003cbr/\u003e\n\u003cbr/\u003e\n\n\u003cp\u003e\nMCNN受MDNNs的启发，由三列并行的CNN组成，每列CNN卷积核大小不同。为了简化，所有列使用相同的网络结构(即conv-pooling-conv-pooling)。每次池化都会使用2*2的Max Pooling，而激活函数全部选择Relu。堆叠三列CNN的输出特征图，并使用1*1的卷积核将其映射为密度图。MCNN的整体架构图如\u003cb\u003eFigure 1\u003c/b\u003e所示：\n\u003c/p\u003e\n\n\u003cbr/\u003e\n\n\u003cimg src=\"https://github.com/DrRyanHuang/MCNN_Paddlepaddle/blob/master/src/archit.png\"  alt=\"archit\" width=\"1000\" height=\"400\"/\u003e\n\n\u003cp align=\"center\"\u003e\u003cb\u003e图 1\u003c/b\u003e：用于人群密度图估计的多列卷积神经网络(MCNN)的结构\u003cbr/\u003e\n\u003cb\u003eFigure 1\u003c/b\u003e：The structure of the proposed multi-column convolutional neural network for crowd density map estimation.\u003c/p\u003e\n\u003cbr/\u003e\n\u003cbr/\u003e\n\n\u003cp\u003e\nMCNN在训练时，存在\u003cb\u003e数据样本少和梯度消失\u003c/b\u003e的问题，受预训练模型RBM的启发，作者将三列CNN单独进行预训练，将这些预训练的CNN参数初始化为对应的MCNN参数并微调。需要补充的是，MCNN使用了最简单的均方误差作为损失函数。\n\u003c/p\u003e\n\n\u003cbr/\u003e\n\n\u003cp\u003e\n论文中使用\u003cb\u003e几何自适应高斯核\u003c/b\u003e去计算数据图片的Ground Truth：\n\u003c/p\u003e\n\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"https://github.com/DrRyanHuang/MCNN_Paddlepaddle/blob/master/src/formula.jpeg\"  alt=\"公式\" width=\"650\" height=\"300\"/\u003e\n\u003c/p\u003e\n\n\n\u003cp\u003e\n在\u003cb\u003eFigure 2\u003c/b\u003e中，显示了两张图片的人群密度图。值得说明的是，由于经过了两次下采样，所以预测出人群密度图的分辨率变为原来的1/4.\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"https://github.com/DrRyanHuang/MCNN_Paddlepaddle/blob/master/src/figure2.png\"  alt=\"figure2\"/\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n\u003cb\u003e图 2\u003c/b\u003e：原始图像和通过几何自适应高斯核进行卷积获得的相应的人群密度图。\u003c/br\u003e\n\u003cb\u003eFigure 2\u003c/b\u003e：Original images and corresponding crowd density maps obtained by convolving geometry-adaptive Gaussian kernels.\n\u003c/p\u003e\n\n\n\u003cp\u003e\nMCNN几乎可以从任何观察角度准确估计单个图像中的人群数，在2016年，取得了人群计数领域\u003cb\u003estate-of-art\u003c/b\u003e的成绩。同时作者还指出，仅需要对模型最后几层进行微调，便可以将模型轻松迁移到目标问题，验证了模型的鲁棒性。\u003c/br\u003e\u003c/br\u003e在论文中，还有很多细节，本篇不再赘述，可以查看原论文\u003ca href=https://www.cv-foundation.org/openaccess/content_cvpr_2016/papers/Zhang_Single-Image_Crowd_Counting_CVPR_2016_paper.pdf\u003eMCNN\u003c/a\u003e\n\u003c/p\u003e\n\n##### 1.基于\u003cb\u003e飞桨开源框架(Paddlepaddle)\u003c/b\u003e复现MCNN\n\n环境依赖:\n\n```shell\npaddlepaddle \u003e= 1.7.0\nnumpy\nmatplotlib\nPIL \nopencv-python\n```\n\n##### 2. 训练策略\n\tMCNN受到预训练模型的启发，先将三列CNN单独训练，之后将CNN的参数初始化为MCNN对应的参数之后，整体再进行训练，在原论文中，训练策略为批随机梯度下降法。\n\n##### 3.模型复现效果\n\n我们可以对比使用飞桨的训练效果和原论文的训练效果，可以看出在AI Studio平台的算力加持下，基于飞桨的训练效果更加精确，多了更多细节.\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"https://github.com/DrRyanHuang/MCNN_Paddlepaddle/blob/master/src/figure3.png\"  alt=\"figure3\"/\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n\u003cb\u003e图 3\u003c/b\u003e：原论文中两张测试集图片的结果对比，从左到右分别是原图,\nGround True,原论文复现图和基于飞桨的复现结果图\u003c/br\u003e\n\u003cb\u003eFigure 3\u003c/b\u003e：Comparing results\n\u003c/p\u003e\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrryanhuang%2Fmcnn_paddlepaddle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrryanhuang%2Fmcnn_paddlepaddle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrryanhuang%2Fmcnn_paddlepaddle/lists"}