Skip to content

RuntimeError: The size of tensor a (4) must match the size of tensor b (3) at non-singleton dimension 0 #2

Description

@abhishek7467

segmentation
Traceback (most recent call last):
File "/home/spx149/Github Projects/treeboore-objectRemove/object-remove/./src/main.py", line 45, in
output = model.run()
File "/home/spx149/Github Projects/treeboore-objectRemove/object-remove/src/objRemove.py", line 31, in run
output = self.segment(images)
File "/home/spx149/Github Projects/treeboore-objectRemove/object-remove/src/objRemove.py", line 177, in segment
out = self.segmentModel(images)
File "/home/spx149/Github Projects/treeboore-objectRemove/venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1511, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "/home/spx149/Github Projects/treeboore-objectRemove/venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1520, in _call_impl
return forward_call(*args, **kwargs)
File "/home/spx149/Github Projects/treeboore-objectRemove/venv/lib/python3.10/site-packages/torchvision/models/detection/generalized_rcnn.py", line 83, in forward
images, targets = self.transform(images, targets)
File "/home/spx149/Github Projects/treeboore-objectRemove/venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1511, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "/home/spx149/Github Projects/treeboore-objectRemove/venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1520, in _call_impl
return forward_call(*args, **kwargs)
File "/home/spx149/Github Projects/treeboore-objectRemove/venv/lib/python3.10/site-packages/torchvision/models/detection/transform.py", line 141, in forward
image = self.normalize(image)
File "/home/spx149/Github Projects/treeboore-objectRemove/venv/lib/python3.10/site-packages/torchvision/models/detection/transform.py", line 169, in normalize
return (image - mean[:, None, None]) / std[:, None, None]
RuntimeError: The size of tensor a (4) must match the size of tensor b (3) at non-singleton dimension 0

The above error is occurred in the below function which is in /src/objRemove.py

def preprocess_image(self):
'''
Read in image and prepare for segmentation
'''
print("self.image_path - in objRemove file > ",self.image_path)
img= [read_image(self.image_path)]
print("img - in objRemove file > ",img)

    _,h,w = img[0].shape
    print("_,h,w  => ",_,h,w)
    size = min(h,w)
    if size > 512:
        img[0] = T.Resize(512, max_size=680, antialias=True)(img[0])

    images_transformed = [self.rcnn_transforms(d) for d in img]
    return images_transformed

def segment(self,images):
    out = self.segmentModel(images)
    return out

and i'm uploading the below image
treeRactangle

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions