What is error in this code when train yolo?

model =YOLO(“/content/runs/segment/train/weights/best.pt”)
result = results[0]

masks = result.masks
len(masks),masks.shape

def instance_segmentation(image_path,masks):
mask=masks
image = Image.open(image_path)
image=torchvision.transforms.Resize(int(masks.shape[1]),int(masks.shape[2]))
image_tensor = torchvision.transforms.ToTensor()(image)
image_tensor=image_tensor.unsqueeze(0)
results = model(image_tensor)
boxes = results.pandas().xyxy[0] # Bounding boxes
labels = results.xyxyn[0][:, -1].int() # Class labels
masks = results.pred[0][‘masks’] # Instance segmentation masks

# Plot the segmented instances
fig, ax = plt.subplots(figsize=(8, 8))
ax.imshow(image)
print(image)
for i, (box, label) in enumerate(zip(boxes, labels)):
    xmin, ymin, xmax, ymax = box
    w, h = xmax - xmin, ymax - ymin
    mask = masks[i, 0].mul(255).byte().numpy()
    instance_image = Image.fromarray(mask)
    ax.imshow(instance_image, alpha=0.5, extent=(xmin, xmax, ymax, ymin))
    ax.text(xmin, ymin, str(label.item()), color='r')

plt.show()

instance_segmentation(“ZH.jpg”,masks)

this error was appear
return inverse_modes_mapping[i]
KeyError: 480

i want to detect object mask and find is coordinate x and y (position mask with respect to the image )
and display it. how can i do that?