CSRNet-pytorch icon indicating copy to clipboard operation
CSRNet-pytorch copied to clipboard

How to get the count from the density map

Open twmht opened this issue 7 years ago • 6 comments

Hi,

you said that the method to generate ground truth is from https://arxiv.org/abs/1608.06197

from that paper, they said

We generate our ground truth by simply blurring each head annotation using a Gaussian kernel normalized to sum to one. This kind of blurring causes the sum of the density map to be the same as the total number of people in the crowd

But I found that the sum of the density map is not exactly the same of the total number of people.

Here is what I've done

img_path = '/home/tumh/crowd/part_A_final/train_data/images/IMG_211.jpg'
mat = io.loadmat(img_path.replace('.jpg','.mat').replace('images','ground_truth').replace('IMG_','GT_IMG_'))
img= plt.imread(img_path)
k = np.zeros((img.shape[0],img.shape[1]))
gt = mat["image_info"][0,0][0,0][0]

for i in range(0,len(gt)):
    if int(gt[i][1])<img.shape[0] and int(gt[i][0])<img.shape[1]:
        k[int(gt[i][1]),int(gt[i][0])]=1
k = gaussian_filter_density(k)
print np.sum(k)
assert(np.sum(k) == len(gt)) 

would result

Traceback (most recent call last):
  File "make_dataset.py", line 71, in <module>
    assert(np.sum(k) == len(gt)), '{}!= {}'.format(np.sum(k), len(gt))
AssertionError: 185.91192627!= 188

the ground truth is 188, but from the sum of the density map, the count is 185.91192627.

Any advise?

twmht avatar Aug 22 '18 08:08 twmht

@twmht I guess if the map is large enough(ideal), the sum is strictly equals to the ground truth. However, the map has fixed size, after the blurring some points near the map edge, a considerable amount of the countNum were 'crop' by the map edge.

MSoulPlayer avatar Aug 22 '18 10:08 MSoulPlayer

That's right. You can still normalize your intensity values of your Gaussian spread to 1 after cropping, but that would also create an incorrect depiction of the crowdedness for the corresponding area.

BedirYilmaz avatar Aug 24 '18 03:08 BedirYilmaz

You can get count m in the mat through the code below

    mat_file = loadmat(mat_path)
    value_1=mat_file['image_info']
    m,n=value_1[0][0][0][0][0].shape
    print('there are %d people in this image'%m)

SummerHuiZhang avatar Jun 05 '19 09:06 SummerHuiZhang

Hi,

you said that the method to generate ground truth is from https://arxiv.org/abs/1608.06197

from that paper, they said

We generate our ground truth by simply blurring each head annotation using a Gaussian kernel normalized to sum to one. This kind of blurring causes the sum of the density map to be the same as the total number of people in the crowd

But I found that the sum of the density map is not exactly the same of the total number of people.

Here is what I've done

img_path = '/home/tumh/crowd/part_A_final/train_data/images/IMG_211.jpg'
mat = io.loadmat(img_path.replace('.jpg','.mat').replace('images','ground_truth').replace('IMG_','GT_IMG_'))
img= plt.imread(img_path)
k = np.zeros((img.shape[0],img.shape[1]))
gt = mat["image_info"][0,0][0,0][0]

for i in range(0,len(gt)):
    if int(gt[i][1])<img.shape[0] and int(gt[i][0])<img.shape[1]:
        k[int(gt[i][1]),int(gt[i][0])]=1
k = gaussian_filter_density(k)
print np.sum(k)
assert(np.sum(k) == len(gt)) 

would result

Traceback (most recent call last):
  File "make_dataset.py", line 71, in <module>
    assert(np.sum(k) == len(gt)), '{}!= {}'.format(np.sum(k), len(gt))
AssertionError: 185.91192627!= 188

the ground truth is 188, but from the sum of the density map, the count is 185.91192627.

Any advise?

how did you use the Gaussian kernel to blur each head annotation? whats code do we use to blur the head

kevinkwabena avatar Mar 09 '20 04:03 kevinkwabena

@BedirYilmaz can you please help me how to calculate PSNR and SSIM of CSRNet model

Akbarkhan87 avatar Oct 13 '21 01:10 Akbarkhan87