|
1 | | -#!/usr/bin/env python3 |
2 | | -""" |
3 | | -Test YOLOX batch processing functionality. |
4 | | -""" |
| 1 | +import pytest |
5 | 2 |
|
6 | | -import numpy as np |
7 | | -from pathlib import Path |
| 3 | +from boxmot.detectors import get_yolo_inferer |
8 | 4 |
|
9 | | -print("=" * 70) |
10 | | -print("YOLOX BATCH PROCESSING TEST") |
11 | | -print("=" * 70) |
12 | | -print() |
13 | 5 |
|
14 | | -# Test 1: Single image processing (baseline) |
15 | | -print("Test 1: Single image processing...") |
16 | | -try: |
17 | | - from boxmot.detectors import YoloX |
18 | | - |
19 | | - model_path = "yolox_s.pt" |
20 | | - if not Path(model_path).exists(): |
21 | | - print(f"⚠ Model file {model_path} not found, skipping test") |
22 | | - else: |
23 | | - detector = YoloX(model=model_path, device="cpu") |
24 | | - |
25 | | - # Create a dummy image |
26 | | - image = np.random.randint(0, 255, (480, 640, 3), dtype=np.uint8) |
27 | | - |
28 | | - # Process single image |
29 | | - result = detector(image) |
30 | | - print(f" - Single image input shape: {image.shape}") |
31 | | - print(f" - Single image output shape: {result.shape}") |
32 | | - print(f" - Output format: [N, 6] = [{result.shape[0]}, {result.shape[1]}]") |
33 | | - print("✓ Single image processing works") |
34 | | -except Exception as e: |
35 | | - print(f"✗ Single image test failed: {e}") |
36 | | - import traceback |
37 | | - traceback.print_exc() |
| 6 | +def test_get_yolo_inferer_routes_yolox_model(): |
| 7 | + inferer_cls = get_yolo_inferer("yolox_s.pt") |
| 8 | + assert inferer_cls.__name__ == "YoloXStrategy" |
38 | 9 |
|
39 | | -print() |
40 | 10 |
|
41 | | -# Test 2: Batch processing |
42 | | -print("Test 2: Batch processing (list of images)...") |
43 | | -try: |
44 | | - from boxmot.detectors import YoloX |
45 | | - |
46 | | - model_path = "yolox_s.pt" |
47 | | - if not Path(model_path).exists(): |
48 | | - print(f"⚠ Model file {model_path} not found, skipping test") |
49 | | - else: |
50 | | - detector = YoloX(model=model_path, device="cpu") |
51 | | - |
52 | | - # Create batch of dummy images (different sizes to test flexibility) |
53 | | - batch_size = 3 |
54 | | - images = [ |
55 | | - np.random.randint(0, 255, (480, 640, 3), dtype=np.uint8), |
56 | | - np.random.randint(0, 255, (720, 1280, 3), dtype=np.uint8), |
57 | | - np.random.randint(0, 255, (360, 480, 3), dtype=np.uint8), |
58 | | - ] |
59 | | - |
60 | | - print(f" - Batch size: {batch_size}") |
61 | | - print(f" - Image shapes: {[img.shape for img in images]}") |
62 | | - |
63 | | - # Process batch |
64 | | - results = detector(images) |
65 | | - |
66 | | - if isinstance(results, list): |
67 | | - print(f" - Batch output: list of {len(results)} arrays") |
68 | | - for i, result in enumerate(results): |
69 | | - print(f" - Image {i+1} detections: {result.shape}") |
70 | | - print("✓ Batch processing works (returns list)") |
71 | | - else: |
72 | | - print(f" - Unexpected output type: {type(results)}") |
73 | | - print("⚠ Expected list output for batch processing") |
74 | | - |
75 | | -except Exception as e: |
76 | | - print(f"✗ Batch processing test failed: {e}") |
77 | | - import traceback |
78 | | - traceback.print_exc() |
| 11 | +def test_get_yolo_inferer_returns_callable_strategy_for_yolox(): |
| 12 | + inferer_cls = get_yolo_inferer("yolox_n.pt") |
| 13 | + assert callable(inferer_cls) |
79 | 14 |
|
80 | | -print() |
81 | 15 |
|
82 | | -# Test 3: Verify preprocessing handles batches correctly |
83 | | -print("Test 3: Testing preprocess method directly...") |
84 | | -try: |
85 | | - from boxmot.detectors import YoloX |
86 | | - |
87 | | - model_path = "yolox_s.pt" |
88 | | - if not Path(model_path).exists(): |
89 | | - print(f"⚠ Model file {model_path} not found, skipping test") |
90 | | - else: |
91 | | - detector = YoloX(model=model_path, device="cpu") |
92 | | - |
93 | | - # Test single image preprocessing |
94 | | - image = np.random.randint(0, 255, (480, 640, 3), dtype=np.uint8) |
95 | | - tensor_single = detector.preprocess(image) |
96 | | - print(f" - Single image tensor shape: {tensor_single.shape}") |
97 | | - print(f" Expected: [3, H, W], Got: {list(tensor_single.shape)}") |
98 | | - |
99 | | - # Test batch preprocessing |
100 | | - images = [ |
101 | | - np.random.randint(0, 255, (480, 640, 3), dtype=np.uint8), |
102 | | - np.random.randint(0, 255, (720, 1280, 3), dtype=np.uint8), |
103 | | - ] |
104 | | - tensor_batch = detector.preprocess(images) |
105 | | - print(f" - Batch tensor shape: {tensor_batch.shape}") |
106 | | - print(f" Expected: [B, 3, H, W], Got: {list(tensor_batch.shape)}") |
107 | | - |
108 | | - if len(tensor_batch.shape) == 4 and tensor_batch.shape[0] == 2: |
109 | | - print("✓ Preprocess handles batches correctly") |
110 | | - else: |
111 | | - print("⚠ Unexpected batch tensor shape") |
112 | | - |
113 | | -except Exception as e: |
114 | | - print(f"✗ Preprocess test failed: {e}") |
115 | | - import traceback |
116 | | - traceback.print_exc() |
117 | | - |
118 | | -print() |
119 | | -print("=" * 70) |
120 | | -print("BATCH PROCESSING TEST COMPLETED") |
121 | | -print("=" * 70) |
| 16 | +@pytest.mark.parametrize("name", ["yolox_s.pt", "yolox_x_MOT17_ablation.pt"]) |
| 17 | +def test_get_yolo_inferer_accepts_common_yolox_names(name): |
| 18 | + inferer_cls = get_yolo_inferer(name) |
| 19 | + assert inferer_cls.__name__ == "YoloXStrategy" |
0 commit comments