UNet¶
Inheritance Diagram

-
class
ashpy.models.convolutional.unet.UNet(input_res, min_res, kernel_size, initial_filters, filters_cap, channels, use_dropout_encoder=True, use_dropout_decoder=True, dropout_prob=0.3, encoder_non_linearity=<class 'tensorflow.python.keras.layers.advanced_activations.LeakyReLU'>, decoder_non_linearity=<class 'tensorflow.python.keras.layers.advanced_activations.ReLU'>, normalization_layer=<class 'ashpy.layers.instance_normalization.InstanceNormalization'>, last_activation=<function tanh>, use_attention=False)[source]¶ Bases:
ashpy.models.convolutional.interfaces.Conv2DInterfaceUNet Architecture
Used in Image-to-Image Translation with Conditional Adversarial Nets 1
Examples
Direct Usage:
x = tf.ones((1, 512, 512, 3)) u_net = UNet(input_res = 512, min_res=4, kernel_size=4, initial_filters=64, filters_cap=512, channels=3) y = u_net(x) print(y.shape) print(len(u_net.trainable_variables)>0)
(1, 512, 512, 3) True
- 1
Image-to-Image Translation with Conditional Adversarial Nets https://arxiv.org/abs/1611.04076
Methods
__init__(input_res, min_res, kernel_size, …)- type input_res
call(inputs[, training])Execute the model on input data.
get_decoder_block(filters[, use_bn, …])Returns a block to be used in the decoder part of the UNET :param filters: number of filters :param use_bn: whether to use batch normalization :param use_dropout: whether to use dropout :param use_attention: whether to use attention
get_encoder_block(filters[, use_bn, …])Returns a block to be used in the encoder part of the UNET :param filters: number of filters :param use_bn: whether to use batch normalization :param use_attention: whether to use attention
Attributes
activity_regularizerOptional regularizer function for the output of this layer.
dtypedynamicinbound_nodesDeprecated, do NOT use! Only for compatibility with external Keras.
inputRetrieves the input tensor(s) of a layer.
input_maskRetrieves the input mask tensor(s) of a layer.
input_shapeRetrieves the input shape(s) of a layer.
input_specGets the network’s input specs.
layerslossesLosses which are associated with this Layer.
metricsReturns the model’s metrics added using compile, add_metric APIs.
metrics_namesReturns the model’s display labels for all outputs.
nameReturns the name of this module as passed or determined in the ctor.
name_scopeReturns a tf.name_scope instance for this class.
non_trainable_variablesnon_trainable_weightsoutbound_nodesDeprecated, do NOT use! Only for compatibility with external Keras.
outputRetrieves the output tensor(s) of a layer.
output_maskRetrieves the output mask tensor(s) of a layer.
output_shapeRetrieves the output shape(s) of a layer.
run_eagerlySettable attribute indicating whether the model should run eagerly.
sample_weightsstate_updatesReturns the updates from all layers that are stateful.
statefulsubmodulesSequence of all sub-modules.
trainabletrainable_variablesSequence of variables owned by this module and it’s submodules.
trainable_weightsupdatesvariablesReturns the list of all layer variables/weights.
weightsReturns the list of all layer variables/weights.
-
__init__(input_res, min_res, kernel_size, initial_filters, filters_cap, channels, use_dropout_encoder=True, use_dropout_decoder=True, dropout_prob=0.3, encoder_non_linearity=<class 'tensorflow.python.keras.layers.advanced_activations.LeakyReLU'>, decoder_non_linearity=<class 'tensorflow.python.keras.layers.advanced_activations.ReLU'>, normalization_layer=<class 'ashpy.layers.instance_normalization.InstanceNormalization'>, last_activation=<function tanh>, use_attention=False)[source]¶ - Parameters
input_res (
int) – input resolutionmin_res (
int) – minimum resolution reached after decodekernel_size (
int) – kernel size used in the networkinitial_filters (
int) – number of filter of the initial convolutionfilters_cap (
int) – maximum number of filterschannels (
int) – number of output channelsuse_dropout_encoder (
bool) – whether to use dropout in the encoder moduleuse_dropout_decoder (
bool) – whether to use dropout in the decoder moduledropout_prob (
float) – probability of dropoutencoder_non_linearity (
Type[Layer]) – non linearity of encoderdecoder_non_linearity (
Type[Layer]) – non linearity of decoderlast_activation (<module 'tensorflow.python.keras.api._v2.keras.activations' from '/home/docs/checkouts/readthedocs.org/user_builds/ashpy/envs/v0.1.3/lib/python3.7/site-packages/tensorflow/python/keras/api/_v2/keras/activations/__init__.py'>) – last activation function, tanh or softmax (for semantic images)
use_attention (
bool) – whether to use attention
-
get_decoder_block(filters, use_bn=True, use_dropout=False, use_attention=False)[source]¶ Returns a block to be used in the decoder part of the UNET :param filters: number of filters :param use_bn: whether to use batch normalization :param use_dropout: whether to use dropout :param use_attention: whether to use attention
- Returns
A block to be used in the decoder part
-
get_encoder_block(filters, use_bn=True, use_attention=False)[source]¶ Returns a block to be used in the encoder part of the UNET :param filters: number of filters :param use_bn: whether to use batch normalization :param use_attention: whether to use attention
- Returns
A block to be used in the encoder part