-
Notifications
You must be signed in to change notification settings - Fork 14
/
plot.py
45 lines (36 loc) · 1.23 KB
/
plot.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import torch
import config
import os
import utils
from tqdm import tqdm
from data import YoloPascalVocDataset
from models import *
from torch.utils.data import DataLoader
MODEL_DIR = 'models/yolo_v1/08_19_2022/08_42_58'
def plot_test_images():
classes = utils.load_class_array()
dataset = YoloPascalVocDataset('test', normalize=True, augment=False)
loader = DataLoader(dataset, batch_size=8, shuffle=True)
model = YOLOv1ResNet()
model.eval()
model.load_state_dict(torch.load(os.path.join(MODEL_DIR, 'weights', 'final')))
count = 0
with torch.no_grad():
for image, labels, original in tqdm(loader):
predictions = model.forward(image)
for i in range(image.size(dim=0)):
utils.plot_boxes(
original[i, :, :, :],
predictions[i, :, :, :],
classes,
file=os.path.join('results', f'{count}')
)
# utils.plot_boxes(
# original[i, :, :, :],
# labels[i, :, :, :],
# classes,
# color='green'
# )
count += 1
if __name__ == '__main__':
plot_test_images()