TypeError: pad(): argument 'value' (position 4) must be float, not Tensor #215
Unanswered
rajaankit13
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have converted a Caffe model to onnx model using caffe2onnx, then used onnx2pytorch to convert my onnx model to pytorch model. Now when I pass an image as input to the model I get the below error. I am unable to understand how to fix it.
My Caffe model is a hand keypoint detection model:
pose_deploy.prototxt
pose_iter_102000.caffemodel)
Here is my code:
import torch
import cv2
import numpy as np
model_path = "/hand/pose_deploy.pth"
model = torch.load(model_path)
model.eval()
image_path = "/hand1.jpeg"
image = cv2.imread(image_path)
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
image_resized = cv2.resize(image_rgb, (224, 224))
image_normalized = image_resized / 255.0 # Assuming the image is in the range [0, 255]
image_tensor = torch.tensor(image_normalized.transpose(2, 0, 1), dtype=torch.float32)
image_tensor = image_tensor.unsqueeze(0)
with torch.no_grad():
output, x = model(image_tensor) # Add a batch dimension
TypeError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_15900\3745826071.py in
2 with torch.no_grad():
3 #image_tensor = image_tensor.to(device)
----> 4 output, x = model(image_tensor) # Add a batch dimension
5
6 # Postprocess the keypoints (if necessary)
~\anaconda3\lib\site-packages\torch\nn\modules\module.py in _wrapped_call_impl(self, *args, **kwargs)
1509 return self._compiled_call_impl(*args, **kwargs) # type: ignore[misc]
1510 else:
-> 1511 return self._call_impl(*args, **kwargs)
1512
1513 def _call_impl(self, *args, **kwargs):
~\anaconda3\lib\site-packages\torch\nn\modules\module.py in _call_impl(self, *args, **kwargs)
1518 or _global_backward_pre_hooks or _global_backward_hooks
1519 or _global_forward_hooks or _global_forward_pre_hooks):
-> 1520 return forward_call(*args, **kwargs)
1521
1522 try:
~\anaconda3\lib\site-packages\onnx2pytorch\convert\model.py in forward(self, *input_list, **input_dict)
222 activations[out_op_id] = output
223 else:
--> 224 activations[out_op_id] = op(*in_activations)
225
226 # Remove activations that are no longer needed
~\anaconda3\lib\site-packages\torch\nn\modules\module.py in _wrapped_call_impl(self, *args, **kwargs)
1509 return self._compiled_call_impl(*args, **kwargs) # type: ignore[misc]
1510 else:
-> 1511 return self._call_impl(*args, **kwargs)
1512
1513 def _call_impl(self, *args, **kwargs):
~\anaconda3\lib\site-packages\torch\nn\modules\module.py in _call_impl(self, *args, **kwargs)
1518 or _global_backward_pre_hooks or _global_backward_hooks
1519 or _global_forward_hooks or _global_forward_pre_hooks):
-> 1520 return forward_call(*args, **kwargs)
1521
1522 try:
~\anaconda3\lib\site-packages\onnx2pytorch\operations\pad.py in forward(self, input, pads, value)
15 elif pads is None:
16 raise TypeError("forward() missing 1 required positional argument: 'pads'")
---> 17 out = F.pad(input, list(pads), mode=self.mode, value=value)
18 return out
19
~\anaconda3\lib\site-packages\torch\nn\functional.py in pad(input, pad, mode, value)
4493 input, pad
4494 )
-> 4495 return torch._C._nn.pad(input, pad, mode, value)
4496
4497 # TODO: Fix via pytorch/pytorch#75798
TypeError: pad(): argument 'value' (position 4) must be float, not Tensor
Beta Was this translation helpful? Give feedback.
All reactions