✅ [Pass] the data augment test, make test stronger
Browse files
.github/workflows/main.yaml
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
name: YOLOv9 - Model test
|
2 |
|
3 |
on:
|
4 |
push:
|
@@ -8,7 +8,6 @@ on:
|
|
8 |
|
9 |
jobs:
|
10 |
build:
|
11 |
-
|
12 |
runs-on: ubuntu-latest
|
13 |
|
14 |
steps:
|
@@ -17,10 +16,25 @@ jobs:
|
|
17 |
uses: actions/setup-python@v2
|
18 |
with:
|
19 |
python-version: 3.8
|
|
|
20 |
- name: Install dependencies
|
21 |
run: |
|
22 |
python -m pip install --upgrade pip
|
23 |
pip install -r requirements.txt
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
- name: Test with pytest
|
25 |
-
run:
|
26 |
-
pytest
|
|
|
1 |
+
name: YOLOv9 - Model test and Code Style Check
|
2 |
|
3 |
on:
|
4 |
push:
|
|
|
8 |
|
9 |
jobs:
|
10 |
build:
|
|
|
11 |
runs-on: ubuntu-latest
|
12 |
|
13 |
steps:
|
|
|
16 |
uses: actions/setup-python@v2
|
17 |
with:
|
18 |
python-version: 3.8
|
19 |
+
|
20 |
- name: Install dependencies
|
21 |
run: |
|
22 |
python -m pip install --upgrade pip
|
23 |
pip install -r requirements.txt
|
24 |
+
|
25 |
+
- name: Install pre-commit
|
26 |
+
run: pip install pre-commit
|
27 |
+
|
28 |
+
- name: Cache pre-commit environment
|
29 |
+
uses: actions/cache@v2
|
30 |
+
with:
|
31 |
+
path: ~/.cache/pre-commit
|
32 |
+
key: ${{ runner.os }}-precommit-${{ hashFiles('**/.pre-commit-config.yaml') }}
|
33 |
+
restore-keys: |
|
34 |
+
${{ runner.os }}-precommit-
|
35 |
+
|
36 |
+
- name: Run pre-commit (black and isort)
|
37 |
+
run: pre-commit run --all-files
|
38 |
+
|
39 |
- name: Test with pytest
|
40 |
+
run: pytest
|
|
tests/test_utils/test_dataaugment.py
CHANGED
@@ -6,23 +6,22 @@ from PIL import Image
|
|
6 |
from torchvision.transforms import functional as TF
|
7 |
|
8 |
sys.path.append("./")
|
9 |
-
from utils.data_augment import Compose, Mosaic,
|
10 |
|
11 |
|
12 |
-
def
|
13 |
# Create a mock image and bounding boxes
|
14 |
img = Image.new("RGB", (100, 100), color="red")
|
15 |
-
boxes = torch.tensor([[1, 0.
|
16 |
|
17 |
-
flip_transform =
|
18 |
flipped_img, flipped_boxes = flip_transform(img, boxes)
|
19 |
|
20 |
# Assert image is flipped by comparing it to a manually flipped image
|
21 |
assert TF.hflip(img) == flipped_img
|
22 |
|
23 |
# Assert bounding boxes are flipped correctly
|
24 |
-
expected_boxes = torch.tensor([[1, 0.
|
25 |
-
expected_boxes[:, [1, 3]] = 1 - expected_boxes[:, [3, 1]]
|
26 |
assert torch.allclose(flipped_boxes, expected_boxes), "Bounding boxes were not flipped correctly"
|
27 |
|
28 |
|
@@ -60,5 +59,5 @@ def test_mosaic():
|
|
60 |
# Checks here would depend on the exact expected behavior of the mosaic function,
|
61 |
# such as dimensions and content of the output image and boxes.
|
62 |
|
63 |
-
assert mosaic_img.size == (
|
64 |
assert len(mosaic_boxes) > 0, "Should have some bounding boxes"
|
|
|
6 |
from torchvision.transforms import functional as TF
|
7 |
|
8 |
sys.path.append("./")
|
9 |
+
from utils.data_augment import Compose, HorizontalFlip, Mosaic, VerticalFlip
|
10 |
|
11 |
|
12 |
+
def test_horizontal_flip():
|
13 |
# Create a mock image and bounding boxes
|
14 |
img = Image.new("RGB", (100, 100), color="red")
|
15 |
+
boxes = torch.tensor([[1, 0.05, 0.1, 0.7, 0.9]]) # class, xmin, ymin, xmax, ymax
|
16 |
|
17 |
+
flip_transform = HorizontalFlip(prob=1) # Set probability to 1 to ensure flip
|
18 |
flipped_img, flipped_boxes = flip_transform(img, boxes)
|
19 |
|
20 |
# Assert image is flipped by comparing it to a manually flipped image
|
21 |
assert TF.hflip(img) == flipped_img
|
22 |
|
23 |
# Assert bounding boxes are flipped correctly
|
24 |
+
expected_boxes = torch.tensor([[1, 0.3, 0.1, 0.95, 0.9]])
|
|
|
25 |
assert torch.allclose(flipped_boxes, expected_boxes), "Bounding boxes were not flipped correctly"
|
26 |
|
27 |
|
|
|
59 |
# Checks here would depend on the exact expected behavior of the mosaic function,
|
60 |
# such as dimensions and content of the output image and boxes.
|
61 |
|
62 |
+
assert mosaic_img.size == (100, 100), "Mosaic image size should be same"
|
63 |
assert len(mosaic_boxes) > 0, "Should have some bounding boxes"
|