class_docstr: Parent class for deepchem Tensorflow models.
  
  Classifier:
    n_classes
  
  Has the following attributes:
  
    placeholder_root: String placeholder prefix, used to create
      placeholder_scope.
  
  Generic base class for defining, training, and evaluating TensorflowGraphs.
  
  Subclasses must implement the following methods:
    build
    add_output_ops
    add_training_cost 
  
  Args:
    train: If True, model is in training mode.
    logdir: Directory for output files.
class_docstr_tok: ["Parent","class","for","deepchem","Tensorflow","models",".","Classifier",":","n_classes","Has","the","following","attributes",":","placeholder_root",":","String","placeholder","prefix",",","used","to","create","placeholder_scope",".","Generic","base","class","for","defining",",","training",",","and","evaluating","TensorflowGraphs",".","Subclasses","must","implement","the","following","methods",":","build","add_output_ops","add_training_cost","Args",":","train",":","If","True",",","model","is","in","training","mode",".","logdir",":","Directory","for","output","files","."]
code: def add_training_cost(
      self, graph, name_scopes, output, labels, weights
  ):
      with graph.as_default():
          epsilon = 1e-3  # small float to avoid dividing by zero
          weighted_costs = []  # weighted costs for each example
          gradient_costs = []  # costs used for gradient calculation
  
          with TensorflowGraph.shared_name_scope(
              "costs", graph, name_scopes
          ):
              for task in range(self.n_tasks):
                  task_str = str(task).zfill(len(str(self.n_tasks)))
                  with TensorflowGraph.shared_name_scope(
                      "cost_{}".format(task_str), graph, name_scopes
                  ):
                      with tf.name_scope("weighted"):
                          weighted_cost = self.cost(
                              output[task], labels[task], weights[task]
                          )
                          weighted_costs.append(weighted_cost)
  
                      with tf.name_scope("gradient"):
                          # Note that we divide by the batch size and not the number of
                          # non-zero weight examples in the batch.  Also, instead of using
                          # tf.reduce_mean (which can put ops on the CPU) we explicitly
                          # calculate with div/sum so it stays on the GPU.
                          gradient_cost = tf.math.divide(
                              tf.reduce_sum(weighted_cost),
                              self.batch_size,
                          )
                          gradient_costs.append(gradient_cost)
  
              # aggregated costs
              with TensorflowGraph.shared_name_scope(
                  "aggregated", graph, name_scopes
              ):
                  with tf.name_scope("gradient"):
                      loss = tf.add_n(gradient_costs)
  
                  # weight decay
                  if self.penalty != 0.0:
                      penalty = model_ops.weight_decay(
                          self.penalty_type, self.penalty
                      )
                      loss += penalty
  
          return loss
  
imports: from __future__ import print_function
  from __future__ import division
  from __future__ import unicode_literals
  import collections
  import pickle
  import os
  import time
  import warnings
  import numpy
  import pandas
  import tensorflow
  import tempfile
  from deepchem.models import Model
  from deepchem.metrics import from_one_hot
  from deepchem.nn import model_ops
  from deepchem.models.tensorflow_models import utils
  from deepchem.trans import undo_transforms
  from deepchem.utils.save import log
  from deepchem.utils.evaluate import Evaluator
  from deepchem.data import pad_features
  from tensorflow.contrib.layers.python.layers import batch_norm
label_desc: Use image node_id 6 for calling the TensorflowGraphModel obj's underlying member method code with example usage: obj.add_training_cost(graph, name_scopes, output, labels, weights) and returns: loss