This is the DataLoader:
class dataLoader(Dataset):
    def __init__(self, path, root, transforms=None):
        self.path = path
        self.root = root 
        self.transforms = transforms
        self.img_loc, self.data = get_file_path(self.path)
        self.data_len = len(self.data)
    
    def __getitem__(self, index):
        img_path = (self.img_loc[index])
        img = Image.open(img_path).convert("RGB")
        image_id = torch.tensor([index])
        
        data = self.data[index]
        xml = ET.parse(data).getroot()
        
        objects = [n.text for n in xml.findall('.//object/name')]
        if not objects:
            objects.append(('None'))
        num_objs = len(objects)
        
        labels = []
        for i in range(num_objs):
            get_id = get_class_id(objects[i])
            labels.append(get_id)
        labels = torch.tensor(labels)

        box = [[int(box.find('w').text) - 1,
                int(box.find('h').text) - 1,
                int(box.find('x').text) - 1,
                int(box.find('y').text) - 1]
                for box in xml.findall('.//object/bndbox')]

        boxes = torch.as_tensor(box, dtype=torch.float32)
        
        if not box:
            area = 0
        else:
            area = (boxes[:, 3] - boxes[:, 1]) * (boxes[:, 2] - boxes[:, 0])
                 
        iscrowd = torch.zeros((num_objs,), dtype=torch.int64)
        
        keep = (boxes[:, 3]>boxes[:, 1]) & (boxes[:, 2]>boxes[:, 0])
        print(all(keep))
        boxes = boxes[keep]
        labels = labels[keep]
        area = area[keep]
        iscrowd = iscrowd[keep]
       
        target = {}
        target['labels'] = labels
        target["image_id"] = image_id
        target['boxes'] = boxes
        target["area"] = area
        target["iscrowd"] = iscrowd
                         
        if self.transforms is not None:
            img, target = self.transforms(img, target)
        
        return img, target, img_path
                                 
    def __len__(self):
        return self.data_len

The annotations are stored in a xml format. What i want to do is something like when the len(boxes) == 0, the current index should be skipped and move to the next index. I don’t want to return any of the data of the index  when there len(boxes) == 0 as that indicates that there is no objects in the image.
Is there a simple way to skip an index?