from typing import Tuple
import keras
from keras.layers import BatchNormalization, Concatenate, Conv2D, Conv2DTranspose, MaxPooling2D, ReLU, UpSampling2D
[docs]def Conv2D_Options(inlayer: keras.layers, options: dict) -> keras.layers.Conv2D:
""" Perform a keras 2D convolution with the specified options.
Args:
inlayer: Input layer to the convolution.
options: All options to pass into the input layer.
Returns:
output_layer: Keras layer ready to start the main network
"""
use_batch_norm = options.pop('use_batch_norm', False)
output_layer = Conv2D(**options)(inlayer)
if use_batch_norm:
output_layer = BatchNormalization()(output_layer)
return output_layer
[docs]def dense_2d_block(inlayer: keras.layers, conv_options: dict, block_depth: int) -> keras.layers.Conv2D:
""" Create a single, dense block.
Args:
inlayer: Input layer to the convolution.
conv_options: All options to pass into the input convolution layer.
block_depth: How deep (many layers) is the dense block.
Returns:
output_layer: Keras layer ready to start the main network
"""
dense_layer = inlayer
for _block_step in range(block_depth):
intermediate_layer = Conv2D_Options(dense_layer, conv_options)
dense_layer = Concatenate(axis=-1)([dense_layer, intermediate_layer])
return dense_layer