Exemplo n.º 1
0
def pipeline(opt):
    solver_and_prototxt('/ssd/yqian/prune/model/ResNet50', opt.compress_layer,
                        opt.compress_rate, opt.compress_block)
    index, w = get_index(list(opt.compress_rate), opt.compress_layer, opt.gpu,
                         list(opt.compress_block), opt.method)

    compress_net(index, w, opt.compress_layer, list(opt.compress_block),
                 list(opt.compress_rate))
Exemplo n.º 2
0
            weight[:, i, :, :] *= w[i]
    elif next_layer == 'fc6':
        # fc6
        weight = weight.reshape([4096, 512, 7, 7])
        weight = weight[:, index, :, :]
        for i in range(weight.shape[1]):
            weight[:, i, :, :] *= w[i]
        weight = weight.reshape([4096, -1])
    else:
        # fc7 or fc8 layer
        weight = weight[:, index]
        for i in range(weight.shape[1]):
            weight[:, i] *= w[i]

    net_new.params[next_layer][0].data[...] = weight
    net_new.params[next_layer][1].data[...] = bias

    net_new.save('model.caffemodel')
    print 'OK!'


if __name__ == '__main__':
    compress_layer = int(sys.argv[1])
    gpu = int(sys.argv[2])
    compress_rate = float(sys.argv[3])

    solver_and_prototxt(compress_layer, compress_rate)
    index, w = get_index(compress_rate, compress_layer, gpu)

    compress_net(index, w, compress_layer)
Exemplo n.º 3
0
    opt = parser.parse_args()
    return opt


def pipeline(opt):
    solver_and_prototxt('/ssd/yqian/prune/model/ResNet50', opt.compress_layer,
                        opt.compress_rate, opt.compress_block)
    index, w = get_index(list(opt.compress_rate), opt.compress_layer, opt.gpu,
                         list(opt.compress_block), opt.method)

    compress_net(index, w, opt.compress_layer, list(opt.compress_block),
                 list(opt.compress_rate))


if __name__ == '__main__':
    # compress_layer = int(sys.argv[1])
    # compress_block = int(sys.argv[2])
    # compress_rate = float(sys.argv[3])
    # gpu = int(sys.argv[4])

    opt = get_opt()

    solver_and_prototxt('/ssd/yqian/prune/model/ResNet50', opt.compress_layer,
                        opt.compress_rate, opt.compress_block)
    index, w = get_index(opt.compress_rate, opt.compress_layer, opt.gpu,
                         list(opt.compress_block))

    compress_net(index, w, opt.compress_layer, list(opt.compress_block),
                 opt.compress_rate)
Exemplo n.º 4
0
                                      index, w)
        else:
            # copy block
            net_new = copy_net(net_new, net, layer_name + '_branch2a')
            net_new = copy_net(net_new, net, layer_name + '_branch2b')
            net_new = copy_net(net_new, net, layer_name + '_branch2c')

    # branch 1
    candidate = ['2a', '3a', '4a', '5a']
    for i in range(0, 4):
        layer_name = candidate[i]
        net_new = copy_net(net_new, net, layer_name + '_branch1')

    # fc
    net_new.params['fc1000'][0].data[...] = net.params['fc1000'][0].data
    net_new.params['fc1000'][1].data[...] = net.params['fc1000'][1].data
    net_new.save('model.caffemodel')
    print 'OK!'


if __name__ == '__main__':
    compress_layer = int(sys.argv[1])
    compress_block = int(sys.argv[2])
    compress_rate = float(sys.argv[3])
    gpu = int(sys.argv[4])

    solver_and_prototxt(compress_layer, compress_rate, compress_block)
    index, w = get_index(compress_rate, compress_layer, gpu, compress_block)

    compress_net(index, w, compress_layer, compress_block)