Exemple #1
0
def get_graph_init(train=False):
    g = Graph('YOLOv2-Test: 16-bit',
              dataset='imagenet',
              log_level=logging.INFO)
    batch_size = 1

    with g.as_default():
        with g.name_scope('inputs'):
            i = get_tensor(shape=(batch_size, 416, 416, 3),
                           name='data',
                           dtype=FQDtype.FXP16,
                           trainable=False)
        with g.name_scope('conv0'):
            conv0 = yolo_convolution(i,
                                     filters=16,
                                     kernel_size=3,
                                     batch_normalize=True,
                                     act='leakyReLU',
                                     w_dtype=FixedPoint(16, 14),
                                     c_dtype=FixedPoint(16, 12),
                                     s_dtype=FixedPoint(16, 9),
                                     bn_dtype=FixedPoint(16, 8))
        with g.name_scope('pool0'):
            pool0 = maxPool(conv0,
                            pooling_kernel=(1, 2, 2, 1),
                            stride=(1, 2, 2, 1),
                            pad='VALID')
        with g.name_scope('conv1'):
            conv1 = yolo_convolution(pool0,
                                     filters=32,
                                     kernel_size=3,
                                     batch_normalize=True,
                                     act='leakyReLU',
                                     w_dtype=FixedPoint(16, 14),
                                     c_dtype=FixedPoint(16, 8),
                                     s_dtype=FixedPoint(16, 14),
                                     bn_dtype=FixedPoint(16, 8))
        with g.name_scope('pool1'):
            pool1 = maxPool(conv1,
                            pooling_kernel=(1, 2, 2, 1),
                            stride=(1, 2, 2, 1),
                            pad='VALID')
        with g.name_scope('conv2'):
            conv2 = yolo_convolution(
                pool1,
                filters=64,
                kernel_size=3,
                batch_normalize=True,
                act='leakyReLU',
                # batch_normalize=False, act='linear',
                w_dtype=FixedPoint(16, 14),
                c_dtype=FixedPoint(16, 10),
                s_dtype=FixedPoint(16, 13),
                bn_dtype=FixedPoint(16, 9))
        with g.name_scope('pool2'):
            pool2 = maxPool(conv2,
                            pooling_kernel=(1, 2, 2, 1),
                            stride=(1, 2, 2, 1),
                            pad='VALID')
        with g.name_scope('conv3'):
            conv3 = yolo_convolution(pool2,
                                     filters=128,
                                     kernel_size=3,
                                     batch_normalize=True,
                                     act='leakyReLU',
                                     w_dtype=FixedPoint(16, 14),
                                     c_dtype=FixedPoint(16, 10),
                                     s_dtype=FixedPoint(16, 13),
                                     bn_dtype=FixedPoint(16, 10))
        with g.name_scope('pool3'):
            pool3 = maxPool(conv3,
                            pooling_kernel=(1, 2, 2, 1),
                            stride=(1, 2, 2, 1),
                            pad='VALID')
        with g.name_scope('conv4'):
            conv4 = yolo_convolution(pool3,
                                     filters=256,
                                     kernel_size=3,
                                     batch_normalize=True,
                                     act='leakyReLU',
                                     w_dtype=FixedPoint(16, 14),
                                     c_dtype=FixedPoint(16, 11),
                                     s_dtype=FixedPoint(16, 13),
                                     bn_dtype=FixedPoint(16, 10))

        with g.name_scope('pool4'):
            pool4 = maxPool(conv4,
                            pooling_kernel=(1, 2, 2, 1),
                            stride=(1, 2, 2, 1),
                            pad='VALID')
        with g.name_scope('conv5'):
            conv5 = yolo_convolution(pool4,
                                     filters=512,
                                     kernel_size=3,
                                     batch_normalize=True,
                                     act='leakyReLU',
                                     w_dtype=FixedPoint(16, 14),
                                     c_dtype=FixedPoint(16, 12),
                                     s_dtype=FixedPoint(16, 13),
                                     bn_dtype=FixedPoint(16, 11))
        with g.name_scope('pool5'):
            pool5 = maxPool(conv5,
                            pooling_kernel=(1, 2, 2, 1),
                            stride=(1, 1, 1, 1),
                            pad=((0, 0), (0, 1), (0, 1), (0, 0)))
        with g.name_scope('conv6'):
            conv6 = yolo_convolution(pool5,
                                     filters=1024,
                                     kernel_size=3,
                                     batch_normalize=True,
                                     act='leakyReLU',
                                     w_dtype=FixedPoint(16, 14),
                                     c_dtype=FixedPoint(16, 12),
                                     s_dtype=FixedPoint(16, 11),
                                     bn_dtype=FixedPoint(16, 9))
        with g.name_scope('conv7'):
            conv7 = yolo_convolution(conv6,
                                     filters=1024,
                                     kernel_size=3,
                                     batch_normalize=True,
                                     act='leakyReLU',
                                     w_dtype=FixedPoint(16, 14),
                                     c_dtype=FixedPoint(16, 11),
                                     s_dtype=FixedPoint(16, 14),
                                     bn_dtype=FixedPoint(16, 12))
        with g.name_scope('conv8'):
            conv8 = yolo_convolution(conv7,
                                     filters=125,
                                     kernel_size=1,
                                     batch_normalize=False,
                                     act='linear',
                                     w_dtype=FixedPoint(16, 14),
                                     c_dtype=FixedPoint(16, 11))

    return g
Exemple #2
0
 def _get_output_dtype(self):
     return FixedPoint(32, self.data.dtype.frac_bits + self.scale.dtype.frac_bits)
Exemple #3
0
def dnnweaver_init_weight(g, scope, *args, **kwargs):
    fname = "cmstack.codegen.dnnweavergen.dnnweaver2.get_tensor"

    with g.as_default():
        with g.name_scope(scope):
            return get_func(fname)(*args, dtype=FixedPoint(16, 14), **kwargs)