MSCNN估计人流密度
收藏
本文记录参加“深度学习7日入门-CV疫情特辑”课程中的“人流密度估计”比赛所用的算法,虽然并没有达到很好的名次,但是初识了PaddlePaddle,更重要的是还有免费V100 GPU算力可以蹭,正好后面会有一些项目,想要在AI Studio上用免费GPU进行验证,所以在此记录下这次比赛所用的算法,顺便攒一攒算力卡~~
本次用的是MSCNN,基于人流密度图来估计人流数量的算法。MSCNN可以说是人流密度估计方法的始祖(古董)了,但是很有助于理解人流密度估计关键模型的原理,何况本人也是刚刚接触Paddle,就先拿来练练手吧。
直接上代码:
def MSCNN(x):
x = fluid.layers.conv2d(input=x, num_filters=64, filter_size=9, padding=4, act='relu')
x1_1 = fluid.layers.conv2d(input=x, num_filters=64, filter_size=9, padding=4, act='relu')
x1_2 = fluid.layers.conv2d(input=x, num_filters=64, filter_size=7, padding=3, act='relu')
x1_3 = fluid.layers.conv2d(input=x, num_filters=64, filter_size=5, padding=2, act='relu')
x1_4 = fluid.layers.conv2d(input=x, num_filters=64, filter_size=3, padding=1, act='relu')
x = fluid.layers.concat(input=[x1_1, x1_2, x1_3, x1_4], axis=1)
x = fluid.layers.batch_norm(input=x, act=None)
x = fluid.layers.pool2d(input=x, pool_size=2, pool_stride=2, pool_type='max')
x2_1 = fluid.layers.conv2d(input=x, num_filters=128, filter_size=9, padding=4, act='relu')
x2_2 = fluid.layers.conv2d(input=x, num_filters=128, filter_size=7, padding=3, act='relu')
x2_3 = fluid.layers.conv2d(input=x, num_filters=128, filter_size=5, padding=2, act='relu')
x2_4 = fluid.layers.conv2d(input=x, num_filters=128, filter_size=3, padding=1, act='relu')
x = fluid.layers.concat(input=[x2_1, x2_2, x2_3, x2_4], axis=1)
x = fluid.layers.batch_norm(input=x, act=None)
x3_1 = fluid.layers.conv2d(input=x, num_filters=128, filter_size=9, padding=4, act='relu')
x3_2 = fluid.layers.conv2d(input=x, num_filters=128, filter_size=7, padding=3, act='relu')
x3_3 = fluid.layers.conv2d(input=x, num_filters=128, filter_size=5, padding=2, act='relu')
x3_4 = fluid.layers.conv2d(input=x, num_filters=128, filter_size=3, padding=1, act='relu')
x = fluid.layers.concat(input=[x3_1, x3_2, x3_3, x3_4], axis=1)
x = fluid.layers.batch_norm(input=x, act=None)
x = fluid.layers.pool2d(input=x, pool_size=2, pool_stride=2, pool_type='max')
x4_1 = fluid.layers.conv2d(input=x, num_filters=64, filter_size=7, padding=3, act='relu')
x4_2 = fluid.layers.conv2d(input=x, num_filters=64, filter_size=5, padding=2, act='relu')
x4_3 = fluid.layers.conv2d(input=x, num_filters=64, filter_size=3, padding=1, act='relu')
x = fluid.layers.concat(input=[x4_1, x4_2, x4_3], axis=1)
x = fluid.layers.batch_norm(input=x, act='relu')
x5_1 = fluid.layers.conv2d(input=x, num_filters=64, filter_size=7, padding=3, act='relu')
x5_2 = fluid.layers.conv2d(input=x, num_filters=64, filter_size=5, padding=2, act='relu')
x5_3 = fluid.layers.conv2d(input=x, num_filters=64, filter_size=3, padding=1, act='relu')
x = fluid.layers.concat(input=[x5_1, x5_2, x5_3], axis=1)
x = fluid.layers.batch_norm(input=x, act='relu')
x = fluid.layers.pool2d(input=x, pool_size=2, pool_stride=2, pool_type='max')
x = fluid.layers.conv2d(input=x, num_filters=1000, filter_size=1, act='relu')
x = fluid.layers.conv2d(input=x, num_filters=1, filter_size=1, act=None)
x = fluid.layers.sigmoid(x)
x = fluid.layers.relu(x)
print('output x.shape:', x.shape)
return x
可以看到,这个实际上可以理解成是多尺度的一个VGG,并且通过使用合适的filter_size,padding,使得卷积层的输入输出的宽高不变,所以输入网络的图像,最终的大小就由pooling层决定。因为使用了3个2*2的pooling,所以实际上输入的图像,输出的宽高是降采样了8倍,也就是宽高变为原来的八分之一。
技术心得的提交时间快截至了,就先写这么多,后面再来分享。。。。
0
收藏
请登录后评论
很认真 不错
棒!最后结果怎么样呀
棒 公开完整项目吧
可以,飞桨新人学习了