SemTorch: A Semantic Segmentation library build above FastAI

username: WaterKnight
cooked: <p>Hi, guys:</p>
<p>I am happy to announce that I have released <a href="https://github.com/WaterKnight1998/SemTorch" rel="nofollow noopener">SemTorch</a>.</p>
<p>This library allows you to train 5 different Sementation Models: UNet, DeepLabV3+, HRNet, Mask-RCNN and U²-Net in the same way.</p>
<p>For example:</p>
<pre><code class="lang-auto"># SemTorch
from semtorch import get_segmentation_learner

learn = get_segmentation_learner(dls=dls, number_classes=2, segmentation_type="Semantic Segmentation",
                                 architecture_name="deeplabv3+", backbone_name="resnet50", 
                                 metrics=[tumour, Dice(), JaccardCoeff()],wd=1e-2,
                                 splitter=segmentron_splitter).to_fp16()
</code></pre>
<p>This library was used in my other project: <strong><a href="https://github.com/WaterKnight1998/Deep-Tumour-Spheroid" rel="nofollow noopener">Deep-Tumour-Spheroid</a></strong>. In this project I trained segmentation models for segmenting brain tumours.<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://raw.githubusercontent.com/WaterKnight1998/Deep-Tumour-Spheroid/feature/python-package/python-package/readme_images/predict_tumour.png" title="image" rel="nofollow noopener"><img src="https://raw.githubusercontent.com/WaterKnight1998/Deep-Tumour-Spheroid/feature/python-package/python-package/readme_images/predict_tumour.png" alt="image" width="689" height="489"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use xlink:href="#far-image"></use></svg><span class="filename">image</span><span class="informations">1374×975</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use xlink:href="#discourse-expand"></use></svg></div></a></div></p>
<p>The notebooks can be found <a href="https://github.com/WaterKnight1998/Deep-Tumour-Spheroid/tree/develop/notebooks" rel="nofollow noopener">here</a>. They are an example of how easily is to train a model with this library. You can use SemTorch with your own datasets!</p>
<p>In addition, if you want to know more about this project you can go to<br>
</p><aside class="onebox allowlistedgeneric">
  <header class="source">
      <img src="https://forums.fast.ai/uploads/default/optimized/3X/b/3/b395de7a2ba00b82865031c97a8cadf3d80e71e5_2_32x32.png" class="site-icon" width="32" height="32">
      <a href="https://forums.fast.ai/t/deep-tumour-spheroid-segmentation-of-brain-tumours-with-fastai-semtorch/79195" target="_blank" rel="nofollow noopener" title="05:52PM - 18 September 2020">Deep Learning Course Forums – 18 Sep 20</a>
  </header>
  <article class="onebox-body">
    <div class="aspect-image" style="--aspect-ratio:690/489;"><img src="https://forums.fast.ai/uploads/default/optimized/3X/6/e/6eea898fbd6677037d6a84c925b8acb49b5100c6_2_1024x726.jpeg" class="thumbnail" width="690" height="489"></div>

<h3><a href="https://forums.fast.ai/t/deep-tumour-spheroid-segmentation-of-brain-tumours-with-fastai-semtorch/79195" target="_blank" rel="nofollow noopener">Deep-Tumour-Spheroid: Segmentation of Brain Tumours with FastAI &amp; SemTorch</a></h3>

<p>Hi,  I am happy to announce that I have published my final degree project: Deep-Tumour-Spheroid   Deep Learning is making a big impact in areas such as autonomous driving, medicine and robotics  among others. In medicine, it is helping doctors to...</p>

  <p><span class="label1">Reading time: 1 mins 🕑</span>
    <span class="label2">Likes: 9 ❤</span></p>

  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>

<p><strong>Deeper look in all the parameters of Semtorch</strong><br>
All this library is focused in this function that will get new models and options over time.</p>
<pre><code class="lang-auto">def get_segmentation_learner(dls, number_classes, segmentation_type, architecture_name, backbone_name,
                             loss_func=None, opt_func=Adam, lr=defaults.lr, splitter=trainable_params, 
                             cbs=None, pretrained=True, normalize=True, image_size=None, metrics=None, 
                             path=None, model_dir='models', wd=None, wd_bn_bias=False, train_bn=True,
                             moms=(0.95,0.85,0.95)):
</code></pre>
<p>This function return a learner for the provided architecture and backbone</p>
<h3><strong>Parameters:</strong></h3>
<ul>
<li>
<strong>dls (DataLoader):</strong> the dataloader to use with the learner</li>
<li>
<strong>number_classes (int):</strong> the number of clases in the project. It should be &gt;=2</li>
<li>
<strong>segmentation_type (str):</strong> just <code>Semantic Segmentation</code> accepted for now</li>
<li>
<strong>architecture_name (str):</strong> name of the architecture. The following ones are supported: <code>unet</code>, <code>deeplabv3+</code>, <code>hrnet</code>, <code>maskrcnn</code> and <code>u2^net</code>
</li>
<li>
<strong>backbone_name (str):</strong> name of the backbone</li>
<li>
<strong>loss_func ():</strong> loss function.</li>
<li>
<strong>opt_func ():</strong> opt function.</li>
<li>
<strong>lr ():</strong> learning rates</li>
<li>
<strong>splitter ():</strong> splitter function for freazing the learner</li>
<li>
<strong>cbs (List[cb]):</strong> list of callbacks</li>
<li>
<strong>pretrained (bool):</strong> it defines if a trained backbone is needed</li>
<li>
<strong>normalize (bool):</strong> if normalization  is applied</li>
<li>
<strong>image_size (int):</strong> REQUIRED for MaskRCNN. It indicates the desired size of the image.</li>
<li>
<strong>metrics (List[metric]):</strong> list of metrics</li>
<li>
<strong>path ():</strong> path parameter</li>
<li>
<strong>model_dir (str):</strong> the path in which save models</li>
<li>
<strong>wd (float):</strong> wieght decay</li>
<li><strong>wd_bn_bias (bool):</strong></li>
<li><strong>train_bn (bool):</strong></li>
<li>
<strong>moms (Tuple(float)):</strong> tuple of different momentuns</li>
</ul>
<h3><strong>Returns:</strong></h3>
<ul>
<li>
<strong>learner:</strong> value containing the learner object</li>
</ul>
<h3><strong>Supported configs</strong></h3>
<div class="md-table">
<table>
<thead>
<tr>
<th>Architecture</th>
<th style="text-align:center">supported config</th>
<th style="text-align:center">backbones</th>
</tr>
</thead>
<tbody>
<tr>
<td>unet</td>
<td style="text-align:center">
<code>Semantic Segmentation</code>,<code>binary</code> <code>Semantic Segmentation</code>,<code>multiple</code>
</td>
<td style="text-align:center">
<code>resnet18</code>, <code>resnet34</code>, <code>resnet50</code>, <code>resnet101</code>, <code>resnet152</code>, <code>xresnet18</code>, <code>xresnet34</code>, <code>xresnet50</code>, <code>xresnet101</code>, <code>xresnet152</code>, <code>squeezenet1_0</code>, <code>squeezenet1_1</code>, <code>densenet121</code>, <code>densenet169</code>, <code>densenet201</code>, <code>densenet161</code>, <code>vgg11_bn</code>, <code>vgg13_bn</code>, <code>vgg16_bn</code>, <code>vgg19_bn</code>, <code>alexnet</code>
</td>
</tr>
<tr>
<td>deeplabv3+</td>
<td style="text-align:center">
<code>Semantic Segmentation</code>,<code>binary</code> <code>Semantic Segmentation</code>,<code>multiple</code>
</td>
<td style="text-align:center">
<code>resnet18</code>,  <code>resnet34</code>,  <code>resnet50</code>,  <code>resnet101</code>,  <code>resnet152</code>,  <code>resnet50c</code>,  <code>resnet101c</code>,  <code>resnet152c</code>,  <code>xception65</code>,  <code>mobilenet_v2</code>
</td>
</tr>
<tr>
<td>hrnet</td>
<td style="text-align:center">
<code>Semantic Segmentation</code>,<code>binary</code>  <code>Semantic Segmentation</code>,<code>multiple</code>
</td>
<td style="text-align:center">
<code>hrnet_w18_small_model_v1</code>,  <code>hrnet_w18_small_model_v2</code>,  <code>hrnet_w18</code>,  <code>hrnet_w30</code>,  <code>hrnet_w32</code>,  <code>hrnet_w48</code>
</td>
</tr>
<tr>
<td>maskrcnn</td>
<td style="text-align:center">
<code>Semantic Segmentation</code>,<code>binary</code>
</td>
<td style="text-align:center"><code>resnet50</code></td>
</tr>
<tr>
<td>u2^net</td>
<td style="text-align:center">
<code>Semantic Segmentation</code>,<code>binary</code>
</td>
<td style="text-align:center">
<code>small</code>,  <code>normal</code>
</td>
</tr>
</tbody>
</table>
</div>

username: ptrblck
cooked: <p>Thanks for sharing <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=9" title=":slight_smile:" class="emoji" alt=":slight_smile:"></p>