-
Notifications
You must be signed in to change notification settings - Fork 323
/
Copy patheval.py
36 lines (28 loc) · 1.12 KB
/
eval.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
import paddle
from coco import build_coco
from coco import get_loader
from detr import build_detr
def main():
model, criterion, postprocessors = build_detr()
model_state = paddle.load('./detr_resnet50.pdparams')
model.set_dict(model_state)
model.eval()
# 2. Create val dataloader
dataset_val = build_coco('val', '/dataset/coco/')
dataloader_val = get_loader(dataset_val,
batch_size=4,
mode='val',
multi_gpu=False)
with paddle.no_grad():
for batch_id, data in enumerate(dataloader_val):
samples = data[0]
targets = data[1]
outputs = model(samples)
loss_dict = criterion(outputs, targets)
orig_target_sizes = paddle.stack([t['orig_size'] for t in targets], axis=0)
results = postprocessors['bbox'](outputs, orig_target_sizes)
res = {target['image_id']: output for target, output in zip(targets, results)}
print(f'{batch_id}/{len(dataloader_val)} done')
print('all done')
if __name__ == '__main__':
main()