code: def get_loss_fn(final_loss):
      # Obtain appropriate loss function
      if final_loss == "L2":
  
          def loss_fn(x, t):
              diff = tf.subtract(x, t)
              return tf.reduce_sum(tf.square(diff), 0)
  
      elif final_loss == "weighted_L2":
  
          def loss_fn(x, t, w):
              diff = tf.subtract(x, t)
              weighted_diff = tf.multiply(diff, w)
              return tf.reduce_sum(tf.square(weighted_diff), 0)
  
      elif final_loss == "L1":
  
          def loss_fn(x, t):
              diff = tf.subtract(x, t)
              return tf.reduce_sum(tf.abs(diff), 0)
  
      elif final_loss == "huber":
  
          def loss_fn(x, t):
              diff = tf.subtract(x, t)
              return tf.reduce_sum(
                  tf.minimum(
                      0.5 * tf.square(diff),
                      huber_d * (tf.abs(diff) - 0.5 * huber_d),
                  ),
                  0,
              )
  
      elif final_loss == "cross_entropy":
  
          def loss_fn(x, t, w):
              costs = tf.nn.sigmoid_cross_entropy_with_logits(
                  logits=x, labels=t
              )
              weighted_costs = tf.multiply(costs, w)
              return tf.reduce_sum(weighted_costs)
  
      elif final_loss == "hinge":
  
          def loss_fn(x, t, w):
              t = tf.multiply(2.0, t) - 1
              costs = tf.maximum(0.0, 1.0 - tf.multiply(t, x))
              weighted_costs = tf.multiply(costs, w)
              return tf.reduce_sum(weighted_costs)
  
      return loss_fn
  
imports: from __future__ import print_function
  from __future__ import division
  from __future__ import unicode_literals
  import warnings
  import os
  import sys
  import numpy
  import tensorflow
  import sklearn.metrics
  import tempfile
  from deepchem.data import pad_features
  from deepchem.utils.save import log
  from deepchem.models import Model
  from deepchem.nn.copy import Input
  from deepchem.nn.copy import Dense
  from deepchem.nn import model_ops
  from deepchem.models.tf_new_models.graph_topology import merge_dicts
label_desc: Use image node_id 1 for calling a global function with example usage: get_loss_fn(final_loss) and returns: loss_fn, tf, tf, tf, tf, tf, tf