anchor.diff:  import tensorflow as tf
   
   from keras import backend as K
  -from keras.layers import merge, Lambda, Layer
  +from keras.layers import Lambda, Layer
   
   class Connection(Layer):
       """Takes a list of inputs, resizes them to the same shape, and outputs a weighted merge.
       """
  -    def __init__(self, init_value=0.5, merge_mode='concat', **kwargs):
  +    def __init__(self, init_value=0.5, merge_mode='concat',
  +                 resize_interpolation=tf.image.ResizeMethod.BILINEAR,
  +                 shared_weights=True):
  +        """Creates a connection that encapsulates weighted connection of input feature maps.
  +
  +        :param init_value: The init value for connection weight
  +        :param merge_mode: Defines how feature maps from inputs are aggregated.
  +        :param resize_interpolation: The downscaling interpolation to use. Instance of `tf.image.ResizeMethod`.
  +            Note that ResizeMethod.AREA will fail as its gradient is not yet implemented.
  +        :param shared_weights: True to share the same weight for all feature maps from inputs[i].
  +        False creates a separate weight per feature map.
  +        """
           self.init_value = init_value
           self.merge_mode = merge_mode
  -        super(Connection, self).__init__(**kwargs)
  +        self.resize_interpolation = resize_interpolation
  +        self.shared_weights = shared_weights
  +        super(Connection, self).__init__()
   
       def _ensure_same_size(self, inputs):
           """Ensures that all inputs match last input size.
  
positive.code:         return self._out_shape
  ----
  
  Lets look at this step by step. Note that this implementation only illustrates shared weights for all features of `layer_inputs[i]` for simplicity. Se e the full implementation on link:https://github.com/raghakot/deep-learning-experiments/blob/master/exp3/architecture.py#L8[github] for creating a unique weight per feature map from previous layers.
  
  1. `_ensure_same_size` computes smallest \((rows, cols)\) amongst all inputs and uses it to resize all inputs to be the same shape. 
  2. We have to define trainable weights in `build` per keras custom layer link:https://keras.io/layers/writing-your-own-keras-layers/[docs]. We need as many weights and number of inputs.
  3. `call` computes sigmoid weighted inputs (I tested without sigmoid, and as expected, sigmoid weighing which mostly "allows or disallows inputs" worked a lot better), merged with defined merge strategy. We can tweak `init_value` and `merge_mode` to try various init strategies for weights and different merge strategies.
  
  The fully connected net using layers defined below, followed by sequential `Dense` layers using the above code is shown in fig.
  
negative.code:         resized_inputs = self._ensure_same_size(layer_inputs)
  
          # Compute sigmoid weighted inputs
          stacked = K.concatenate(resized_inputs, axis=-1)
          weighted = stacked * K.sigmoid(self.W)
  
          # Merge according to provided merge strategy.
          merged = self._merge(weighted)
  
          # Cache this for use in `get_output_shape_for`
          self._out_shape = K.int_shape(merged)
  