-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathtest_widerface.py
More file actions
48 lines (38 loc) · 1.24 KB
/
test_widerface.py
File metadata and controls
48 lines (38 loc) · 1.24 KB
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
46
47
48
import pytorch_lightning as pl
import torch
import fastface as ff
# model device, select gpu if exists
device = "cuda" if torch.cuda.is_available() else "cpu"
# widerface dataset partition
partition = "easy" # also `medium` or `hard` can be selectable
# select and build pretrained model to test on widerface
# for this tutorial `lffd_original` is selected
# for selectable models checkout ff.list_pretrained_models()
model = ff.FaceDetector.from_pretrained("lffd_original")
# model: pl.LightningModule
# get widerface average precision metric, defined in the competition
metric = ff.metric.WiderFaceAP(iou_threshold=0.5)
# metric: pl.metrics.Metric
# add metric to the model
model.add_metric("widerface_ap", metric)
# get widerface dataset
ds = ff.dataset.WiderFaceDataset(
phase="test",
partitions=[partition],
transforms=ff.transforms.Compose(
ff.transforms.ConditionalInterpolate(max_size=1500)
),
)
# ds: torch.utils.data.Dataset
# get dataloader
dl = ds.get_dataloader(batch_size=1, num_workers=1)
# dl: torch.utils.data.DataLoader
# define trainer
trainer = pl.Trainer(
logger=False,
checkpoint_callback=False,
gpus=1 if device == "cuda" else 0,
precision=32,
)
# run test
trainer.test(model, test_dataloaders=dl)