-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.py
More file actions
30 lines (25 loc) · 898 Bytes
/
Copy pathtest.py
File metadata and controls
30 lines (25 loc) · 898 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import pathlib
import torch
import numpy as np
import matplotlib.pyplot as plt
from torchvision.transforms import v2
from torchvision import datasets, tv_tensors
from torchvision.utils import draw_bounding_boxes, draw_segmentation_masks
import torchvision.transforms.functional as F
from helpers import plot
ROOT = pathlib.Path('./data/train/')
IMAGES_PATH = str(ROOT / 'images')
ANNOTATIONS_PATH = str(ROOT / 'annotation-small.json')
dataset = datasets.CocoDetection(
IMAGES_PATH,
ANNOTATIONS_PATH,
transforms=v2.Compose([
v2.ToImage(),
v2.SanitizeBoundingBoxes(),
])
)
dataset = datasets.wrap_dataset_for_transforms_v2(dataset, target_keys=("boxes", "labels", "masks"))
indices = torch.randperm(len(dataset)).tolist()
dataset = torch.utils.data.Subset(dataset, indices[:4])
plot([[dataset[0], dataset[1]], [dataset[2], dataset[3]]])
plt.savefig('output.png')