forked from samuki/oCILots
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
26 lines (23 loc) · 829 Bytes
/
test.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
import cv2
import numpy as np
from config import config
def test_prediction(model, test_images, size, cutoff = config.CUTOFF):
test_pred = [model(t).detach().cpu().numpy() for t in test_images.unsqueeze(1)]
test_pred = np.concatenate(test_pred, 0)
test_pred = np.moveaxis(test_pred, 1, -1) # CHW to HWC
probabs = np.stack(
[cv2.resize(img, dsize=size) for img in test_pred], 0
) # resize to original shape
# now compute labels
test_pred = probabs.reshape(
(
-1,
size[0] // config.PATCH_SIZE,
config.PATCH_SIZE,
size[0] // config.PATCH_SIZE,
config.PATCH_SIZE,
)
)
test_pred = np.moveaxis(test_pred, 2, 3)
test_pred = np.round(np.mean(test_pred, (-1, -2)) > cutoff)
return test_pred, probabs