2021-08-29

Getting Error too many indices for tensor of dimension 3

I am trying to Read an Image using GeneralizedRCNN, Input shape is given as a comment with code. The problem is I am getting an error while tracing the model with input shape. The error is :

> trace = torch.jit.trace(model, input_batch) line Providing the error
> "/usr/local/lib/python3.7/dist-packages/torch/tensor.py:467:
> RuntimeWarning: Iterating over a tensor might cause the trace to be
> incorrect. Passing a tensor of different shape won't change the number
> of iterations executed (and might lead to errors or silently give
> incorrect results).   'incorrect results).', category=RuntimeWarning)
> --------------------------------------------------------------------------- IndexError                                Traceback (most recent call
> last) <ipython-input-25-52ff7ef794de> in <module>()
>       1 #First attempt at tracing
> ----> 2 trace = torch.jit.trace(model, input_batch)
> 
> 7 frames
> /usr/local/lib/python3.7/dist-packages/detectron2/modeling/meta_arch/rcnn.py
> in <listcomp>(.0)
>     182         Normalize, pad and batch the input images.
>     183         """
> --> 184         images = [x["image"].to(self.device) for x in batched_inputs]
>     185         images = [(x - self.pixel_mean) / self.pixel_std for x in images]
>     186         images = ImageList.from_tensors(images, self.backbone.size_divisibility)
> 
> IndexError: too many indices for tensor of dimension 3
model = build_model(cfg)
model.eval()
# print(model)
input_image = Image.open("model/xxx.jpg")
display(input_image)
to_tensor = transforms.ToTensor()
input_tensor = to_tensor(input_image)
# input_tensor.size = torch.Size([3, 519, 1038])
input_batch = input_tensor.unsqueeze(0)
# input_batch.size = torch.Size([1, 3, 519, 1038])
trace = torch.jit.trace(model, input_batch)


from Recent Questions - Stack Overflow https://ift.tt/3sWexQl
https://ift.tt/eA8V8J

No comments:

Post a Comment