Hi, Doing object detection with F-RCNN.
Faster RCNN requires boxes to be a float tensor of shape [N,4].
Since pandas dataframe is very slow i decided to put all different columns in list like that:
subxmin=[xmins for xmins in df['xmin']]
subymin=[ymins for ymins in df['ymin']]
subxmax=[xmaxs for xmaxs in df['xmax']]
subymax=[ymaxs for ymaxs in df['ymax']]
train_images=[image for image in df['image']]
bboxes=np.array([list(bbox) for bbox in zip(subxmin, subymin, subxmax,subymax)])

The dataset is :
class CarData(torch.utils.data.Dataset):
  def __init__(self,dir,images,boxes,df):
    self.dir=dir
    self.images=images
    self.boxes=bboxes
    self.df=df

  def __len__(self):
    return len(self.images)

  
  def __getitem__(self,index):
    id_for_label=self.df[self.df["image"] == self.images[index]]
    img_path=os.path.join(self.dir,self.images[index])
    img=Image.open(img_path).convert('RGB')
    img=transforms.ToTensor()(img).float()
    img=img.permute(1,2,0)
    boxes=self.boxes[index]

    area = boxes[:][2] * boxes[:][3]
    area = torch.as_tensor(area, dtype=torch.float32)

    boxes[:][2] = boxes[:][0] + boxes[:] [2]
    boxes[:][3] = boxes[:][1] + boxes[:][3]

    labels = torch.ones((id_for_label.shape[0]), dtype=torch.int64)
     
    target = {}
    target["boxes"] = torch.tensor(boxes)
    target["labels"] = torch.tensor(labels)
    target["image_id"] = torch.tensor([index])
    target["area"] = area

    return img,target

The training function :
def train(model,optim,dataloader,path,num_of_epochs):
  os.mkdir(path)
  train_losses=[]
  losses_value=0

  for epoch in range(num_of_epochs):
    for images,targets in dataloader:
      images=[im.to(device) for im in images]
      targets = [{k: v.to(device) for k, v in t.items()} for t in targets]
      loss_dict = model(images, targets)
      losses = sum(loss for loss in loss_dict.values())
      losses_value = losses.item()
      train_loss.append(losses_value)

      optim.zero_grad()
      losses.backward()
      optimizer.step()
      break

Error i’m getting is :

ValueError: Expected target boxes to be a tensorof shape [N, 4], got torch.Size([4]).

Any solutions?