Esempio n. 1
0
def slice_dyn(test_shape=[2,8,10,10]):
    paddle.disable_static()

    data = paddle.rand(shape=test_shape, dtype='float32')

    '''
    slice w/ decrease_axis
    '''
    @paddle.jit.to_static
    def test_slice_decrease_axis(x):
        return x[0, 1:3, :, 5]
    exportModel('slice_decrease_axis', test_slice_decrease_axis, [data], target_dir=sys.argv[1]) # output shape (2, 10)

    '''
    slice w/o decrease_axis
    '''
    @paddle.jit.to_static
    def test_slice(x):
        return paddle.slice(x, axes=[0,1,3], starts=[0,1,5], ends=[1,3,6])
    # exportModel('slice_dyn', test_slice, [data], target_dir=sys.argv[1]) # output shape (1, 2, 10, 1)  # disable it by default as this kind of test model already there. It's for comparsion only.

    '''
    slice w/ decrease_axis of all dims
    '''
    @paddle.jit.to_static
    def test_slice_decrease_axis_all(x):
        return x[0, 0, 0, 0]
    exportModel('slice_decrease_axis_all', test_slice_decrease_axis_all, [data], target_dir=sys.argv[1]) # output shape (1,)

    '''
    slice w/o decrease_axis of all dims
    '''
    @paddle.jit.to_static
    def test_slice_alldim(x):
        return paddle.slice(x, axes=[0,1,2,3], starts=[0,0,0,0], ends=[1,1,1,1])
Esempio n. 2
0
def slice_reshape(B=1, C=256, H=16, W=32):
    paddle.disable_static()

    data = paddle.rand(shape=[B, C, H*W], dtype='float32')

    @paddle.jit.to_static
    def test_model(x):
        x2 = paddle.assign([-1, -1, 16, 32]).astype('int32')
        node_reshape = paddle.reshape(x, [0, 256, x2[2], x2[3]])
        return node_reshape
    exportModel('slice_reshape', test_model, [data], target_dir=sys.argv[1])
Esempio n. 3
0
def meshgrid():
    paddle.disable_static()

    @paddle.jit.to_static
    def test_model(x, y, z):
        return paddle.meshgrid(x, y, z)

    x = paddle.randint(low=0, high=100, shape=[5])
    y = paddle.randint(low=0, high=100, shape=[3])
    z = paddle.randint(low=0, high=100, shape=[2])
    return exportModel('meshgrid',
                       test_model, [x, y, z],
                       target_dir=sys.argv[1])
Esempio n. 4
0
from save_model import exportModel
'''
assign w/ ouput
'''


@paddle.jit.to_static
def test_assign_output(array):
    result1 = paddle.zeros(shape=[3, 2], dtype='float32')
    paddle.assign(array, result1)  # result1 = [[1, 1], [3 4], [1, 3]]
    return result1


array = np.array([[1, 1], [3, 4], [1, 3]]).astype(np.int64)
exportModel('assign_output',
            test_assign_output, [array],
            target_dir=sys.argv[1])
'''
assign w/o ouput
'''


@paddle.jit.to_static
def test_assign_none(data):
    result2 = paddle.assign(
        data)  # result2 = [[2.5, 2.5], [2.5, 2.5], [2.5, 2.5]]
    return result2


data = paddle.full(shape=[3, 2], fill_value=2.5,
                   dtype='float32')  # [[2.5, 2.5], [2.5, 2.5], [2.5, 2.5]]