LTS4 / DeepFool

A simple and accurate method to fool deep neural networks
356 stars 130 forks source link

There is a error:must be real number, not map when run the test_deepfool.py #2

Closed zhjikoshlizhzc closed 5 years ago

zhjikoshlizhzc commented 5 years ago

File "C:\Users\acer\Anaconda3\lib\site-packages\torchvision\transforms\functional.py", line 207, in normalize std = torch.tensor(std, dtype=torch.float32)

TypeError: must be real number, not map

<Figure size 432x288 with 0 Axes>

zhjikoshlizhzc commented 5 years ago

Before I install cuda9.0,there is no error,but after I install cuda,this error occured.

File "", line 1, in runfile('D:/Graduate/DeepFool-master/DeepFool-master/Python/test_deepfool.py', wdir='D:/Graduate/DeepFool-master/DeepFool-master/Python')

File "C:\Users\acer\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 704, in runfile execfile(filename, namespace)

File "C:\Users\acer\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 108, in execfile exec(compile(f.read(), filename, 'exec'), namespace)

File "D:/Graduate/DeepFool-master/DeepFool-master/Python/test_deepfool.py", line 60, in plt.imshow(tf(pert_image.cuda()[0]))

File "C:\Users\acer\Anaconda3\lib\site-packages\torchvision\transforms\transforms.py", line 60, in call img = t(img)

File "C:\Users\acer\Anaconda3\lib\site-packages\torchvision\transforms\transforms.py", line 163, in call return F.normalize(tensor, self.mean, self.std, self.inplace)

File "C:\Users\acer\Anaconda3\lib\site-packages\torchvision\transforms\functional.py", line 207, in normalize std = torch.tensor(std, dtype=torch.float32)

TypeError: must be real number, not map

<Figure size 432x288 with 0 Axes>

YogaLYJ commented 5 years ago

I use python 3.7. Pytorch 0.4.1. After "map" in line 62 , std and mean are map not list, you need to transfer it into list. Original code: tf = transforms.Compose([transforms.Normalize(mean=[0, 0, 0],std=map(lambda x: 1 / x, std)), transforms.Normalize(mean=map(lambda x: -x, mean), std=[1, 1, 1]), transforms.Lambda(clip), transforms.ToPILImage(), transforms.CenterCrop(224)]) Change into: tf = transforms.Compose([transforms.Normalize(mean=[0, 0, 0], std=list(map(lambda x: 1 / x, std))), transforms.Normalize(mean=list(map(lambda x: -x, mean)), std=[1, 1, 1]), transforms.Lambda(clip), transforms.ToPILImage(), transforms.CenterCrop(224)])

zhjikoshlizhzc commented 5 years ago

Thanks a lot,this error is completed fixed!Thanks !