chenyuntc / simple-faster-rcnn-pytorch

A simplified implemention of Faster R-CNN that replicate performance from origin paper
Other
3.99k stars 1.14k forks source link

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

Open zhengxinvip opened 5 years ago

zhengxinvip commented 5 years ago

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!
mengce97 commented 5 years ago

i meet the same error

zhengxinvip commented 5 years ago

i meet the same error

did you fix it?

BCWang93 commented 5 years ago

i meet the same error

did you fix it?

I have the same error!Did you saved this?

zhengxinvip commented 5 years ago

i meet the same error

did you fix it?

I have the same error!Did you saved this?

no how about you?

BCWang93 commented 5 years ago

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.

YangYangGirl commented 5 years ago

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.astensor(std, dtype=dtype, device=tensor.device) tensor.sub(mean[:, None, None]).div_(std[:, None, None]) return tensor.numpy()

fmscole commented 5 years ago

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

7-qiliu commented 5 years ago

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

Leonliou commented 4 years ago

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

metoo, and now? how did u fix it?