@@ -0,0 +1,2007 @@
+from .model import Model%0Afrom .batchnorm import BatchNormalization, ScaleShift%0Afrom ...api import layerize%0Afrom .affine import Affine%0A%0A%0Aclass ResBlock(Model):%0A    @property%0A    def input_shape(self):%0A        return (self.nr_out,)%0A%0A    @property%0A    def output_shape(self):%0A        return (self.nr_out,)%0A%0A    def __init__(self, width, **kwargs):%0A        self.nr_out = width%0A        self.nr_in = width%0A        layers = %5B%0A            BatchNormalization(name='%25s-bn1' %25 self.name),%0A            ScaleShift(width, name='%25s-scaleshift1' %25 self.name),%0A            layerize(_relu, name='relu1'),%0A            Affine(width, width, name='%25s-weight1' %25 self.name),%0A            BatchNormalization(name='%25s-bn2' %25 self.name),%0A            ScaleShift(width, name='%25s-scaleshift2' %25 self.name),%0A            layerize(_relu, name='relu2'),%0A            Affine(width, width, name='%25s-weight2' %25 self.name),%0A        %5D%0A        Model.__init__(self, *layers, **kwargs)%0A%0A%0Adef _relu(X, dropout=0.0):%0A    mask = X %3E 0%0A    def finish_update(gradient, *args, **kwargs):%0A        return gradient * mask%0A    return X * mask, finish_update%0A%0A%0Aclass ReLuResBN(Model):%0A    name = 'resblock'%0A    @property%0A    def input_shape(self):%0A        return (self.nr_out,)%0A%0A    @property%0A    def output_shape(self):%0A        return (self.nr_out,)%0A%0A    def __init__(self, width, **kwargs):%0A        self.nr_out = width%0A        layers = %5BResBlock(width, **kwargs), ResBlock(width, **kwargs)%5D%0A        Model.__init__(self, *layers, **kwargs)%0A%0A    def begin_update(self, X, dropout=0.0):%0A        out1, upd1 = self.layers%5B0%5D.begin_update(X, dropout=0.)%0A        out2, upd2 = self.layers%5B1%5D.begin_update(out1, dropout=0.)%0A        output, bp_dropout = self.ops.dropout(out1 + out2, dropout)%0A        def finish_update(gradient, optimizer=None, **kwargs):%0A            grad2 = upd2(gradient, optimizer=optimizer, **kwargs)%0A            grad1 = upd1(grad2, optimizer=optimizer, **kwargs)%0A            return grad1 + grad2%0A        return output, bp_dropout(finish_update)%0A%0A%0A

Add residual block