def test__call__if_score_is_(self, scores, expected_error, multiple_inputs_model): cam = Xcam(multiple_inputs_model) with assert_raises(expected_error): result = cam(scores, [dummy_sample((1, 8, 8, 3)), dummy_sample((1, 10, 10, 3))]) assert len(result) == 2 assert result[0].shape == (1, 8, 8) assert result[1].shape == (1, 10, 10)
def test__call__if_max_N_is_(self, max_N, expected_error, conv_model): with assert_raises(expected_error): cam = Scorecam(conv_model) result = cam(CategoricalScore(0), dummy_sample((2, 8, 8, 3)), max_N=max_N) assert result.shape == (2, 8, 8)
def test__call__(self, model, layer, expected_error): assert model.outputs[0].shape.as_list() == [None, 2] with assert_raises(expected_error): instance = ActivationMaximization(model, model_modifier=ExtractIntermediateLayer(layer)) assert instance.model != model assert instance.model.outputs[0].shape.as_list() == [None, 6, 6, 6] instance([CategoricalScore(0)])
def test__init__(self, degree, axes, expected_error): with assert_raises(expected_error): if axes is None: instance = Rotate(degree=degree) else: instance = Rotate(axes=axes, degree=degree) assert instance.axes == axes assert instance.degree == float(degree)
def test__call__if_penultimate_layer_is(self, penultimate_layer, seek_penultimate_conv_layer, expected_error, conv_model): cam = Xcam(conv_model) with assert_raises(expected_error): result = cam(CategoricalScore(0), dummy_sample((1, 8, 8, 3)), penultimate_layer=penultimate_layer, seek_penultimate_conv_layer=seek_penultimate_conv_layer) assert result.shape == (1, 8, 8)
def test__call__if_seed_input_is_(self, seed_input, expected, expected_error, conv_model): cam = Xcam(conv_model) with assert_raises(expected_error): result = cam(CategoricalScore(0), seed_input) if type(expected) is list: assert type(result) is list expected = expected[0] result = result[0] assert result.shape == expected
def test__call__if_seed_input_is_(self, seed_input, expected, expected_error, multiple_outputs_model): cam = Xcam(multiple_outputs_model) with assert_raises(expected_error): result = cam([CategoricalScore(0), BinaryScore(0)], seed_input) if type(expected) is list: assert type(result) is list expected = expected[0] result = result[0] assert result.shape == expected
def test__call__(self, indices, output_shape, expected_error): output = tf.constant(dummy_sample(output_shape), tf.float32) score = CategoricalScore(indices) with assert_raises(expected_error): score_value = score(output) assert score_value.shape == output_shape[0:1]
def test__init__(self, indices, expected, expected_error): with assert_raises(expected_error): score = CategoricalScore(indices) assert score.indices == expected
def test__call__(self, target_values, output, expected, expected_error): output = tf.constant(output, tf.float32) score = BinaryScore(target_values) with assert_raises(expected_error): score_value = score(output) assert tf.math.reduce_all(score_value == expected)
def test__init__(self, target_values, expected, expected_error): with assert_raises(expected_error): score = BinaryScore(target_values) assert score.target_values == expected
def test__call__(self, output, expected_shape, expected_error): with assert_raises(expected_error): actual = InactiveScore()(output) assert np.all(actual == 0.0) assert actual.shape == expected_shape
def test__call__if_score_is_(self, scores, expected_error, conv_model): cam = Xcam(conv_model) with assert_raises(expected_error): result = cam(scores, dummy_sample((1, 8, 8, 3))) assert result.shape == (1, 8, 8)
def test__call__(self, dense_model): cam = Xcam(dense_model) with assert_raises(ValueError): result = cam(CategoricalScore(0), dummy_sample((1, 8, 8, 3))) assert result.shape == (1, 8, 8)
def test__call__if_seed_input_is_(self, seed_input, expected_error, multiple_io_model): cam = Xcam(multiple_io_model) with assert_raises(expected_error): result = cam([CategoricalScore(0), BinaryScore(0)], seed_input) assert result[0].shape == (1, 8, 8) assert result[1].shape == (1, 10, 10)