2023-04-14 20:36:16 +08:00
|
|
|
# YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
|
2024-01-08 08:29:14 +08:00
|
|
|
"""Plotting utils."""
|
2020-11-14 18:50:32 +08:00
|
|
|
|
2022-08-21 07:34:03 +08:00
|
|
|
import contextlib
|
2021-09-20 19:57:23 +08:00
|
|
|
import math
|
|
|
|
import os
|
2021-12-08 23:46:24 +08:00
|
|
|
from copy import copy
|
2020-11-14 18:50:32 +08:00
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
import cv2
|
|
|
|
import matplotlib
|
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
import numpy as np
|
2020-12-19 10:05:38 +08:00
|
|
|
import pandas as pd
|
2021-06-10 19:51:29 +08:00
|
|
|
import seaborn as sn
|
2020-11-14 18:50:32 +08:00
|
|
|
import torch
|
2023-08-02 02:56:35 +08:00
|
|
|
from PIL import Image, ImageDraw
|
2023-05-22 20:12:10 +08:00
|
|
|
from scipy.ndimage.filters import gaussian_filter1d
|
2023-08-02 02:56:35 +08:00
|
|
|
from ultralytics.utils.plotting import Annotator
|
2020-11-14 18:50:32 +08:00
|
|
|
|
2022-08-25 20:34:26 +08:00
|
|
|
from utils import TryExcept, threaded
|
2023-08-02 02:56:35 +08:00
|
|
|
from utils.general import LOGGER, clip_boxes, increment_path, xywh2xyxy, xyxy2xywh
|
2020-11-14 18:50:32 +08:00
|
|
|
from utils.metrics import fitness
|
|
|
|
|
2020-11-16 23:34:07 +08:00
|
|
|
# Settings
|
2024-01-08 08:29:14 +08:00
|
|
|
RANK = int(os.getenv("RANK", -1))
|
|
|
|
matplotlib.rc("font", **{"size": 11})
|
|
|
|
matplotlib.use("Agg") # for writing to files only
|
2020-11-16 23:34:07 +08:00
|
|
|
|
2020-11-14 18:50:32 +08:00
|
|
|
|
2021-04-28 22:05:14 +08:00
|
|
|
class Colors:
|
|
|
|
# Ultralytics color palette https://ultralytics.com/
|
|
|
|
def __init__(self):
|
2024-02-25 21:04:01 +08:00
|
|
|
"""
|
|
|
|
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()`.
|
|
|
|
"""
|
2024-01-08 08:29:14 +08:00
|
|
|
hexs = (
|
|
|
|
"FF3838",
|
|
|
|
"FF9D97",
|
|
|
|
"FF701F",
|
|
|
|
"FFB21D",
|
|
|
|
"CFD231",
|
|
|
|
"48F90A",
|
|
|
|
"92CC17",
|
|
|
|
"3DDB86",
|
|
|
|
"1A9334",
|
|
|
|
"00D4BB",
|
|
|
|
"2C99A8",
|
|
|
|
"00C2FF",
|
|
|
|
"344593",
|
|
|
|
"6473FF",
|
|
|
|
"0018EC",
|
|
|
|
"8438FF",
|
|
|
|
"520085",
|
|
|
|
"CB38FF",
|
|
|
|
"FF95C8",
|
|
|
|
"FF37C7",
|
|
|
|
)
|
|
|
|
self.palette = [self.hex2rgb(f"#{c}") for c in hexs]
|
2021-04-28 22:05:14 +08:00
|
|
|
self.n = len(self.palette)
|
|
|
|
|
|
|
|
def __call__(self, i, bgr=False):
|
2024-02-25 21:04:01 +08:00
|
|
|
"""Returns color from palette by index `i`, in BGR format if `bgr=True`, else RGB; `i` is an integer index."""
|
2021-04-28 22:05:14 +08:00
|
|
|
c = self.palette[int(i) % self.n]
|
|
|
|
return (c[2], c[1], c[0]) if bgr else c
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def hex2rgb(h): # rgb order (PIL)
|
2024-01-08 08:29:14 +08:00
|
|
|
return tuple(int(h[1 + i : 1 + i + 2], 16) for i in (0, 2, 4))
|
2020-11-14 18:50:32 +08:00
|
|
|
|
2021-04-28 22:05:14 +08:00
|
|
|
|
|
|
|
colors = Colors() # create instance for 'from utils.plots import colors'
|
2020-11-14 18:50:32 +08:00
|
|
|
|
|
|
|
|
2024-01-08 08:29:14 +08:00
|
|
|
def feature_visualization(x, module_type, stage, n=32, save_dir=Path("runs/detect/exp")):
|
2021-11-07 02:28:03 +08:00
|
|
|
"""
|
|
|
|
x: Features to be visualized
|
|
|
|
module_type: Module type
|
|
|
|
stage: Module stage within model
|
|
|
|
n: Maximum number of feature maps to plot
|
|
|
|
save_dir: Directory to save results
|
|
|
|
"""
|
2024-01-08 08:29:14 +08:00
|
|
|
if ("Detect" not in module_type) and (
|
|
|
|
"Segment" not in module_type
|
|
|
|
): # 'Detect' for Object Detect task,'Segment' for Segment task
|
2021-11-07 02:28:03 +08:00
|
|
|
batch, channels, height, width = x.shape # batch, channels, height, width
|
|
|
|
if height > 1 and width > 1:
|
2021-11-22 03:21:44 +08:00
|
|
|
f = save_dir / f"stage{stage}_{module_type.split('.')[-1]}_features.png" # filename
|
2021-11-07 02:28:03 +08:00
|
|
|
|
|
|
|
blocks = torch.chunk(x[0].cpu(), channels, dim=0) # select batch index 0, block by channels
|
|
|
|
n = min(n, channels) # number of plots
|
|
|
|
fig, ax = plt.subplots(math.ceil(n / 8), 8, tight_layout=True) # 8 rows x n/8 cols
|
|
|
|
ax = ax.ravel()
|
|
|
|
plt.subplots_adjust(wspace=0.05, hspace=0.05)
|
|
|
|
for i in range(n):
|
|
|
|
ax[i].imshow(blocks[i].squeeze()) # cmap='gray'
|
2024-01-08 08:29:14 +08:00
|
|
|
ax[i].axis("off")
|
2021-11-07 02:28:03 +08:00
|
|
|
|
2024-01-08 08:29:14 +08:00
|
|
|
LOGGER.info(f"Saving {f}... ({n}/{channels})")
|
|
|
|
plt.savefig(f, dpi=300, bbox_inches="tight")
|
2021-11-07 02:28:03 +08:00
|
|
|
plt.close()
|
2024-01-08 08:29:14 +08:00
|
|
|
np.save(str(f.with_suffix(".npy")), x[0].cpu().numpy()) # npy save
|
2021-11-07 02:28:03 +08:00
|
|
|
|
|
|
|
|
2021-08-29 23:44:51 +08:00
|
|
|
def hist2d(x, y, n=100):
|
2024-02-25 21:04:01 +08:00
|
|
|
"""
|
|
|
|
Generates a logarithmic 2D histogram, useful for visualizing label or evolution distributions.
|
|
|
|
|
|
|
|
Used in used in labels.png and evolve.png.
|
|
|
|
"""
|
2021-08-29 23:44:51 +08:00
|
|
|
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)
|
|
|
|
yidx = np.clip(np.digitize(y, yedges) - 1, 0, hist.shape[1] - 1)
|
|
|
|
return np.log(hist[xidx, yidx])
|
|
|
|
|
|
|
|
|
|
|
|
def butter_lowpass_filtfilt(data, cutoff=1500, fs=50000, order=5):
|
2024-02-25 21:04:01 +08:00
|
|
|
"""Applies a low-pass Butterworth filter to `data` with specified `cutoff`, `fs`, and `order`."""
|
2021-08-29 23:44:51 +08:00
|
|
|
from scipy.signal import butter, filtfilt
|
|
|
|
|
|
|
|
# https://stackoverflow.com/questions/28536191/how-to-filter-smooth-with-scipy-numpy
|
|
|
|
def butter_lowpass(cutoff, fs, order):
|
|
|
|
nyq = 0.5 * fs
|
|
|
|
normal_cutoff = cutoff / nyq
|
2024-01-08 08:29:14 +08:00
|
|
|
return butter(order, normal_cutoff, btype="low", analog=False)
|
2021-08-29 23:44:51 +08:00
|
|
|
|
|
|
|
b, a = butter_lowpass(cutoff, fs, order=order)
|
|
|
|
return filtfilt(b, a, data) # forward-backward filter
|
|
|
|
|
|
|
|
|
YOLOv5 segmentation model support (#9052)
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fix duplicate plots.py
* Fix check_font()
* # torch.use_deterministic_algorithms(True)
* update doc detect->predict
* Resolve precommit for segment/train and segment/val
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Resolve precommit for utils/segment
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Resolve precommit min_wh
* Resolve precommit utils/segment/plots
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Resolve precommit utils/segment/general
* Align NMS-seg closer to NMS
* restore deterministic init_seeds code
* remove easydict dependency
* update
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* restore output_to_target mask
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update
* cleanup
* Remove unused ImageFont import
* Unified NMS
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* DetectMultiBackend compatibility
* segment/predict.py update
* update plot colors
* fix bbox shifted
* sort bbox by confidence
* enable overlap by default
* Merge detect/segment output_to_target() function
* Start segmentation CI
* fix plots
* Update ci-testing.yml
* fix training whitespace
* optimize process mask functions (can we merge both?)
* Update predict/detect
* Update plot_images
* Update plot_images_and_masks
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fix
* Add train to CI
* fix precommit
* fix precommit CI
* fix precommit pycocotools
* fix val float issues
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fix masks float float issues
* suppress errors
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fix no-predictions plotting bug
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Add CSV Logger
* fix val len(plot_masks)
* speed up evaluation
* fix process_mask
* fix plots
* update segment/utils build_targets
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* optimize utils/segment/general crop()
* optimize utils/segment/general crop() 2
* minor updates
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* torch.where revert
* downsample only if different shape
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* loss cleanup
* loss cleanup 2
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* loss cleanup 3
* update project names
* Rename -seg yamls from _underscore to -dash
* prepare for yolov5n-seg.pt
* precommit space fix
* add coco128-seg.yaml
* update coco128-seg comments
* cleanup val.py
* Major val.py cleanup
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* precommit fix
* precommit fix
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* optional pycocotools
* remove CI pip install pycocotools (auto-installed now)
* seg yaml fix
* optimize mask_iou() and masks_iou()
* threaded fix
* Major train.py update
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Major segments/val/process_batch() update
* yolov5/val updates from segment
* process_batch numpy/tensor fix
* opt-in to pycocotools with --save-json
* threaded pycocotools ops for 2x speed increase
* Avoid permute contiguous if possible
* Add max_det=300 argument to both val.py and segment/val.py
* fix onnx_dynamic
* speed up pycocotools ops
* faster process_mask(upsample=True) for predict
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* eliminate permutations for process_mask(upsample=True)
* eliminate permute-contiguous in crop(), use native dimension order
* cleanup comment
* Add Proto() module
* fix class count
* fix anchor order
* broadcast mask_gti in loss for speed
* Cleanup seg loss
* faster indexing
* faster indexing fix
* faster indexing fix2
* revert faster indexing
* fix validation plotting
* Loss cleanup and mxyxy simplification
* Loss cleanup and mxyxy simplification 2
* revert validation plotting
* replace missing tanh
* Eliminate last permutation
* delete unneeded .float()
* Remove MaskIOULoss and crop(if HWC)
* Final v6.3 SegmentationModel architecture updates
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Add support for TF export
* remove debugger trace
* add call
* update
* update
* Merge master
* Merge master
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update dataloaders.py
* Restore CI
* Update dataloaders.py
* Fix TF/TFLite export for segmentation model
* Merge master
* Cleanup predict.py mask plotting
* cleanup scale_masks()
* rename scale_masks to scale_image
* cleanup/optimize plot_masks
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Add Annotator.masks()
* Annotator.masks() fix
* Update plots.py
* Annotator mask optimization
* Rename crop() to crop_mask()
* Do not crop in predict.py
* crop always
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Merge master
* Add vid-stride from master PR
* Update seg model outputs
* Update seg model outputs
* Add segmentation benchmarks
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Add segmentation benchmarks
* Add segmentation benchmarks
* Add segmentation benchmarks
* Fix DetectMultiBackend for OpenVINO
* update Annotator.masks
* fix val plot
* revert val plot
* clean up
* revert pil
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fix CI error
* fix predict log
* remove upsample
* update interpolate
* fix validation plot logging
* Annotator.masks() cleanup
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Remove segmentation_model definition
* Restore 0.99999 decimals
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
Co-authored-by: Laughing-q <1185102784@qq.com>
Co-authored-by: Jiacong Fang <zldrobit@126.com>
2022-09-16 06:12:46 +08:00
|
|
|
def output_to_target(output, max_det=300):
|
2024-02-25 21:04:01 +08:00
|
|
|
"""Converts YOLOv5 model output to [batch_id, class_id, x, y, w, h, conf] format for plotting, limiting detections
|
|
|
|
to `max_det`.
|
|
|
|
"""
|
2020-11-14 18:50:32 +08:00
|
|
|
targets = []
|
|
|
|
for i, o in enumerate(output):
|
YOLOv5 segmentation model support (#9052)
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fix duplicate plots.py
* Fix check_font()
* # torch.use_deterministic_algorithms(True)
* update doc detect->predict
* Resolve precommit for segment/train and segment/val
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Resolve precommit for utils/segment
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Resolve precommit min_wh
* Resolve precommit utils/segment/plots
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Resolve precommit utils/segment/general
* Align NMS-seg closer to NMS
* restore deterministic init_seeds code
* remove easydict dependency
* update
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* restore output_to_target mask
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update
* cleanup
* Remove unused ImageFont import
* Unified NMS
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* DetectMultiBackend compatibility
* segment/predict.py update
* update plot colors
* fix bbox shifted
* sort bbox by confidence
* enable overlap by default
* Merge detect/segment output_to_target() function
* Start segmentation CI
* fix plots
* Update ci-testing.yml
* fix training whitespace
* optimize process mask functions (can we merge both?)
* Update predict/detect
* Update plot_images
* Update plot_images_and_masks
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fix
* Add train to CI
* fix precommit
* fix precommit CI
* fix precommit pycocotools
* fix val float issues
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fix masks float float issues
* suppress errors
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fix no-predictions plotting bug
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Add CSV Logger
* fix val len(plot_masks)
* speed up evaluation
* fix process_mask
* fix plots
* update segment/utils build_targets
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* optimize utils/segment/general crop()
* optimize utils/segment/general crop() 2
* minor updates
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* torch.where revert
* downsample only if different shape
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* loss cleanup
* loss cleanup 2
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* loss cleanup 3
* update project names
* Rename -seg yamls from _underscore to -dash
* prepare for yolov5n-seg.pt
* precommit space fix
* add coco128-seg.yaml
* update coco128-seg comments
* cleanup val.py
* Major val.py cleanup
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* precommit fix
* precommit fix
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* optional pycocotools
* remove CI pip install pycocotools (auto-installed now)
* seg yaml fix
* optimize mask_iou() and masks_iou()
* threaded fix
* Major train.py update
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Major segments/val/process_batch() update
* yolov5/val updates from segment
* process_batch numpy/tensor fix
* opt-in to pycocotools with --save-json
* threaded pycocotools ops for 2x speed increase
* Avoid permute contiguous if possible
* Add max_det=300 argument to both val.py and segment/val.py
* fix onnx_dynamic
* speed up pycocotools ops
* faster process_mask(upsample=True) for predict
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* eliminate permutations for process_mask(upsample=True)
* eliminate permute-contiguous in crop(), use native dimension order
* cleanup comment
* Add Proto() module
* fix class count
* fix anchor order
* broadcast mask_gti in loss for speed
* Cleanup seg loss
* faster indexing
* faster indexing fix
* faster indexing fix2
* revert faster indexing
* fix validation plotting
* Loss cleanup and mxyxy simplification
* Loss cleanup and mxyxy simplification 2
* revert validation plotting
* replace missing tanh
* Eliminate last permutation
* delete unneeded .float()
* Remove MaskIOULoss and crop(if HWC)
* Final v6.3 SegmentationModel architecture updates
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Add support for TF export
* remove debugger trace
* add call
* update
* update
* Merge master
* Merge master
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update dataloaders.py
* Restore CI
* Update dataloaders.py
* Fix TF/TFLite export for segmentation model
* Merge master
* Cleanup predict.py mask plotting
* cleanup scale_masks()
* rename scale_masks to scale_image
* cleanup/optimize plot_masks
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Add Annotator.masks()
* Annotator.masks() fix
* Update plots.py
* Annotator mask optimization
* Rename crop() to crop_mask()
* Do not crop in predict.py
* crop always
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Merge master
* Add vid-stride from master PR
* Update seg model outputs
* Update seg model outputs
* Add segmentation benchmarks
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Add segmentation benchmarks
* Add segmentation benchmarks
* Add segmentation benchmarks
* Fix DetectMultiBackend for OpenVINO
* update Annotator.masks
* fix val plot
* revert val plot
* clean up
* revert pil
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fix CI error
* fix predict log
* remove upsample
* update interpolate
* fix validation plot logging
* Annotator.masks() cleanup
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Remove segmentation_model definition
* Restore 0.99999 decimals
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
Co-authored-by: Laughing-q <1185102784@qq.com>
Co-authored-by: Jiacong Fang <zldrobit@126.com>
2022-09-16 06:12:46 +08:00
|
|
|
box, conf, cls = o[:max_det, :6].cpu().split((4, 1, 1), 1)
|
|
|
|
j = torch.full((conf.shape[0], 1), i)
|
|
|
|
targets.append(torch.cat((j, cls, xyxy2xywh(box), conf), 1))
|
|
|
|
return torch.cat(targets, 0).numpy()
|
2020-11-14 18:50:32 +08:00
|
|
|
|
|
|
|
|
2022-05-14 22:12:08 +08:00
|
|
|
@threaded
|
2024-01-08 08:29:14 +08:00
|
|
|
def plot_images(images, targets, paths=None, fname="images.jpg", names=None):
|
2024-02-25 21:04:01 +08:00
|
|
|
"""Plots an image grid with labels from YOLOv5 predictions or targets, saving to `fname`."""
|
2020-11-14 18:50:32 +08:00
|
|
|
if isinstance(images, torch.Tensor):
|
|
|
|
images = images.cpu().float().numpy()
|
|
|
|
if isinstance(targets, torch.Tensor):
|
|
|
|
targets = targets.cpu().numpy()
|
YOLOv5 segmentation model support (#9052)
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fix duplicate plots.py
* Fix check_font()
* # torch.use_deterministic_algorithms(True)
* update doc detect->predict
* Resolve precommit for segment/train and segment/val
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Resolve precommit for utils/segment
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Resolve precommit min_wh
* Resolve precommit utils/segment/plots
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Resolve precommit utils/segment/general
* Align NMS-seg closer to NMS
* restore deterministic init_seeds code
* remove easydict dependency
* update
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* restore output_to_target mask
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update
* cleanup
* Remove unused ImageFont import
* Unified NMS
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* DetectMultiBackend compatibility
* segment/predict.py update
* update plot colors
* fix bbox shifted
* sort bbox by confidence
* enable overlap by default
* Merge detect/segment output_to_target() function
* Start segmentation CI
* fix plots
* Update ci-testing.yml
* fix training whitespace
* optimize process mask functions (can we merge both?)
* Update predict/detect
* Update plot_images
* Update plot_images_and_masks
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fix
* Add train to CI
* fix precommit
* fix precommit CI
* fix precommit pycocotools
* fix val float issues
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fix masks float float issues
* suppress errors
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fix no-predictions plotting bug
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Add CSV Logger
* fix val len(plot_masks)
* speed up evaluation
* fix process_mask
* fix plots
* update segment/utils build_targets
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* optimize utils/segment/general crop()
* optimize utils/segment/general crop() 2
* minor updates
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* torch.where revert
* downsample only if different shape
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* loss cleanup
* loss cleanup 2
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* loss cleanup 3
* update project names
* Rename -seg yamls from _underscore to -dash
* prepare for yolov5n-seg.pt
* precommit space fix
* add coco128-seg.yaml
* update coco128-seg comments
* cleanup val.py
* Major val.py cleanup
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* precommit fix
* precommit fix
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* optional pycocotools
* remove CI pip install pycocotools (auto-installed now)
* seg yaml fix
* optimize mask_iou() and masks_iou()
* threaded fix
* Major train.py update
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Major segments/val/process_batch() update
* yolov5/val updates from segment
* process_batch numpy/tensor fix
* opt-in to pycocotools with --save-json
* threaded pycocotools ops for 2x speed increase
* Avoid permute contiguous if possible
* Add max_det=300 argument to both val.py and segment/val.py
* fix onnx_dynamic
* speed up pycocotools ops
* faster process_mask(upsample=True) for predict
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* eliminate permutations for process_mask(upsample=True)
* eliminate permute-contiguous in crop(), use native dimension order
* cleanup comment
* Add Proto() module
* fix class count
* fix anchor order
* broadcast mask_gti in loss for speed
* Cleanup seg loss
* faster indexing
* faster indexing fix
* faster indexing fix2
* revert faster indexing
* fix validation plotting
* Loss cleanup and mxyxy simplification
* Loss cleanup and mxyxy simplification 2
* revert validation plotting
* replace missing tanh
* Eliminate last permutation
* delete unneeded .float()
* Remove MaskIOULoss and crop(if HWC)
* Final v6.3 SegmentationModel architecture updates
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Add support for TF export
* remove debugger trace
* add call
* update
* update
* Merge master
* Merge master
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update dataloaders.py
* Restore CI
* Update dataloaders.py
* Fix TF/TFLite export for segmentation model
* Merge master
* Cleanup predict.py mask plotting
* cleanup scale_masks()
* rename scale_masks to scale_image
* cleanup/optimize plot_masks
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Add Annotator.masks()
* Annotator.masks() fix
* Update plots.py
* Annotator mask optimization
* Rename crop() to crop_mask()
* Do not crop in predict.py
* crop always
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Merge master
* Add vid-stride from master PR
* Update seg model outputs
* Update seg model outputs
* Add segmentation benchmarks
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Add segmentation benchmarks
* Add segmentation benchmarks
* Add segmentation benchmarks
* Fix DetectMultiBackend for OpenVINO
* update Annotator.masks
* fix val plot
* revert val plot
* clean up
* revert pil
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fix CI error
* fix predict log
* remove upsample
* update interpolate
* fix validation plot logging
* Annotator.masks() cleanup
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Remove segmentation_model definition
* Restore 0.99999 decimals
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
Co-authored-by: Laughing-q <1185102784@qq.com>
Co-authored-by: Jiacong Fang <zldrobit@126.com>
2022-09-16 06:12:46 +08:00
|
|
|
|
|
|
|
max_size = 1920 # max image size
|
|
|
|
max_subplots = 16 # max image subplots, i.e. 4x4
|
2020-11-14 18:50:32 +08:00
|
|
|
bs, _, h, w = images.shape # batch size, _, height, width
|
|
|
|
bs = min(bs, max_subplots) # limit plot images
|
2024-01-08 08:29:14 +08:00
|
|
|
ns = np.ceil(bs**0.5) # number of subplots (square)
|
YOLOv5 segmentation model support (#9052)
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fix duplicate plots.py
* Fix check_font()
* # torch.use_deterministic_algorithms(True)
* update doc detect->predict
* Resolve precommit for segment/train and segment/val
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Resolve precommit for utils/segment
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Resolve precommit min_wh
* Resolve precommit utils/segment/plots
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Resolve precommit utils/segment/general
* Align NMS-seg closer to NMS
* restore deterministic init_seeds code
* remove easydict dependency
* update
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* restore output_to_target mask
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update
* cleanup
* Remove unused ImageFont import
* Unified NMS
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* DetectMultiBackend compatibility
* segment/predict.py update
* update plot colors
* fix bbox shifted
* sort bbox by confidence
* enable overlap by default
* Merge detect/segment output_to_target() function
* Start segmentation CI
* fix plots
* Update ci-testing.yml
* fix training whitespace
* optimize process mask functions (can we merge both?)
* Update predict/detect
* Update plot_images
* Update plot_images_and_masks
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fix
* Add train to CI
* fix precommit
* fix precommit CI
* fix precommit pycocotools
* fix val float issues
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fix masks float float issues
* suppress errors
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fix no-predictions plotting bug
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Add CSV Logger
* fix val len(plot_masks)
* speed up evaluation
* fix process_mask
* fix plots
* update segment/utils build_targets
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* optimize utils/segment/general crop()
* optimize utils/segment/general crop() 2
* minor updates
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* torch.where revert
* downsample only if different shape
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* loss cleanup
* loss cleanup 2
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* loss cleanup 3
* update project names
* Rename -seg yamls from _underscore to -dash
* prepare for yolov5n-seg.pt
* precommit space fix
* add coco128-seg.yaml
* update coco128-seg comments
* cleanup val.py
* Major val.py cleanup
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* precommit fix
* precommit fix
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* optional pycocotools
* remove CI pip install pycocotools (auto-installed now)
* seg yaml fix
* optimize mask_iou() and masks_iou()
* threaded fix
* Major train.py update
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Major segments/val/process_batch() update
* yolov5/val updates from segment
* process_batch numpy/tensor fix
* opt-in to pycocotools with --save-json
* threaded pycocotools ops for 2x speed increase
* Avoid permute contiguous if possible
* Add max_det=300 argument to both val.py and segment/val.py
* fix onnx_dynamic
* speed up pycocotools ops
* faster process_mask(upsample=True) for predict
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* eliminate permutations for process_mask(upsample=True)
* eliminate permute-contiguous in crop(), use native dimension order
* cleanup comment
* Add Proto() module
* fix class count
* fix anchor order
* broadcast mask_gti in loss for speed
* Cleanup seg loss
* faster indexing
* faster indexing fix
* faster indexing fix2
* revert faster indexing
* fix validation plotting
* Loss cleanup and mxyxy simplification
* Loss cleanup and mxyxy simplification 2
* revert validation plotting
* replace missing tanh
* Eliminate last permutation
* delete unneeded .float()
* Remove MaskIOULoss and crop(if HWC)
* Final v6.3 SegmentationModel architecture updates
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Add support for TF export
* remove debugger trace
* add call
* update
* update
* Merge master
* Merge master
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update dataloaders.py
* Restore CI
* Update dataloaders.py
* Fix TF/TFLite export for segmentation model
* Merge master
* Cleanup predict.py mask plotting
* cleanup scale_masks()
* rename scale_masks to scale_image
* cleanup/optimize plot_masks
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Add Annotator.masks()
* Annotator.masks() fix
* Update plots.py
* Annotator mask optimization
* Rename crop() to crop_mask()
* Do not crop in predict.py
* crop always
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Merge master
* Add vid-stride from master PR
* Update seg model outputs
* Update seg model outputs
* Add segmentation benchmarks
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Add segmentation benchmarks
* Add segmentation benchmarks
* Add segmentation benchmarks
* Fix DetectMultiBackend for OpenVINO
* update Annotator.masks
* fix val plot
* revert val plot
* clean up
* revert pil
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fix CI error
* fix predict log
* remove upsample
* update interpolate
* fix validation plot logging
* Annotator.masks() cleanup
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Remove segmentation_model definition
* Restore 0.99999 decimals
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
Co-authored-by: Laughing-q <1185102784@qq.com>
Co-authored-by: Jiacong Fang <zldrobit@126.com>
2022-09-16 06:12:46 +08:00
|
|
|
if np.max(images[0]) <= 1:
|
|
|
|
images *= 255 # de-normalise (optional)
|
2020-11-14 18:50:32 +08:00
|
|
|
|
2021-08-29 22:46:13 +08:00
|
|
|
# Build Image
|
2020-11-14 18:50:32 +08:00
|
|
|
mosaic = np.full((int(ns * h), int(ns * w), 3), 255, dtype=np.uint8) # init
|
2021-08-29 22:46:13 +08:00
|
|
|
for i, im in enumerate(images):
|
2020-11-14 18:50:32 +08:00
|
|
|
if i == max_subplots: # if last batch has fewer images than we expect
|
|
|
|
break
|
2021-08-29 22:46:13 +08:00
|
|
|
x, y = int(w * (i // ns)), int(h * (i % ns)) # block origin
|
|
|
|
im = im.transpose(1, 2, 0)
|
2024-01-08 08:29:14 +08:00
|
|
|
mosaic[y : y + h, x : x + w, :] = im
|
2021-08-29 22:46:13 +08:00
|
|
|
|
|
|
|
# Resize (optional)
|
|
|
|
scale = max_size / ns / max(h, w)
|
|
|
|
if scale < 1:
|
|
|
|
h = math.ceil(scale * h)
|
|
|
|
w = math.ceil(scale * w)
|
|
|
|
mosaic = cv2.resize(mosaic, tuple(int(x * ns) for x in (w, h)))
|
|
|
|
|
|
|
|
# Annotate
|
2021-08-30 00:05:49 +08:00
|
|
|
fs = int((h + w) * ns * 0.01) # font size
|
2022-02-04 02:09:24 +08:00
|
|
|
annotator = Annotator(mosaic, line_width=round(fs / 10), font_size=fs, pil=True, example=names)
|
2021-08-29 22:46:13 +08:00
|
|
|
for i in range(i + 1):
|
|
|
|
x, y = int(w * (i // ns)), int(h * (i % ns)) # block origin
|
|
|
|
annotator.rectangle([x, y, x + w, y + h], None, (255, 255, 255), width=2) # borders
|
|
|
|
if paths:
|
2023-08-02 02:56:35 +08:00
|
|
|
annotator.text([x + 5, y + 5], text=Path(paths[i]).name[:40], txt_color=(220, 220, 220)) # filenames
|
2020-11-14 18:50:32 +08:00
|
|
|
if len(targets) > 0:
|
2021-08-29 22:46:13 +08:00
|
|
|
ti = targets[targets[:, 0] == i] # image targets
|
|
|
|
boxes = xywh2xyxy(ti[:, 2:6]).T
|
2024-01-08 08:29:14 +08:00
|
|
|
classes = ti[:, 1].astype("int")
|
2021-08-29 22:46:13 +08:00
|
|
|
labels = ti.shape[1] == 6 # labels if no conf column
|
|
|
|
conf = None if labels else ti[:, 6] # check for confidence presence (label vs pred)
|
2020-11-14 18:50:32 +08:00
|
|
|
|
2020-12-01 18:29:59 +08:00
|
|
|
if boxes.shape[1]:
|
2020-12-09 10:44:13 +08:00
|
|
|
if boxes.max() <= 1.01: # if normalized with tolerance 0.01
|
2020-12-01 18:29:59 +08:00
|
|
|
boxes[[0, 2]] *= w # scale to pixels
|
|
|
|
boxes[[1, 3]] *= h
|
2021-08-29 22:46:13 +08:00
|
|
|
elif scale < 1: # absolute coords need scale if image scales
|
|
|
|
boxes *= scale
|
|
|
|
boxes[[0, 2]] += x
|
|
|
|
boxes[[1, 3]] += y
|
|
|
|
for j, box in enumerate(boxes.T.tolist()):
|
|
|
|
cls = classes[j]
|
2021-04-28 22:05:14 +08:00
|
|
|
color = colors(cls)
|
2020-11-14 18:50:32 +08:00
|
|
|
cls = names[cls] if names else cls
|
2020-11-16 20:35:34 +08:00
|
|
|
if labels or conf[j] > 0.25: # 0.25 conf thresh
|
2024-01-08 08:29:14 +08:00
|
|
|
label = f"{cls}" if labels else f"{cls} {conf[j]:.1f}"
|
2021-08-29 22:46:13 +08:00
|
|
|
annotator.box_label(box, label, color=color)
|
|
|
|
annotator.im.save(fname) # save
|
2020-11-14 18:50:32 +08:00
|
|
|
|
|
|
|
|
2024-01-08 08:29:14 +08:00
|
|
|
def plot_lr_scheduler(optimizer, scheduler, epochs=300, save_dir=""):
|
2024-02-25 21:04:01 +08:00
|
|
|
"""Plots learning rate schedule for given optimizer and scheduler, saving plot to `save_dir`."""
|
2021-12-08 23:46:24 +08:00
|
|
|
optimizer, scheduler = copy(optimizer), copy(scheduler) # do not modify originals
|
2020-11-14 18:50:32 +08:00
|
|
|
y = []
|
|
|
|
for _ in range(epochs):
|
|
|
|
scheduler.step()
|
2024-01-08 08:29:14 +08:00
|
|
|
y.append(optimizer.param_groups[0]["lr"])
|
|
|
|
plt.plot(y, ".-", label="LR")
|
|
|
|
plt.xlabel("epoch")
|
|
|
|
plt.ylabel("LR")
|
2020-11-14 18:50:32 +08:00
|
|
|
plt.grid()
|
|
|
|
plt.xlim(0, epochs)
|
|
|
|
plt.ylim(0)
|
2024-01-08 08:29:14 +08:00
|
|
|
plt.savefig(Path(save_dir) / "LR.png", dpi=200)
|
2021-01-05 07:49:08 +08:00
|
|
|
plt.close()
|
2020-11-14 18:50:32 +08:00
|
|
|
|
|
|
|
|
2021-07-14 21:43:54 +08:00
|
|
|
def plot_val_txt(): # from utils.plots import *; plot_val()
|
|
|
|
# Plot val.txt histograms
|
2024-01-08 08:29:14 +08:00
|
|
|
x = np.loadtxt("val.txt", dtype=np.float32)
|
2020-11-14 18:50:32 +08:00
|
|
|
box = xyxy2xywh(x[:, :4])
|
|
|
|
cx, cy = box[:, 0], box[:, 1]
|
|
|
|
|
|
|
|
fig, ax = plt.subplots(1, 1, figsize=(6, 6), tight_layout=True)
|
|
|
|
ax.hist2d(cx, cy, bins=600, cmax=10, cmin=0)
|
2024-01-08 08:29:14 +08:00
|
|
|
ax.set_aspect("equal")
|
|
|
|
plt.savefig("hist2d.png", dpi=300)
|
2020-11-14 18:50:32 +08:00
|
|
|
|
|
|
|
fig, ax = plt.subplots(1, 2, figsize=(12, 6), tight_layout=True)
|
|
|
|
ax[0].hist(cx, bins=600)
|
|
|
|
ax[1].hist(cy, bins=600)
|
2024-01-08 08:29:14 +08:00
|
|
|
plt.savefig("hist1d.png", dpi=200)
|
2020-11-14 18:50:32 +08:00
|
|
|
|
|
|
|
|
2020-11-18 00:29:55 +08:00
|
|
|
def plot_targets_txt(): # from utils.plots import *; plot_targets_txt()
|
2020-11-14 18:50:32 +08:00
|
|
|
# Plot targets.txt histograms
|
2024-01-08 08:29:14 +08:00
|
|
|
x = np.loadtxt("targets.txt", dtype=np.float32).T
|
|
|
|
s = ["x targets", "y targets", "width targets", "height targets"]
|
2020-11-14 18:50:32 +08:00
|
|
|
fig, ax = plt.subplots(2, 2, figsize=(8, 8), tight_layout=True)
|
|
|
|
ax = ax.ravel()
|
|
|
|
for i in range(4):
|
2024-01-08 08:29:14 +08:00
|
|
|
ax[i].hist(x[i], bins=100, label=f"{x[i].mean():.3g} +/- {x[i].std():.3g}")
|
2020-11-14 18:50:32 +08:00
|
|
|
ax[i].legend()
|
|
|
|
ax[i].set_title(s[i])
|
2024-01-08 08:29:14 +08:00
|
|
|
plt.savefig("targets.jpg", dpi=200)
|
2020-11-14 18:50:32 +08:00
|
|
|
|
|
|
|
|
2024-01-08 08:29:14 +08:00
|
|
|
def plot_val_study(file="", dir="", x=None): # from utils.plots import *; plot_val_study()
|
2021-09-16 23:55:58 +08:00
|
|
|
# Plot file=study.txt generated by val.py (or plot all study*.txt in dir)
|
|
|
|
save_dir = Path(file).parent if file else Path(dir)
|
2021-06-09 22:25:17 +08:00
|
|
|
plot2 = False # plot additional results
|
|
|
|
if plot2:
|
|
|
|
ax = plt.subplots(2, 4, figsize=(10, 6), tight_layout=True)[1].ravel()
|
2020-11-14 18:50:32 +08:00
|
|
|
|
|
|
|
fig2, ax2 = plt.subplots(1, 1, figsize=(8, 4), tight_layout=True)
|
2021-10-11 16:59:22 +08:00
|
|
|
# for f in [save_dir / f'study_coco_{x}.txt' for x in ['yolov5n6', 'yolov5s6', 'yolov5m6', 'yolov5l6', 'yolov5x6']]:
|
2024-01-08 08:29:14 +08:00
|
|
|
for f in sorted(save_dir.glob("study*.txt")):
|
2020-11-14 18:50:32 +08:00
|
|
|
y = np.loadtxt(f, dtype=np.float32, usecols=[0, 1, 2, 3, 7, 8, 9], ndmin=2).T
|
|
|
|
x = np.arange(y.shape[1]) if x is None else np.array(x)
|
2021-06-09 22:25:17 +08:00
|
|
|
if plot2:
|
2024-01-08 08:29:14 +08:00
|
|
|
s = ["P", "R", "mAP@.5", "mAP@.5:.95", "t_preprocess (ms/img)", "t_inference (ms/img)", "t_NMS (ms/img)"]
|
2021-06-09 22:25:17 +08:00
|
|
|
for i in range(7):
|
2024-01-08 08:29:14 +08:00
|
|
|
ax[i].plot(x, y[i], ".-", linewidth=2, markersize=8)
|
2021-06-09 22:25:17 +08:00
|
|
|
ax[i].set_title(s[i])
|
2020-11-14 18:50:32 +08:00
|
|
|
|
|
|
|
j = y[3].argmax() + 1
|
2024-01-08 08:29:14 +08:00
|
|
|
ax2.plot(
|
|
|
|
y[5, 1:j],
|
|
|
|
y[3, 1:j] * 1e2,
|
|
|
|
".-",
|
|
|
|
linewidth=2,
|
|
|
|
markersize=8,
|
|
|
|
label=f.stem.replace("study_coco_", "").replace("yolo", "YOLO"),
|
|
|
|
)
|
|
|
|
|
|
|
|
ax2.plot(
|
|
|
|
1e3 / np.array([209, 140, 97, 58, 35, 18]),
|
|
|
|
[34.6, 40.5, 43.0, 47.5, 49.7, 51.5],
|
|
|
|
"k.-",
|
|
|
|
linewidth=2,
|
|
|
|
markersize=8,
|
|
|
|
alpha=0.25,
|
|
|
|
label="EfficientDet",
|
|
|
|
)
|
2020-11-14 18:50:32 +08:00
|
|
|
|
2021-02-02 05:51:11 +08:00
|
|
|
ax2.grid(alpha=0.2)
|
|
|
|
ax2.set_yticks(np.arange(20, 60, 5))
|
2021-04-12 01:23:47 +08:00
|
|
|
ax2.set_xlim(0, 57)
|
2021-10-11 16:59:22 +08:00
|
|
|
ax2.set_ylim(25, 55)
|
2024-01-08 08:29:14 +08:00
|
|
|
ax2.set_xlabel("GPU Speed (ms/img)")
|
|
|
|
ax2.set_ylabel("COCO AP val")
|
|
|
|
ax2.legend(loc="lower right")
|
|
|
|
f = save_dir / "study.png"
|
|
|
|
print(f"Saving {f}...")
|
2021-09-16 23:55:58 +08:00
|
|
|
plt.savefig(f, dpi=300)
|
2020-11-14 18:50:32 +08:00
|
|
|
|
|
|
|
|
2022-08-25 20:34:26 +08:00
|
|
|
@TryExcept() # known issue https://github.com/ultralytics/yolov5/issues/5395
|
2024-01-08 08:29:14 +08:00
|
|
|
def plot_labels(labels, names=(), save_dir=Path("")):
|
2024-02-25 21:04:01 +08:00
|
|
|
"""Plots dataset labels, saving correlogram and label images, handles classes, and visualizes bounding boxes."""
|
2021-11-13 22:40:18 +08:00
|
|
|
LOGGER.info(f"Plotting labels to {save_dir / 'labels.jpg'}... ")
|
2020-11-14 18:50:32 +08:00
|
|
|
c, b = labels[:, 0], labels[:, 1:].transpose() # classes, boxes
|
|
|
|
nc = int(c.max() + 1) # number of classes
|
2024-01-08 08:29:14 +08:00
|
|
|
x = pd.DataFrame(b.transpose(), columns=["x", "y", "width", "height"])
|
2020-11-14 18:50:32 +08:00
|
|
|
|
2020-11-18 19:27:30 +08:00
|
|
|
# seaborn correlogram
|
2024-01-08 08:29:14 +08:00
|
|
|
sn.pairplot(x, corner=True, diag_kind="auto", kind="hist", diag_kws=dict(bins=50), plot_kws=dict(pmax=0.9))
|
|
|
|
plt.savefig(save_dir / "labels_correlogram.jpg", dpi=200)
|
2020-12-19 10:05:38 +08:00
|
|
|
plt.close()
|
2020-11-18 19:27:30 +08:00
|
|
|
|
|
|
|
# matplotlib labels
|
2024-01-08 08:29:14 +08:00
|
|
|
matplotlib.use("svg") # faster
|
2020-11-18 19:27:30 +08:00
|
|
|
ax = plt.subplots(2, 2, figsize=(8, 8), tight_layout=True)[1].ravel()
|
2021-05-17 17:44:22 +08:00
|
|
|
y = ax[0].hist(c, bins=np.linspace(0, nc, nc + 1) - 0.5, rwidth=0.8)
|
2022-08-21 07:34:03 +08:00
|
|
|
with contextlib.suppress(Exception): # color histogram bars by class
|
2022-02-08 21:03:50 +08:00
|
|
|
[y[2].patches[i].set_color([x / 255 for x in colors(i)]) for i in range(nc)] # known issue #3195
|
2024-01-08 08:29:14 +08:00
|
|
|
ax[0].set_ylabel("instances")
|
2021-03-13 14:15:41 +08:00
|
|
|
if 0 < len(names) < 30:
|
|
|
|
ax[0].set_xticks(range(len(names)))
|
2022-09-11 03:24:46 +08:00
|
|
|
ax[0].set_xticklabels(list(names.values()), rotation=90, fontsize=10)
|
2021-03-13 14:15:41 +08:00
|
|
|
else:
|
2024-01-08 08:29:14 +08:00
|
|
|
ax[0].set_xlabel("classes")
|
|
|
|
sn.histplot(x, x="x", y="y", ax=ax[2], bins=50, pmax=0.9)
|
|
|
|
sn.histplot(x, x="width", y="height", ax=ax[3], bins=50, pmax=0.9)
|
2020-11-18 07:17:33 +08:00
|
|
|
|
|
|
|
# rectangles
|
|
|
|
labels[:, 1:3] = 0.5 # center
|
|
|
|
labels[:, 1:] = xywh2xyxy(labels[:, 1:]) * 2000
|
|
|
|
img = Image.fromarray(np.ones((2000, 2000, 3), dtype=np.uint8) * 255)
|
|
|
|
for cls, *box in labels[:1000]:
|
2021-04-28 22:05:14 +08:00
|
|
|
ImageDraw.Draw(img).rectangle(box, width=1, outline=colors(cls)) # plot
|
2020-11-18 07:17:33 +08:00
|
|
|
ax[1].imshow(img)
|
2024-01-08 08:29:14 +08:00
|
|
|
ax[1].axis("off")
|
2020-11-18 07:17:33 +08:00
|
|
|
|
|
|
|
for a in [0, 1, 2, 3]:
|
2024-01-08 08:29:14 +08:00
|
|
|
for s in ["top", "right", "left", "bottom"]:
|
2020-11-18 07:17:33 +08:00
|
|
|
ax[a].spines[s].set_visible(False)
|
2020-12-02 22:53:16 +08:00
|
|
|
|
2024-01-08 08:29:14 +08:00
|
|
|
plt.savefig(save_dir / "labels.jpg", dpi=200)
|
|
|
|
matplotlib.use("Agg")
|
2020-11-14 18:50:32 +08:00
|
|
|
plt.close()
|
|
|
|
|
|
|
|
|
2024-01-08 08:29:14 +08:00
|
|
|
def imshow_cls(im, labels=None, pred=None, names=None, nmax=25, verbose=False, f=Path("images.jpg")):
|
2024-02-25 21:04:01 +08:00
|
|
|
"""Displays a grid of images with optional labels and predictions, saving to a file."""
|
New YOLOv5 Classification Models (#8956)
* Update
* Logger step fix: Increment step with epochs (#8654)
* enhance
* revert
* allow training from scratch
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update --img argument from train.py
single line
* fix image size from 640 to 128
* suport custom dataloader and augmentation
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* format
* Update dataloaders.py
* Single line return, single line comment, remove unused argument
* address PR comments
* fix spelling
* don't augment eval set
* use fstring
* update augmentations.py
* new maning convention for transforms
* reverse if statement, inline ops
* reverse if statement, inline ops
* updates
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update dataloaders
* Remove additional if statement
* Remove is_train as redundant
* Cleanup
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Cleanup2
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update classifier.py
* Update augmentations.py
* fix: imshow clip warning
* update
* Revert ToTensorV2 removal
* Update classifier.py
* Update normalize values, revert uint8
* normalize image using cv2
* remove dedundant comment
* Update classifier.py
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* replace print with logger
* commit steps
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Allow logging models from GenericLogger (#8676)
* enhance
* revert
* allow training from scratch
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update --img argument from train.py
single line
* fix image size from 640 to 128
* suport custom dataloader and augmentation
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* format
* Update dataloaders.py
* Single line return, single line comment, remove unused argument
* address PR comments
* fix spelling
* don't augment eval set
* use fstring
* update augmentations.py
* new maning convention for transforms
* reverse if statement, inline ops
* reverse if statement, inline ops
* updates
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update dataloaders
* Remove additional if statement
* Remove is_train as redundant
* Cleanup
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Cleanup2
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update classifier.py
* Update augmentations.py
* fix: imshow clip warning
* update
* Revert ToTensorV2 removal
* Update classifier.py
* Update normalize values, revert uint8
* normalize image using cv2
* remove dedundant comment
* Update classifier.py
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* replace print with logger
* commit steps
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* support final model logging
* update
* update
* update
* update
* remove curses
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update classifier.py
* Update __init__.py
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
* Update
* Update
* Update
* Update
* Update dataset download
* Update dataset download
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Pass imgsz to classify_transforms()
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Cos scheduler
* Cos scheduler
* Remove unused args
* Update
* Add seed
* Add seed
* Update
* Update
* Add run(), main()
* Merge master
* Merge master
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Create YOLOv5 BaseModel class (#8829)
* Create BaseModel
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fix
* Hub load device fix
* Update
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Add experiment
* Merge master
* Attach names
* weight decay = 1e-4
* weight decay = 5e-5
* update smart_optimizer console printout
* fashion-mnist fix
* Merge master
* Update Table
* Update Table
* Remove destroy process group
* add kwargs to forward()
* fuse fix for resnet50
* nc, names fix for resnet50
* nc, names fix for resnet50
* ONNX CPU inference fix
* revert
* cuda
* if augment or visualize
* if augment or visualize
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* New smart_inference_mode()
* Update README
* Refactor into /classify dir
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* reset defaults
* reset defaults
* fix gpu predict
* warmup
* ema half fix
* spacing
* remove data
* remove cache
* remove denormalize
* save run settings
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* verbose false on initial plots
* new save_yaml() function
* Update ci-testing.yml
* Path(data) CI fix
* Separate classification CI
* fix val
* fix val
* fix val
* smartCrossEntropyLoss
* skip validation on hub load
* autodownload with working dir root
* str(data)
* Dataset usage example
* im_show normalize
* im_show normalize
* add imagenet simple names to multibackend
* Add validation speeds
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* 24-space names
* Update bash scripts
* Update permissions
* Add bash script arguments
* remove verbose
* TRT data fix
* names generator fix
* optimize if names
* update usage
* Add local loading
* Verbose=False
* update names printing
* Add Usage examples
* Add Usage examples
* Add Usage examples
* Add Usage examples
* named_children
* reshape_classifier_outputs
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update
* update
* fix CI
* fix incorrect class substitution
* fix incorrect class substitution
* remove denormalize
* ravel fix
* cleanup
* update opt file printing
* update opt file printing
* update defaults
* add opt to checkpoint
* Add warning
* Add comment
* plot half bug fix
* Use NotImplementedError
* fix export shape report
* Fix TRT load
* cleanup CI
* profile comment
* CI fix
* Add cls models
* avoid inplace error
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fix usage examples
* Update README
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
Co-authored-by: Ayush Chaurasia <ayush.chaurarsia@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-08-17 17:59:01 +08:00
|
|
|
from utils.augmentations import denormalize
|
|
|
|
|
2024-01-08 08:29:14 +08:00
|
|
|
names = names or [f"class{i}" for i in range(1000)]
|
|
|
|
blocks = torch.chunk(
|
|
|
|
denormalize(im.clone()).cpu().float(), len(im), dim=0
|
|
|
|
) # select batch index 0, block by channels
|
New YOLOv5 Classification Models (#8956)
* Update
* Logger step fix: Increment step with epochs (#8654)
* enhance
* revert
* allow training from scratch
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update --img argument from train.py
single line
* fix image size from 640 to 128
* suport custom dataloader and augmentation
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* format
* Update dataloaders.py
* Single line return, single line comment, remove unused argument
* address PR comments
* fix spelling
* don't augment eval set
* use fstring
* update augmentations.py
* new maning convention for transforms
* reverse if statement, inline ops
* reverse if statement, inline ops
* updates
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update dataloaders
* Remove additional if statement
* Remove is_train as redundant
* Cleanup
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Cleanup2
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update classifier.py
* Update augmentations.py
* fix: imshow clip warning
* update
* Revert ToTensorV2 removal
* Update classifier.py
* Update normalize values, revert uint8
* normalize image using cv2
* remove dedundant comment
* Update classifier.py
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* replace print with logger
* commit steps
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Allow logging models from GenericLogger (#8676)
* enhance
* revert
* allow training from scratch
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update --img argument from train.py
single line
* fix image size from 640 to 128
* suport custom dataloader and augmentation
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* format
* Update dataloaders.py
* Single line return, single line comment, remove unused argument
* address PR comments
* fix spelling
* don't augment eval set
* use fstring
* update augmentations.py
* new maning convention for transforms
* reverse if statement, inline ops
* reverse if statement, inline ops
* updates
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update dataloaders
* Remove additional if statement
* Remove is_train as redundant
* Cleanup
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Cleanup2
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update classifier.py
* Update augmentations.py
* fix: imshow clip warning
* update
* Revert ToTensorV2 removal
* Update classifier.py
* Update normalize values, revert uint8
* normalize image using cv2
* remove dedundant comment
* Update classifier.py
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* replace print with logger
* commit steps
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* support final model logging
* update
* update
* update
* update
* remove curses
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update classifier.py
* Update __init__.py
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
* Update
* Update
* Update
* Update
* Update dataset download
* Update dataset download
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Pass imgsz to classify_transforms()
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Cos scheduler
* Cos scheduler
* Remove unused args
* Update
* Add seed
* Add seed
* Update
* Update
* Add run(), main()
* Merge master
* Merge master
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Create YOLOv5 BaseModel class (#8829)
* Create BaseModel
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fix
* Hub load device fix
* Update
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Add experiment
* Merge master
* Attach names
* weight decay = 1e-4
* weight decay = 5e-5
* update smart_optimizer console printout
* fashion-mnist fix
* Merge master
* Update Table
* Update Table
* Remove destroy process group
* add kwargs to forward()
* fuse fix for resnet50
* nc, names fix for resnet50
* nc, names fix for resnet50
* ONNX CPU inference fix
* revert
* cuda
* if augment or visualize
* if augment or visualize
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* New smart_inference_mode()
* Update README
* Refactor into /classify dir
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* reset defaults
* reset defaults
* fix gpu predict
* warmup
* ema half fix
* spacing
* remove data
* remove cache
* remove denormalize
* save run settings
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* verbose false on initial plots
* new save_yaml() function
* Update ci-testing.yml
* Path(data) CI fix
* Separate classification CI
* fix val
* fix val
* fix val
* smartCrossEntropyLoss
* skip validation on hub load
* autodownload with working dir root
* str(data)
* Dataset usage example
* im_show normalize
* im_show normalize
* add imagenet simple names to multibackend
* Add validation speeds
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* 24-space names
* Update bash scripts
* Update permissions
* Add bash script arguments
* remove verbose
* TRT data fix
* names generator fix
* optimize if names
* update usage
* Add local loading
* Verbose=False
* update names printing
* Add Usage examples
* Add Usage examples
* Add Usage examples
* Add Usage examples
* named_children
* reshape_classifier_outputs
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update
* update
* fix CI
* fix incorrect class substitution
* fix incorrect class substitution
* remove denormalize
* ravel fix
* cleanup
* update opt file printing
* update opt file printing
* update defaults
* add opt to checkpoint
* Add warning
* Add comment
* plot half bug fix
* Use NotImplementedError
* fix export shape report
* Fix TRT load
* cleanup CI
* profile comment
* CI fix
* Add cls models
* avoid inplace error
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fix usage examples
* Update README
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
Co-authored-by: Ayush Chaurasia <ayush.chaurarsia@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-08-17 17:59:01 +08:00
|
|
|
n = min(len(blocks), nmax) # number of plots
|
2024-01-08 08:29:14 +08:00
|
|
|
m = min(8, round(n**0.5)) # 8 x 8 default
|
New YOLOv5 Classification Models (#8956)
* Update
* Logger step fix: Increment step with epochs (#8654)
* enhance
* revert
* allow training from scratch
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update --img argument from train.py
single line
* fix image size from 640 to 128
* suport custom dataloader and augmentation
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* format
* Update dataloaders.py
* Single line return, single line comment, remove unused argument
* address PR comments
* fix spelling
* don't augment eval set
* use fstring
* update augmentations.py
* new maning convention for transforms
* reverse if statement, inline ops
* reverse if statement, inline ops
* updates
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update dataloaders
* Remove additional if statement
* Remove is_train as redundant
* Cleanup
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Cleanup2
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update classifier.py
* Update augmentations.py
* fix: imshow clip warning
* update
* Revert ToTensorV2 removal
* Update classifier.py
* Update normalize values, revert uint8
* normalize image using cv2
* remove dedundant comment
* Update classifier.py
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* replace print with logger
* commit steps
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Allow logging models from GenericLogger (#8676)
* enhance
* revert
* allow training from scratch
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update --img argument from train.py
single line
* fix image size from 640 to 128
* suport custom dataloader and augmentation
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* format
* Update dataloaders.py
* Single line return, single line comment, remove unused argument
* address PR comments
* fix spelling
* don't augment eval set
* use fstring
* update augmentations.py
* new maning convention for transforms
* reverse if statement, inline ops
* reverse if statement, inline ops
* updates
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update dataloaders
* Remove additional if statement
* Remove is_train as redundant
* Cleanup
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Cleanup2
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update classifier.py
* Update augmentations.py
* fix: imshow clip warning
* update
* Revert ToTensorV2 removal
* Update classifier.py
* Update normalize values, revert uint8
* normalize image using cv2
* remove dedundant comment
* Update classifier.py
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* replace print with logger
* commit steps
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* support final model logging
* update
* update
* update
* update
* remove curses
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update classifier.py
* Update __init__.py
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
* Update
* Update
* Update
* Update
* Update dataset download
* Update dataset download
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Pass imgsz to classify_transforms()
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Cos scheduler
* Cos scheduler
* Remove unused args
* Update
* Add seed
* Add seed
* Update
* Update
* Add run(), main()
* Merge master
* Merge master
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Create YOLOv5 BaseModel class (#8829)
* Create BaseModel
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fix
* Hub load device fix
* Update
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Add experiment
* Merge master
* Attach names
* weight decay = 1e-4
* weight decay = 5e-5
* update smart_optimizer console printout
* fashion-mnist fix
* Merge master
* Update Table
* Update Table
* Remove destroy process group
* add kwargs to forward()
* fuse fix for resnet50
* nc, names fix for resnet50
* nc, names fix for resnet50
* ONNX CPU inference fix
* revert
* cuda
* if augment or visualize
* if augment or visualize
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* New smart_inference_mode()
* Update README
* Refactor into /classify dir
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* reset defaults
* reset defaults
* fix gpu predict
* warmup
* ema half fix
* spacing
* remove data
* remove cache
* remove denormalize
* save run settings
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* verbose false on initial plots
* new save_yaml() function
* Update ci-testing.yml
* Path(data) CI fix
* Separate classification CI
* fix val
* fix val
* fix val
* smartCrossEntropyLoss
* skip validation on hub load
* autodownload with working dir root
* str(data)
* Dataset usage example
* im_show normalize
* im_show normalize
* add imagenet simple names to multibackend
* Add validation speeds
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* 24-space names
* Update bash scripts
* Update permissions
* Add bash script arguments
* remove verbose
* TRT data fix
* names generator fix
* optimize if names
* update usage
* Add local loading
* Verbose=False
* update names printing
* Add Usage examples
* Add Usage examples
* Add Usage examples
* Add Usage examples
* named_children
* reshape_classifier_outputs
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update
* update
* fix CI
* fix incorrect class substitution
* fix incorrect class substitution
* remove denormalize
* ravel fix
* cleanup
* update opt file printing
* update opt file printing
* update defaults
* add opt to checkpoint
* Add warning
* Add comment
* plot half bug fix
* Use NotImplementedError
* fix export shape report
* Fix TRT load
* cleanup CI
* profile comment
* CI fix
* Add cls models
* avoid inplace error
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fix usage examples
* Update README
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
Co-authored-by: Ayush Chaurasia <ayush.chaurarsia@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-08-17 17:59:01 +08:00
|
|
|
fig, ax = plt.subplots(math.ceil(n / m), m) # 8 rows x n/8 cols
|
|
|
|
ax = ax.ravel() if m > 1 else [ax]
|
|
|
|
# plt.subplots_adjust(wspace=0.05, hspace=0.05)
|
|
|
|
for i in range(n):
|
|
|
|
ax[i].imshow(blocks[i].squeeze().permute((1, 2, 0)).numpy().clip(0.0, 1.0))
|
2024-01-08 08:29:14 +08:00
|
|
|
ax[i].axis("off")
|
New YOLOv5 Classification Models (#8956)
* Update
* Logger step fix: Increment step with epochs (#8654)
* enhance
* revert
* allow training from scratch
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update --img argument from train.py
single line
* fix image size from 640 to 128
* suport custom dataloader and augmentation
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* format
* Update dataloaders.py
* Single line return, single line comment, remove unused argument
* address PR comments
* fix spelling
* don't augment eval set
* use fstring
* update augmentations.py
* new maning convention for transforms
* reverse if statement, inline ops
* reverse if statement, inline ops
* updates
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update dataloaders
* Remove additional if statement
* Remove is_train as redundant
* Cleanup
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Cleanup2
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update classifier.py
* Update augmentations.py
* fix: imshow clip warning
* update
* Revert ToTensorV2 removal
* Update classifier.py
* Update normalize values, revert uint8
* normalize image using cv2
* remove dedundant comment
* Update classifier.py
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* replace print with logger
* commit steps
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Allow logging models from GenericLogger (#8676)
* enhance
* revert
* allow training from scratch
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update --img argument from train.py
single line
* fix image size from 640 to 128
* suport custom dataloader and augmentation
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* format
* Update dataloaders.py
* Single line return, single line comment, remove unused argument
* address PR comments
* fix spelling
* don't augment eval set
* use fstring
* update augmentations.py
* new maning convention for transforms
* reverse if statement, inline ops
* reverse if statement, inline ops
* updates
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update dataloaders
* Remove additional if statement
* Remove is_train as redundant
* Cleanup
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Cleanup2
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update classifier.py
* Update augmentations.py
* fix: imshow clip warning
* update
* Revert ToTensorV2 removal
* Update classifier.py
* Update normalize values, revert uint8
* normalize image using cv2
* remove dedundant comment
* Update classifier.py
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* replace print with logger
* commit steps
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* support final model logging
* update
* update
* update
* update
* remove curses
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update classifier.py
* Update __init__.py
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
* Update
* Update
* Update
* Update
* Update dataset download
* Update dataset download
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Pass imgsz to classify_transforms()
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Cos scheduler
* Cos scheduler
* Remove unused args
* Update
* Add seed
* Add seed
* Update
* Update
* Add run(), main()
* Merge master
* Merge master
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Create YOLOv5 BaseModel class (#8829)
* Create BaseModel
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fix
* Hub load device fix
* Update
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Add experiment
* Merge master
* Attach names
* weight decay = 1e-4
* weight decay = 5e-5
* update smart_optimizer console printout
* fashion-mnist fix
* Merge master
* Update Table
* Update Table
* Remove destroy process group
* add kwargs to forward()
* fuse fix for resnet50
* nc, names fix for resnet50
* nc, names fix for resnet50
* ONNX CPU inference fix
* revert
* cuda
* if augment or visualize
* if augment or visualize
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* New smart_inference_mode()
* Update README
* Refactor into /classify dir
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* reset defaults
* reset defaults
* fix gpu predict
* warmup
* ema half fix
* spacing
* remove data
* remove cache
* remove denormalize
* save run settings
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* verbose false on initial plots
* new save_yaml() function
* Update ci-testing.yml
* Path(data) CI fix
* Separate classification CI
* fix val
* fix val
* fix val
* smartCrossEntropyLoss
* skip validation on hub load
* autodownload with working dir root
* str(data)
* Dataset usage example
* im_show normalize
* im_show normalize
* add imagenet simple names to multibackend
* Add validation speeds
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* 24-space names
* Update bash scripts
* Update permissions
* Add bash script arguments
* remove verbose
* TRT data fix
* names generator fix
* optimize if names
* update usage
* Add local loading
* Verbose=False
* update names printing
* Add Usage examples
* Add Usage examples
* Add Usage examples
* Add Usage examples
* named_children
* reshape_classifier_outputs
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update
* update
* fix CI
* fix incorrect class substitution
* fix incorrect class substitution
* remove denormalize
* ravel fix
* cleanup
* update opt file printing
* update opt file printing
* update defaults
* add opt to checkpoint
* Add warning
* Add comment
* plot half bug fix
* Use NotImplementedError
* fix export shape report
* Fix TRT load
* cleanup CI
* profile comment
* CI fix
* Add cls models
* avoid inplace error
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fix usage examples
* Update README
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
Co-authored-by: Ayush Chaurasia <ayush.chaurarsia@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-08-17 17:59:01 +08:00
|
|
|
if labels is not None:
|
2024-01-08 08:29:14 +08:00
|
|
|
s = names[labels[i]] + (f"—{names[pred[i]]}" if pred is not None else "")
|
|
|
|
ax[i].set_title(s, fontsize=8, verticalalignment="top")
|
|
|
|
plt.savefig(f, dpi=300, bbox_inches="tight")
|
New YOLOv5 Classification Models (#8956)
* Update
* Logger step fix: Increment step with epochs (#8654)
* enhance
* revert
* allow training from scratch
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update --img argument from train.py
single line
* fix image size from 640 to 128
* suport custom dataloader and augmentation
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* format
* Update dataloaders.py
* Single line return, single line comment, remove unused argument
* address PR comments
* fix spelling
* don't augment eval set
* use fstring
* update augmentations.py
* new maning convention for transforms
* reverse if statement, inline ops
* reverse if statement, inline ops
* updates
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update dataloaders
* Remove additional if statement
* Remove is_train as redundant
* Cleanup
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Cleanup2
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update classifier.py
* Update augmentations.py
* fix: imshow clip warning
* update
* Revert ToTensorV2 removal
* Update classifier.py
* Update normalize values, revert uint8
* normalize image using cv2
* remove dedundant comment
* Update classifier.py
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* replace print with logger
* commit steps
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Allow logging models from GenericLogger (#8676)
* enhance
* revert
* allow training from scratch
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update --img argument from train.py
single line
* fix image size from 640 to 128
* suport custom dataloader and augmentation
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* format
* Update dataloaders.py
* Single line return, single line comment, remove unused argument
* address PR comments
* fix spelling
* don't augment eval set
* use fstring
* update augmentations.py
* new maning convention for transforms
* reverse if statement, inline ops
* reverse if statement, inline ops
* updates
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update dataloaders
* Remove additional if statement
* Remove is_train as redundant
* Cleanup
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Cleanup2
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update classifier.py
* Update augmentations.py
* fix: imshow clip warning
* update
* Revert ToTensorV2 removal
* Update classifier.py
* Update normalize values, revert uint8
* normalize image using cv2
* remove dedundant comment
* Update classifier.py
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* replace print with logger
* commit steps
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* support final model logging
* update
* update
* update
* update
* remove curses
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update classifier.py
* Update __init__.py
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
* Update
* Update
* Update
* Update
* Update dataset download
* Update dataset download
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Pass imgsz to classify_transforms()
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Cos scheduler
* Cos scheduler
* Remove unused args
* Update
* Add seed
* Add seed
* Update
* Update
* Add run(), main()
* Merge master
* Merge master
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Create YOLOv5 BaseModel class (#8829)
* Create BaseModel
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fix
* Hub load device fix
* Update
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Add experiment
* Merge master
* Attach names
* weight decay = 1e-4
* weight decay = 5e-5
* update smart_optimizer console printout
* fashion-mnist fix
* Merge master
* Update Table
* Update Table
* Remove destroy process group
* add kwargs to forward()
* fuse fix for resnet50
* nc, names fix for resnet50
* nc, names fix for resnet50
* ONNX CPU inference fix
* revert
* cuda
* if augment or visualize
* if augment or visualize
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* New smart_inference_mode()
* Update README
* Refactor into /classify dir
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* reset defaults
* reset defaults
* fix gpu predict
* warmup
* ema half fix
* spacing
* remove data
* remove cache
* remove denormalize
* save run settings
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* verbose false on initial plots
* new save_yaml() function
* Update ci-testing.yml
* Path(data) CI fix
* Separate classification CI
* fix val
* fix val
* fix val
* smartCrossEntropyLoss
* skip validation on hub load
* autodownload with working dir root
* str(data)
* Dataset usage example
* im_show normalize
* im_show normalize
* add imagenet simple names to multibackend
* Add validation speeds
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* 24-space names
* Update bash scripts
* Update permissions
* Add bash script arguments
* remove verbose
* TRT data fix
* names generator fix
* optimize if names
* update usage
* Add local loading
* Verbose=False
* update names printing
* Add Usage examples
* Add Usage examples
* Add Usage examples
* Add Usage examples
* named_children
* reshape_classifier_outputs
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update
* update
* fix CI
* fix incorrect class substitution
* fix incorrect class substitution
* remove denormalize
* ravel fix
* cleanup
* update opt file printing
* update opt file printing
* update defaults
* add opt to checkpoint
* Add warning
* Add comment
* plot half bug fix
* Use NotImplementedError
* fix export shape report
* Fix TRT load
* cleanup CI
* profile comment
* CI fix
* Add cls models
* avoid inplace error
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fix usage examples
* Update README
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
Co-authored-by: Ayush Chaurasia <ayush.chaurarsia@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-08-17 17:59:01 +08:00
|
|
|
plt.close()
|
|
|
|
if verbose:
|
2024-01-08 08:29:14 +08:00
|
|
|
LOGGER.info(f"Saving {f}")
|
New YOLOv5 Classification Models (#8956)
* Update
* Logger step fix: Increment step with epochs (#8654)
* enhance
* revert
* allow training from scratch
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update --img argument from train.py
single line
* fix image size from 640 to 128
* suport custom dataloader and augmentation
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* format
* Update dataloaders.py
* Single line return, single line comment, remove unused argument
* address PR comments
* fix spelling
* don't augment eval set
* use fstring
* update augmentations.py
* new maning convention for transforms
* reverse if statement, inline ops
* reverse if statement, inline ops
* updates
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update dataloaders
* Remove additional if statement
* Remove is_train as redundant
* Cleanup
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Cleanup2
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update classifier.py
* Update augmentations.py
* fix: imshow clip warning
* update
* Revert ToTensorV2 removal
* Update classifier.py
* Update normalize values, revert uint8
* normalize image using cv2
* remove dedundant comment
* Update classifier.py
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* replace print with logger
* commit steps
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Allow logging models from GenericLogger (#8676)
* enhance
* revert
* allow training from scratch
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update --img argument from train.py
single line
* fix image size from 640 to 128
* suport custom dataloader and augmentation
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* format
* Update dataloaders.py
* Single line return, single line comment, remove unused argument
* address PR comments
* fix spelling
* don't augment eval set
* use fstring
* update augmentations.py
* new maning convention for transforms
* reverse if statement, inline ops
* reverse if statement, inline ops
* updates
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update dataloaders
* Remove additional if statement
* Remove is_train as redundant
* Cleanup
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Cleanup2
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update classifier.py
* Update augmentations.py
* fix: imshow clip warning
* update
* Revert ToTensorV2 removal
* Update classifier.py
* Update normalize values, revert uint8
* normalize image using cv2
* remove dedundant comment
* Update classifier.py
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* replace print with logger
* commit steps
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* support final model logging
* update
* update
* update
* update
* remove curses
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update classifier.py
* Update __init__.py
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
* Update
* Update
* Update
* Update
* Update dataset download
* Update dataset download
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Pass imgsz to classify_transforms()
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Cos scheduler
* Cos scheduler
* Remove unused args
* Update
* Add seed
* Add seed
* Update
* Update
* Add run(), main()
* Merge master
* Merge master
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Create YOLOv5 BaseModel class (#8829)
* Create BaseModel
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fix
* Hub load device fix
* Update
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Add experiment
* Merge master
* Attach names
* weight decay = 1e-4
* weight decay = 5e-5
* update smart_optimizer console printout
* fashion-mnist fix
* Merge master
* Update Table
* Update Table
* Remove destroy process group
* add kwargs to forward()
* fuse fix for resnet50
* nc, names fix for resnet50
* nc, names fix for resnet50
* ONNX CPU inference fix
* revert
* cuda
* if augment or visualize
* if augment or visualize
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* New smart_inference_mode()
* Update README
* Refactor into /classify dir
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* reset defaults
* reset defaults
* fix gpu predict
* warmup
* ema half fix
* spacing
* remove data
* remove cache
* remove denormalize
* save run settings
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* verbose false on initial plots
* new save_yaml() function
* Update ci-testing.yml
* Path(data) CI fix
* Separate classification CI
* fix val
* fix val
* fix val
* smartCrossEntropyLoss
* skip validation on hub load
* autodownload with working dir root
* str(data)
* Dataset usage example
* im_show normalize
* im_show normalize
* add imagenet simple names to multibackend
* Add validation speeds
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* 24-space names
* Update bash scripts
* Update permissions
* Add bash script arguments
* remove verbose
* TRT data fix
* names generator fix
* optimize if names
* update usage
* Add local loading
* Verbose=False
* update names printing
* Add Usage examples
* Add Usage examples
* Add Usage examples
* Add Usage examples
* named_children
* reshape_classifier_outputs
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update
* update
* fix CI
* fix incorrect class substitution
* fix incorrect class substitution
* remove denormalize
* ravel fix
* cleanup
* update opt file printing
* update opt file printing
* update defaults
* add opt to checkpoint
* Add warning
* Add comment
* plot half bug fix
* Use NotImplementedError
* fix export shape report
* Fix TRT load
* cleanup CI
* profile comment
* CI fix
* Add cls models
* avoid inplace error
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fix usage examples
* Update README
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
Co-authored-by: Ayush Chaurasia <ayush.chaurarsia@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-08-17 17:59:01 +08:00
|
|
|
if labels is not None:
|
2024-01-08 08:29:14 +08:00
|
|
|
LOGGER.info("True: " + " ".join(f"{names[i]:3s}" for i in labels[:nmax]))
|
New YOLOv5 Classification Models (#8956)
* Update
* Logger step fix: Increment step with epochs (#8654)
* enhance
* revert
* allow training from scratch
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update --img argument from train.py
single line
* fix image size from 640 to 128
* suport custom dataloader and augmentation
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* format
* Update dataloaders.py
* Single line return, single line comment, remove unused argument
* address PR comments
* fix spelling
* don't augment eval set
* use fstring
* update augmentations.py
* new maning convention for transforms
* reverse if statement, inline ops
* reverse if statement, inline ops
* updates
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update dataloaders
* Remove additional if statement
* Remove is_train as redundant
* Cleanup
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Cleanup2
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update classifier.py
* Update augmentations.py
* fix: imshow clip warning
* update
* Revert ToTensorV2 removal
* Update classifier.py
* Update normalize values, revert uint8
* normalize image using cv2
* remove dedundant comment
* Update classifier.py
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* replace print with logger
* commit steps
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Allow logging models from GenericLogger (#8676)
* enhance
* revert
* allow training from scratch
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update --img argument from train.py
single line
* fix image size from 640 to 128
* suport custom dataloader and augmentation
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* format
* Update dataloaders.py
* Single line return, single line comment, remove unused argument
* address PR comments
* fix spelling
* don't augment eval set
* use fstring
* update augmentations.py
* new maning convention for transforms
* reverse if statement, inline ops
* reverse if statement, inline ops
* updates
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update dataloaders
* Remove additional if statement
* Remove is_train as redundant
* Cleanup
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Cleanup2
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update classifier.py
* Update augmentations.py
* fix: imshow clip warning
* update
* Revert ToTensorV2 removal
* Update classifier.py
* Update normalize values, revert uint8
* normalize image using cv2
* remove dedundant comment
* Update classifier.py
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* replace print with logger
* commit steps
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* support final model logging
* update
* update
* update
* update
* remove curses
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update classifier.py
* Update __init__.py
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
* Update
* Update
* Update
* Update
* Update dataset download
* Update dataset download
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Pass imgsz to classify_transforms()
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Cos scheduler
* Cos scheduler
* Remove unused args
* Update
* Add seed
* Add seed
* Update
* Update
* Add run(), main()
* Merge master
* Merge master
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Create YOLOv5 BaseModel class (#8829)
* Create BaseModel
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fix
* Hub load device fix
* Update
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Add experiment
* Merge master
* Attach names
* weight decay = 1e-4
* weight decay = 5e-5
* update smart_optimizer console printout
* fashion-mnist fix
* Merge master
* Update Table
* Update Table
* Remove destroy process group
* add kwargs to forward()
* fuse fix for resnet50
* nc, names fix for resnet50
* nc, names fix for resnet50
* ONNX CPU inference fix
* revert
* cuda
* if augment or visualize
* if augment or visualize
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* New smart_inference_mode()
* Update README
* Refactor into /classify dir
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* reset defaults
* reset defaults
* fix gpu predict
* warmup
* ema half fix
* spacing
* remove data
* remove cache
* remove denormalize
* save run settings
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* verbose false on initial plots
* new save_yaml() function
* Update ci-testing.yml
* Path(data) CI fix
* Separate classification CI
* fix val
* fix val
* fix val
* smartCrossEntropyLoss
* skip validation on hub load
* autodownload with working dir root
* str(data)
* Dataset usage example
* im_show normalize
* im_show normalize
* add imagenet simple names to multibackend
* Add validation speeds
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* 24-space names
* Update bash scripts
* Update permissions
* Add bash script arguments
* remove verbose
* TRT data fix
* names generator fix
* optimize if names
* update usage
* Add local loading
* Verbose=False
* update names printing
* Add Usage examples
* Add Usage examples
* Add Usage examples
* Add Usage examples
* named_children
* reshape_classifier_outputs
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update
* update
* fix CI
* fix incorrect class substitution
* fix incorrect class substitution
* remove denormalize
* ravel fix
* cleanup
* update opt file printing
* update opt file printing
* update defaults
* add opt to checkpoint
* Add warning
* Add comment
* plot half bug fix
* Use NotImplementedError
* fix export shape report
* Fix TRT load
* cleanup CI
* profile comment
* CI fix
* Add cls models
* avoid inplace error
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fix usage examples
* Update README
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
Co-authored-by: Ayush Chaurasia <ayush.chaurarsia@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-08-17 17:59:01 +08:00
|
|
|
if pred is not None:
|
2024-01-08 08:29:14 +08:00
|
|
|
LOGGER.info("Predicted:" + " ".join(f"{names[i]:3s}" for i in pred[:nmax]))
|
New YOLOv5 Classification Models (#8956)
* Update
* Logger step fix: Increment step with epochs (#8654)
* enhance
* revert
* allow training from scratch
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update --img argument from train.py
single line
* fix image size from 640 to 128
* suport custom dataloader and augmentation
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* format
* Update dataloaders.py
* Single line return, single line comment, remove unused argument
* address PR comments
* fix spelling
* don't augment eval set
* use fstring
* update augmentations.py
* new maning convention for transforms
* reverse if statement, inline ops
* reverse if statement, inline ops
* updates
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update dataloaders
* Remove additional if statement
* Remove is_train as redundant
* Cleanup
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Cleanup2
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update classifier.py
* Update augmentations.py
* fix: imshow clip warning
* update
* Revert ToTensorV2 removal
* Update classifier.py
* Update normalize values, revert uint8
* normalize image using cv2
* remove dedundant comment
* Update classifier.py
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* replace print with logger
* commit steps
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Allow logging models from GenericLogger (#8676)
* enhance
* revert
* allow training from scratch
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update --img argument from train.py
single line
* fix image size from 640 to 128
* suport custom dataloader and augmentation
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* format
* Update dataloaders.py
* Single line return, single line comment, remove unused argument
* address PR comments
* fix spelling
* don't augment eval set
* use fstring
* update augmentations.py
* new maning convention for transforms
* reverse if statement, inline ops
* reverse if statement, inline ops
* updates
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update dataloaders
* Remove additional if statement
* Remove is_train as redundant
* Cleanup
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Cleanup2
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update classifier.py
* Update augmentations.py
* fix: imshow clip warning
* update
* Revert ToTensorV2 removal
* Update classifier.py
* Update normalize values, revert uint8
* normalize image using cv2
* remove dedundant comment
* Update classifier.py
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* replace print with logger
* commit steps
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* support final model logging
* update
* update
* update
* update
* remove curses
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update classifier.py
* Update __init__.py
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
* Update
* Update
* Update
* Update
* Update dataset download
* Update dataset download
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Pass imgsz to classify_transforms()
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Cos scheduler
* Cos scheduler
* Remove unused args
* Update
* Add seed
* Add seed
* Update
* Update
* Add run(), main()
* Merge master
* Merge master
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Create YOLOv5 BaseModel class (#8829)
* Create BaseModel
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fix
* Hub load device fix
* Update
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Add experiment
* Merge master
* Attach names
* weight decay = 1e-4
* weight decay = 5e-5
* update smart_optimizer console printout
* fashion-mnist fix
* Merge master
* Update Table
* Update Table
* Remove destroy process group
* add kwargs to forward()
* fuse fix for resnet50
* nc, names fix for resnet50
* nc, names fix for resnet50
* ONNX CPU inference fix
* revert
* cuda
* if augment or visualize
* if augment or visualize
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* New smart_inference_mode()
* Update README
* Refactor into /classify dir
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* reset defaults
* reset defaults
* fix gpu predict
* warmup
* ema half fix
* spacing
* remove data
* remove cache
* remove denormalize
* save run settings
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* verbose false on initial plots
* new save_yaml() function
* Update ci-testing.yml
* Path(data) CI fix
* Separate classification CI
* fix val
* fix val
* fix val
* smartCrossEntropyLoss
* skip validation on hub load
* autodownload with working dir root
* str(data)
* Dataset usage example
* im_show normalize
* im_show normalize
* add imagenet simple names to multibackend
* Add validation speeds
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* 24-space names
* Update bash scripts
* Update permissions
* Add bash script arguments
* remove verbose
* TRT data fix
* names generator fix
* optimize if names
* update usage
* Add local loading
* Verbose=False
* update names printing
* Add Usage examples
* Add Usage examples
* Add Usage examples
* Add Usage examples
* named_children
* reshape_classifier_outputs
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update
* update
* fix CI
* fix incorrect class substitution
* fix incorrect class substitution
* remove denormalize
* ravel fix
* cleanup
* update opt file printing
* update opt file printing
* update defaults
* add opt to checkpoint
* Add warning
* Add comment
* plot half bug fix
* Use NotImplementedError
* fix export shape report
* Fix TRT load
* cleanup CI
* profile comment
* CI fix
* Add cls models
* avoid inplace error
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fix usage examples
* Update README
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
Co-authored-by: Ayush Chaurasia <ayush.chaurarsia@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-08-17 17:59:01 +08:00
|
|
|
return f
|
|
|
|
|
|
|
|
|
2024-01-08 08:29:14 +08:00
|
|
|
def plot_evolve(evolve_csv="path/to/evolve.csv"): # from utils.plots import *; plot_evolve()
|
2021-08-04 23:13:38 +08:00
|
|
|
# Plot evolve.csv hyp evolution results
|
2021-09-01 21:00:13 +08:00
|
|
|
evolve_csv = Path(evolve_csv)
|
2021-08-04 23:13:38 +08:00
|
|
|
data = pd.read_csv(evolve_csv)
|
|
|
|
keys = [x.strip() for x in data.columns]
|
|
|
|
x = data.values
|
|
|
|
f = fitness(x)
|
|
|
|
j = np.argmax(f) # max fitness index
|
|
|
|
plt.figure(figsize=(10, 12), tight_layout=True)
|
2024-01-08 08:29:14 +08:00
|
|
|
matplotlib.rc("font", **{"size": 8})
|
|
|
|
print(f"Best results from row {j} of {evolve_csv}:")
|
2021-08-04 23:13:38 +08:00
|
|
|
for i, k in enumerate(keys[7:]):
|
|
|
|
v = x[:, 7 + i]
|
|
|
|
mu = v[j] # best single result
|
|
|
|
plt.subplot(6, 5, i + 1)
|
2024-01-08 08:29:14 +08:00
|
|
|
plt.scatter(v, f, c=hist2d(v, f, 20), cmap="viridis", alpha=0.8, edgecolors="none")
|
|
|
|
plt.plot(mu, f.max(), "k+", markersize=15)
|
|
|
|
plt.title(f"{k} = {mu:.3g}", fontdict={"size": 9}) # limit to 40 characters
|
2021-08-04 23:13:38 +08:00
|
|
|
if i % 5 != 0:
|
|
|
|
plt.yticks([])
|
2024-01-08 08:29:14 +08:00
|
|
|
print(f"{k:>15}: {mu:.3g}")
|
|
|
|
f = evolve_csv.with_suffix(".png") # filename
|
2021-08-04 23:13:38 +08:00
|
|
|
plt.savefig(f, dpi=200)
|
2021-08-30 23:22:21 +08:00
|
|
|
plt.close()
|
2024-01-08 08:29:14 +08:00
|
|
|
print(f"Saved {f}")
|
2021-08-04 23:13:38 +08:00
|
|
|
|
|
|
|
|
2024-01-08 08:29:14 +08:00
|
|
|
def plot_results(file="path/to/results.csv", dir=""):
|
2024-02-25 21:04:01 +08:00
|
|
|
"""
|
|
|
|
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')
|
|
|
|
"""
|
2021-07-26 01:06:37 +08:00
|
|
|
save_dir = Path(file).parent if file else Path(dir)
|
2020-12-02 22:53:16 +08:00
|
|
|
fig, ax = plt.subplots(2, 5, figsize=(12, 6), tight_layout=True)
|
2020-11-14 18:50:32 +08:00
|
|
|
ax = ax.ravel()
|
2024-01-08 08:29:14 +08:00
|
|
|
files = list(save_dir.glob("results*.csv"))
|
|
|
|
assert len(files), f"No results.csv files found in {save_dir.resolve()}, nothing to plot."
|
2022-05-14 22:12:08 +08:00
|
|
|
for f in files:
|
2020-11-14 18:50:32 +08:00
|
|
|
try:
|
2021-07-26 01:06:37 +08:00
|
|
|
data = pd.read_csv(f)
|
|
|
|
s = [x.strip() for x in data.columns]
|
|
|
|
x = data.values[:, 0]
|
|
|
|
for i, j in enumerate([1, 2, 3, 4, 5, 8, 9, 10, 6, 7]):
|
2024-01-08 08:29:14 +08:00
|
|
|
y = data.values[:, j].astype("float")
|
2021-07-26 01:06:37 +08:00
|
|
|
# y[y == 0] = np.nan # don't show zero values
|
2024-01-08 08:29:14 +08:00
|
|
|
ax[i].plot(x, y, marker=".", label=f.stem, linewidth=2, markersize=8) # actual results
|
|
|
|
ax[i].plot(x, gaussian_filter1d(y, sigma=3), ":", label="smooth", linewidth=2) # smoothing line
|
2021-07-26 01:06:37 +08:00
|
|
|
ax[i].set_title(s[j], fontsize=12)
|
|
|
|
# if j in [8, 9, 10]: # share train and val loss y axes
|
2020-11-14 18:50:32 +08:00
|
|
|
# ax[i].get_shared_y_axes().join(ax[i], ax[i - 5])
|
|
|
|
except Exception as e:
|
2024-01-08 08:29:14 +08:00
|
|
|
LOGGER.info(f"Warning: Plotting error for {f}: {e}")
|
2020-11-14 18:50:32 +08:00
|
|
|
ax[1].legend()
|
2024-01-08 08:29:14 +08:00
|
|
|
fig.savefig(save_dir / "results.png", dpi=200)
|
2021-08-30 23:22:21 +08:00
|
|
|
plt.close()
|
2021-06-28 19:18:45 +08:00
|
|
|
|
|
|
|
|
2024-01-08 08:29:14 +08:00
|
|
|
def profile_idetection(start=0, stop=0, labels=(), save_dir=""):
|
2024-02-25 21:04:01 +08:00
|
|
|
"""
|
|
|
|
Plots per-image iDetection logs, comparing metrics like storage and performance over time.
|
|
|
|
|
|
|
|
Example: from utils.plots import *; profile_idetection()
|
|
|
|
"""
|
2021-11-07 02:28:03 +08:00
|
|
|
ax = plt.subplots(2, 4, figsize=(12, 6), tight_layout=True)[1].ravel()
|
2024-01-08 08:29:14 +08:00
|
|
|
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"))
|
2021-11-07 02:28:03 +08:00
|
|
|
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)
|
|
|
|
results = results[:, x]
|
2024-01-08 08:29:14 +08:00
|
|
|
t = results[0] - results[0].min() # set t0=0s
|
2021-11-07 02:28:03 +08:00
|
|
|
results[0] = x
|
|
|
|
for i, a in enumerate(ax):
|
|
|
|
if i < len(results):
|
2024-01-08 08:29:14 +08:00
|
|
|
label = labels[fi] if len(labels) else f.stem.replace("frames_", "")
|
|
|
|
a.plot(t, results[i], marker=".", label=label, linewidth=1, markersize=5)
|
2021-11-07 02:28:03 +08:00
|
|
|
a.set_title(s[i])
|
2024-01-08 08:29:14 +08:00
|
|
|
a.set_xlabel("time (s)")
|
2021-11-07 02:28:03 +08:00
|
|
|
# if fi == len(files) - 1:
|
|
|
|
# a.set_ylim(bottom=0)
|
2024-01-08 08:29:14 +08:00
|
|
|
for side in ["top", "right"]:
|
2021-11-07 02:28:03 +08:00
|
|
|
a.spines[side].set_visible(False)
|
|
|
|
else:
|
|
|
|
a.remove()
|
|
|
|
except Exception as e:
|
2024-01-08 08:29:14 +08:00
|
|
|
print(f"Warning: Plotting error for {f}; {e}")
|
2021-11-07 02:28:03 +08:00
|
|
|
ax[1].legend()
|
2024-01-08 08:29:14 +08:00
|
|
|
plt.savefig(Path(save_dir) / "idetection_profile.png", dpi=200)
|
2021-07-07 21:41:58 +08:00
|
|
|
|
|
|
|
|
2024-01-08 08:29:14 +08:00
|
|
|
def save_one_box(xyxy, im, file=Path("im.jpg"), gain=1.02, pad=10, square=False, BGR=False, save=True):
|
2024-02-25 21:04:01 +08:00
|
|
|
"""Crops and saves an image from bounding box `xyxy`, applied with `gain` and `pad`, optionally squares and adjusts
|
|
|
|
for BGR.
|
|
|
|
"""
|
2021-11-07 02:28:03 +08:00
|
|
|
xyxy = torch.tensor(xyxy).view(-1, 4)
|
|
|
|
b = xyxy2xywh(xyxy) # boxes
|
|
|
|
if square:
|
|
|
|
b[:, 2:] = b[:, 2:].max(1)[0].unsqueeze(1) # attempt rectangle to square
|
|
|
|
b[:, 2:] = b[:, 2:] * gain + pad # box wh * gain + pad
|
|
|
|
xyxy = xywh2xyxy(b).long()
|
2022-09-24 22:02:41 +08:00
|
|
|
clip_boxes(xyxy, im.shape)
|
2024-01-08 08:29:14 +08:00
|
|
|
crop = im[int(xyxy[0, 1]) : int(xyxy[0, 3]), int(xyxy[0, 0]) : int(xyxy[0, 2]), :: (1 if BGR else -1)]
|
2021-11-07 02:28:03 +08:00
|
|
|
if save:
|
|
|
|
file.parent.mkdir(parents=True, exist_ok=True) # make directory
|
2024-01-08 08:29:14 +08:00
|
|
|
f = str(increment_path(file).with_suffix(".jpg"))
|
2022-07-24 05:30:30 +08:00
|
|
|
# cv2.imwrite(f, crop) # save BGR, https://github.com/ultralytics/yolov5/issues/7007 chroma subsampling issue
|
|
|
|
Image.fromarray(crop[..., ::-1]).save(f, quality=95, subsampling=0) # save RGB
|
2021-11-07 02:28:03 +08:00
|
|
|
return crop
|