Ejemplo n.º 1
0
def test_native_convolution(tmpdir):  
    # this test needs native binary convolution library built with halide.
    if not C.contrib.netopt.native_convolve_function_registered:     
        pytest.skip()

    z = _create_convolution_model()
    binz = qc.convert_to_binary_convolution(z, _filter)
    
    # save and load to transfer the model to CPU device as native binary
    # convolution does not run on GPU yet.
    model_file = str(tmpdir / ('binary_model.cmf'))
    binz.save(model_file)

    eval_device = C.cpu()
    model = C.Function.load(model_file, device=eval_device)

    # convert to native halide implementation.
    native_binz = qc.convert_to_native_binary_convolution(model)

    functions = C.logging.graph.depth_first_search(
                native_binz, (lambda x : type(x) == C.Function and x.op_name =='BinaryConvolveOp') , depth = 0)
    assert(len(functions) == 3)

    img_data = np.reshape(dat, (1, 1, 28, 28))

    res = native_binz.eval(img_data, device=eval_device)
    assert(len(res) > 0) # evaluation should work with the new model.
Ejemplo n.º 2
0
def test_native_convolution(tmpdir):
  
    # this test needs native binary convolution library built with halide.
    if not C.contrib.netopt.native_convolve_function_registered:     
        pytest.skip()

    z = _create_convolution_model()
    binz = qc.convert_to_binary_convolution(z, _filter)
    
    # save and load to transfer the model to CPU device as native binary
    # convolution does not run on GPU yet.
    model_file = str(tmpdir / ('binary_model.cmf'))
    binz.save(model_file)

    eval_device = C.cpu()
    model = C.Function.load(model_file, device=eval_device)
    
    # convert to native halide implementation.
    native_binz = qc.convert_to_native_binary_convolution(model)

    functions = C.logging.graph.depth_first_search(
                native_binz, (lambda x : type(x) == C.Function and x.op_name =='BinaryConvolveOp') , depth = 0)    
    assert(len(functions) == 3)
    
    img_data = np.reshape(dat, (1, 1, 28, 28))

    res = native_binz.eval(img_data, device=eval_device)
    assert(len(res) > 0) # evaluation should work with the new model.
Ejemplo n.º 3
0
def test_binarization():
    z = _create_convolution_model_with_skip_level_links()
    binz = qc.convert_to_binary_convolution(z)

    blocks = C.logging.graph.depth_first_search(
                binz, (lambda x : type(x) == C.Function and x.is_block and x.op_name =='BinaryConvolution') , depth = 0)

    assert(len(blocks) == 4) # all convolution blocks should be converted.

    binz = qc.convert_to_binary_convolution(z, _filter)

    blocks = C.logging.graph.depth_first_search(
                binz, (lambda x : type(x) == C.Function and x.is_block and x.op_name =='BinaryConvolution') , depth = 0)

    assert(len(blocks) == 3) # now only three of them should be converted.
    assert(all(b.op_name != 'first_convo' for b in blocks))