From 69ea70cd3b4c3e908bbfac094bc4550a3dcf43e3 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 15 Dec 2020 18:35:47 -0800 Subject: [PATCH] Add idetection_profile() function to plots.py (#1700) --- utils/plots.py | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/utils/plots.py b/utils/plots.py index d3dff65..dd25fac 100644 --- a/utils/plots.py +++ b/utils/plots.py @@ -1,13 +1,13 @@ # Plotting utils import glob +import math import os import random from copy import copy from pathlib import Path import cv2 -import math import matplotlib import matplotlib.pyplot as plt import numpy as np @@ -329,6 +329,39 @@ def plot_evolution(yaml_file='data/hyp.finetune.yaml'): # from utils.plots impo print('\nPlot saved as evolve.png') +def profile_idetection(start=0, stop=0, labels=(), save_dir=''): + # Plot iDetection '*.txt' per-image logs. from . import *; profile_idetection() + fig, ax = plt.subplots(2, 4, figsize=(12, 6), tight_layout=True) + ax = ax.ravel() + s = ['Images', 'Free Storage (GB)', 'RAM Usage (GB)', 'Battery', 'dt_raw (ms)', 'dt_smooth (ms)', 'real-world FPS'] + files = list(Path(save_dir).glob('frames*.txt')) + for fi, f in enumerate(files): + try: + results = np.loadtxt(f, ndmin=2).T[:, 90:-30] # clip first and last rows + n = results.shape[1] # number of rows + x = np.arange(start, min(stop, n) if stop else n) + t = (results[0] - results[0].min()) # set t0=0s + results[0] = x + for i, a in enumerate(ax): + if i < len(results): + y = results[i, x] + label = labels[fi] if len(labels) else f.stem.replace('frames_', '') + a.plot(t, y, marker='.', label=label, linewidth=1, markersize=5) + a.set_title(s[i]) + a.set_xlabel('time (s)') + # if fi == len(files) - 1: + # a.set_ylim(bottom=0) + for side in ['top', 'right']: + a.spines[side].set_visible(False) + else: + a.remove() + except Exception as e: + print('Warning: Plotting error for %s; %s' % (f, e)) + + ax[1].legend() + fig.savefig(Path(save_dir) / 'idetection_profile.png', dpi=200) + + def plot_results_overlay(start=0, stop=0): # from utils.plots import *; plot_results_overlay() # Plot training 'results*.txt', overlaying train and val losses s = ['train', 'train', 'train', 'Precision', 'mAP@0.5', 'val', 'val', 'val', 'Recall', 'mAP@0.5:0.95'] # legends