Skip to content

Commit

Permalink
deploy: 719bbac
Browse files Browse the repository at this point in the history
  • Loading branch information
mieskolainen committed Oct 20, 2024
1 parent 77be4fb commit c68a3e0
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions _modules/icenet/deep/losstools.html
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,7 @@ <h1>Source code for icenet.deep.losstools</h1><div class="highlight"><pre>
<span class="k">return</span> <span class="n">loss</span></div>



<div class="viewcode-block" id="SWD_reweight_loss">
<a class="viewcode-back" href="../../../modules/icenet.html#icenet.deep.losstools.SWD_reweight_loss">[docs]</a>
<span class="k">def</span> <span class="nf">SWD_reweight_loss</span><span class="p">(</span><span class="n">logits</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">weights</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">p</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">num_slices</span><span class="o">=</span><span class="mi">1000</span><span class="p">,</span> <span class="n">norm_weights</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">mode</span><span class="o">=</span><span class="s1">&#39;SWD&#39;</span><span class="p">):</span>
Expand All @@ -902,23 +903,20 @@ <h1>Source code for icenet.deep.losstools</h1><div class="highlight"><pre>
<span class="n">p</span><span class="o">=</span><span class="n">p</span><span class="p">,</span> <span class="n">num_slices</span><span class="o">=</span><span class="n">num_slices</span><span class="p">,</span>
<span class="n">norm_weights</span><span class="o">=</span><span class="n">norm_weights</span><span class="p">,</span>
<span class="n">mode</span><span class="o">=</span><span class="n">mode</span><span class="p">)</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> # Overall statistics scale normalization (based on class = 1) done afterwards [experimental]</span>
<span class="sd"> </span>
<span class="sd"> print(f&#39;before: {loss_uv}&#39;)</span>

<span class="sd"> if (norm_weights == False):</span>
<span class="sd"> if v_weights is not None:</span>
<span class="sd"> loss_uv = loss_uv / torch.sum(v_weights)</span>
<span class="sd"> else:</span>
<span class="sd"> loss_uv = loss_uv / torch.sum(v_idx)</span>
<span class="sd"> </span>
<span class="sd"> print(f&#39;after: {loss_uv}&#39;)</span>
<span class="sd"> &quot;&quot;&quot;</span>

<span class="c1"># Overall statistics scale normalization (based on class = 1) done afterwards</span>
<span class="c1"># (due to possible maxevent cutoff for the SWD loss vs BCE loss due to GPU VRAM limit)</span>

<span class="k">if</span> <span class="p">(</span><span class="n">norm_weights</span> <span class="o">==</span> <span class="kc">False</span><span class="p">):</span>
<span class="k">if</span> <span class="n">v_weights</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">loss_uv</span> <span class="o">=</span> <span class="n">loss_uv</span> <span class="o">/</span> <span class="n">torch</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">v_weights</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">loss_uv</span> <span class="o">=</span> <span class="n">loss_uv</span> <span class="o">/</span> <span class="n">torch</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">v_idx</span><span class="p">)</span>

<span class="k">return</span> <span class="n">loss_uv</span></div>



<div class="viewcode-block" id="Lq_binary_loss">
<a class="viewcode-back" href="../../../modules/icenet.html#icenet.deep.losstools.Lq_binary_loss">[docs]</a>
<span class="k">def</span> <span class="nf">Lq_binary_loss</span><span class="p">(</span><span class="n">logits</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">q</span><span class="p">,</span> <span class="n">weights</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
Expand Down

0 comments on commit c68a3e0

Please sign in to comment.