def __init__(self, blocks=16, hidden_units=128, kernel_size=3, *args, **kwargs): super(DCResNet, self).__init__(*args, **kwargs) self.blocks = blocks self.hidden_units = hidden_units w_regularizer = keras.regularizers.l2(self.wd) self.conv1 = keras.layers.Conv2D(hidden_units, kernel_size, activation=tf.nn.relu, kernel_regularizer=w_regularizer, bias_regularizer=w_regularizer, padding="same") self.concrete1 = bdl.ConcreteLayer(dropout_decay=self.dd) self.residual_blocks = [] for _ in range(self.blocks): self.residual_blocks.append( ResidualBlock(hidden_units, weight_decay=self.wd, dropout_decay=self.dd)) self.concrete2 = bdl.ConcreteLayer(dropout_decay=self.dd) w_regularizer = keras.regularizers.l2(self.wd) self.conv2 = keras.layers.Conv2D(hidden_units, kernel_size, activation=tf.nn.relu, kernel_regularizer=w_regularizer, bias_regularizer=w_regularizer, padding="same") self.concrete3 = bdl.ConcreteLayer(dropout_decay=self.dd) w_regularizer = keras.regularizers.l2(self.wd) self.conv3 = keras.layers.Conv2D(self.output_bands * 2 + 1, kernel_size, activation=None, kernel_regularizer=w_regularizer, bias_regularizer=w_regularizer, padding="same")
def __init__(self, output_bands, hidden_layers=(512, ) * 3, *args, **kwargs): super(DCVDSR_New, self).__init__(output_bands, *args, **kwargs) self.hidden_layers = hidden_layers # w_regularizer = keras.regularizers.l2(self.wd) self.conv1 = keras.layers.Conv2D( self.hidden_layers[0], 4, activation=tf.nn.relu, # kernel_regularizer=w_regularizer, # bias_regularizer=w_regularizer, padding="same") self.concrete_layers = [] self.conv_layers = [] for i, hunits in enumerate(self.hidden_layers): self.concrete_layers.append(bdl.ConcreteLayer(self.dd)) # w_regularizer = keras.regularizers.l2(self.wd) self.conv_layers.append([ keras.layers.Conv2D(hunits, 3, activation=tf.nn.relu, padding="same"), keras.layers.Conv2D(hunits, 5, activation=tf.nn.relu, padding="same"), keras.layers.Conv2D(hunits, 7, activation=tf.nn.relu, padding="same") ]) self.concrete_output = bdl.ConcreteLayer(self.dd) # w_regularizer = keras.regularizers.l2(self.wd) self.conv_output = keras.layers.Conv2D( self.output_bands * 2 + 1, 3, activation=None, # kernel_regularizer=w_regularizer, # bias_regularizer=w_regularizer, padding="same")
def __init__(self, hidden_units, weight_decay=1e-4, dropout_decay=1e-4, bayesian=True): super(ResidualBlock, self).__init__() self.bayesian = bayesian self.weight_decay = weight_decay if bayesian: self.concrete1 = bdl.ConcreteLayer(dropout_decay=dropout_decay) w_regularizer = keras.regularizers.l2(weight_decay) self.conv1 = keras.layers.Conv2D(hidden_units, 3, activation=tf.nn.leaky_relu, kernel_regularizer=w_regularizer, bias_regularizer=w_regularizer, padding="same") if bayesian: self.concrete2 = bdl.ConcreteLayer(dropout_decay=dropout_decay) w_regularizer = keras.regularizers.l2(weight_decay) self.conv2 = keras.layers.Conv2D(hidden_units, 3, activation=None, kernel_regularizer=w_regularizer, bias_regularizer=w_regularizer, padding="same") if bayesian: self.concrete3 = bdl.ConcreteLayer(dropout_decay=dropout_decay) w_regularizer = keras.regularizers.l2(weight_decay) self.conv3 = keras.layers.Conv2D(hidden_units, 3, activation=tf.nn.leaky_relu, kernel_regularizer=w_regularizer, bias_regularizer=w_regularizer, padding="same")
def __init__(self, filter_sizes, layer_sizes, *args, **kwargs): super(DCCNN, self).__init__(*args, **kwargs) self.filter_sizes = filter_sizes self.layer_sizes = layer_sizes self.concrete_layers = [] self.conv2d_layers = [] for i, k in enumerate(self.filter_sizes): if i != 0: concrete_layer = bdl.ConcreteLayer(dropout_decay=self.dd) self.concrete_layers.append(concrete_layer) if i == len(filter_sizes) - 1: activation = None else: activation = tf.nn.relu self.conv2d_layers.append( keras.layers.Conv2D(self.layer_sizes[i], k, activation=activation, padding='same'))