Skip to content

Commit

Permalink
Fix val.py study plot (ultralytics#4831)
Browse files Browse the repository at this point in the history
* Fix val.py study plot

* call plot_val_study

* Rename plot_study_txt to plot_val_study
  • Loading branch information
glenn-jocher authored and CesarBazanAV committed Sep 29, 2021
1 parent b5546b6 commit 3af3b0e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
11 changes: 7 additions & 4 deletions utils/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,16 @@ def plot_targets_txt(): # from utils.plots import *; plot_targets_txt()
plt.savefig('targets.jpg', dpi=200)


def plot_study_txt(path='', x=None): # from utils.plots import *; plot_study_txt()
# Plot study.txt generated by val.py
def plot_val_study(file='', dir='', x=None): # from utils.plots import *; plot_val_study()
# 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)
plot2 = False # plot additional results
if plot2:
ax = plt.subplots(2, 4, figsize=(10, 6), tight_layout=True)[1].ravel()

fig2, ax2 = plt.subplots(1, 1, figsize=(8, 4), tight_layout=True)
# for f in [Path(path) / f'study_coco_{x}.txt' for x in ['yolov5s6', 'yolov5m6', 'yolov5l6', 'yolov5x6']]:
for f in sorted(Path(path).glob('study*.txt')):
for f in sorted(save_dir.glob('study*.txt')):
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)
if plot2:
Expand All @@ -278,7 +279,9 @@ def plot_study_txt(path='', x=None): # from utils.plots import *; plot_study_tx
ax2.set_xlabel('GPU Speed (ms/img)')
ax2.set_ylabel('COCO AP val')
ax2.legend(loc='lower right')
plt.savefig(str(Path(path).name) + '.png', dpi=300)
f = save_dir / 'study.png'
print(f'Saving {f}...')
plt.savefig(f, dpi=300)


def plot_labels(labels, names=(), save_dir=Path('')):
Expand Down
4 changes: 2 additions & 2 deletions val.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
check_suffix, check_yaml, box_iou, non_max_suppression, scale_coords, xyxy2xywh, xywh2xyxy, set_logging, \
increment_path, colorstr
from utils.metrics import ap_per_class, ConfusionMatrix
from utils.plots import plot_images, output_to_target, plot_study_txt
from utils.plots import output_to_target, plot_images, plot_val_study
from utils.torch_utils import select_device, time_sync
from utils.callbacks import Callbacks

Expand Down Expand Up @@ -348,7 +348,7 @@ def main(opt):
y.append(r + t) # results and times
np.savetxt(f, y, fmt='%10.4g') # save
os.system('zip -r study.zip study_*.txt')
plot_study_txt(x=x) # plot
plot_val_study(x=x) # plot


if __name__ == "__main__":
Expand Down

0 comments on commit 3af3b0e

Please sign in to comment.