Exemplo n.º 1
0
    def inception_inception(self, kvals):
        (p1, p2, p3, p4) = kvals
        branch1 = [Conv(**self.conv_params(1, p1[0], padding=0, strides=1))]

        i2_branch1 = [
            Conv(**self.conv_params((1, 3), p2[1], padding='SAME', strides=1))
        ]
        i2_branch2 = [
            Conv(**self.conv_params((3, 1), p2[1], padding='SAME', strides=1))
        ]
        branch2 = [
            Conv(**self.conv_params(1, p2[0], padding=0, strides=1)),
            MergeBroadcast(layers=[i2_branch1, i2_branch2], merge="depth")
        ]

        i3_branch1 = [
            Conv(**self.conv_params((1, 3), p3[2], padding='SAME', strides=1))
        ]
        i3_branch2 = [
            Conv(**self.conv_params((3, 1), p3[2], padding='SAME', strides=1))
        ]
        branch3 = [
            Conv(**self.conv_params(1, p3[0], padding=0, strides=1)),
            Conv(**self.conv_params(3, p3[1], padding='SAME', strides=1)),
            MergeBroadcast(layers=[i3_branch1, i3_branch2], merge="depth")
        ]

        branch4 = [
            Pooling(**self.pool3s1p1),
            Conv(**self.conv_params(1, p4[0], padding=0, strides=1))
        ]

        return MergeBroadcast(layers=[branch1, branch2, branch3, branch4],
                              merge="depth")
Exemplo n.º 2
0
def inception(kvals):
    (p1, p2, p3, p4) = kvals

    branch1 = [Conv((1, 1, p1[0]), **common)]
    branch2 = [Conv((1, 1, p2[0]), **common), Conv((3, 3, p2[1]), **commonp1)]
    branch3 = [Conv((1, 1, p3[0]), **common), Conv((5, 5, p3[1]), **commonp2)]
    branch4 = [Pooling(op="max", **pool3s1p1), Conv((1, 1, p4[0]), **common)]
    return MergeBroadcast(layers=[branch1, branch2, branch3, branch4], merge="depth")
Exemplo n.º 3
0
def inception(kvals, name="i"):
    (p1, p2, p3) = kvals

    branch1 = [Sequential([Conv(fshape(1, p1[0]), **common)])] if p1[0] else []
    branch2 = [Sequential([Conv(fshape(1, p2[0]), **common),
                           Conv(fshape(3, p2[1]), **commonp1)])]
    branch3 = [Sequential([Pooling(op=p3[0], **pool3s1p1)] + (
                          [Conv(fshape(1, p3[1]), **common)] if p3[1] else []))]
    partitions = branch1 + branch2 + branch3
    return [MergeBroadcast(layers=partitions, merge="depth")]
Exemplo n.º 4
0
def inception(kvals, name):
    (p1, p2, p3, p4) = kvals

    branch1 = [Conv((1, 1, p1[0]), name=name+'1x1', **common)]
    branch2 = [Conv((1, 1, p2[0]), name=name+'3x3_reduce', **common),
               Conv((3, 3, p2[1]), name=name+'3x3', **commonp1)]
    branch3 = [Conv((1, 1, p3[0]), name=name+'5x5_reduce', **common),
               Conv((5, 5, p3[1]), name=name+'5x5', **commonp2)]
    branch4 = [Pooling(op="max", name=name+'pool', **pool3s1p1),
               Conv((1, 1, p4[0]), name=name+'pool_proj', **common)]
    return MergeBroadcast(layers=[branch1, branch2, branch3, branch4], merge="depth")
Exemplo n.º 5
0
    def conv_net(self, activation, init=Kaiming(), version=-1):
        width = max([self.width, self.lookup_dim])
        if version == -1:
            if self.lookup_size:
                pre_layers = [
                    LookupTable(vocab_size=self.lookup_size,
                                embedding_dim=width,
                                init=GlorotUniform()),
                    Reshape((1, self.num_words, width)),
                ]
                first_width = width
            else:
                pre_layers = [
                    Conv((1, width, width),
                         padding=0,
                         init=init,
                         activation=activation)
                ]
                first_width = 1

            return pre_layers + \
                   [
                       MergeBroadcast(
                           [
                               [
                                   Conv((3, first_width, 15), padding={'pad_h': 1, 'pad_w': 0}, init=init,
                                        activation=activation)
                               ],
                               [
                                   Conv((5, first_width, 15), padding={'pad_h': 2, 'pad_w': 0}, init=init,
                                        activation=activation)
                               ],
                               [
                                   Conv((7, first_width, 15), padding={'pad_h': 3, 'pad_w': 0}, init=init,
                                        activation=activation)
                               ],
                           ],
                           merge='depth'
                       ),
                       NoisyDropout(keep=0.5, noise_pct=1.0, noise_std=0.001),
                       Conv((5, 1, 15), strides={'str_h': 2 if self.num_words > 59 else 1,
                                                 'str_w': 1}, padding=0, init=init,
                            activation=activation),
                       NoisyDropout(keep=0.9, noise_pct=1.0, noise_std=0.00001),
                       Conv((3, 1, 9), strides={'str_h': 2, 'str_w': 1}, padding=0, init=init,
                            activation=activation),
                       NoisyDropout(keep=0.9, noise_pct=1.0, noise_std=0.00001),
                       Conv((9, 1, 9), strides={'str_h': 2, 'str_w': 1}, padding=0, init=init,
                            activation=activation)
                   ]
Exemplo n.º 6
0
 def inception(self, kvals, b2fsz=5):
     (p1, p2, p3, p4) = kvals
     branch1 = [Conv(**self.conv_params(1, p1[0], padding=0, strides=1))]
     branch2 = [
         Conv(**self.conv_params(1, p2[0], padding=0, strides=1)),
         Conv(**self.conv_params(b2fsz, p2[1], padding='SAME', strides=1))
     ],
     branch3 = [
         Conv(**self.conv_params(1, p3[0], padding=0, strides=1)),
         Conv(**self.conv_params(3, p3[1], padding='SAME', strides=1)),
         Conv(**self.conv_params(3, p3[1], padding='SAME', strides=1))
     ]
     branch4 = [
         Pooling(**self.pool3s1p1),
         Conv(**self.conv_params(1, p4[0], padding=0, strides=1))
     ]
     return MergeBroadcast(layers=[branch1, branch2, branch3, branch4],
                           merge="depth")