Пример #1
0
def Inception7B(data, num_3x3, num_d3x3_red, num_d3x3_1, num_d3x3_2, pool,
                name):
    tower_3x3 = Conv(data,
                     num_3x3,
                     kernel=(3, 3),
                     pad=(0, 0),
                     stride=(2, 2),
                     name=('%s_conv' % name))
    tower_d3x3 = Conv(data,
                      num_d3x3_red,
                      name=('%s_tower' % name),
                      suffix='_conv')
    tower_d3x3 = Conv(tower_d3x3,
                      num_d3x3_1,
                      kernel=(3, 3),
                      pad=(1, 1),
                      stride=(1, 1),
                      name=('%s_tower' % name),
                      suffix='_conv_1')
    tower_d3x3 = Conv(tower_d3x3,
                      num_d3x3_2,
                      kernel=(3, 3),
                      pad=(0, 0),
                      stride=(2, 2),
                      name=('%s_tower' % name),
                      suffix='_conv_2')
    pooling = Pooling(data=data,
                      kernel=(3, 3),
                      stride=(2, 2),
                      pad=(0, 0),
                      pool_type="max",
                      name=('max_pool_%s_pool' % name))
    concat = sym.concatenate(*[tower_3x3, tower_d3x3, pooling],
                             name='ch_concat_%s_chconcat' % name)
    return concat
Пример #2
0
    def cell(x_t, s_t, h_t):
        xh_t = sym.concatenate(x_t, h_t, axis=1)
        g = lstm_gate(sym.tanh, Ug, bg, xh_t, num_units)
        i = lstm_gate(sym.sigmoid, Ui, bi, xh_t, num_units)
        f = lstm_gate(sym.sigmoid, Uf, bf, xh_t, num_units)
        o = lstm_gate(sym.sigmoid, Uo, bo, xh_t, num_units)

        s_t1 = s_t * f + g * i
        h_t1 = sym.tanh(s_t1) * o
        return (s_t1, h_t1)
Пример #3
0
def Inception7D(data, num_3x3_red, num_3x3, num_d7_3x3_red, num_d7_1, num_d7_2,
                num_d7_3x3, pool, name):
    tower_3x3 = Conv(data=data,
                     num_filter=num_3x3_red,
                     name=('%s_tower' % name),
                     suffix='_conv')
    tower_3x3 = Conv(data=tower_3x3,
                     num_filter=num_3x3,
                     kernel=(3, 3),
                     pad=(0, 0),
                     stride=(2, 2),
                     name=('%s_tower' % name),
                     suffix='_conv_1')
    tower_d7_3x3 = Conv(data=data,
                        num_filter=num_d7_3x3_red,
                        name=('%s_tower_1' % name),
                        suffix='_conv')
    tower_d7_3x3 = Conv(data=tower_d7_3x3,
                        num_filter=num_d7_1,
                        kernel=(1, 7),
                        pad=(0, 3),
                        name=('%s_tower_1' % name),
                        suffix='_conv_1')
    tower_d7_3x3 = Conv(data=tower_d7_3x3,
                        num_filter=num_d7_2,
                        kernel=(7, 1),
                        pad=(3, 0),
                        name=('%s_tower_1' % name),
                        suffix='_conv_2')
    tower_d7_3x3 = Conv(data=tower_d7_3x3,
                        num_filter=num_d7_3x3,
                        kernel=(3, 3),
                        stride=(2, 2),
                        name=('%s_tower_1' % name),
                        suffix='_conv_3')
    pooling = Pooling(data=data,
                      kernel=(3, 3),
                      stride=(2, 2),
                      pool_type=pool,
                      pad=(0, 0),
                      name=('%s_pool_%s_pool' % (pool, name)))
    # concat
    concat = sym.concatenate(*[tower_3x3, tower_d7_3x3, pooling],
                             name='ch_concat_%s_chconcat' % name)
    return concat
Пример #4
0
def Inception7A(data, num_1x1, num_3x3_red, num_3x3_1, num_3x3_2, num_5x5_red,
                num_5x5, pool, proj, name):
    tower_1x1 = Conv(data, num_1x1, name=('%s_conv' % name))
    tower_5x5 = Conv(data,
                     num_5x5_red,
                     name=('%s_tower' % name),
                     suffix='_conv')
    tower_5x5 = Conv(tower_5x5,
                     num_5x5,
                     kernel=(5, 5),
                     pad=(2, 2),
                     name=('%s_tower' % name),
                     suffix='_conv_1')
    tower_3x3 = Conv(data,
                     num_3x3_red,
                     name=('%s_tower_1' % name),
                     suffix='_conv')
    tower_3x3 = Conv(tower_3x3,
                     num_3x3_1,
                     kernel=(3, 3),
                     pad=(1, 1),
                     name=('%s_tower_1' % name),
                     suffix='_conv_1')
    tower_3x3 = Conv(tower_3x3,
                     num_3x3_2,
                     kernel=(3, 3),
                     pad=(1, 1),
                     name=('%s_tower_1' % name),
                     suffix='_conv_2')
    pooling = Pooling(data=data,
                      kernel=(3, 3),
                      stride=(1, 1),
                      pad=(1, 1),
                      pool_type=pool,
                      name=('%s_pool_%s_pool' % (pool, name)))

    cproj = Conv(pooling, proj, name=('%s_tower_2' % name), suffix='_conv')
    concat = sym.concatenate(*[tower_1x1, tower_5x5, tower_3x3, cproj],
                             name='ch_concat_%s_chconcat' % name)
    return concat
Пример #5
0
def Inception7E(data, num_1x1, num_d3_red, num_d3_1, num_d3_2, num_3x3_d3_red,
                num_3x3, num_3x3_d3_1, num_3x3_d3_2, pool, proj, name):
    tower_1x1 = Conv(data=data,
                     num_filter=num_1x1,
                     kernel=(1, 1),
                     name=('%s_conv' % name))
    tower_d3 = Conv(data=data,
                    num_filter=num_d3_red,
                    name=('%s_tower' % name),
                    suffix='_conv')
    tower_d3_a = Conv(data=tower_d3,
                      num_filter=num_d3_1,
                      kernel=(1, 3),
                      pad=(0, 1),
                      name=('%s_tower' % name),
                      suffix='_mixed_conv')
    tower_d3_b = Conv(data=tower_d3,
                      num_filter=num_d3_2,
                      kernel=(3, 1),
                      pad=(1, 0),
                      name=('%s_tower' % name),
                      suffix='_mixed_conv_1')
    tower_3x3_d3 = Conv(data=data,
                        num_filter=num_3x3_d3_red,
                        name=('%s_tower_1' % name),
                        suffix='_conv')
    tower_3x3_d3 = Conv(data=tower_3x3_d3,
                        num_filter=num_3x3,
                        kernel=(3, 3),
                        pad=(1, 1),
                        name=('%s_tower_1' % name),
                        suffix='_conv_1')
    tower_3x3_d3_a = Conv(data=tower_3x3_d3,
                          num_filter=num_3x3_d3_1,
                          kernel=(1, 3),
                          pad=(0, 1),
                          name=('%s_tower_1' % name),
                          suffix='_mixed_conv')
    tower_3x3_d3_b = Conv(data=tower_3x3_d3,
                          num_filter=num_3x3_d3_2,
                          kernel=(3, 1),
                          pad=(1, 0),
                          name=('%s_tower_1' % name),
                          suffix='_mixed_conv_1')
    pooling = Pooling(data=data,
                      kernel=(3, 3),
                      stride=(1, 1),
                      pad=(1, 1),
                      pool_type=pool,
                      name=('%s_pool_%s_pool' % (pool, name)))
    cproj = Conv(data=pooling,
                 num_filter=proj,
                 kernel=(1, 1),
                 name=('%s_tower_2' % name),
                 suffix='_conv')
    # concat
    concat = sym.concatenate(*[
        tower_1x1, tower_d3_a, tower_d3_b, tower_3x3_d3_a, tower_3x3_d3_b,
        cproj
    ],
                             name='ch_concat_%s_chconcat' % name)
    return concat
Пример #6
0
def Inception7C(data, num_1x1, num_d7_red, num_d7_1, num_d7_2, num_q7_red,
                num_q7_1, num_q7_2, num_q7_3, num_q7_4, pool, proj, name):
    tower_1x1 = Conv(data=data,
                     num_filter=num_1x1,
                     kernel=(1, 1),
                     name=('%s_conv' % name))
    tower_d7 = Conv(data=data,
                    num_filter=num_d7_red,
                    name=('%s_tower' % name),
                    suffix='_conv')
    tower_d7 = Conv(data=tower_d7,
                    num_filter=num_d7_1,
                    kernel=(1, 7),
                    pad=(0, 3),
                    name=('%s_tower' % name),
                    suffix='_conv_1')
    tower_d7 = Conv(data=tower_d7,
                    num_filter=num_d7_2,
                    kernel=(7, 1),
                    pad=(3, 0),
                    name=('%s_tower' % name),
                    suffix='_conv_2')
    tower_q7 = Conv(data=data,
                    num_filter=num_q7_red,
                    name=('%s_tower_1' % name),
                    suffix='_conv')
    tower_q7 = Conv(data=tower_q7,
                    num_filter=num_q7_1,
                    kernel=(7, 1),
                    pad=(3, 0),
                    name=('%s_tower_1' % name),
                    suffix='_conv_1')
    tower_q7 = Conv(data=tower_q7,
                    num_filter=num_q7_2,
                    kernel=(1, 7),
                    pad=(0, 3),
                    name=('%s_tower_1' % name),
                    suffix='_conv_2')
    tower_q7 = Conv(data=tower_q7,
                    num_filter=num_q7_3,
                    kernel=(7, 1),
                    pad=(3, 0),
                    name=('%s_tower_1' % name),
                    suffix='_conv_3')
    tower_q7 = Conv(data=tower_q7,
                    num_filter=num_q7_4,
                    kernel=(1, 7),
                    pad=(0, 3),
                    name=('%s_tower_1' % name),
                    suffix='_conv_4')
    pooling = Pooling(data=data,
                      kernel=(3, 3),
                      stride=(1, 1),
                      pad=(1, 1),
                      pool_type=pool,
                      name=('%s_pool_%s_pool' % (pool, name)))
    cproj = Conv(data=pooling,
                 num_filter=proj,
                 kernel=(1, 1),
                 name=('%s_tower_2' % name),
                 suffix='_conv')
    # concat
    concat = sym.concatenate(*[tower_1x1, tower_d7, tower_q7, cproj],
                             name='ch_concat_%s_chconcat' % name)
    return concat