-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyolo_stats.py
80 lines (62 loc) · 2.12 KB
/
yolo_stats.py
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
import wandb
from ultralytics import YOLO
import time
import psutil
import threading
def log_usage(interval=1):
global stop_threads
while not stop_threads:
# Get current time
now = time.time()
# Get CPU and memory usage
cpu_usage = psutil.cpu_percent(interval=0.1)
memory_info = psutil.virtual_memory()
memory_usage = memory_info.used / 1024 / 1024
cpu_freq = psutil.cpu_freq().current
# Log to Weights & Biases
wandb.log({"CPU Usage (%)": cpu_usage, "CPU Frequency (MHz)": cpu_freq, "Memory Usage (MB)": memory_usage, "Timestamp": now})
# Wait for the next interval
time.sleep(interval)
def start_wandb_logging(interval=1):
# Create a thread for the log_usage function
logging_thread = threading.Thread(target=log_usage, args=(interval,))
# Set the thread as a daemon so it exits when the main program does
logging_thread.daemon = True
# Start the thread
logging_thread.start()
max_imgsz = 1280
device = 'CM4'
wandb.init(
# set the wandb project where this run will be logged
project="yolo-stats",
# track hyperparameters and run metadata
config={
'max_imgsz': max_imgsz,
'device': device
}
)
stop_threads = False
start_wandb_logging(interval=1)
model = YOLO(f'./YOLO/img{max_imgsz}/weights/best.pt')
results = model('../datasets/DOTAv1.5/images/test', imgsz=max_imgsz, stream=True)
avg_speed = 0
total = 0
for result in results:
preprocess_time = result.speed['preprocess']
inference_time = result.speed['inference']
postprocess_time = result.speed['postprocess']
avg_speed += preprocess_time + inference_time + postprocess_time
total += 1
wandb.log({
"preprocess_time": preprocess_time,
"inference_time": inference_time,
"postprocess_time": postprocess_time,
"total_time": preprocess_time + inference_time + postprocess_time
})
avg_speed = avg_speed / total
wandb.log({"avg_speed": avg_speed})
print(f'Average Speed for imgsz {max_imgsz}: ', avg_speed)
time.sleep(5)
stop_threads = True
time.time(1)
wandb.finish()