class_docstr: A class to generate CNN.
  Attributes:
        n_dim: `len(self.input_shape) - 1`
        conv: A class that represents `(n_dim-1)` dimensional convolution.
        dropout: A class that represents `(n_dim-1)` dimensional dropout.
        global_avg_pooling: A class that represents `(n_dim-1)` dimensional Global Average Pooling.
        pooling: A class that represents `(n_dim-1)` dimensional pooling.
        batch_norm: A class that represents `(n_dim-1)` dimensional batch normalization.
class_docstr_tok: ["A","class","to","generate","CNN",".","Attributes",":","n_dim",":","`","len","(","self.input_shape",")","-","1","`","conv",":","A","class","that","represents","`","(","n_dim-1",")","`","dimensional","convolution",".","dropout",":","A","class","that","represents","`","(","n_dim-1",")","`","dimensional","dropout",".","global_avg_pooling",":","A","class","that","represents","`","(","n_dim-1",")","`","dimensional","Global","Average","Pooling",".","pooling",":","A","class","that","represents","`","(","n_dim-1",")","`","dimensional","pooling",".","batch_norm",":","A","class","that","represents","`","(","n_dim-1",")","`","dimensional","batch","normalization","."]
docstr: Generates a CNN.
  Args:
      model_len: An integer. Number of convolutional layers.
      model_width: An integer. Number of filters for the convolutional layers.
  Returns:
      An instance of the class Graph. Represents the neural architecture graph of the generated model.
docstr_tok: ["Generates","a","CNN",".","Args",":","model_len",":","An","integer",".","Number","of","convolutional","layers",".","model_width",":","An","integer",".","Number","of","filters","for","the","convolutional","layers",".","Returns",":","An","instance","of","the","class","Graph",".","Represents","the","neural","architecture","graph","of","the","generated","model","."]
code: def generate(self, model_len=None, model_width=None):
      """Generates a CNN.
      Args:
          model_len: An integer. Number of convolutional layers.
          model_width: An integer. Number of filters for the convolutional layers.
      Returns:
          An instance of the class Graph. Represents the neural architecture graph of the generated model.
      """
  
      if model_len is None:
          model_len = Constant.MODEL_LEN
      if model_width is None:
          model_width = Constant.MODEL_WIDTH
      pooling_len = int(model_len / 4)
      graph = Graph(self.input_shape, False)
      temp_input_channel = self.input_shape[-1]
      output_node_id = 0
      stride = 1
      for i in range(model_len):
          output_node_id = graph.add_layer(StubReLU(), output_node_id)
          output_node_id = graph.add_layer(
              self.batch_norm(
                  graph.node_list[output_node_id].shape[-1]
              ),
              output_node_id,
          )
          output_node_id = graph.add_layer(
              self.conv(
                  temp_input_channel,
                  model_width,
                  kernel_size=3,
                  stride=stride,
              ),
              output_node_id,
          )
          temp_input_channel = model_width
          if pooling_len == 0 or (
              (i + 1) % pooling_len == 0 and i != model_len - 1
          ):
              output_node_id = graph.add_layer(
                  self.pooling(), output_node_id
              )
  
      output_node_id = graph.add_layer(
          self.global_avg_pooling(), output_node_id
      )
      output_node_id = graph.add_layer(
          self.dropout(Constant.CONV_DROPOUT_RATE), output_node_id
      )
      output_node_id = graph.add_layer(
          StubDense(
              graph.node_list[output_node_id].shape[0], model_width
          ),
          output_node_id,
      )
      output_node_id = graph.add_layer(StubReLU(), output_node_id)
      graph.add_layer(
          StubDense(model_width, self.n_output_node), output_node_id
      )
      return graph
  
file_path: nni/nni/algorithms/hpo/networkmorphism_tuner/nn.py
imports: from abc import abstractmethod
  from .graph import Graph
  from .layers import StubDense, StubDropout1d, StubReLU, get_batch_norm_class, get_conv_class, get_dropout_class, get_global_avg_pooling_class, get_pooling_class
  from .utils import Constant
label_desc: Use image node_id 2 for calling the CnnGenerator obj's underlying member method code with example usage: obj.generate(model_len, model_width) and returns: graph