def compile_saliency_map(connection):
    """
    Compile Theano function that returns saliency map.

    Parameters
    ----------
    connection : connection
    """
    x = create_input_variable(connection.input_shape,
                              name='plots:saliency-map/var:input')

    with connection.disable_training_state():
        prediction = connection.output(x)

    output_class = T.argmax(prediction)
    saliency = T.grad(T.max(prediction), x)

    return theano.function([x], [saliency, output_class])
Пример #2
0
def create_input_variables(input_layers):
    """
    Create input variables for each input layer
    in the graph.

    Parameters
    ----------
    input_layers : list of layers

    Returns
    -------
    list of Theano variables
    """
    inputs = []

    for input_layer in input_layers:
        variable = create_input_variable(input_layer.input_shape,
                                         name="layer:{}/var:input".format(
                                             input_layer.name))
        inputs.append(variable)

    return inputs
Пример #3
0
 def test_create_input_variable_exception(self):
     with self.assertRaises(ValueError):
         create_input_variable((1, 2, 3, 4), name='test')