def _layer_stats(info, layer_name, output, layers_incr, weights_incr):
    """Internal utility function. Counts weights and layers. Produces a message. Pass in
    info=None to start counting. The return valus is an info dictionary with the following
    data:
        info["layers"]: total number of layers in the neural network (maxpool layers do not count)
        info["weights"]: total number of trainable parameters
        info['description']: description of the structure of the neural network"""

    # Initialization
    if (info == None):
        info = {'layers':0, 'weights':0, 'description':""}

    info["layers"] += layers_incr
    info["weights"] += weights_incr
    depth = output.get_shape()[3]
    message_weights = "({:,d} weights)".format(weights_incr).rjust(20)
    message_shape = "{}x{}x{}".format(output.get_shape()[1], output.get_shape()[2], depth).ljust(14)
    message1 = "NN layer {:>2}: {:>20} -> {} {}".format(info["layers"], layer_name, message_shape, message_weights)
    message2 = "NN layer {:>24} -> {} {}".format(layer_name, message_shape, message_weights)
    info['description'] += "\n"
    if layers_incr > 0:
        info['description'] += message1
    else:
        info['description'] += message2
    return info