Skip to content

Commit ccf93c2

Browse files
authored
Merge pull request #205 from Visual-Behavior/github_actions
GitHub actions
2 parents 1aa27b5 + 9c90b2c commit ccf93c2

File tree

8 files changed

+87
-25
lines changed

8 files changed

+87
-25
lines changed

.github/workflows/action.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Aloception unit tests
2+
on:
3+
push:
4+
branches:
5+
- 'master'
6+
pull_request:
7+
branches:
8+
- 'master'
9+
10+
jobs:
11+
unit_tests:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
- name: Install packages
16+
run : |
17+
pip install numpy==1.22.2
18+
pip install torch==1.10.2+cpu torchvision==0.11.3+cpu torchaudio==0.10.2 -f https://download.pytorch.org/whl/torch_stable.html
19+
pip install -r requirements.txt
20+
shell: bash
21+
- name: Run python unit tests
22+
run: |
23+
invalid=0
24+
for file in unittest/*;
25+
do
26+
echo "Testing : $file"
27+
res=$(grep "GithubActionsIgnore" "$file" | wc -l || true)
28+
if [ "$res" = "0" ]
29+
then
30+
if PYTHONPATH=${GITHUB_WORKSPACE} python3 "$file"; then
31+
echo "::notice file=$file::Tests : ok"
32+
else
33+
echo "::error file=$file::Something wrong happened during execution"
34+
invalid=$((invalid+1))
35+
fi
36+
else
37+
echo "::warning file=$file::This file should be ignore on github actions"
38+
fi
39+
done
40+
if [ "$invalid" -eq 0 ]
41+
then
42+
echo "::notice title="All possible tests are valid"::Congratulation !"
43+
exit 0
44+
else
45+
echo "::error title="Final review"::Some tests return errors"
46+
exit 1
47+
fi
48+
shell: bash

aloscene/tensors/augmented_tensor.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,10 +299,11 @@ def __getitem__(self, idx):
299299
)
300300

301301
if isinstance(idx, torch.Tensor):
302-
if not idx.dtype == torch.bool:
303-
if not torch.equal(idx ** 3, idx):
304-
raise IndexError(f"Unvalid mask. Expected mask elements to be in [0, 1, True, False]")
305-
tensor = self * idx
302+
tensor = torch.Tensor.__getitem__(self.rename(None), idx).reset_names()
303+
#if not idx.dtype == torch.bool:
304+
# if not torch.equal(idx ** 3, idx):
305+
# raise IndexError(f"Unvalid mask. Expected mask elements to be in [0, 1, True, False]")
306+
#tensor = self * idx
306307
else:
307308
tensor = torch.Tensor.__getitem__(self, idx)
308309

aloscene/utils/rotated_iou/cuda_op/cuda_ext.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
try:
55
import sort_vertices
66
sort_vertices_error = None
7-
except Exception as sort_vertices_error:
7+
except Exception as e:
88
sort_vertices= None
9+
sort_vertices_error = e
910
pass
1011

1112

@@ -14,8 +15,7 @@ class SortVertices(Function):
1415
def forward(ctx, vertices, mask, num_valid):
1516

1617
if sort_vertices is None:
17-
print(sort_vertices_error)
18-
raise Exception("To install: cd aloception/aloscene/utils/rotated_iou/cuda_op; python setup.py install --user ")
18+
raise Exception(f"To install: cd aloception/aloscene/utils/rotated_iou/cuda_op; python setup.py install --user. Error={sort_vertices_error}")
1919

2020
idx = sort_vertices.sort_vertices_forward(vertices, mask, num_valid)
2121
ctx.mark_non_differentiable(idx)

unittest/test_boxes.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -384,10 +384,7 @@ def test_crop_abs():
384384
boxes, boxes_format="xcyc", frame_size=(frame.H, frame.W), absolute=True, labels=labels
385385
)
386386
frame.append_boxes2d(boxes)
387-
# frame.get_view().render()
388-
frame = frame.crop(H_crop=(0.0, 0.5), W_crop=(0.0, 0.5))
389-
# frame.get_view().render()
390-
# frame.get_view().render()
387+
frame = frame.crop(H_crop=(0.0, 0.4), W_crop=(0.0, 0.4))
391388
assert torch.allclose(frame.boxes2d[0].as_tensor(), boxes[0].as_tensor())
392389
assert np.allclose(frame.boxes2d.frame_size[0], frame.HW[0])
393390
assert np.allclose(frame.boxes2d.frame_size[1], frame.HW[1])

unittest/test_boxes_3d.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
TEST_FRAME = 0
88
CAMERAS = ["front", "front_left", "front_right", "side_left", "side_right"]
9-
device = torch.device("cuda")
9+
device = torch.device("cpu")
1010

1111
waymo_dataset = WaymoDataset(sample=True)
1212

@@ -133,7 +133,9 @@ def test_giou3d_2():
133133
test_shape_vertices_3d_proj()
134134
test_shape_boxes_3d_proj()
135135
test_hflip()
136-
test_giou3d_same_box()
137-
test_giou3d_same_face()
138-
test_giou3d_1()
139-
test_giou3d_2()
136+
# if cuda is available, run the tests on cuda. (giou use custom cuda op to compile)
137+
if torch.cuda.is_available():
138+
test_giou3d_same_box()
139+
test_giou3d_same_face()
140+
test_giou3d_1()
141+
test_giou3d_2()

unittest/test_frame.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -504,14 +504,15 @@ def test_device_propagation():
504504
assert frame.disparity.occlusion["occ2"].device == torch.device("cpu")
505505
assert frame.flow[0].occlusion.device == torch.device("cpu")
506506

507-
cuda_frame = frame.cuda()
508-
assert cuda_frame.boxes2d["boxes1"][0].device != torch.device("cpu")
509-
assert cuda_frame.boxes2d["boxes2"][0].device != torch.device("cpu")
510-
assert cuda_frame.disparity.device != torch.device("cpu")
511-
assert cuda_frame.flow[0].device != torch.device("cpu")
512-
assert cuda_frame.disparity.occlusion["occ1"].device != torch.device("cpu")
513-
assert cuda_frame.disparity.occlusion["occ2"].device != torch.device("cpu")
514-
assert cuda_frame.flow[0].occlusion.device != torch.device("cpu")
507+
if torch.cuda.is_available():
508+
cuda_frame = frame.cuda()
509+
assert cuda_frame.boxes2d["boxes1"][0].device != torch.device("cpu")
510+
assert cuda_frame.boxes2d["boxes2"][0].device != torch.device("cpu")
511+
assert cuda_frame.disparity.device != torch.device("cpu")
512+
assert cuda_frame.flow[0].device != torch.device("cpu")
513+
assert cuda_frame.disparity.occlusion["occ1"].device != torch.device("cpu")
514+
assert cuda_frame.disparity.occlusion["occ2"].device != torch.device("cpu")
515+
assert cuda_frame.flow[0].occlusion.device != torch.device("cpu")
515516

516517
cpu_frame = frame.cpu()
517518
assert cpu_frame.boxes2d["boxes1"][0].device == torch.device("cpu")

unittest/test_oriented_boxes_2d.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import aloscene
44
from aloscene import OrientedBoxes2D
55

6-
device = torch.device("cuda")
6+
device = torch.device("cpu")
77

88

99
def tensor_equal(tensor1, tensor2, threshold=1e-4):
@@ -14,6 +14,8 @@ def tensor_equal(tensor1, tensor2, threshold=1e-4):
1414

1515

1616
def test_same_box():
17+
# if cuda not avaible
18+
if not torch.cuda.is_available(): return
1719
box1 = OrientedBoxes2D(torch.tensor([[0.0, 0.0, 2.0, 2.0, 0.0]], device=device))
1820
box2 = OrientedBoxes2D(torch.tensor([[0.0, 0.0, 2.0, 2.0, 0.0]], device=device))
1921
expected_iou = torch.tensor([1.0], device=device)
@@ -24,6 +26,8 @@ def test_same_box():
2426

2527

2628
def test_same_edge():
29+
# if cuda not avaible
30+
if not torch.cuda.is_available(): return
2731
box1 = OrientedBoxes2D(torch.tensor([[0.0, 0.0, 2.0, 2.0, 0.0]], device=device))
2832
box2 = OrientedBoxes2D(torch.tensor([[2.0, 0.0, 2.0, 2.0, 0.0]], device=device))
2933
expected_iou = torch.tensor([0.0], device=device)
@@ -35,6 +39,8 @@ def test_same_edge():
3539

3640

3741
def test_1():
42+
# if cuda not avaible
43+
if not torch.cuda.is_available(): return
3844
box1 = OrientedBoxes2D(torch.tensor([[0.0, 0.0, 2.0, 2.0, 0.0]], device=device))
3945
box2 = OrientedBoxes2D(torch.tensor([[1.0, 0.0, 2.0, 2.0, 0.0]], device=device))
4046
expected_iou = torch.tensor([1 / 3], device=device)
@@ -45,6 +51,8 @@ def test_1():
4551

4652

4753
def test_2():
54+
# if cuda not avaible
55+
if not torch.cuda.is_available(): return
4856
box1 = OrientedBoxes2D(torch.tensor([[0.0, 0.0, 2.0, 2.0, 0.0]], device=device))
4957
box2 = OrientedBoxes2D(torch.tensor([[1.0, 1.0, 2.0, 2.0, 0.0]], device=device))
5058
expected_iou = torch.tensor([1 / 7], device=device)
@@ -55,6 +63,8 @@ def test_2():
5563

5664

5765
def test_3():
66+
# if cuda not avaible
67+
if not torch.cuda.is_available(): return
5868
box1 = OrientedBoxes2D(torch.tensor([[0.0, 0.0, 2.0, 2.0, 0.0]], device=device))
5969
box2 = OrientedBoxes2D(torch.tensor([[1.0, 1.0, 2.0, 2.0, np.pi / 2]], device=device))
6070
expected_iou = torch.tensor([1 / 7], device=device)
@@ -65,6 +75,8 @@ def test_3():
6575

6676

6777
def test_4():
78+
# if cuda not avaible
79+
if not torch.cuda.is_available(): return
6880
box1 = OrientedBoxes2D(torch.tensor([[0.0, 0.0, 2.0, 2.0, 0.0]], device=device))
6981
box2 = OrientedBoxes2D(
7082
torch.tensor([[1.0, 1.0, np.sqrt(2), np.sqrt(2), np.pi / 4]], device=device, dtype=torch.float)

unittest/test_train.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import argparse
22
from unittest import mock
33

4+
# GithubActionsIgnore : cuda
45

56
def get_argparse_defaults(parser):
67
defaults = {}

0 commit comments

Comments
 (0)