def main():

    args = _parse_args()

    model = serial.load(args.input)
    if not isinstance(model, MLP):
        print("Expected the .pkl file to contain an MLP, got a %s." %
              str(model.type))
        sys.exit(1)

    def get_figure_and_axes(conv_layers, window_width=800):
        kernel_display_width = 20
        margin = 5
        grid_square_width = kernel_display_width + margin
        num_columns = window_width // grid_square_width

        max_num_channels = numpy.max([layer.get_input_space().num_channels
                                      for layer in conv_layers])
        # pdb.set_trace()
        num_rows = max_num_channels // num_columns
        if num_rows * num_columns < max_num_channels:
            num_rows += 1

        assert num_rows * num_columns >= max_num_channels

        window_width = 15

        # '* 1.8' comse from the fact that rows take up about 1.8 times as much
        # space as columns, due to the title text.
        window_height = window_width * ((num_rows * 1.8) / num_columns)
        figure, all_axes = pyplot.subplots(num_rows,
                                           num_columns,
                                           squeeze=False,
                                           figsize=(window_width,
                                                    window_height))

        for unit_index, axes in enumerate(all_axes.flat):
            subplot_title = axes.set_title('%d' % unit_index)
            subplot_title.set_size(8)
            subplot_title.set_color((.3, .3, .3))

        # Hides tickmarks
        for axes_row in all_axes:
            for axes in axes_row:
                axes.get_xaxis().set_visible(False)
                axes.get_yaxis().set_visible(False)

        return figure, all_axes

    conv_layers = _get_conv_layers(model)
    figure, all_axes = get_figure_and_axes(conv_layers)
    title_text = figure.suptitle("title")
    pyplot.tight_layout(h_pad=.1, w_pad=.5)  # in inches

    layer_index = numpy.array(0)
    unit_indices = numpy.zeros(len(model.layers), dtype=int)

    def redraw():
        '''
        Draws the currently selected convolutional kernel.
        '''

        axes_list = all_axes.flatten()
        layer = conv_layers[layer_index]
        unit_index = unit_indices[layer_index, ...]
        weights = _get_conv_weights_bc01(layer)[unit_index, ...]

        active_axes = axes_list[:weights.shape[0]]

        for axes, weights in safe_zip(active_axes, weights):
            axes.set_visible(True)
            axes.imshow(weights, cmap='gray', interpolation='nearest')

        assert len(frozenset(active_axes)) == len(active_axes)

        unused_axes = axes_list[len(active_axes):]
        assert len(frozenset(unused_axes)) == len(unused_axes)
        assert len(axes_list) == len(active_axes) + len(unused_axes)

        for axes in unused_axes:
            axes.set_visible(False)

        title_text.set_text("Layer %s, unit %d" %
                            (layer.layer_name,
                             unit_indices[layer_index]))

        figure.canvas.draw()

    def on_key_press(event):
        "Callback for key press events"

        def increment(index, size, step):
            """
            Increments an index in-place.

            Parameters
            ----------
            index: numpy.ndarray
              scalar (0-dim array) of dtype=int. Non-negative.

            size: int
              One more than the maximum permissible index.

            step: int
              -1, 0, or 1.
            """
            assert index >= 0
            assert step in (0, -1, 1)

            index[...] = (index + size + step) % size

        if event.key in ('up', 'down'):
            increment(layer_index,
                      len(conv_layers),
                      1 if event.key == 'up' else -1)
            unit_index = unit_indices[layer_index]
            redraw()
        elif event.key in ('right', 'left'):
            unit_index = unit_indices[layer_index:layer_index + 1]
            increment(unit_index,
                      _num_conv_units(conv_layers[layer_index]),
                      1 if event.key == 'right' else -1)
            redraw()
        elif event.key == 'q':
            sys.exit(0)

    figure.canvas.mpl_connect('key_press_event', on_key_press)
    redraw()
    pyplot.show()
Extracts opt in status from request
dataset/ETHPy150Open lisa-lab/pylearn2/pylearn2/scripts/browse_conv_weights.py/main--crossover with--dataset/ETHPy150Open openstack/fuel-web/nailgun/nailgun/api/v1/handlers/master_node_settings.py/MasterNodeSettingsHandler._get_new_opt_in_status