# Object detection: TypeError: \_\_call\_\_() takes 2 positional arguments but 3 were given

**URL:** <https://discuss.pytorch.org/t/object-detection-typeerror-call-takes-2-positional-arguments-but-3-were-given/142824>\
**Category:** vision\
**Created:** [January 29, 2022, 8:51am UTC](https://discuss.pytorch.org/t/object-detection-typeerror-call-takes-2-positional-arguments-but-3-were-given/142824 "2022-01-29T08:51:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shantanu\_Ghosh](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/shantanu_ghosh/32/24369_2.png) [@Shantanu\_Ghosh](https://discuss.pytorch.org/u/Shantanu_Ghosh)\
**Post date:** [January 29, 2022, 8:51am UTC](https://discuss.pytorch.org/t/object-detection-typeerror-call-takes-2-positional-arguments-but-3-were-given/142824/1 "2022-01-29T08:51:22Z")

</div>

Hi i am creating an object detector, for that I am using the following code for creating the custom dataset:

class MIMICCXRDataset(Dataset):

```
def __init__ (self,
             split,
             args,
             radgraph_sids,
             radgraph_adj_mtx,
             mode,
             transform=None):

    self.args = args
    self.mode = mode
    self.transform = transform
 ..........

def __getitem__ (self, idx):
    # 1. get the sample key, i.e., DICOM ID
    dicom_id = self.dicom_ids[idx]
    study_id = list(self.df_master_sel.loc[self.df_master_sel['dicom_id'] == dicom_id, 'study_id'])[0]
    idx_sid = list(self.arr_radgraph_sids).index(str(study_id))

    # 2. select and load image
    img_pth_old = self.df_master_sel.iloc[idx, 4]
    img_pth_components = img_pth_old.split("/")
    img_pth = os.path.join(
        self.args.image_path_ocean_shared,
        *img_pth_components[11:]
    )

    image = Image.open(img_pth).convert('RGB')
    np_res_bbox = np.array(res_bbox)

    if len(np_res_bbox.shape) == 1:
        np_res_bbox = np.reshape(np_res_bbox, (1, -1))

    for i in range(np_res_bbox.shape[0]):
        x1 = np_res_bbox[i, 0]
        y1 = np_res_bbox[i, 1]
        x2 = np_res_bbox[i, 2]
        y2 = np_res_bbox[i, 3]
        boxes.append([x1, y1, x2, y2])

    boxes = torch.as_tensor(boxes, dtype=torch.float32)
    if disease == "pneumonia":
        labels = torch.ones((boxes.size(0),), dtype=torch.int64)
    elif disease == "pneumothorax":
        labels = torch.ones((boxes.size(0),), dtype=torch.int64)

    area = (boxes[:, 3] - boxes[:, 1]) * (boxes[:, 2] - boxes[:, 0])
    iscrowd = torch.zeros((boxes.size(0),), dtype=torch.int64)
    target = {}
    target["boxes"] = boxes
    target["labels"] = labels
    target["image_id"] = torch.tensor(idx)
    target["area"] = area
    target["iscrowd"] = iscrowd

    if self.transform is not None:
        image, target = self.transform(image, target)

```

I am getting the error in the transforms. My transforms are as follows:  
train\_dataset = MIMICCXRDataset(  
split=split,  
args=args,  
radgraph\_sids=arr\_radgraph\_sids,  
radgraph\_adj\_mtx=arr\_radgraph\_adj,  
mode=‘bbox’,  
transform=transforms.Compose([  
transforms.Resize(args.resize),  
# resize smaller edge to args.resize and the  
# aspect ratio the same for the longer edge  
transforms.CenterCrop(args.resize),  
transforms.ToTensor(), # convert pixel value to [0, 1]  
normalize  
])  
)

---

<div class="post-metadata">

**Author:** ![ptrblck](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/32/1823_2.png) [@ptrblck](https://discuss.pytorch.org/u/ptrblck)\
**Post date:** [January 30, 2022, 9:50pm UTC](https://discuss.pytorch.org/t/object-detection-typeerror-call-takes-2-positional-arguments-but-3-were-given/142824/2 "2022-01-30T21:50:24Z")

</div>

The used transformations accept a single input only while you are passing the `image` and `target` to them.  
To allow two inputs, you could refer to the [Object Detection tutorial](https://pytorch.org/tutorials/intermediate/torchvision_tutorial.html#putting-everything-together) and use the util. functions from [`references/detection/transforms.py`](https://github.com/pytorch/vision/blob/7d868aa608b94d022c42357ede40bda06af942f4/references/detection/transforms.py).
