Add train.py and val.py callbacks (#4220)
* added callbacks * Update callbacks.py * Update train.py * Update val.py * Fix CamlCase add staticmethod * Refactor logger into callbacks * Cleanup * New callback on_val_image_end() * Add curves and results images to TensorBoard Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
This commit is contained in:
1 parent
d8f18834a2
commit
b74929c910
6 files changed
+230
-41
No files matched your search
@@ -25,7 +25,7 @@ from utils.general import coco80_to_coco91_class, check_dataset, check_file, che
|
||||
from utils.metrics import ap_per_class, ConfusionMatrix
|
||||
from utils.plots import plot_images, output_to_target, plot_study_txt
|
||||
from utils.torch_utils import select_device, time_sync
|
||||
from utils.loggers import Loggers
|
||||
from utils.callbacks import Callbacks
|
||||
|
||||
|
||||
def save_one_txt(predn, save_conf, shape, file):
|
||||
@@ -97,7 +97,7 @@ def run(data,
|
||||
dataloader=None,
|
||||
save_dir=Path(''),
|
||||
plots=True,
|
||||
loggers=Loggers(),
|
||||
callbacks=Callbacks(),
|
||||
compute_loss=None,
|
||||
):
|
||||
# Initialize/load model and set device
|
||||
@@ -213,7 +213,7 @@ def run(data,
|
||||
save_one_txt(predn, save_conf, shape, file=save_dir / 'labels' / (path.stem + '.txt'))
|
||||
if save_json:
|
||||
save_one_json(predn, jdict, path, class_map) # append to COCO-JSON dictionary
|
||||
loggers.on_val_batch_end(pred, predn, path, names, img[si])
|
||||
callbacks.on_val_image_end(pred, predn, path, names, img[si])
|
||||
|
||||
# Plot images
|
||||
if plots and batch_i < 3:
|
||||
@@ -250,7 +250,7 @@ def run(data,
|
||||
# Plots
|
||||
if plots:
|
||||
confusion_matrix.plot(save_dir=save_dir, names=list(names.values()))
|
||||
loggers.on_val_end()
|
||||
callbacks.on_val_end()
|
||||
|
||||
# Save JSON
|
||||
if save_json and len(jdict):
|
||||
@@ -282,7 +282,7 @@ def run(data,
|
||||
model.float() # for training
|
||||
if not training:
|
||||
s = f"\n{len(list(save_dir.glob('labels/*.txt')))} labels saved to {save_dir / 'labels'}" if save_txt else ''
|
||||
print(f"Results saved to {save_dir}{s}")
|
||||
print(f"Results saved to {colorstr('bold', save_dir)}{s}")
|
||||
maps = np.zeros(nc) + map
|
||||
for i, c in enumerate(ap_class):
|
||||
maps[c] = ap[i]
|
||||
|
||||
Reference in new issue
Block a user