build_featurizer_test.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:pic2vec 作者: datarobot 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号