-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfinal_test.py
More file actions
206 lines (160 loc) · 6.97 KB
/
final_test.py
File metadata and controls
206 lines (160 loc) · 6.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
"""
Фінальний тест проекту - перевірка всіх компонентів
"""
import os
import sys
import subprocess
def check_file_exists(path, description):
"""Перевіряє існування файлу"""
if os.path.exists(path):
print(f"✅ {description}: {path}")
return True
else:
print(f"❌ {description} не знайдено: {path}")
return False
def check_model_files():
"""Перевіряє наявність файлів моделей"""
print("=== Перевірка файлів моделей ===")
files_to_check = [
("weights/YOLO/model_3_best.pt", "PyTorch модель"),
("weights/YOLO/model_3_best.onnx", "ONNX модель"),
("weights/YOLO/model_3_simple.tflite", "TensorFlow Lite модель"),
]
all_good = True
for path, description in files_to_check:
if not check_file_exists(path, description):
all_good = False
else:
# Показуємо розмір файлу
size_mb = os.path.getsize(path) / (1024 * 1024)
print(f" 📊 Розмір: {size_mb:.2f} MB")
return all_good
def check_python_files():
"""Перевіряє наявність Python файлів"""
print("\n=== Перевірка Python файлів ===")
files_to_check = [
("main.py", "Основний файл (PyTorch)"),
("main_tflite.py", "TensorFlow Lite версія"),
("test_tflite.py", "Тест TFLite моделі"),
("src/convert_to_tflite/onnx2tf_converter.py", "Конвертер ONNX → TFLite"),
("requirements.txt", "Файл залежностей"),
("README.md", "Документація"),
]
all_good = True
for path, description in files_to_check:
if not check_file_exists(path, description):
all_good = False
return all_good
def test_import_tflite():
"""Тестує імпорт TensorFlow Lite"""
print("\n=== Тест імпорту TensorFlow Lite ===")
try:
import tensorflow as tf
print("✅ TensorFlow імпортовано успішно")
print(f" 📊 Версія TensorFlow: {tf.__version__}")
# Перевіряємо TFLite
interpreter = tf.lite.Interpreter("weights/YOLO/model_3_simple.tflite")
interpreter.allocate_tensors()
print("✅ TFLite інтерпретатор працює")
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
print(f" 📊 Вхідна форма: {input_details[0]['shape']}")
print(f" 📊 Вихідна форма: {output_details[0]['shape']}")
return True
except Exception as e:
print(f"❌ Помилка імпорту TensorFlow Lite: {e}")
return False
def test_opencv():
"""Тестує OpenCV"""
print("\n=== Тест OpenCV ===")
try:
import cv2 as cv
print("✅ OpenCV імпортовано успішно")
print(f" 📊 Версія OpenCV: {cv.__version__}")
# Тестуємо створення зображення
import numpy as np
test_img = np.zeros((480, 640, 3), dtype=np.uint8)
resized = cv.resize(test_img, (320, 240))
print("✅ OpenCV операції працюють")
return True
except Exception as e:
print(f"❌ Помилка OpenCV: {e}")
return False
def test_deep_sort():
"""Тестує Deep Sort"""
print("\n=== Тест Deep Sort ===")
try:
from deep_sort_realtime.deepsort_tracker import DeepSort
deep_sort = DeepSort(max_age=30, n_init=3)
print("✅ Deep Sort працює")
return True
except Exception as e:
print(f"❌ Помилка Deep Sort: {e}")
return False
def run_quick_tflite_test():
"""Швидкий тест TFLite моделі"""
print("\n=== Швидкий тест TFLite моделі ===")
try:
# Імпортуємо наш клас
sys.path.append('.')
from main_tflite import TFLiteYOLO
# Створюємо модель
yolo_model = TFLiteYOLO("weights/YOLO/model_3_simple.tflite")
# Тестове зображення
import numpy as np
test_image = np.random.randint(0, 255, (480, 640, 3), dtype=np.uint8)
# Детекція
detections = yolo_model.detect(test_image)
print(f"✅ TFLite модель працює! Знайдено {len(detections)} об'єктів")
# Показуємо кілька перших детекцій
for i, detection in enumerate(detections[:3]):
x1, y1, x2, y2, conf = detection
print(f" Об'єкт {i+1}: [{x1:.0f}, {y1:.0f}, {x2:.0f}, {y2:.0f}] conf={conf:.2f}")
return True
except Exception as e:
print(f"❌ Помилка TFLite тесту: {e}")
return False
def main():
"""Основна функція тестування"""
print("🧪 Фінальний тест проекту Drone AI v.0.9.1t")
print("=" * 50)
# Список тестів
tests = [
("Файли моделей", check_model_files),
("Python файли", check_python_files),
("TensorFlow Lite", test_import_tflite),
("OpenCV", test_opencv),
("Deep Sort", test_deep_sort),
("TFLite модель", run_quick_tflite_test),
]
results = []
for test_name, test_func in tests:
try:
result = test_func()
results.append((test_name, result))
except Exception as e:
print(f"❌ Критична помилка в тесті '{test_name}': {e}")
results.append((test_name, False))
# Підсумок
print("\n" + "=" * 50)
print("🎯 ПІДСУМОК ТЕСТУВАННЯ")
print("=" * 50)
passed = 0
total = len(results)
for test_name, result in results:
status = "✅ ПРОЙДЕНО" if result else "❌ НЕ ПРОЙДЕНО"
print(f"{status}: {test_name}")
if result:
passed += 1
print(f"\n📊 Результат: {passed}/{total} тестів пройдено")
if passed == total:
print("🎉 ВСІ ТЕСТИ ПРОЙДЕНО! Проект готовий до використання.")
print("\n🚀 Для запуску:")
print(" PyTorch версія: python main.py")
print(" TFLite версія: python main_tflite.py")
else:
print("⚠️ Деякі тести не пройдено. Перевірте помилки вище.")
return passed == total
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)