simple-faster-rcnn-pytorch icon indicating copy to clipboard operation
simple-faster-rcnn-pytorch copied to clipboard

RuntimeError: Expected object of type torch.DoubleTensor but found type torch.FloatTensor for argument #4 'other'

Open zhengxinvip opened this issue 5 years ago • 9 comments

pytorch 4.0.1 windows: 10 cuda: 9.0 python: 3.6 when I run the demo:

trainer.load('C:\Users\25118\.torch\models\fasterrcnn_12211511_0.701052458187_torchvision_pretrain.pth') opt.caffe_pretrain=False # this model was trained from torchvision-pretrained model _bboxes, _labels, _scores = trainer.faster_rcnn.predict(img,visualize=True) vis_bbox(at.tonumpy(img[0]), at.tonumpy(_bboxes[0]), at.tonumpy(_labels[0]).reshape(-1), at.tonumpy(_scores[0]).reshape(-1))

it failed to find the dog, but if you set threshold from 0.7 to 0.6, you'll find it

I got this error:

RuntimeError Traceback (most recent call last) in () 1 trainer.load('C:\Users\25118\.torch\models\fasterrcnn_12211511_0.701052458187_torchvision_pretrain.pth') 2 opt.caffe_pretrain=False # this model was trained from torchvision-pretrained model ----> 3 _bboxes, _labels, _scores = trainer.faster_rcnn.predict(img,visualize=True) 4 vis_bbox(at.tonumpy(img[0]), 5 at.tonumpy(_bboxes[0]),

C:\Users\25118\Anaconda3\lib\site-packages\model\faster_rcnn.py in new_f(*args, **kwargs) 17 def new_f(*args,**kwargs): 18 with t.no_grad(): ---> 19 return f(*args,**kwargs) 20 return new_f 21

C:\Users\25118\Anaconda3\lib\site-packages\model\faster_rcnn.py in predict(self, imgs, sizes, visualize) 220 for img in imgs: 221 size = img.shape[1:] --> 222 img = preprocess(at.tonumpy(img)) 223 prepared_imgs.append(img) 224 sizes.append(size)

C:\Users\25118\Anaconda3\lib\site-packages\data\dataset.py in preprocess(img, min_size, max_size) 72 else: 73 normalize = pytorch_normalze ---> 74 return normalize(img) 75 76

C:\Users\25118\Anaconda3\lib\site-packages\data\dataset.py in pytorch_normalze(img) 25 normalize = tvtsf.Normalize(mean=[0.485, 0.456, 0.406], 26 std=[0.229, 0.224, 0.225]) ---> 27 img = normalize(t.from_numpy(img)).float() 28 return img.numpy() 29

C:\Users\25118\Anaconda3\lib\site-packages\torchvision\transforms\transforms.py in call(self, tensor) 161 Tensor: Normalized Tensor image. 162 """ --> 163 return F.normalize(tensor, self.mean, self.std, self.inplace) 164 165 def repr(self):

C:\Users\25118\Anaconda3\lib\site-packages\torchvision\transforms\functional.py in normalize(tensor, mean, std, inplace) 206 mean = torch.tensor(mean, dtype=torch.float32) 207 std = torch.tensor(std, dtype=torch.float32) --> 208 tensor.sub_(mean[:, None, None]).div_(std[:, None, None]) 209 return tensor 210

RuntimeError: Expected object of type torch.DoubleTensor but found type torch.FloatTensor for argument #4 'other' what should I do to fix it? thanks for your answer!

zhengxinvip avatar Jun 01 '19 03:06 zhengxinvip

i meet the same error

mengce97 avatar Jun 03 '19 07:06 mengce97

i meet the same error

did you fix it?

zhengxinvip avatar Jun 04 '19 12:06 zhengxinvip

i meet the same error

did you fix it?

I have the same error!Did you saved this?

BCWang93 avatar Jun 14 '19 14:06 BCWang93

i meet the same error

did you fix it?

I have the same error!Did you saved this?

no how about you?

zhengxinvip avatar Jun 21 '19 09:06 zhengxinvip

i meet the same error did you fix it? I have the same error!Did you saved this?

no how about you?

I change some code in the dataset.py pytorch_normalize img = normalize(t.from_numpy(img))to img = normalize(t.from_numpy(img)).float().It can run normaly.You can test it.

BCWang93 avatar Jun 21 '19 10:06 BCWang93

def pytorch_normalze(img): """ https://github.com/pytorch/vision/issues/223 return appr -1~1 RGB """ tensor = t.from_numpy(img) dtype = tensor.dtype mean = [0.485, 0.456, 0.406] std = [0.229, 0.224, 0.225] mean = t.as_tensor(mean, dtype=dtype, device=tensor.device) std = t.as_tensor(std, dtype=dtype, device=tensor.device) tensor.sub_(mean[:, None, None]).div_(std[:, None, None]) return tensor.numpy()

YangYangGirl avatar Jun 27 '19 15:06 YangYangGirl

i meet the same error. @YangYangGirl's code is right. thanks!

fmscole avatar Aug 15 '19 15:08 fmscole

the solutions mentioned above do not work for me. any other solutions?

7-qiliu avatar Aug 25 '19 03:08 7-qiliu

the solutions mentioned above do not work for me. any other solutions?

metoo, and now? how did u fix it?

Leonliou avatar Dec 03 '19 10:12 Leonliou