Skip to content

Commit b8e38da

Browse files
AyushExelpre-commit-ci[bot]glenn-jocher
authored andcommitted
Add --noplots flag to suppress figures and images logging (ultralytics#7534)
* support nomedia * support nomedia for validation * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update train.py * Revert no plot evolve evolve plots do not contain any images * Revert plot_results contains no media * Update wandb_utils.py * sync-bn cleanup * Cleanup * Rename nomedia -> noplots Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Glenn Jocher <[email protected]>
1 parent 933e869 commit b8e38da

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

train.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def train(hyp, opt, device, callbacks): # hyp is path/to/hyp.yaml or hyp dictio
100100
callbacks.register_action(k, callback=getattr(loggers, k))
101101

102102
# Config
103-
plots = not evolve # create plots
103+
plots = not evolve and not opt.noplots # create plots
104104
cuda = device.type != 'cpu'
105105
init_seeds(1 + RANK)
106106
with torch_distributed_zero_first(LOCAL_RANK):
@@ -373,7 +373,7 @@ def train(hyp, opt, device, callbacks): # hyp is path/to/hyp.yaml or hyp dictio
373373
mem = f'{torch.cuda.memory_reserved() / 1E9 if torch.cuda.is_available() else 0:.3g}G' # (GB)
374374
pbar.set_description(('%10s' * 2 + '%10.4g' * 5) %
375375
(f'{epoch}/{epochs - 1}', mem, *mloss, targets.shape[0], imgs.shape[-1]))
376-
callbacks.run('on_train_batch_end', ni, model, imgs, targets, paths, plots, opt.sync_bn)
376+
callbacks.run('on_train_batch_end', ni, model, imgs, targets, paths, plots)
377377
if callbacks.stop_training:
378378
return
379379
# end batch ------------------------------------------------------------------------------------------------
@@ -488,6 +488,7 @@ def parse_opt(known=False):
488488
parser.add_argument('--nosave', action='store_true', help='only save final checkpoint')
489489
parser.add_argument('--noval', action='store_true', help='only validate final epoch')
490490
parser.add_argument('--noautoanchor', action='store_true', help='disable AutoAnchor')
491+
parser.add_argument('--noplots', action='store_true', help='save no plot files')
491492
parser.add_argument('--evolve', type=int, nargs='?', const=300, help='evolve hyperparameters for x generations')
492493
parser.add_argument('--bucket', type=str, default='', help='gsutil bucket')
493494
parser.add_argument('--cache', type=str, nargs='?', const='ram', help='--cache images in "ram" (default) or "disk"')

utils/loggers/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,11 @@ def on_pretrain_routine_end(self):
9999
if self.wandb:
100100
self.wandb.log({"Labels": [wandb.Image(str(x), caption=x.name) for x in paths]})
101101

102-
def on_train_batch_end(self, ni, model, imgs, targets, paths, plots, sync_bn):
102+
def on_train_batch_end(self, ni, model, imgs, targets, paths, plots):
103103
# Callback runs on train batch end
104104
if plots:
105105
if ni == 0:
106-
if not sync_bn: # tb.add_graph() --sync known issue https://github.com/ultralytics/yolov5/issues/3754
106+
if not self.opt.sync_bn: # --sync known issue https://github.com/ultralytics/yolov5/issues/3754
107107
with warnings.catch_warnings():
108108
warnings.simplefilter('ignore') # suppress jit trace warning
109109
self.tb.add_graph(torch.jit.trace(de_parallel(model), imgs[0:1], strict=False), [])

utils/loggers/wandb/wandb_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,8 @@ def setup_training(self, opt):
250250
self.map_val_table_path()
251251
if opt.bbox_interval == -1:
252252
self.bbox_interval = opt.bbox_interval = (opt.epochs // 10) if opt.epochs > 10 else 1
253-
if opt.evolve:
254-
self.bbox_interval = opt.bbox_interval = opt.epochs + 1
253+
if opt.evolve or opt.noplots:
254+
self.bbox_interval = opt.bbox_interval = opt.epochs + 1 # disable bbox_interval
255255
train_from_artifact = self.train_artifact_path is not None and self.val_artifact_path is not None
256256
# Update the the data_dict to point to local artifacts dir
257257
if train_from_artifact:

0 commit comments

Comments
 (0)