✅ [Pass] pytest of new structure
Browse files
tests/test_model/test_yolo.py
CHANGED
|
@@ -1,20 +1,20 @@
|
|
| 1 |
import sys
|
|
|
|
| 2 |
|
| 3 |
-
import pytest
|
| 4 |
import torch
|
| 5 |
from hydra import compose, initialize
|
| 6 |
-
from
|
| 7 |
-
from omegaconf import DictConfig, OmegaConf
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
| 13 |
config_name = "v7-base"
|
| 14 |
|
| 15 |
|
| 16 |
def test_build_model():
|
| 17 |
-
|
| 18 |
with initialize(config_path=config_path, version_base=None):
|
| 19 |
model_cfg = compose(config_name=config_name)
|
| 20 |
OmegaConf.set_struct(model_cfg, False)
|
|
|
|
| 1 |
import sys
|
| 2 |
+
from pathlib import Path
|
| 3 |
|
|
|
|
| 4 |
import torch
|
| 5 |
from hydra import compose, initialize
|
| 6 |
+
from omegaconf import OmegaConf
|
|
|
|
| 7 |
|
| 8 |
+
project_root = Path(__file__).resolve().parent.parent.parent
|
| 9 |
+
sys.path.append(str(project_root))
|
| 10 |
|
| 11 |
+
from yolo.model.yolo import YOLO, get_model
|
| 12 |
+
|
| 13 |
+
config_path = "../../yolo/config/model"
|
| 14 |
config_name = "v7-base"
|
| 15 |
|
| 16 |
|
| 17 |
def test_build_model():
|
|
|
|
| 18 |
with initialize(config_path=config_path, version_base=None):
|
| 19 |
model_cfg = compose(config_name=config_name)
|
| 20 |
OmegaConf.set_struct(model_cfg, False)
|
tests/test_utils/test_dataaugment.py
CHANGED
|
@@ -1,12 +1,15 @@
|
|
| 1 |
import sys
|
|
|
|
| 2 |
|
| 3 |
import pytest
|
| 4 |
import torch
|
| 5 |
from PIL import Image
|
| 6 |
from torchvision.transforms import functional as TF
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
| 10 |
|
| 11 |
|
| 12 |
def test_horizontal_flip():
|
|
|
|
| 1 |
import sys
|
| 2 |
+
from pathlib import Path
|
| 3 |
|
| 4 |
import pytest
|
| 5 |
import torch
|
| 6 |
from PIL import Image
|
| 7 |
from torchvision.transforms import functional as TF
|
| 8 |
|
| 9 |
+
project_root = Path(__file__).resolve().parent.parent.parent
|
| 10 |
+
sys.path.append(str(project_root))
|
| 11 |
+
|
| 12 |
+
from yolo.utils.data_augment import Compose, HorizontalFlip, Mosaic, VerticalFlip
|
| 13 |
|
| 14 |
|
| 15 |
def test_horizontal_flip():
|
tests/test_utils/test_loss.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
|
| 4 |
+
import pytest
|
| 5 |
+
import torch
|
| 6 |
+
from hydra import compose, initialize
|
| 7 |
+
|
| 8 |
+
project_root = Path(__file__).resolve().parent.parent.parent
|
| 9 |
+
sys.path.append(str(project_root))
|
| 10 |
+
|
| 11 |
+
from yolo.utils.loss import YOLOLoss
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
@pytest.fixture
|
| 15 |
+
def cfg():
|
| 16 |
+
with initialize(config_path="../../yolo/config", version_base=None):
|
| 17 |
+
cfg = compose(config_name="config")
|
| 18 |
+
return cfg
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
@pytest.fixture
|
| 22 |
+
def loss_function(cfg) -> YOLOLoss:
|
| 23 |
+
return YOLOLoss(cfg)
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
@pytest.fixture
|
| 27 |
+
def data():
|
| 28 |
+
[[torch.zeros]]
|
| 29 |
+
targets = torch.zeros(20, 6, device=torch.device("cuda"))
|
| 30 |
+
predicts = [
|
| 31 |
+
[torch.zeros(1, 144, 80 // i, 80 // i, device=torch.device("cuda")) for i in [1, 2, 4]] for _ in range(2)
|
| 32 |
+
]
|
| 33 |
+
return predicts, targets
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def test_yolo_loss(loss_function, data):
|
| 37 |
+
predicts, targets = data
|
| 38 |
+
loss_iou, loss_dfl, loss_cls = loss_function(predicts, targets)
|
| 39 |
+
assert torch.isnan(loss_iou)
|
| 40 |
+
assert torch.isnan(loss_dfl)
|
| 41 |
+
assert torch.isinf(loss_cls)
|