def test_two_preprocessor_layers_in_a_preprocessor_stack(self): space = Dict(a=FloatBox(shape=(1, 2)), b=FloatBox(shape=(2, 2, 2)), c=Tuple(FloatBox(shape=(2, )), Dict(ca=FloatBox(shape=(3, 3, 2))))) # Construct the Component to test (PreprocessorStack). scale = Multiply(factor=2) gray = GrayScale(weights=(0.5, 0.5), keep_rank=False) stack = PreprocessorStack(scale, gray) test = ComponentTest(component=stack, input_spaces=dict(inputs=space)) input_ = dict( a=np.array([[3.0, 5.0]]), b=np.array([[[2.0, 4.0], [2.0, 4.0]], [[2.0, 4.0], [2.0, 4.0]]]), c=(np.array([10.0, 20.0]), dict(ca=np.array([[[1.0, 2.0], [1.0, 2.0], [1.0, 2.0]], [[1.0, 2.0], [1.0, 2.0], [1.0, 2.0]], [[1.0, 2.0], [1.0, 2.0], [1.0, 2.0]]])))) expected = dict(a=np.array([8.0]), b=np.array([[6.0, 6.0], [6.0, 6.0]]), c=(30.0, dict(ca=np.array([[3.0, 3.0, 3.0], [3.0, 3.0, 3.0], [3.0, 3.0, 3.0]])))) test.test("reset") test.test(("preprocess", input_), expected_outputs=expected)
def test_multiply(self): multiply = Multiply(factor=2.0) test = ComponentTest(component=multiply, input_spaces=dict(preprocessing_inputs=FloatBox( shape=(2, 1), add_batch_rank=True))) test.test("reset") # Batch=2 input_ = np.array([[[1.0], [2.0]], [[3.0], [4.0]]]) expected = np.array([[[2.0], [4.0]], [[6.0], [8.0]]]) test.test(("apply", input_), expected_outputs=expected)