class_docstr: Convolutional Neural Network for image classification.
  
  It assumes the inputs are images of shape width x height x channels.
  The precise architecture follows the Tensorflow CNN
  tutorial at https://www.tensorflow.org/tutorials/images/deep_cnn.
  Note that this CNN works both for the agreement and classification models.
  In the agreement case, the provided inputs will be a tuple
  (inputs_src, inputs_target), which are aggregated into one input after the
  convolution layers, right before the fully connected network that makes the
  final prediction.
  
  Attributes:
    output_dim: Integer representing the number of classes.
    channels: Integer representing the number of channels in the input images
      (e.g., 1 for black and white, 3 for RGB).
    aggregation: String representing an aggregation operation, that is applied
      on the two inputs of the agreement model, after they are encoded through
      the convolution layers. See superclass attributes for details.
    activation: An activation function to be applied to the outputs of each
      fully connected layer of the aggregation network.
    is_binary_classification: Boolean specifying if this is model for
      binary classification. If so, it uses a different loss function and
      returns predictions with a single dimension, batch size.
    name: String representing the model name.
class_docstr_tok: ["Convolutional","Neural","Network","for","image","classification",".","It","assumes","the","inputs","are","images","of","shape","width","x","height","x","channels",".","The","precise","architecture","follows","the","Tensorflow","CNN","tutorial","at","https",":","\/\/www.tensorflow.org\/tutorials\/images\/deep_cnn",".","Note","that","this","CNN","works","both","for","the","agreement","and","classification","models",".","In","the","agreement","case",",","the","provided","inputs","will","be","a","tuple","(","inputs_src",",","inputs_target",")",",","which","are","aggregated","into","one","input","after","the","convolution","layers",",","right","before","the","fully","connected","network","that","makes","the","final","prediction",".","Attributes",":","output_dim",":","Integer","representing","the","number","of","classes",".","channels",":","Integer","representing","the","number","of","channels","in","the","input","images","(","e.g.",",","1","for","black","and","white",",","3","for","RGB",")",".","aggregation",":","String","representing","an","aggregation","operation",",","that","is","applied","on","the","two","inputs","of","the","agreement","model",",","after","they","are","encoded","through","the","convolution","layers",".","See","superclass","attributes","for","details",".","activation",":","An","activation","function","to","be","applied","to","the","outputs","of","each","fully","connected","layer","of","the","aggregation","network",".","is_binary_classification",":","Boolean","specifying","if","this","is","model","for","binary","classification",".","If","so",",","it","uses","a","different","loss","function","and","returns","predictions","with","a","single","dimension",",","batch","size",".","name",":","String","representing","the","model","name","."]
docstr: Returns a loss between the provided targets and predictions.
  
  For binary classification, this loss is sigmoid cross entropy. For
  multi-class classification, it is softmax cross entropy.
  A weight decay loss is also added to the parameters passed in reg_params.
  
  Args:
    predictions: A tensor of predictions. For multiclass classification its
      shape is (num_samples, num_classes), where the second dimension contains
      a logit per class. For binary classification, its shape is
      (num_samples,), where each element is the probability of class 1 for
      that sample.
    targets: A tensor of targets of shape (num_samples,), where each row
      contains the label index of the corresponding sample.
    name_scope: A string containing the name scope used in TensorFlow.
    reg_params: A dictonary of parameters, mapping from name to parameter, for
      the variables to be included in the weight decay loss. If None, no
      weight decay is applied.
    **kwargs: Keyword arguments, potentially containing the weight of the
      regularization term, passed under the name `weight_decay`. If this is
      not provided, it defaults to 0.004.
  
  Returns:
    loss: The cummulated loss value.
docstr_tok: ["Returns","a","loss","between","the","provided","targets","and","predictions",".","For","binary","classification",",","this","loss","is","sigmoid","cross","entropy",".","For","multi-class","classification",",","it","is","softmax","cross","entropy",".","A","weight","decay","loss","is","also","added","to","the","parameters","passed","in","reg_params",".","Args",":","predictions",":","A","tensor","of","predictions",".","For","multiclass","classification","its","shape","is","(","num_samples",",","num_classes",")",",","where","the","second","dimension","contains","a","logit","per","class",".","For","binary","classification",",","its","shape","is","(","num_samples",",",")",",","where","each","element","is","the","probability","of","class","1","for","that","sample",".","targets",":","A","tensor","of","targets","of","shape","(","num_samples",",",")",",","where","each","row","contains","the","label","index","of","the","corresponding","sample",".","name_scope",":","A","string","containing","the","name","scope","used","in","TensorFlow",".","reg_params",":","A","dictonary","of","parameters",",","mapping","from","name","to","parameter",",","for","the","variables","to","be","included","in","the","weight","decay","loss",".","If","None",",","no","weight","decay","is","applied",".","*","*","kwargs",":","Keyword","arguments",",","potentially","containing","the","weight","of","the","regularization","term",",","passed","under","the","name","`","weight_decay","`",".","If","this","is","not","provided",",","it","defaults","to","0.004",".","Returns",":","loss",":","The","cummulated","loss","value","."]
code: def get_loss(
      self,
      predictions,
      targets,
      name_scope="loss",
      reg_params=None,
      **kwargs,
  ):
      """Returns a loss between the provided targets and predictions.
  
      For binary classification, this loss is sigmoid cross entropy. For
      multi-class classification, it is softmax cross entropy.
      A weight decay loss is also added to the parameters passed in reg_params.
  
      Args:
        predictions: A tensor of predictions. For multiclass classification its
          shape is (num_samples, num_classes), where the second dimension contains
          a logit per class. For binary classification, its shape is
          (num_samples,), where each element is the probability of class 1 for
          that sample.
        targets: A tensor of targets of shape (num_samples,), where each row
          contains the label index of the corresponding sample.
        name_scope: A string containing the name scope used in TensorFlow.
        reg_params: A dictonary of parameters, mapping from name to parameter, for
          the variables to be included in the weight decay loss. If None, no
          weight decay is applied.
        **kwargs: Keyword arguments, potentially containing the weight of the
          regularization term, passed under the name `weight_decay`. If this is
          not provided, it defaults to 0.004.
  
      Returns:
        loss: The cummulated loss value.
      """
      reg_params = reg_params if reg_params is not None else {}
      weight_decay = (
          kwargs["weight_decay"] if "weight_decay" in kwargs else 0.004
      )
  
      with tf.name_scope(name_scope):
          # Cross entropy error.
          if self.is_binary_classification:
              loss = tf.reduce_sum(
                  tf.nn.sigmoid_cross_entropy_with_logits(
                      labels=targets, logits=predictions
                  )
              )
          else:
              loss = tf.losses.softmax_cross_entropy(
                  targets, predictions
              )
  
          # Weight decay loss.
          if weight_decay is not None:
              for var in reg_params.values():
                  loss += weight_decay * tf.nn.l2_loss(var)
      return loss
  
file_path: neural-structured-learning/research/gam/gam/models/cnn.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from .models_base import Model
  import tensorflow
label_desc: Use image node_id 5 for calling the ImageCNNAgreement obj's underlying member method code with example usage: obj.get_loss(predictions, targets, name_scope, reg_params) and returns: loss