Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/docstrings' into docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
glenn-jocher committed Feb 25, 2024
2 parents 9cd86c4 + 3de20b5 commit f704a79
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions utils/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@
class Colors:
# Ultralytics color palette https://ultralytics.com/
def __init__(self):
"""Initializes the Colors class with a palette derived from Ultralytics color scheme, converting hex codes to RGB. Colors derived from `hex = matplotlib.colors.TABLEAU_COLORS.values()`."""
"""
Initializes the Colors class with a palette derived from Ultralytics color scheme, converting hex codes to RGB.
Colors derived from `hex = matplotlib.colors.TABLEAU_COLORS.values()`.
"""
hexs = (
"FF3838",
"FF9D97",
Expand Down Expand Up @@ -101,7 +105,11 @@ def feature_visualization(x, module_type, stage, n=32, save_dir=Path("runs/detec


def hist2d(x, y, n=100):
"""Generates a logarithmic 2D histogram, useful for visualizing label or evolution distributions. Used in used in labels.png and evolve.png."""
"""
Generates a logarithmic 2D histogram, useful for visualizing label or evolution distributions.
Used in used in labels.png and evolve.png.
"""
xedges, yedges = np.linspace(x.min(), x.max(), n), np.linspace(y.min(), y.max(), n)
hist, xedges, yedges = np.histogram2d(x, y, (xedges, yedges))
xidx = np.clip(np.digitize(x, xedges) - 1, 0, hist.shape[0] - 1)
Expand All @@ -124,7 +132,9 @@ def butter_lowpass(cutoff, fs, order):


def output_to_target(output, max_det=300):
"""Converts YOLOv5 model output to [batch_id, class_id, x, y, w, h, conf] format for plotting, limiting detections to `max_det`."""
"""Converts YOLOv5 model output to [batch_id, class_id, x, y, w, h, conf] format for plotting, limiting detections
to `max_det`.
"""
targets = []
for i, o in enumerate(output):
box, conf, cls = o[:max_det, :6].cpu().split((4, 1, 1), 1)
Expand Down Expand Up @@ -399,7 +409,11 @@ def plot_evolve(evolve_csv="path/to/evolve.csv"): # from utils.plots import *;


def plot_results(file="path/to/results.csv", dir=""):
"""Plots training results from a 'results.csv' file; accepts file path and directory as arguments. Example: from utils.plots import *; plot_results('path/to/results.csv')"""
"""
Plots training results from a 'results.csv' file; accepts file path and directory as arguments.
Example: from utils.plots import *; plot_results('path/to/results.csv')
"""
save_dir = Path(file).parent if file else Path(dir)
fig, ax = plt.subplots(2, 5, figsize=(12, 6), tight_layout=True)
ax = ax.ravel()
Expand All @@ -426,7 +440,11 @@ def plot_results(file="path/to/results.csv", dir=""):


def profile_idetection(start=0, stop=0, labels=(), save_dir=""):
"""Plots per-image iDetection logs, comparing metrics like storage and performance over time. Example: from utils.plots import *; profile_idetection()"""
"""
Plots per-image iDetection logs, comparing metrics like storage and performance over time.
Example: from utils.plots import *; profile_idetection()
"""
ax = plt.subplots(2, 4, figsize=(12, 6), tight_layout=True)[1].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"))
Expand Down Expand Up @@ -457,7 +475,9 @@ def profile_idetection(start=0, stop=0, labels=(), save_dir=""):


def save_one_box(xyxy, im, file=Path("im.jpg"), gain=1.02, pad=10, square=False, BGR=False, save=True):
"""Crops and saves an image from bounding box `xyxy`, applied with `gain` and `pad`, optionally squares and adjusts for BGR."""
"""Crops and saves an image from bounding box `xyxy`, applied with `gain` and `pad`, optionally squares and adjusts
for BGR.
"""
xyxy = torch.tensor(xyxy).view(-1, 4)
b = xyxy2xywh(xyxy) # boxes
if square:
Expand Down

0 comments on commit f704a79

Please sign in to comment.