Daemon thread plotting (#1561)
* Daemon thread plotting * remove process_batch * plot after print
This commit is contained in:
1 parent
68211f72c9
commit
b6ed1104a6
3 files changed
+25
-19
No files matched your search
@@ -3,6 +3,7 @@ import glob
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
from threading import Thread
|
||||
|
||||
import numpy as np
|
||||
import torch
|
||||
@@ -206,10 +207,10 @@ def test(data,
|
||||
|
||||
# Plot images
|
||||
if plots and batch_i < 3:
|
||||
f = save_dir / f'test_batch{batch_i}_labels.jpg' # filename
|
||||
plot_images(img, targets, paths, f, names) # labels
|
||||
f = save_dir / f'test_batch{batch_i}_pred.jpg'
|
||||
plot_images(img, output_to_target(output), paths, f, names) # predictions
|
||||
f = save_dir / f'test_batch{batch_i}_labels.jpg' # labels
|
||||
Thread(target=plot_images, args=(img, targets, paths, f, names), daemon=True).start()
|
||||
f = save_dir / f'test_batch{batch_i}_pred.jpg' # predictions
|
||||
Thread(target=plot_images, args=(img, output_to_target(output), paths, f, names), daemon=True).start()
|
||||
|
||||
# Compute statistics
|
||||
stats = [np.concatenate(x, 0) for x in zip(*stats)] # to numpy
|
||||
@@ -221,13 +222,6 @@ def test(data,
|
||||
else:
|
||||
nt = torch.zeros(1)
|
||||
|
||||
# Plots
|
||||
if plots:
|
||||
confusion_matrix.plot(save_dir=save_dir, names=list(names.values()))
|
||||
if wandb and wandb.run:
|
||||
wandb.log({"Images": wandb_images})
|
||||
wandb.log({"Validation": [wandb.Image(str(f), caption=f.name) for f in sorted(save_dir.glob('test*.jpg'))]})
|
||||
|
||||
# Print results
|
||||
pf = '%20s' + '%12.3g' * 6 # print format
|
||||
print(pf % ('all', seen, nt.sum(), mp, mr, map50, map))
|
||||
@@ -242,6 +236,13 @@ def test(data,
|
||||
if not training:
|
||||
print('Speed: %.1f/%.1f/%.1f ms inference/NMS/total per %gx%g image at batch-size %g' % t)
|
||||
|
||||
# Plots
|
||||
if plots:
|
||||
confusion_matrix.plot(save_dir=save_dir, names=list(names.values()))
|
||||
if wandb and wandb.run:
|
||||
wandb.log({"Images": wandb_images})
|
||||
wandb.log({"Validation": [wandb.Image(str(f), caption=f.name) for f in sorted(save_dir.glob('test*.jpg'))]})
|
||||
|
||||
# Save JSON
|
||||
if save_json and len(jdict):
|
||||
w = Path(weights[0] if isinstance(weights, list) else weights).stem if weights is not None else '' # weights
|
||||
|
||||
Reference in new issue
Block a user