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),
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)
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
from fusion.scheduling import Network from fusion.scheduling import InputLayer, ConvLayer, FCLayer, PoolingLayer, DWConvLayer from fusion.scheduling.batch_size import get_batch_size """ MobileNet Andrew G. Howard, Menglong Zhu, Bo Chen, ect., 2017 """ batch_size = get_batch_size() NN = Network('MobileNet') NN.set_input_layer(InputLayer(3, 224, nimg=batch_size)) NN.add('conv1', ConvLayer(3, 32, 112, 3, 2, nimg=batch_size)) NN.add('conv2_1_dw', DWConvLayer(32, 112, 3, 1, nimg=batch_size)) NN.add('conv2_1_pw', ConvLayer(32, 64, 112, 1, 1, nimg=batch_size)) 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))
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))
# NN.add('conv3_a', ConvLayer(256, 192, 13, 3, nimg=batch_size), prevs=('conv2_concat',)) # NN.add('conv3_b', ConvLayer(256, 192, 13, 3, nimg=batch_size), prevs=('conv2_concat',)) # NN.add('conv4_a', ConvLayer(192, 192, 13, 3, nimg=batch_size), prevs=('conv3_a',)) # NN.add('conv4_b', ConvLayer(192, 192, 13, 3, nimg=batch_size), prevs=('conv3_b',)) # NN.add('conv5_a', ConvLayer(192, 128, 13, 3, nimg=batch_size), prevs=('conv4_a',)) # NN.add('conv5_b', ConvLayer(192, 128, 13, 3, nimg=batch_size), prevs=('conv4_b',)) # NN.add('pool3_a', PoolingLayer(128, 6, 3, strd=2, nimg=batch_size), prevs=('conv5_a',)) # NN.add('pool3_b', PoolingLayer(128, 6, 3, strd=2, nimg=batch_size), prevs=('conv5_b',)) # NN.add('conv5_concat', ConcatLayer(256, 6, nimg=batch_size), prevs=('pool3_a', 'pool3_b')) # 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', ))