Tensorboard add_custom_scalars() for KFold Training Loss Visualization

username: a.arbabian
cooked: <p>I am trying to neatly log my train/val losses for a KFold training scheme.<br>
I want all the train losses between the K folds to be on the same multi-line graph. Similarly for the val losses. I also want this to be done with 1 SummaryWriter object so my /runs/ folder is neat.</p>
<p>So far I’ve researched and messed around with add_scalars() and add_custom_scalars(). Nothing has given me the correct layout. add_scalars() keeps making extra SummaryWriters and filling up the /runs/ folder.</p>
<p>Here is the layout dictionary I’m using:</p>
<pre><code class="lang-auto">layout = {'loss': {'train': ['Multiline', [f"train/fold{i}" for i in range(N_FOLDS)]],
                    'val': ['Multiline', [f"val/fold{i}" for i in range(N_FOLDS)]]}}
</code></pre>
<p>and how I’m currently trying to hook up the add_scalar() calls to this layout:</p>
<pre><code class="lang-auto">writer.add_scalar(f'loss/train/fold{i_fold}', train_loss, epoch)
writer.add_scalar(f'loss/val/fold{i_fold}', val_loss, epoch)
</code></pre>
<p>But here is what I’m getting, each curve for training loss is on its own axes.<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/5/4/54fa631b69910d5f00909c8b389f760031ee0093.png" data-download-href="https://discuss.pytorch.org/uploads/default/54fa631b69910d5f00909c8b389f760031ee0093" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/5/4/54fa631b69910d5f00909c8b389f760031ee0093_2_690x220.png" alt="image" data-base62-sha1="c7KyGES9F3uSW8znindT83yb8iL" width="690" height="220" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/5/4/54fa631b69910d5f00909c8b389f760031ee0093_2_690x220.png, https://discuss.pytorch.org/uploads/default/optimized/3X/5/4/54fa631b69910d5f00909c8b389f760031ee0093_2_1035x330.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/5/4/54fa631b69910d5f00909c8b389f760031ee0093_2_1380x440.png 2x" data-dominant-color="F5EEE3"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">1847×591 41.9 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>Thanks</p>

username: a.arbabian
cooked: <p>For the record, when I use writer.add_scalars() like this:</p>
<pre><code class="lang-auto">writer.add_scalars('loss/train', {f'fold{i_fold}': train_loss}, epoch)
</code></pre>
<p>I get a result like this:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/0/d/0dda8151968501088da66286f5dcf144d0728c2a.png" data-download-href="https://discuss.pytorch.org/uploads/default/0dda8151968501088da66286f5dcf144d0728c2a" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/0/d/0dda8151968501088da66286f5dcf144d0728c2a_2_690x471.png" alt="image" data-base62-sha1="1YylQ1pFRlMsGS9ZfELWuSDy48a" width="690" height="471" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/0/d/0dda8151968501088da66286f5dcf144d0728c2a_2_690x471.png, https://discuss.pytorch.org/uploads/default/optimized/3X/0/d/0dda8151968501088da66286f5dcf144d0728c2a_2_1035x706.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/0/d/0dda8151968501088da66286f5dcf144d0728c2a.png 2x" data-dominant-color="F4EFE7"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">1068×730 45.6 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>Which gives the desired effect but makes extra run objects as you can see in the bottom left.</p>