kuaikuaikim/dface

Expected object of type torch.DoubleTensor but found type torch.FloatTensor for argument #2 'weight'

zhukkang opened this issue · 10 comments

when test the model ,got the issue as below ,plz help to check the issue

RuntimeError Traceback (most recent call last)
in ()
17
18 print("start to detect ")
---> 19 bboxs, landmarks = mtcnn_detector.detect_face(img)
20 # print box_align
21

~/jupyter/DFACE/DFace/dface/core/detect.py in detect_face(self, img)
612 # pnet
613 if self.pnet_detector:
--> 614 boxes, boxes_align = self.detect_pnet(img)
615 if boxes_align is None:
616 return np.array([]), np.array([])

~/jupyter/DFACE/DFace/dface/core/detect.py in detect_pnet(self, im)
269
270 print('type of feed_imgs:',type(feed_imgs))
--> 271 cls_map, reg = self.pnet_detector(feed_imgs)
272
273 cls_map_np = image_tools.convert_chwTensor_to_hwcNumpy(cls_map.cpu())

/usr/local/lib/python3.5/dist-packages/torch/nn/modules/module.py in call(self, *input, **kwargs)
489 result = self._slow_forward(*input, **kwargs)
490 else:
--> 491 result = self.forward(*input, **kwargs)
492 for hook in self._forward_hooks.values():
493 hook_result = hook(self, input, result)

~/jupyter/DFACE/DFace/dface/core/models.py in forward(self, x)
95
96 def forward(self, x):
---> 97 x = self.pre_layer(x)
98 label = F.sigmoid(self.conv4_1(x))
99 offset = self.conv4_2(x)

I met the same problem, I fix this problem by change "image = image.astype(np.float)" to "image = image.astype(np.float32)" in fuction convert_image_to_tensor, which is in the file image_tools.py

@Lan-st I change "image = image.astype(np.float32)", got the new issues as below:
Traceback (most recent call last):
File "/Users/wangting/OneDrive/Pycharm/DeepLearning/dface/test_image.py", line 20, in
bboxs, landmarks = mtcnn_detector.detect_face(img)
File "/Users/wangting/OneDrive/Pycharm/DeepLearning/dface/dface/core/detect.py", line 618, in detect_face
boxes, boxes_align = self.detect_rnet(img, boxes_align)
File "/Users/wangting/OneDrive/Pycharm/DeepLearning/dface/dface/core/detect.py", line 390, in detect_rnet
tmp = np.zeros((tmph[i], tmpw[i], 3), dtype=np.float64)
ValueError: negative dimensions are not allowed

/usr/bin/python /Users/cgf/GitHub/GitWeb/dface/test_image.py
/Users/cgf/GitHub/GitWeb/dface/dface/core/models.py:8: UserWarning: nn.init.xavier_uniform is now deprecated in favor of nn.init.xavier_uniform_.
nn.init.xavier_uniform(m.weight.data)
/Users/cgf/GitHub/GitWeb/dface/dface/core/models.py:9: UserWarning: nn.init.constant is now deprecated in favor of nn.init.constant_.
nn.init.constant(m.bias, 0.1)
Traceback (most recent call last):
File "/Users/cgf/GitHub/GitWeb/dface/test_image.py", line 24, in
bboxs, landmarks = mtcnn_detector.detect_face(img)
File "/Users/cgf/GitHub/GitWeb/dface/dface/core/detect.py", line 638, in detect_face
boxes, boxes_align = self.detect_rnet(img, boxes_align)
File "/Users/cgf/GitHub/GitWeb/dface/dface/core/detect.py", line 393, in detect_rnet
tmp = np.zeros((tmph[i], tmpw[i], 3), dtype=np.uint8)
ValueError: negative dimensions are not allowed

Process finished with exit code 1
same question as wting861006

@wting861006,I meet the same error with you, but I am running the code in mac osx, it is ok if you use ubuntu. I think it may be a bug for mac running.

i also have same problem. i change the 'np.float', but it isn't solved.

@guanfuchen ,I uses ubuntu. But it is not solved

@wting861006 ,did you solved this problem?

@HPL123 You can try use pytorch version<=0.2.0.I sloved it when use version as 0.2.0.

@wting861006 ,Thanks,I solved it by deleting “image = image.astype(np.float)”

0xNF commented

With respect to the deletion of image = image.astype(np.float), I am running this unmodified on an ubuntu box and it works, but I have to delete this line to get it to work under Windows.

Does anyone have any insight as to what the differences could be? Does it come down to PyTorch version?