u_net {imageseg} | R Documentation |
Create a U-Net architecture
Description
Create a U-Net architecture
Usage
u_net(
net_h,
net_w,
grayscale = FALSE,
layers_per_block = 2,
blocks = 4,
n_class = 1,
filters = 16,
dropout = 0,
batch_normalization = TRUE,
kernel_initializer = "he_normal"
)
Arguments
net_h |
Input layer height. |
net_w |
Input layer width. |
grayscale |
Defines input layer color channels - 1 if 'TRUE', 3 if 'FALSE'. |
layers_per_block |
Number of convolutional layers per block (can be 2 or 3) |
blocks |
Number of blocks in the model. |
n_class |
Number of classes. |
filters |
Integer, the dimensionality of the output space (i.e. the number of output filters in the convolution). |
dropout |
Dropout rate (between 0 and 1). |
batch_normalization |
Should batch normalization be used in the block? |
kernel_initializer |
Initializer for the kernel weights matrix. |
Details
This function creates a U-Net model architecture according to user input. It allows flexibility regarding input, output and the hidden layers. See the package vignette for examples.
The function was adapted and slightly modified from the u_net()
function in the platypus package (https://github.com/maju116/platypus/blob/master/R/u_net.R).
Differences compared to platypus implementation:
added argument: layers_per_block (can be 2 or 3)
kernel size in layer_conv_2d_transpose is 2, not 3.
dropout layers are only included if user specifies dropout > 0
n_class = 1 by default (sufficient for binary classification used for vegetation model, e.g. sky or not sky)
automatic choice of activation of output layer: "sigmoid" if n_class = 1, otherwise "softmax"
allows non-square input images (e.g. 160x256 used in understory vegetation density model)
Value
U-Net model.
A keras model as returned by keras_model
Examples
## Not run:
# U-Net model for 256x256 pixel RGB input images with a single output class
# this model was used for canopy density
model <- u_net(net_h = 256,
net_w = 256,
grayscale = FALSE,
filters = 32,
blocks = 4,
layers_per_block = 2
)
# several arguments above were not necessary because they were kept at their default.
# Below is the same model, but shorter:
model <- u_net(net_h = 256,
net_w = 256,
filters = 32
)
model
## End(Not run)