项目作者: embracesource-cv-com

项目描述 :
keras实现的人群密度检测网络"Single Image Crowd Counting via Multi Column Convolutional Neural Network",欢迎试用、关注并反馈问题...
高级语言: Python
项目地址: git://github.com/embracesource-cv-com/keras-mcnn.git
创建时间: 2019-04-01T09:22:47Z
项目社区:https://github.com/embracesource-cv-com/keras-mcnn

开源协议:Apache License 2.0

关键词:
crowd-analysis crowd-counting

下载


keras-mcnn

keras复现人群数量估计网络“Single Image Crowd Counting via Multi Column Convolutional Neural Network”

参考pytorch版:https://github.com/svishwa/crowdcount-mcnn

安装

  1. Clone

    1. git clone https://github.com/embracesource-cv-com/keras-mcnn.git
  2. 安装依赖库

    1. cd keras-mcnn
    2. pip install -r requirements.txt

数据配置

  1. 下载ShanghaiTech数据集:
    Dropbox
    or 百度云盘

  2. 创建数据存放目录$ORIGIN_DATA_PATH

    1. mkdir /opt/dataset/crowd_counting/shanghaitech/original
  3. part_A_finalpart_B_final存放到$ORIGIN_DATA_PATH目录下

  4. 生成测试集的ground truth文件

    1. python create_gt_test_set_shtech.py [A or B] # Part_A or Part_B

    生成好的ground-truth文件将会保存在$TEST_GT_PATH/test_data/ground_truth_csv目录下

  5. 生成训练集和验证集

    1. python create_training_set_shtech.py [A or B]

    生成好的数据保存将会在$TRAIN_PATH、$TRAIN_GT_PATH、$VAL_PATH、$VAL_GT_PATH目录下

  6. 生成热力图
    如果你想生成测试集的ground truth热力图:

    1. python create_heatmaps.py [A or B]

2~6步均在工程根目录下操作

测试

a)下载训练模型

mcnn-A.160.h5mcnn-B.035.h5

b) 如下命令分别测试A和B

  1. python test.py --dataset A --weight_path /tmp/mcnn-A.160.h5 --output_dir /tmp/mcnn_A
  2. python test.py --dataset B --weight_path /tmp/mcnn-B.035.h5 --output_dir /tmp/mcnn_B

训练

如果你想自己训练模型,很简单:

  1. python train.py [A or B]

结果

  1. | | MAE | MSE |
  2. ----------------------------
  3. | Part_A | 127.88 | 194.19 |
  4. ----------------------------
  5. | Part_B | 30.71 | 46.81 |

改进点

​ 由于GT密度图每个像素点的值都很小(A数据集平均为0.02,B数据集平均为0.002),这样小的值不利于网络优化,因此对GT做了标准化(减去均值,然后除方差);预测时将预测的值先乘方差,再加上均值,就是最终的预测值。这个改进对最终的结果提升明显,使用标准化后,A数据集的MAE127.88没有使用标准化时只有154.7

样例

Part_A
原图:
原图
Ground Truth (1111) & Estimate (1256):
GT Estimate

Part_B
原图:
原图
Ground Truth (252) & Estimate(242):
GT Estimate