Esempio n. 1
0
def test_space_to_depth(image_shape, num_channels, block_size, device_id, precision):
    dev = cntk_device(device_id)
    from cntk.internal import sanitize_dtype_cntk

    input_val = np.random.randint(low=0, high=100, size=(num_channels,) + image_shape).astype(PRECISION_TO_TYPE[precision])
    img = C.input_variable((num_channels,) + image_shape, dtype=sanitize_dtype_cntk(PRECISION_TO_TYPE[precision]))
    depth_to_space_op = C.depth_to_space(img, block_size)
    space_to_depth_op = C.space_to_depth(depth_to_space_op, block_size)
    output_val = np.squeeze(space_to_depth_op.eval({ img : input_val }), 0)

    assert np.array_equal(output_val, input_val)
Esempio n. 2
0
def test_SpaceToDepth(tmpdir):
    num_channels = 3
    block_size = 3
    image_shape = (12, 15)
    input_val = np.array(np.reshape(range(num_channels), (num_channels, 1, 1)), dtype=np.float32)
    input_val = np.tile(input_val, (1,) + image_shape)
    input_val.shape = (1,) + input_val.shape
    img = C.input_variable((num_channels,) + image_shape, dtype=np.float32)
    model = C.space_to_depth(img, block_size)

    verify_one_input(model, input_val, tmpdir, 'SpaceToDepth')
Esempio n. 3
0
def test_space_to_depth(image_shape, num_channels, block_size, device_id, precision):
    dev = cntk_device(device_id)
    from cntk.internal import sanitize_dtype_cntk

    input_val = np.random.randint(low=0, high=100, size=(num_channels,) + image_shape).astype(PRECISION_TO_TYPE[precision])
    img = C.input_variable((num_channels,) + image_shape, dtype=sanitize_dtype_cntk(PRECISION_TO_TYPE[precision]))
    depth_to_space_op = C.depth_to_space(img, block_size)
    space_to_depth_op = C.space_to_depth(depth_to_space_op, block_size)
    output_val = np.squeeze(space_to_depth_op.eval({ img : input_val }), 0)

    assert np.array_equal(output_val, input_val)
Esempio n. 4
0
def test_SpaceToDepth(tmpdir):
    num_channels = 3
    block_size = 3
    image_shape = (12, 15)
    input_val = np.array(np.reshape(range(num_channels), (num_channels, 1, 1)), dtype=np.float32)
    input_val = np.tile(input_val, (1,) + image_shape)
    input_val.shape = (1,) + input_val.shape
    img = C.input_variable((num_channels,) + image_shape, dtype=np.float32)
    model = C.space_to_depth(img, block_size)

    verify_one_input(model, input_val, tmpdir, 'SpaceToDepth')
Esempio n. 5
0
def space_to_depth_x2(x):
    """Thin wrapper for Tensorflow space_to_depth with block_size=2."""
    # Import currently required to make Lambda work.
    # See: https://github.com/fchollet/keras/issues/5088#issuecomment-273851273
    return C.space_to_depth(x, 2)