leeyeehoo / CSRNet-pytorch

CSRNet: Dilated Convolutional Neural Networks for Understanding the Highly Congested Scenes
642 stars 259 forks source link

validation yields very high crowd counts on the pretrained model #23

Open abuvaneswari opened 5 years ago

abuvaneswari commented 5 years ago

Hello,

Thanks a lot for the very easy-to-follow instructions and the code. I am having difficulty reproducing your results. I am using your pretrained model 'PartAmodel_best.pth.tar'. And I am using the test_data set of ShanghaiTech. Getting very high MAE - in the 1000's.

PyTorch 0.4.1 CUDA 9.0 Python 2.7

Please let me know if I am doing anything wrong. Thanks, Buvana

Snippet of code (based on your val.ipynb) and result:

model = CSRNet()
model = model.cuda()
checkpoint = torch.load('PartAmodel_best.pth.tar')
model.load_state_dict(checkpoint['state_dict'])

import random
n=random.randint(0,182)
image_file=img_paths[n]
print n, image_file

17 /home/scene/CSRNet-pytorch/ShanghaiTech/part_A/test_data/images/IMG_34.jpg

gt_file = h5py.File(image_file.replace('.jpg','.h5').replace('images','ground-truth'),'r')
groundtruth = np.asarray(gt_file['density'])
print np.sum(groundtruth)
plt.imshow(groundtruth,cmap=CM.jet)

84.752235

img = 255.0 * F.to_tensor(Image.open(image_file).convert('RGB'))
img[0,:,:]=img[0,:,:]-92.8207477031
img[1,:,:]=img[1,:,:]-95.2757037428
img[2,:,:]=img[2,:,:]-104.877445883

img = img.cuda()
output = model(img.unsqueeze(0))
print (output.detach().cpu().sum().numpy(), np.sum(groundtruth))
630.8671 84.752235

mae=abs(output.detach().cpu().sum().numpy()-np.sum(groundtruth))
print mae
546.11487

image image image

linqiaozhou commented 5 years ago

I also meet this problem, it seems that right results can be output when change the image reading method as the comment sentence.

img = transform(Image.open(img_paths[i]).convert('RGB')).cuda()

talentCODE commented 3 years ago

did you solve the problem? I also find the pretrained model not works well. I'm new at the crowd counting field