Replace your implementation of MyDataset with:
import random

class MyDataset(Dataset):
    def __init__(self):
        self.length = 100

    def __len__(self):
        return self.length

    def __getitem__(self, idx):
        image = torch.randn(3, 520, 704)
        
        n = random.randint(1,100)
        bbox = torch.zeros(n, 4).long()
        for i in range(n):
            bbox[i, 0] = torch.randint(0, 256, (1,))
            bbox[i, 2] = bbox[i, 0] + torch.randint(1, 256, (1,))
            bbox[i, 1] = torch.randint(0, 256, (1,))
            bbox[i, 3] = bbox[i, 1] + torch.randint(1, 256, (1,))
        mask = torch.randint(0, 2, (1, 520, 704)).float()
              
        return image, bbox, mask

and the error occurs