forked from fastai/fastai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vision.models.unet.html
105 lines (75 loc) · 7.97 KB
/
vision.models.unet.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
---
title: vision.models.unet
keywords: fastai
sidebar: home_sidebar
summary: "Dynamic Unet that can use any pretrained model as a backbone."
---
<!--
#################################################
### THIS FILE WAS AUTOGENERATED! DO NOT EDIT! ###
#################################################
# file to edit: docs_src/vision.models.unet.ipynb
# instructions: https://docs.fast.ai/gen_doc_main.html
-->
<div class="container" id="notebook-container">
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Dynamic-U-Net">Dynamic U-Net<a class="anchor-link" href="#Dynamic-U-Net">¶</a></h2>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>This module builds a dynamic <a href="https://arxiv.org/abs/1505.04597">U-Net</a> from any backbone pretrained on ImageNet, automatically inferring the intermediate sizes.</p>
</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p><img src="imgs/u-net-architecture.png" alt="U-Net architecture"></p>
<p>This is the original U-Net. The difference here is that the left part is a pretrained model.</p>
</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="output_wrapper">
<div class="output">
<div class="output_area">
<div class="output_markdown rendered_html output_subarea ">
<h2 id="DynamicUnet" class="doc_header"><code>class</code> <code>DynamicUnet</code><a href="https://github.com/fastai/fastai/blob/master/fastai/vision/models/unet.py#L37" class="source_link" style="float:right">[source]</a><a class="source_link" data-toggle="collapse" data-target="#DynamicUnet-pytest" style="float:right; padding-right:10px">[test]</a></h2><blockquote><p><code>DynamicUnet</code>(<strong><code>encoder</code></strong>:<a href="https://pytorch.org/docs/stable/nn.html#torch.nn.Module"><code>Module</code></a>, <strong><code>n_classes</code></strong>:<code>int</code>, <strong><code>img_size</code></strong>:<code>Tuple</code>[<code>int</code>, <code>int</code>]=<strong><em><code>(256, 256)</code></em></strong>, <strong><code>blur</code></strong>:<code>bool</code>=<strong><em><code>False</code></em></strong>, <strong><code>blur_final</code></strong>=<strong><em><code>True</code></em></strong>, <strong><code>self_attention</code></strong>:<code>bool</code>=<strong><em><code>False</code></em></strong>, <strong><code>y_range</code></strong>:<code>OptRange</code>=<strong><em><code>None</code></em></strong>, <strong><code>last_cross</code></strong>:<code>bool</code>=<strong><em><code>True</code></em></strong>, <strong><code>bottle</code></strong>:<code>bool</code>=<strong><em><code>False</code></em></strong>, <strong>**<code>kwargs</code></strong>) :: <a href="/core.html#PrePostInitMeta"><code>PrePostInitMeta</code></a> :: <a href="/layers.html#SequentialEx"><code>SequentialEx</code></a></p>
</blockquote>
<div class="collapse" id="DynamicUnet-pytest"><div class="card card-body pytest_card"><a type="button" data-toggle="collapse" data-target="#DynamicUnet-pytest" class="close" aria-label="Close"><span aria-hidden="true">×</span></a><p>Tests found for <code>DynamicUnet</code>:</p><ul><li><code>pytest -sv tests/test_vision_models_unet.py::test_dynamic_unet_shape</code> <a href="https://github.com/fastai/fastai/blob/master/tests/test_vision_models_unet.py#L39" class="source_link" style="float:right">[source]</a></li><li><code>pytest -sv tests/test_vision_models_unet.py::test_unet_block_shapes</code> <a href="https://github.com/fastai/fastai/blob/master/tests/test_vision_models_unet.py#L45" class="source_link" style="float:right">[source]</a></li></ul><p>To run tests please refer to this <a href="/dev/test.html#quick-guide">guide</a>.</p></div></div><p>Create a U-Net from a given architecture.</p>
</div>
</div>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>This U-Net will sit on top of an <code>encoder</code> (that can be a pretrained model) and with a final output of <code>n_classes</code>. During the initialization, it uses <a href="/callbacks.hooks.html#Hooks"><code>Hooks</code></a> to determine the intermediate features sizes by passing a dummy input through the model and create the upward path automatically.</p>
<p><code>blur</code> is used to avoid checkerboard artifacts at each layer, <code>blur_final</code> is specific to the last layer. <code>self_attention</code> determines if we use a self attention layer at the third block before the end. If <code>y_range</code> is passed, the last activations go through a sigmoid rescaled to that range. <code>last_cross</code> determines if we use a cross-connection with the direct input of the model, and in this case <code>bottle</code> flags if we use a bottleneck or not for that skip connection.</p>
</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="output_wrapper">
<div class="output">
<div class="output_area">
<div class="output_markdown rendered_html output_subarea ">
<h2 id="UnetBlock" class="doc_header"><code>class</code> <code>UnetBlock</code><a href="https://github.com/fastai/fastai/blob/master/fastai/vision/models/unet.py#L14" class="source_link" style="float:right">[source]</a><a class="source_link" data-toggle="collapse" data-target="#UnetBlock-pytest" style="float:right; padding-right:10px">[test]</a></h2><blockquote><p><code>UnetBlock</code>(<strong><code>up_in_c</code></strong>:<code>int</code>, <strong><code>x_in_c</code></strong>:<code>int</code>, <strong><code>hook</code></strong>:<a href="/callbacks.hooks.html#Hook"><code>Hook</code></a>, <strong><code>final_div</code></strong>:<code>bool</code>=<strong><em><code>True</code></em></strong>, <strong><code>blur</code></strong>:<code>bool</code>=<strong><em><code>False</code></em></strong>, <strong><code>leaky</code></strong>:<code>float</code>=<strong><em><code>None</code></em></strong>, <strong><code>self_attention</code></strong>:<code>bool</code>=<strong><em><code>False</code></em></strong>, <strong>**<code>kwargs</code></strong>) :: <a href="/core.html#PrePostInitMeta"><code>PrePostInitMeta</code></a> :: <a href="/torch_core.html#Module"><code>Module</code></a></p>
</blockquote>
<div class="collapse" id="UnetBlock-pytest"><div class="card card-body pytest_card"><a type="button" data-toggle="collapse" data-target="#UnetBlock-pytest" class="close" aria-label="Close"><span aria-hidden="true">×</span></a><p>No tests found for <code>UnetBlock</code>. To contribute a test please refer to <a href="/dev/test.html">this guide</a> and <a href="https://forums.fast.ai/t/improving-expanding-functional-tests/32929">this discussion</a>.</p></div></div><p>A quasi-UNet block, using <code>PixelShuffle_ICNR upsampling</code>.</p>
</div>
</div>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>This block receives the output of the last block to be upsampled (size <code>up_in_c</code>) and the activations features from an intermediate layer of the <code>encoder</code> (size <code>x_in_c</code>, this is the lateral connection). The <code>hook</code> is set to this intermediate layer to store the output needed for this block. <code>final_div</code> determines if we divide the number of features by 2 with the upsampling, <code>blur</code> is to avoid checkerboard artifacts. If <code>leaky</code> is set, use a leaky ReLU with a slope equals to that parameter instead of a ReLU, and <code>self_attention</code> determines if we use a self-attention layer. <code>kwargs</code> are passed to <a href="/layers.html#conv_layer"><code>conv_layer</code></a>.</p>
</div>
</div>
</div>
</div>