Exemplo n.º 1
0
def test_complexity():
    from lego.base import BaseLegoFunction
    from lego.hybrid import ConvBNReLULego
    from tools.complexity import get_complexity

    n = caffe.NetSpec()
    params = dict(name='data', batch_size=16, ntop=2,
                  transform_param=dict(crop_size=224),
                  memory_data_param=dict(batch_size=16, channels=3,
                                         height=224, width=224))
    n.data, n.label = BaseLegoFunction('MemoryData', params).attach(n, [])
    params = dict(name='1', num_output=64, kernel_size=7,
                  use_global_stats=True, pad=3, stride=2)
    stage1 = ConvBNReLULego(params).attach(n, [n.data])
    params = dict(kernel_size=3, stride=2, pool=P.Pooling.MAX, name='pool1')
    pool1 = BaseLegoFunction('Pooling', params).attach(n, [stage1])


    ip_params = dict(name='fc10', num_output=10,
                     param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)])
    ip = BaseLegoFunction('InnerProduct', ip_params).attach(n, [pool1])
    smax_loss = BaseLegoFunction('SoftmaxWithLoss', dict(name='loss')).attach(n, [ip, n.label])

    params, conn = get_complexity(netspec=n)

    print >> sys.stderr, params, conn
Exemplo n.º 2
0
    relu_params = dict(name='relu7')
    relu7 = BaseLegoFunction('ReLU', relu_params).attach(netspec, [fc7])
    drop_params = dict(name='drop7', dropout_param=dict(dropout_ratio=0.5))
    drop7 = BaseLegoFunction('Dropout', drop_params).attach(netspec, [relu7])

    ip_params = dict(name='fc8', num_output=1000)
    fc8 = BaseLegoFunction('InnerProduct', ip_params).attach(netspec, [drop7])

    # Loss and accuracy
    smax_loss = BaseLegoFunction('SoftmaxWithLoss', dict(name='loss')).attach(netspec, [fc8, netspec.label])

    if include == 'test':
        BaseLegoFunction('Accuracy', dict(name='accuracy')).attach(netspec, [fc8, netspec.label])
    filename = 'train.prototxt' if is_train else 'test.prototxt'
    filepath = output_folder + '/' + filename
    fp = open(filepath, 'w')
    print >> fp, netspec.to_proto()
    fp.close()


if __name__ == '__main__':
    args = parser.parse_args()
    write_prototxt(True, 'train', args.output_folder)
    write_prototxt(False, 'test', args.output_folder)

    filepath = args.output_folder + '/train.prototxt'
    params, flops = get_complexity(prototxt_file=filepath)
    print 'Number of params: ', (1.0 * params) / 1000000.0, ' Million'
    print 'Number of flops: ', (1.0 * flops) / 1000000.0, ' Million'

Exemplo n.º 3
0
    drop_params = dict(name='drop7', dropout_param=dict(dropout_ratio=0.5))
    drop7 = BaseLegoFunction('Dropout', drop_params).attach(netspec, [relu7])

    ip_params = dict(name='fc8', num_output=1000)
    fc8 = BaseLegoFunction('InnerProduct', ip_params).attach(netspec, [drop7])

    # Loss and accuracy
    smax_loss = BaseLegoFunction('SoftmaxWithLoss', dict(name='loss')).attach(
        netspec, [fc8, netspec.label])

    if include == 'test':
        BaseLegoFunction('Accuracy',
                         dict(name='accuracy')).attach(netspec,
                                                       [fc8, netspec.label])
    filename = 'train.prototxt' if is_train else 'test.prototxt'
    filepath = output_folder + '/' + filename
    fp = open(filepath, 'w')
    print >> fp, netspec.to_proto()
    fp.close()


if __name__ == '__main__':
    args = parser.parse_args()
    write_prototxt(True, 'train', args.output_folder)
    write_prototxt(False, 'test', args.output_folder)

    filepath = args.output_folder + '/train.prototxt'
    params, flops = get_complexity(prototxt_file=filepath)
    print 'Number of params: ', (1.0 * params) / 1000000.0, ' Million'
    print 'Number of flops: ', (1.0 * flops) / 1000000.0, ' Million'
Exemplo n.º 4
0
                      fc_layers=args.fc_layers,
                      extra_blocks=args.extra_blocks,
                      extra_num_outputs=args.extra_num_outputs,
                      mbox_source_layers=args.mbox_source_layers,
                      extra_layer_attach=args.extra_layer_attach,
                      num_classes=args.num_classes)

    print args.type
    if args.type == 'VGG':
        netspec = get_vgg_ssdnet(is_train=True)
    else:
        res_params['is_train'] = True
        netspec = get_resnet_ssdnet(res_params)

    from tools.complexity import get_complexity
    params, flops = get_complexity(netspec=netspec)
    print 'Number of params: ', (1.0 * params) / 1000000.0, ' Million'
    print 'Number of flops: ', (1.0 * flops) / 1000000.0, ' Million'

    fp = open(args.output_folder + '/train.prototxt', 'w')
    print >> fp, netspec.to_proto()
    fp.close()

    if args.type == 'VGG':
        netspec = get_vgg_ssdnet(is_train=False)
    else:
        res_params['is_train'] = False
        netspec = get_resnet_ssdnet(res_params)

    fp = open(args.output_folder + '/test.prototxt', 'w')
    print >> fp, netspec.to_proto()
Exemplo n.º 5
0
                  extra_blocks=args.extra_blocks,
                  extra_num_outputs=args.extra_num_outputs,
                  mbox_source_layers=args.mbox_source_layers,
                  extra_layer_attach=args.extra_layer_attach,
                  num_classes=args.num_classes)


    print args.type
    if args.type == 'VGG':
        netspec = get_vgg_ssdnet(is_train=True)
    else:
        res_params['is_train'] = True
        netspec = get_resnet_ssdnet(res_params)

    from tools.complexity import get_complexity
    params, flops = get_complexity(netspec=netspec)
    print 'Number of params: ', (1.0 * params) / 1000000.0, ' Million'
    print 'Number of flops: ', (1.0 * flops) / 1000000.0, ' Million'

    fp = open(args.output_folder + '/train.prototxt', 'w')
    print >> fp, netspec.to_proto()
    fp.close()

    if args.type == 'VGG':
        netspec = get_vgg_ssdnet(is_train=False)
    else:
        res_params['is_train'] = False
        netspec = get_resnet_ssdnet(res_params)

    fp = open(args.output_folder + '/test.prototxt', 'w')
    print >> fp, netspec.to_proto()