def test_downsample_model_features():
"""
Test creates a toy numpy array, and checks that the method
correctly downsamples the array into a hand-checked tensor
"""
# Create the spliced and averaged tensor via downsampling function
array = np.array([[1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
[11, 12, 13, 14, 15, 16, 17, 18, 19, 20],
[21, 22, 23, 24, 25, 26, 27, 28, 29, 30]
])
tensor = K.variable(array)
x = _downsample_model_features(tensor, 5)
# Create the spliced and averaged tensor by hand
check_array = np.array([[1.5, 3.5, 5.5, 7.5, 9.5],
[11.5, 13.5, 15.5, 17.5, 19.5],
[21.5, 23.5, 25.5, 27.5, 29.5]
])
check_tensor = K.variable(check_array)
# Check that they are equal: that it returns the correct tensor
assert np.allclose(K.eval(check_tensor), K.eval(x), atol=ATOL)
评论列表
文章目录