import tensorflow as tf

        tf.summary.histogram("gradient_norm", gradient_norms)
        tf.summary.scalar("max_gradient_norm", tf.reduce_max(gradient_norms))  # visualize 
        # gradients (in case of explosion)
        return tf.summary.merge_all()


def add_eval_stats(summary_writer, step, linear_loss, before_loss, after_loss, stop_token_loss,
                   loss):
    values = [
        tf.Summary.Value(tag="Tacotron_eval_model/eval_stats/eval_before_loss",
                         simple_value=before_loss),
        tf.Summary.Value(tag="Tacotron_eval_model/eval_stats/eval_after_loss",
                         simple_value=after_loss),
        tf.Summary.Value(tag="Tacotron_eval_model/eval_stats/stop_token_loss",
                         simple_value=stop_token_loss),
        tf.Summary.Value(tag="Tacotron_eval_model/eval_stats/eval_loss", simple_value=loss),
    ]
    if linear_loss is not None:
        values.append(tf.Summary.Value(tag="Tacotron_eval_model/eval_stats/eval_linear_loss",
                                       simple_value=linear_loss))
    test_summary = tf.Summary(value=values)
    summary_writer.add_summary(test_summary, step)


def time_string():
    return datetime.now().strftime("%Y-%m-%d %H:%M")
