#NEWLINE# def r2_op( predictions , targets , inputs ) : #NEWLINE# #INDENT# ' r2_op.\n\n    An op that calculates the standard error.\n\n    Examples:\n        ```python\n        input_data = placeholder(shape=[None, 784])\n        y_pred = my_network(input_data) # Apply some ops\n        y_true = placeholder(shape=[None, 10]) # Labels\n        stderr_op = r2_op(y_pred, y_true, input_data)\n\n        # Calculate standard error by feeding data X and labels Y\n        std_error = sess.run(stderr_op, feed_dict={input_data: X, y_true: Y})\n        ```\n\n    Arguments:\n        predictions: `Tensor`.\n        targets: `Tensor`.\n        inputs: `Tensor`.\n\n    Returns:\n        `Float`. The standard error.\n\n    ' #NEWLINE# with tf . name_scope ( 'StandardError' ) : #NEWLINE# #INDENT# if hasattr ( inputs , '__len__' ) : #NEWLINE# #INDENT# inputs = tf . add_n ( inputs ) #NEWLINE# #UNINDENT# if ( inputs . get_shape ( ) . as_list ( ) != targets . get_shape ( ) . as_list ( ) ) : #NEWLINE# #INDENT# raise Exception ( 'R2 metric requires Inputs and Targets to have same shape.' ) #NEWLINE# #UNINDENT# a = tf . reduce_sum ( tf . square ( ( predictions - inputs ) ) ) #NEWLINE# b = tf . reduce_sum ( tf . square ( ( targets - inputs ) ) ) #NEWLINE# return tf . div ( a , b )