示例#1
0
from fusion.scheduling import Network
from fusion.scheduling import InputLayer, ConvLayer, FCLayer, PoolingLayer, ConcatLayer
from fusion.scheduling.batch_size import get_batch_size
"""
GoogLeNet

ILSVRC 2014
"""
batch_size = get_batch_size()

NN = Network('GoogLeNet')

NN.set_input_layer(InputLayer(3, 224, nimg=batch_size))

NN.add('conv1', ConvLayer(3, 64, 112, 7, 2, nimg=batch_size))
NN.add('pool1', PoolingLayer(64, 56, 3, strd=2, nimg=batch_size))
# Norm layer is ignored.

NN.add('conv2_3x3_reduce', ConvLayer(64, 64, 56, 1, nimg=batch_size))
NN.add('conv2_3x3', ConvLayer(64, 192, 56, 3, nimg=batch_size))
# Norm layer is ignored.
NN.add('pool2', PoolingLayer(192, 28, 3, strd=2, nimg=batch_size))


def add_inception(network, incp_id, sfmap, nfmaps_in, nfmaps_1, nfmaps_3r,
                  nfmaps_3, nfmaps_5r, nfmaps_5, nfmaps_pool, prevs):
    ''' Add an inception module to the network. '''
    pfx = 'inception_{}_'.format(incp_id)
    # 1x1 branch.
    network.add(pfx + '1x1',
                ConvLayer(nfmaps_in, nfmaps_1, sfmap, 1, nimg=batch_size),
示例#2
0
from fusion.scheduling import Network
from fusion.scheduling import InputLayer, ConvLayer, FCLayer, PoolingLayer, EltwiseLayer
from fusion.scheduling.batch_size import get_batch_size

"""
ResNet-50

He, Zhang, Ren, and Sun, 2015
"""
batch_size = get_batch_size()
NN = Network('ResNet50')

NN.set_input_layer(InputLayer(3, 224, nimg=batch_size))

NN.add('conv1', ConvLayer(3, 64, 112, 7, 2, nimg=batch_size))
NN.add('pool1', PoolingLayer(64, 56, 3, 2, nimg=batch_size))

RES_PREV = 'pool1'

for i in range(3):
    NN.add('conv2_{}_a'.format(i), ConvLayer(64 if i == 0 else 256, 64, 56, 1, nimg=batch_size))
    NN.add('conv2_{}_b'.format(i), ConvLayer(64, 64, 56, 3, nimg=batch_size))
    NN.add('conv2_{}_c'.format(i), ConvLayer(64, 256, 56, 1, nimg=batch_size))

    # With residual shortcut.
    if i == 0:
        NN.add('conv2_br', ConvLayer(64, 256, 56, 1, nimg=batch_size), prevs=(RES_PREV,))
        RES_PREV = 'conv2_br'
    NN.add('conv2_{}_res'.format(i), EltwiseLayer(256, 56, 2, nimg=batch_size),
           prevs=(RES_PREV, 'conv2_{}_c'.format(i)))
    RES_PREV = 'conv2_{}_res'.format(i)
示例#3
0
from fusion.scheduling import Network
from fusion.scheduling import InputLayer, ConvLayer, FCLayer, PoolingLayer, ConcatLayer
from fusion.scheduling.batch_size import get_batch_size
"""
SqueezeNet

Forrest N. Iandola, Song Han, ect., 2016
"""
batch_size = get_batch_size()

NN = Network('SqueezeNet')

NN.set_input_layer(InputLayer(3, 227, nimg=batch_size))
NN.add('conv1', ConvLayer(3, 96, 111, 7, 2, nimg=batch_size))
NN.add('pool1', PoolingLayer(96, 55, 3, strd=2, nimg=batch_size))


def add_fire(network, incp_id, sfmap, nfmaps_in, nfmaps_s1, nfmaps_e1,
             nfmaps_e3, nfmaps_c):
    ''' Add an inception module to the network. '''
    pfx = 'fire{}_'.format(incp_id)
    # squeeze1x1
    network.add(pfx + 'squeeze1x1',
                ConvLayer(nfmaps_in, nfmaps_s1, sfmap, 1, nimg=batch_size))

    # expand1x1
    prevs = pfx + 'squeeze1x1'
    network.add(pfx + 'expand1x1',
                ConvLayer(nfmaps_s1, nfmaps_e1, sfmap, 1, nimg=batch_size),
                prevs=prevs)
    # expand3x3
示例#4
0
NN.add('conv2_2_dw', DWConvLayer(64, 56, 3, 2, nimg=batch_size))
NN.add('conv2_2_pw', ConvLayer(64, 128, 56, 1, 1, nimg=batch_size))

NN.add('conv3_1_dw', DWConvLayer(128, 56, 3, 1, nimg=batch_size))
NN.add('conv3_1_pw', ConvLayer(128, 128, 56, 1, 1, nimg=batch_size))

NN.add('conv3_2_dw', DWConvLayer(128, 28, 3, 2, nimg=batch_size))
NN.add('conv3_2_pw', ConvLayer(128, 256, 28, 1, 1, nimg=batch_size))

NN.add('conv4_1_dw', DWConvLayer(256, 28, 3, 1, nimg=batch_size))
NN.add('conv4_1_pw', ConvLayer(256, 256, 28, 1, 1, nimg=batch_size))

NN.add('conv4_2_dw', DWConvLayer(256, 14, 3, 2, nimg=batch_size))
NN.add('conv4_2_pw', ConvLayer(256, 512, 14, 1, 1, nimg=batch_size))

for i in range(1, 6):
    NN.add('conv5_{}_dw'.format(i), DWConvLayer(512, 14, 3, 1,
                                                nimg=batch_size))
    NN.add('conv5_{}_pw'.format(i),
           ConvLayer(512, 512, 14, 1, 1, nimg=batch_size))

NN.add('conv5_6_dw', DWConvLayer(512, 7, 3, 2, nimg=batch_size))
NN.add('conv5_6_pw', ConvLayer(512, 1024, 7, 1, 1, nimg=batch_size))

NN.add('conv6_dw', DWConvLayer(1024, 7, 3, 1, nimg=batch_size))
NN.add('conv6_pw', ConvLayer(1024, 1024, 7, 1, 1, nimg=batch_size))

NN.add('pool6', PoolingLayer(1024, 1, 7, nimg=batch_size))
NN.add('fc', FCLayer(1024, 1000, nimg=batch_size))
示例#5
0
from fusion.scheduling import Network
from fusion.scheduling import InputLayer, ConvLayer, FCLayer, PoolingLayer
from fusion.scheduling.batch_size import get_batch_size
"""
VGGNet-16

Simonyan and Zisserman, 2014
"""
batch_size = get_batch_size()
NN = Network('VGG')

NN.set_input_layer(InputLayer(3, 224, nimg=batch_size))

NN.add('conv1', ConvLayer(3, 64, 224, 3, nimg=batch_size))
NN.add('conv2', ConvLayer(64, 64, 224, 3, nimg=batch_size))
NN.add('pool1', PoolingLayer(64, 112, 2, nimg=batch_size))

NN.add('conv3', ConvLayer(64, 128, 112, 3, nimg=batch_size))
NN.add('conv4', ConvLayer(128, 128, 112, 3, nimg=batch_size))
NN.add('pool2', PoolingLayer(128, 56, 2, nimg=batch_size))

NN.add('conv5', ConvLayer(128, 256, 56, 3, nimg=batch_size))
NN.add('conv6', ConvLayer(256, 256, 56, 3, nimg=batch_size))
NN.add('conv7', ConvLayer(256, 256, 56, 3, nimg=batch_size))
NN.add('pool3', PoolingLayer(256, 28, 2, nimg=batch_size))

NN.add('conv8', ConvLayer(256, 512, 28, 3, nimg=batch_size))
NN.add('conv9', ConvLayer(512, 512, 28, 3, nimg=batch_size))
NN.add('conv10', ConvLayer(512, 512, 28, 3, nimg=batch_size))
NN.add('pool4', PoolingLayer(512, 14, 2, nimg=batch_size))
示例#6
0
# NN.add('fc1', FCLayer(256, 4096, 6, nimg=batch_size), prevs=('conv5_concat',))
# NN.add('fc2', FCLayer(4096, 4096, nimg=batch_size))
# NN.add('fc3', FCLayer(4096, 1000, nimg=batch_size))

NN = Network('AlexNet')

NN.set_input_layer(InputLayer(3, 227, nimg=batch_size))

NN.add('conv1_a',
       ConvLayer(3, 48, 55, 11, 4, nimg=batch_size),
       prevs=(NN.INPUT_LAYER_KEY, ))
NN.add('conv1_b',
       ConvLayer(3, 48, 55, 11, 4, nimg=batch_size),
       prevs=(NN.INPUT_LAYER_KEY, ))
NN.add('pool1_a',
       PoolingLayer(48, 27, 3, strd=2, nimg=batch_size),
       prevs=('conv1_a', ))
NN.add('pool1_b',
       PoolingLayer(48, 27, 3, strd=2, nimg=batch_size),
       prevs=('conv1_b', ))
# Norm layer is ignored.

NN.add('conv2_a',
       ConvLayer(48, 128, 27, 5, nimg=batch_size),
       prevs=('pool1_a', ))
NN.add('conv2_b',
       ConvLayer(48, 128, 27, 5, nimg=batch_size),
       prevs=('pool1_b', ))
NN.add('pool2_a',
       PoolingLayer(128, 13, 3, strd=2, nimg=batch_size),
       prevs=('conv2_a', ))