Repository navigation
Expand file tree
/
Copy pathtest_piecewise_schedule.py
More file actions
71 lines (59 loc) · 2.31 KB
/
Copy pathtest_piecewise_schedule.py
File metadata and controls
71 lines (59 loc) · 2.31 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"""Tests for piecewise epoch schedules."""
import pytest
from oriented_det.train.piecewise_schedule import resolve_piecewise_schedule
@pytest.mark.parametrize(
("epoch", "expected"),
[
(0, 0.1),
(19, 0.1),
(20, 0.05),
(23, 0.05),
(24, 0.0),
(100, 0.0),
],
)
def test_resolve_piecewise_schedule_three_segments(epoch: int, expected: float):
value = resolve_piecewise_schedule(
epoch,
boundaries=[20, 24],
values=[0.1, 0.05, 0.0],
default=0.0,
)
assert value == pytest.approx(expected)
def test_resolve_piecewise_schedule_uses_default_when_unset():
assert resolve_piecewise_schedule(5, None, None, 0.2) == pytest.approx(0.2)
assert resolve_piecewise_schedule(5, [], [0.1], 0.2) == pytest.approx(0.2)
def test_rotated_faster_rcnn_iou_weight_schedule():
from oriented_det.models.oriented_rcnn import RotatedFasterRCNN
model = RotatedFasterRCNN(
num_classes=2,
backbone_name="resnet18",
pretrained_backbone=False,
trainable_layers=3,
roi_box_reg_aux_weight=0.1,
roi_box_reg_aux_schedule_epochs=[24, 28],
roi_box_reg_aux_schedule_values=[0.1, 0.05, 0.0],
)
model.set_roi_box_reg_aux_weight_for_epoch(0)
assert model.roi_box_reg_aux_weight == pytest.approx(0.1)
model.set_roi_box_reg_aux_weight_for_epoch(24)
assert model.roi_box_reg_aux_weight == pytest.approx(0.05)
model.set_roi_box_reg_aux_weight_for_epoch(28)
assert model.roi_box_reg_aux_weight == pytest.approx(0.0)
def test_rotated_faster_rcnn_angle_weight_schedule():
from oriented_det.models.oriented_rcnn import RotatedFasterRCNN
model = RotatedFasterRCNN(
num_classes=2,
backbone_name="resnet18",
pretrained_backbone=False,
trainable_layers=3,
roi_box_reg_angle_weight=2.0,
roi_box_reg_angle_schedule_epochs=[12, 24],
roi_box_reg_angle_schedule_values=[2.0, 2.75, 3.5],
)
model.set_roi_box_reg_angle_weight_for_epoch(0)
assert model.roi_box_reg_angle_weight == pytest.approx(2.0)
model.set_roi_box_reg_angle_weight_for_epoch(12)
assert model.roi_box_reg_angle_weight == pytest.approx(2.75)
model.set_roi_box_reg_angle_weight_for_epoch(24)
assert model.roi_box_reg_angle_weight == pytest.approx(3.5)