class_docstr: NeuralNetwork is a class that interfaces the verification code with
  the neural net parameters (weights).
class_docstr_tok: ["NeuralNetwork","is","a","class","that","interfaces","the","verification","code","with","the","neural","net","parameters","(","weights",")","."]
docstr: Function to initialize NeuralNetParams class.
  
  Args:
    net_weights: list of numpy matrices of weights of each layer
     [convention: x[i+1] = W[i] x[i]
    net_biases: list of numpy arrays of biases of each layer
    net_layer_types: type of each layer ['ff' or 'ff_relu' or 'ff_conv' or
      'ff_conv_relu']
  
      'ff': Simple feedforward layer with no activations
      'ff_relu': Simple feedforward layer with ReLU activations
      'ff_conv': Convolution layer with no activation
      'ff_conv_relu': Convolution layer with ReLU activation
    input_shape: [num_rows, num_columns, num_channels] at the input layer
    cnn_params: list of dictionaries containing stride and padding for
      each layer
  
  Raises:
    ValueError: the input lists of net params are not of the same length
docstr_tok: ["Function","to","initialize","NeuralNetParams","class",".","Args",":","net_weights",":","list","of","numpy","matrices","of","weights","of","each","layer","[","convention",":","x","[","i+1","]","=","W","[","i","]","x","[","i","]","net_biases",":","list","of","numpy","arrays","of","biases","of","each","layer","net_layer_types",":","type","of","each","layer","[","'ff","'","or","'ff_relu","'","or","'ff_conv","'","or","'ff_conv_relu","'","]","'ff","'",":","Simple","feedforward","layer","with","no","activations","'ff_relu","'",":","Simple","feedforward","layer","with","ReLU","activations","'ff_conv","'",":","Convolution","layer","with","no","activation","'ff_conv_relu","'",":","Convolution","layer","with","ReLU","activation","input_shape",":","[","num_rows",",","num_columns",",","num_channels","]","at","the","input","layer","cnn_params",":","list","of","dictionaries","containing","stride","and","padding","for","each","layer","Raises",":","ValueError",":","the","input","lists","of","net","params","are","not","of","the","same","length"]
code: def __init__(
      self,
      net_weights,
      net_biases,
      net_layer_types,
      input_shape=None,
      cnn_params=None,
  ):
      """Function to initialize NeuralNetParams class.
  
      Args:
        net_weights: list of numpy matrices of weights of each layer
         [convention: x[i+1] = W[i] x[i]
        net_biases: list of numpy arrays of biases of each layer
        net_layer_types: type of each layer ['ff' or 'ff_relu' or 'ff_conv' or
          'ff_conv_relu']
  
          'ff': Simple feedforward layer with no activations
          'ff_relu': Simple feedforward layer with ReLU activations
          'ff_conv': Convolution layer with no activation
          'ff_conv_relu': Convolution layer with ReLU activation
        input_shape: [num_rows, num_columns, num_channels] at the input layer
        cnn_params: list of dictionaries containing stride and padding for
          each layer
  
      Raises:
        ValueError: the input lists of net params are not of the same length
      """
      if (len(net_weights) != len(net_biases)) or len(
          net_biases
      ) != len(net_layer_types):
          raise ValueError(
              "Inputs of net params are not of same length ...."
          )
      if net_layer_types[len(net_layer_types) - 1] != "ff":
          raise ValueError("Final layer is not linear")
      self.num_hidden_layers = len(net_weights) - 1
      self.weights = []
      self.biases = []
      self.layer_types = []
      self.sizes = []
      self.input_shapes = []
      self.output_shapes = []
      self.has_conv = False
      if input_shape is not None:
          current_num_rows = input_shape[0]
          current_num_columns = input_shape[1]
          current_num_channels = input_shape[2]
      self.cnn_params = cnn_params
  
      # Setting the sizes of the layers of the network
      # sizes[i] contains the size of x_i
      for i in range(self.num_hidden_layers):
          shape = np.shape(net_weights[i])
          self.weights.append(
              tf.convert_to_tensor(net_weights[i], dtype=tf.float32)
          )
          self.layer_types.append(net_layer_types[i])
  
          if self.layer_types[i] in {"ff", "ff_relu"}:
              self.sizes.append(int(shape[1]))
              # For feedforward networks, no unraveling the bias terms
  
              small_bias = tf.convert_to_tensor(
                  net_biases[i], dtype=tf.float32
              )
              self.biases.append(tf.reshape(small_bias, [-1, 1]))
              # Assumes that x^{i+1} = W_i x^i
              self.input_shapes.append([int(shape[1]), 1])
              self.output_shapes.append([int(shape[0]), 1])
  
          # Convolution type
          else:
              self.has_conv = True
              num_filters = shape[3]
              self.input_shapes.append(
                  [
                      1,
                      current_num_rows,
                      current_num_columns,
                      current_num_channels,
                  ]
              )
              self.sizes.append(
                  current_num_rows
                  * current_num_columns
                  * current_num_channels
              )
              current_num_channels = num_filters
              # For propagating across multiple conv layers
              if self.cnn_params[i]["padding"] == "SAME":
                  current_num_rows = int(
                      current_num_rows / self.cnn_params[i]["stride"]
                  )
                  current_num_columns = int(
                      current_num_columns / self.cnn_params[i]["stride"]
                  )
              self.output_shapes.append(
                  [
                      1,
                      current_num_rows,
                      current_num_columns,
                      current_num_channels,
                  ]
              )
  
              # For conv networks, unraveling the bias terms
              small_bias = tf.convert_to_tensor(
                  net_biases[i], dtype=tf.float32
              )
              large_bias = tf.tile(
                  tf.reshape(small_bias, [-1, 1]),
                  [current_num_rows * current_num_columns, 1],
              )
              self.biases.append(large_bias)
  
      # Last layer shape: always ff
      if self.has_conv:
          final_dim = int(
              np.shape(net_weights[self.num_hidden_layers])[1]
          )
          self.input_shapes.append([final_dim, 1])
  
      else:
          final_dim = int(
              np.shape(net_weights[self.num_hidden_layers - 1])[0]
          )
  
      self.sizes.append(final_dim)
      self.final_weights = tf.convert_to_tensor(
          net_weights[self.num_hidden_layers], dtype=tf.float32
      )
      self.final_bias = tf.convert_to_tensor(
          net_biases[self.num_hidden_layers], dtype=tf.float32
      )
  
file_path: cleverhans/cleverhans_v3.1.0/cleverhans/experimental/certification/nn.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import json
  import numpy
  import tensorflow
label_desc: Use image node_id 1 to create a new NeuralNetwork object from inherited base classes: object with example: obj = NeuralNetwork(net_weights, net_biases, net_layer_types, input_shape, cnn_params)