glenn-jocher
commited on
Commit
•
69ea70c
1
Parent(s):
e92245a
Add idetection_profile() function to plots.py (#1700)
Browse files- utils/plots.py +34 -1
utils/plots.py
CHANGED
@@ -1,13 +1,13 @@
|
|
1 |
# Plotting utils
|
2 |
|
3 |
import glob
|
|
|
4 |
import os
|
5 |
import random
|
6 |
from copy import copy
|
7 |
from pathlib import Path
|
8 |
|
9 |
import cv2
|
10 |
-
import math
|
11 |
import matplotlib
|
12 |
import matplotlib.pyplot as plt
|
13 |
import numpy as np
|
@@ -329,6 +329,39 @@ def plot_evolution(yaml_file='data/hyp.finetune.yaml'): # from utils.plots impo
|
|
329 |
print('\nPlot saved as evolve.png')
|
330 |
|
331 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
332 |
def plot_results_overlay(start=0, stop=0): # from utils.plots import *; plot_results_overlay()
|
333 |
# Plot training 'results*.txt', overlaying train and val losses
|
334 |
s = ['train', 'train', 'train', 'Precision', 'mAP@0.5', 'val', 'val', 'val', 'Recall', 'mAP@0.5:0.95'] # legends
|
|
|
1 |
# Plotting utils
|
2 |
|
3 |
import glob
|
4 |
+
import math
|
5 |
import os
|
6 |
import random
|
7 |
from copy import copy
|
8 |
from pathlib import Path
|
9 |
|
10 |
import cv2
|
|
|
11 |
import matplotlib
|
12 |
import matplotlib.pyplot as plt
|
13 |
import numpy as np
|
|
|
329 |
print('\nPlot saved as evolve.png')
|
330 |
|
331 |
|
332 |
+
def profile_idetection(start=0, stop=0, labels=(), save_dir=''):
|
333 |
+
# Plot iDetection '*.txt' per-image logs. from . import *; profile_idetection()
|
334 |
+
fig, ax = plt.subplots(2, 4, figsize=(12, 6), tight_layout=True)
|
335 |
+
ax = ax.ravel()
|
336 |
+
s = ['Images', 'Free Storage (GB)', 'RAM Usage (GB)', 'Battery', 'dt_raw (ms)', 'dt_smooth (ms)', 'real-world FPS']
|
337 |
+
files = list(Path(save_dir).glob('frames*.txt'))
|
338 |
+
for fi, f in enumerate(files):
|
339 |
+
try:
|
340 |
+
results = np.loadtxt(f, ndmin=2).T[:, 90:-30] # clip first and last rows
|
341 |
+
n = results.shape[1] # number of rows
|
342 |
+
x = np.arange(start, min(stop, n) if stop else n)
|
343 |
+
t = (results[0] - results[0].min()) # set t0=0s
|
344 |
+
results[0] = x
|
345 |
+
for i, a in enumerate(ax):
|
346 |
+
if i < len(results):
|
347 |
+
y = results[i, x]
|
348 |
+
label = labels[fi] if len(labels) else f.stem.replace('frames_', '')
|
349 |
+
a.plot(t, y, marker='.', label=label, linewidth=1, markersize=5)
|
350 |
+
a.set_title(s[i])
|
351 |
+
a.set_xlabel('time (s)')
|
352 |
+
# if fi == len(files) - 1:
|
353 |
+
# a.set_ylim(bottom=0)
|
354 |
+
for side in ['top', 'right']:
|
355 |
+
a.spines[side].set_visible(False)
|
356 |
+
else:
|
357 |
+
a.remove()
|
358 |
+
except Exception as e:
|
359 |
+
print('Warning: Plotting error for %s; %s' % (f, e))
|
360 |
+
|
361 |
+
ax[1].legend()
|
362 |
+
fig.savefig(Path(save_dir) / 'idetection_profile.png', dpi=200)
|
363 |
+
|
364 |
+
|
365 |
def plot_results_overlay(start=0, stop=0): # from utils.plots import *; plot_results_overlay()
|
366 |
# Plot training 'results*.txt', overlaying train and val losses
|
367 |
s = ['train', 'train', 'train', 'Precision', 'mAP@0.5', 'val', 'val', 'val', 'Recall', 'mAP@0.5:0.95'] # legends
|