henry000 commited on
Commit
a54ff08
·
1 Parent(s): 09c7ab9

✅ [Pass] Test for using anchor config in Vec2Box

Browse files
tests/conftest.py CHANGED
@@ -67,7 +67,7 @@ def model(train_cfg: Config, device) -> YOLO:
67
 
68
  @pytest.fixture(scope="session")
69
  def vec2box(train_cfg: Config, model: YOLO, device) -> Vec2Box:
70
- vec2box = Vec2Box(model, train_cfg.image_size, device)
71
  return vec2box
72
 
73
 
 
67
 
68
  @pytest.fixture(scope="session")
69
  def vec2box(train_cfg: Config, model: YOLO, device) -> Vec2Box:
70
+ vec2box = Vec2Box(model, train_cfg.model.anchor, train_cfg.image_size, device)
71
  return vec2box
72
 
73
 
tests/test_tools/test_data_loader.py CHANGED
@@ -31,10 +31,10 @@ def test_training_data_loader_correctness(train_dataloader: YoloDataLoader):
31
  assert batch_size == 2
32
  assert images.shape == (2, 3, 640, 640)
33
  assert reverse_tensors.shape == (2, 5)
34
- expected_paths = (
35
  Path("tests/data/images/train/000000050725.jpg"),
36
  Path("tests/data/images/train/000000167848.jpg"),
37
- )
38
  assert image_paths == expected_paths
39
 
40
 
@@ -44,12 +44,12 @@ def test_validation_data_loader_correctness(validation_dataloader: YoloDataLoade
44
  assert images.shape == (4, 3, 640, 640)
45
  assert targets.shape == (4, 18, 5)
46
  assert reverse_tensors.shape == (4, 5)
47
- expected_paths = (
48
  Path("tests/data/images/val/000000151480.jpg"),
49
  Path("tests/data/images/val/000000284106.jpg"),
50
  Path("tests/data/images/val/000000323571.jpg"),
51
  Path("tests/data/images/val/000000570456.jpg"),
52
- )
53
  assert image_paths == expected_paths
54
 
55
 
 
31
  assert batch_size == 2
32
  assert images.shape == (2, 3, 640, 640)
33
  assert reverse_tensors.shape == (2, 5)
34
+ expected_paths = [
35
  Path("tests/data/images/train/000000050725.jpg"),
36
  Path("tests/data/images/train/000000167848.jpg"),
37
+ ]
38
  assert image_paths == expected_paths
39
 
40
 
 
44
  assert images.shape == (4, 3, 640, 640)
45
  assert targets.shape == (4, 18, 5)
46
  assert reverse_tensors.shape == (4, 5)
47
+ expected_paths = [
48
  Path("tests/data/images/val/000000151480.jpg"),
49
  Path("tests/data/images/val/000000284106.jpg"),
50
  Path("tests/data/images/val/000000323571.jpg"),
51
  Path("tests/data/images/val/000000570456.jpg"),
52
+ ]
53
  assert image_paths == expected_paths
54
 
55
 
tests/test_tools/test_loss_functions.py CHANGED
@@ -31,7 +31,7 @@ def model(cfg: Config):
31
  @pytest.fixture
32
  def vec2box(cfg: Config, model):
33
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
34
- return Vec2Box(model, cfg.image_size, device)
35
 
36
 
37
  @pytest.fixture
 
31
  @pytest.fixture
32
  def vec2box(cfg: Config, model):
33
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
34
+ return Vec2Box(model, cfg.model.anchor, cfg.image_size, device)
35
 
36
 
37
  @pytest.fixture
tests/test_utils/test_bounding_box_utils.py CHANGED
@@ -4,7 +4,7 @@ from pathlib import Path
4
  import pytest
5
  import torch
6
  from hydra import compose, initialize
7
- from torch import Tensor, allclose, float32, isclose, nn, tensor
8
 
9
  project_root = Path(__file__).resolve().parent.parent.parent
10
  sys.path.append(str(project_root))
@@ -117,7 +117,7 @@ def test_vec2box_autoanchor():
117
  cfg: Config = compose(config_name="config", overrides=["model=v9-m"])
118
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
119
  model = create_model(cfg.model, weight_path=None).to(device)
120
- vec2box = Vec2Box(model, cfg.image_size, device)
121
  assert vec2box.strides == [8, 16, 32]
122
 
123
  vec2box.update((320, 640))
 
4
  import pytest
5
  import torch
6
  from hydra import compose, initialize
7
+ from torch import allclose, float32, isclose, tensor
8
 
9
  project_root = Path(__file__).resolve().parent.parent.parent
10
  sys.path.append(str(project_root))
 
117
  cfg: Config = compose(config_name="config", overrides=["model=v9-m"])
118
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
119
  model = create_model(cfg.model, weight_path=None).to(device)
120
+ vec2box = Vec2Box(model, cfg.model.anchor, cfg.image_size, device)
121
  assert vec2box.strides == [8, 16, 32]
122
 
123
  vec2box.update((320, 640))
yolo/lazy.py CHANGED
@@ -27,7 +27,7 @@ def main(cfg: Config):
27
  model = create_model(cfg.model, class_num=cfg.class_num, weight_path=cfg.weight)
28
  model = model.to(device)
29
 
30
- vec2box = Vec2Box(model, cfg.image_size, device)
31
  if cfg.task.task == "train":
32
  solver = ModelTrainer(cfg, model, vec2box, progress, device, use_ddp)
33
  if cfg.task.task == "validation":
 
27
  model = create_model(cfg.model, class_num=cfg.class_num, weight_path=cfg.weight)
28
  model = model.to(device)
29
 
30
+ vec2box = Vec2Box(model, cfg.model.anchor, cfg.image_size, device)
31
  if cfg.task.task == "train":
32
  solver = ModelTrainer(cfg, model, vec2box, progress, device, use_ddp)
33
  if cfg.task.task == "validation":
yolo/utils/bounding_box_utils.py CHANGED
@@ -364,7 +364,7 @@ class Anc2Box:
364
  return preds_cls, None, preds_box, preds_cnf.sigmoid()
365
 
366
 
367
- def bbox_nms(cls_dist: Tensor, bbox: Tensor, nms_cfg: NMSConfig, confidence: Optional[Tensor]):
368
  cls_dist = cls_dist.sigmoid() * (1 if confidence is None else confidence)
369
 
370
  # filter class by confidence
 
364
  return preds_cls, None, preds_box, preds_cnf.sigmoid()
365
 
366
 
367
+ def bbox_nms(cls_dist: Tensor, bbox: Tensor, nms_cfg: NMSConfig, confidence: Optional[Tensor] = None):
368
  cls_dist = cls_dist.sigmoid() * (1 if confidence is None else confidence)
369
 
370
  # filter class by confidence