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

Bug in val code

Open aditya-malte opened this issue 7 years ago • 6 comments

While executing the val code, one gets an unexpected output for crowd count(something random). The probable cause is incorrect normalization values that are substracted. Using the same normalization as while training (using torch transform) seems to solve the problem.

A code akin to this should solve the issue:

im = Image.open(path).convert('RGB')

im = np.array(im)

im = im/255.0

im[:,:,0]=(im[:,:,0]-0.485)/0.229
im[:,:,1]=(im[:,:,1]-0.456)/0.224
im[:,:,2]=(im[:,:,2]-0.406)/0.225

Thank you!

aditya-malte avatar Oct 09 '18 19:10 aditya-malte

Thanks

leeyeehoo avatar Oct 19 '18 01:10 leeyeehoo

#img = transform(Image.open(img_paths[i]).convert('RGB')).cuda() while i just used the comment sentence, it can get the right results, and it not divide by 255. why do you think divided by 255 is needed?

linqiaozhou avatar Oct 23 '18 07:10 linqiaozhou

Hello, The transform method is defined in the val code as follows:

transform=transforms.Compose([
                       transforms.ToTensor(),transforms.Normalize(mean=[0.485, 0.456, 0.406],
                                     std=[0.229, 0.224, 0.225]),
                   ])

The transforms function actually scales the values to [0,1] from [0,255] (range of RGB) before normalization. In order to reduce dependencies(for another project), I had directly performed the operations myself and hence uploaded this code:


im = Image.open(path).convert('RGB')

im = np.array(im)

im = im/255.0

im[:,:,0]=(im[:,:,0]-0.485)/0.229
im[:,:,1]=(im[:,:,1]-0.456)/0.224
im[:,:,2]=(im[:,:,2]-0.406)/0.225

Thank you

aditya-malte avatar Oct 23 '18 08:10 aditya-malte

Well, I got, tks~

linqiaozhou avatar Oct 23 '18 08:10 linqiaozhou

You are welcome :)

aditya-malte avatar Oct 23 '18 08:10 aditya-malte

@leeyeehoo , Could you commit the updated snippet into repo?

amiltonwong avatar Nov 06 '18 13:11 amiltonwong