def get_summary(stype, tag, value=None, collection_key=None,
                break_if_exists=False):
    """ get_summary.

    Create or retrieve a summary. It keep tracks of all graph summaries
    through summary_tags collection. If a summary tags already exists,
    it will return that summary tensor or raise an error (according to
    'break_if_exists').

    Arguments:
        stype: `str`. Summary type: 'histogram', 'scalar' or 'image'.
        tag: `str`. The summary tag (name).
        value: `Tensor`. The summary initialization value. Default: None.
        collection_key: `str`. If specified, the created summary will be
            added to that collection (optional).
        break_if_exists: `bool`. If True, if a summary with same tag already
            exists, it will raise an exception (instead of returning that
            existing summary).

    Returns:
        The summary `Tensor`.

    """
    summ = next((item for item in tf.get_collection("summary_tags") if
                 item["tag"] == tag), None)

    if not summ:
        if value is None:
            raise Exception("Summary doesn't exist, a value must be "
                            "specified to initialize it.")
        if stype == "histogram":
            summ = tf.histogram_summary(tag, value)
        elif stype == "scalar":
            summ = tf.scalar_summary(tag, value)
        elif stype == "image":
            pass  # TODO: create summary
        else:
            raise ValueError("Unknow summary type: '" + str(stype) + "'")
        tf.add_to_collection("summary_tags", {"tag": tag, "tensor": summ})
        if collection_key:
            tf.add_to_collection(collection_key, summ)
    elif break_if_exists:
        raise ValueError("Error: Summary tag already exists! (to ignore this "
                         "error, set add_summary() parameter 'break_if_exists'"
                         " to False)")
    else:
        summ = summ["tensor"]

    return summ
dataset/ETHPy150Open tflearn/tflearn/tflearn/summaries.py/get_summary/original