from keras.layers import Convolution2D, Merge
from keras.layers.advanced_activations import PReLU

from eva.layers.masked_convolution2d import MaskedConvolution2D

def ResidualBlock(model, filters):
    # 2h -> h
    block = PReLU()(model)
    block = MaskedConvolution2D(filters//2, 1, 1)(block)

    # h 3x3 -> h
    block = PReLU()(block)
    block = MaskedConvolution2D(filters//2, 3, 3, border_mode='same')(block)

    # h -> 2h
    block = PReLU()(block)
    block = MaskedConvolution2D(filters, 1, 1)(block)

    return Merge(mode='sum')([model, block])

def ResidualBlockList(model, filters, length):
    for _ in range(length):
        model = ResidualBlock(model, filters)

    return model

@@ -157,19 +157,21 @@
 tion2D%0A%0A
-def
+class
  Residua
@@ -181,25 +181,117 @@
 ock(
-model, filters):%0A
+object):%0A    def __init__(self, filters):%0A        self.filters = filters%0A%0A    def __call__(self, model):%0A    
     
@@ -296,24 +296,28 @@
   # 2h -%3E h%0A
+    
     block = 
@@ -331,24 +331,28 @@
 (model)%0A    
+   
+ 
 block = Mask
@@ -359,32 +359,37 @@
 edConvolution2D(
+self.
 filters//2, 1, 1
@@ -398,24 +398,28 @@
 block)%0A%0A    
+   
+ 
 # h 3x3 -%3E h
@@ -415,24 +415,28 @@
  h 3x3 -%3E h%0A
+    
     block = 
@@ -442,32 +442,36 @@
  PReLU()(block)%0A
+    
     block = Mask
@@ -482,24 +482,29 @@
 nvolution2D(
+self.
 filters//2, 
@@ -533,24 +533,28 @@
 e')(block)%0A%0A
+    
     # h -%3E 2
@@ -555,24 +555,28 @@
 h -%3E 2h%0A    
+  
+  
 block = PReL
@@ -586,24 +586,28 @@
 (block)%0A    
+   
+ 
 block = Mask
@@ -622,16 +622,21 @@
 ution2D(
+self.
 filters,
@@ -646,24 +646,28 @@
  1)(block)%0A%0A
+    
     return M
@@ -700,19 +700,21 @@
 lock%5D)%0A%0A
-def
+class
  Residua
@@ -728,33 +728,154 @@
 ist(
-model, filters, length):%0A
+object):%0A    def __init__(self, filters, length):%0A        self.filters = filters%0A        self.length = length%0A%0A    def __call__(self, model):%0A    
     
@@ -889,16 +889,21 @@
 n range(
+self.
 length):
@@ -895,32 +895,36 @@
 e(self.length):%0A
+    
         model = 
@@ -941,23 +941,21 @@
 ock(
-model, 
+self.
 filters)
 %0A%0A  
@@ -950,18 +950,29 @@
 filters)
-%0A%0A
+(model)%0A%0A    
     retu
@@ -979,9 +979,8 @@
 rn model
-%0A

Rewrite residual block as class rather than method